Repository navigation
fix(bin): derive each task's presentation cursor offsets once per wake drain - #85
Merged
Merged
Conversation
One drain presents several sections and then acknowledges and commits, and every one of those passes needed the same two facts per task: the byte offset already presented and the byte offset the outcome backstop already covered. Each pass re-read the whole fleet cursor manifest and re-stat'ed the status file, so a twelve-task home derived the same two answers sixty times. Add a shared presentation cursor index to fm-classify-lib.sh, opened once per presentation by fm-wake-drain.sh and closed after the commit. It derives each task's answers by calling status_presentation_cursor_offset and status_outcome_backstop_cursor_offset themselves, so those functions stay the one owner of what the answers are, including every malformed-manifest and missing-row edge; the derivation reads the manifest once for the whole fleet and reuses the identity and size status_presentation_snapshot already captured under the presentation lock. With the index closed, which is how every caller outside a drain presentation uses them, both functions behave exactly as before. The index stays closed when no manifest exists yet, because that first read falls back to each task's legacy cursor file, and when any derivation fails, so the failure surfaces from the real call rather than from a memo. Measured on a disposable copy of a 12-task, 108-status-line home: manifest reads 60 to 1, stat forks 531 to 291, identity derivations 10 to 5 per task, CPU median 5.76s to 4.14s. Fifteen interleaved before/after pairs were identical on stdout, stderr, exit status and committed cursor offsets. What a section reports and when the cursor advances are unchanged.
One drain presents several sections and then acknowledges and commits, and every one of those passes needed the same two facts per task: the byte offset already presented and the byte offset the outcome backstop already covered. Each pass re-read the whole fleet cursor manifest and re-stat'ed the status file, so a twelve-task home derived the same two answers sixty times. Add a shared presentation cursor index to fm-classify-lib.sh, opened once per presentation by fm-wake-drain.sh and closed after the commit. It derives each task's answers by calling status_presentation_cursor_offset and status_outcome_backstop_cursor_offset themselves, so those functions stay the one owner of what the answers are, including every malformed-manifest and missing-row edge; the derivation reads the manifest once for the whole fleet and reuses the identity and size status_presentation_snapshot already captured under the presentation lock. With the index closed, which is how every caller outside a drain presentation uses them, both functions behave exactly as before. The index stays closed when no manifest exists yet, because that first read falls back to each task's legacy cursor file, and when any derivation fails, so the failure surfaces from the real call rather than from a memo. Measured on a disposable copy of a 12-task, 108-status-line home: manifest reads 60 to 1, stat forks 531 to 291, identity derivations 10 to 5 per task, CPU median 5.76s to 4.14s. Fifteen interleaved before/after pairs were identical on stdout, stderr, exit status and committed cursor offsets. What a section reports and when the cursor advances are unchanged.
The case declares its comparison variables in the outer function, but they belong to the inner `bash -c` that sources the library and has its own scope, so ShellCheck reported six SC2034 findings and CI's Lint job failed. Declare only the two names this shell actually uses. Local changed-file lint excludes SC2034 by design (bin/fm-lint.sh header), which is why this passed locally and failed in CI; linting the changed files by explicit path reproduces CI's posture and now passes.
…ke-drain-shared-cursor
…the local line replaced in 2f5c0cf to fix Lint 1
This was referenced Oct 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Implement the session-start-slow report's fix 3: share one computed unread/cursor snapshot across fm-wake-drain.sh's presentation sections instead of each re-deriving it via fm-classify-lib.sh. Prove it by before/after timing on a disposable copy, same output.
Context from the session-start investigation: the Claude SessionStart hook hits its 120s bound and truncates in the bootstrap stage. One stage later, bin/fm-wake-drain.sh's sections (print_status_outcome_backstop_section, print_branch_outcomes_section, print_record_divergence_section, print_unread_status_section) each call fm-classify-lib.sh cursor/ident functions per task; the trace showed ~47x more status_presentation_cursor_offset calls than status lines, 26.4s on 108 status lines, and the lead home has ~19x more.
What Changed
bin/fm-classify-lib.shadds a shared presentation cursor index (status_presentation_index_open/status_presentation_index_close). It reads.status-presentation-cursoronce for the whole fleet and reuses the identity and size thatstatus_presentation_snapshotalready captured. With those inputs it computes each task's presented and backstop offsets once, by calling the existingstatus_presentation_cursor_offsetandstatus_outcome_backstop_cursor_offsetfunctions. While the index is open, both functions return the stored values. When it is closed they work exactly as before. The index stays closed when there is no manifest yet (the first drain) and when any task's offset cannot be computed, so the original error still comes from the real function.bin/fm-wake-drain.shprint_status_presentationopens the index from its snapshot before the annotation and section passes, and closes it before releasing the presentation lock. The sections, acknowledgement and commit now share one set of offsets instead of each recomputing them per task.tests/fm-wake-drain-shared-cursor.test.shuses a multi-task fixture to check:🤖 Generated with Claude Code
Risk Assessment
✅ Low: The index is a memo that gets its values by calling the existing cursor functions, and only
print_status_presentationopens it. That function holds the presentation lock and runs in a subshell, and it closes the index before returning. The index stays closed when there is no manifest or any derivation fails, and tasks missing from the snapshot fall back to the uncached path. Nothing writes the manifest before the final commit, so the memoized values cannot go stale within one presentation.Testing
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
⏭️ **Test** - skipped
Step was skipped.
✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.