Skip to content

fix(bin): resurface task statuses missed by wake handling - #3495

Merged
kunchenguid merged 12 commits into
mainfrom
fm/fm-pi-drain-resurface-keyless-outcome-r1
Sep 2, 2026
Merged

kunchenguid merged 12 commits into
mainfrom
fm/fm-pi-drain-resurface-keyless-outcome-r1

Conversation

@kunchenguid

@kunchenguid kunchenguid commented Sep 2, 2026 •

Copy link
Copy Markdown
Owner

Intent

Fix Pi loss Mode 5 (drain resurfacing backstop, #3346 keyless-done case): the wake-drain now surfaces a task whose newest status line is terminal or captain-facing and has no branch outcome newer than it, so a lost keyless wake resurfaces without a captain nudge; bounded and deterministic, does not re-present already-processed or routine outcomes; regressions cover the keyless-done surface case and the already-handled no-resurface case

What Changed

  • Surface each task’s newest uncovered terminal or captain-facing status once during main wake drains, while leaving routine, already-presented, and branch-covered outcomes silent.
  • Track causal status positions in bounded per-task branch outcome indexes, with fail-closed validation and startup migration/recovery.
  • Add regression coverage and documentation for keyless resurfacing, deduplication, bounded processing, and delayed annotations.

Risk Assessment

✅ Low: The bounded backstop, causal outcome indexing, one-shot cursor, migration behavior, and executable regressions consistently satisfy the stated intent without a substantiated remaining defect.

Testing

Targeted backstop, unread-status/open-decision integration, and branch-outcome tests succeeded; an end-user drain surfaced a lost keyless completion once, then remained silent on repeat and for a branch-covered completion, with the transcript captured as evidence.

Evidence: Keyless-done backstop end-to-end CLI transcript

Source: Keyless-done backstop end-to-end CLI transcript

END-USER CHECK: lost keyless done, with no queue row
Command: FM_STATE_OVERRIDE=<state> bin/fm-wake-drain.sh

STATUS OUTCOME BACKSTOP (newest captain-facing task event has no covering branch outcome):
keyless-3346 done: PR https://example.test/3346 checks green

END-USER CHECK: immediate repeat of unchanged state
Command: FM_STATE_OVERRIDE=<state> bin/fm-wake-drain.sh
[no output]

END-USER CHECK: branch-handled terminal status
Command: fm-branch-outcome.sh append ..., then fm-wake-drain.sh
[no output]
Evidence: Pi 0.84.4 real-provider keyless outcome recovery

Production shape and model-call bound

Expected

  • Exercise the exact fix(bin): resurface task statuses missed by wake handling #3495 PR head under Pi 0.84.4 with full project AGENTS.md context.
  • Use openai-codex/gpt-5.6-sol at high effort for main and configure openai-codex/gpt-5.6-luna at medium effort for the supervision branch.
  • Keep the supervision branch absent, use only a few bounded provider calls, and expose no credential or token material.

Observed

  • The isolated project HEAD and PR HEAD both resolved to c4cd8517af0055d0049b01bffd849ac7ac47f9a0.
  • The CLI reported Pi 0.84.4.
  • Context-file discovery remained enabled, and the isolated project supplied its complete 587-line AGENTS.md; the first provider request reported 39,922 input tokens.
  • Every assistant event reported provider openai-codex and model gpt-5.6-sol; the session record reported thinking level high.
  • The isolated home pinned branch model openai-codex/gpt-5.6-luna and branch effort medium.
  • The run used --no-extensions; startup reported PI_WATCH_EXTENSION: not loaded, and no branch extension marker existed, so no supervision-branch model call could handle the status.
  • The bounded run used four main-session user turns and eight provider requests in total, including tool-call continuations; it made zero branch requests.
  • Raw JSONL was inspected locally, then reduced to the sanitized transcript below; no credential, token, local path, process ID, or session ID is included.

Expected versus observed

  1. Startup with the branch absent
    • Expected: initialize one main session without draining the later fixture, with the branch absent.
    • Observed: the real provider invoked only bin/fm-session-start.sh, returned VALIDATION_READY, and startup reported the Pi watcher extension was not loaded.
  2. Crew completion with no surviving queue row
    • Expected: a keyless done: status exists while the durable wake queue remains empty.
    • Observed: an external producer wrote 54 bytes, done: PR https://example.test/live-mode5 checks green, while .wake-queue remained 0 bytes and the branch outcome store was absent.
  3. First main drain
    • Expected: the next drain prints the outcome backstop and status exactly once.
    • Observed: the real-provider main session invoked bin/fm-wake-drain.sh; its tool result contained one backstop header and one matching status line.
  4. Unchanged repeat
    • Expected: a second drain of unchanged state is silent.
    • Observed: the real-provider main session invoked the same command once; Pi rendered (no output), its representation of empty command stdout.
  5. Branch-outcome coverage
    • Expected: after a real branch outcome covers the current status position, the next drain remains silent.
    • Observed: bin/fm-branch-outcome.sh append stored sequence 1 with statusEndpoint: 54, matching the status length, and the next real-provider main drain again rendered (no output).
  6. Whole-scenario count
    • Expected: no duplicate presentation across all three drains.
    • Observed: the backstop header count was 1 and the status-line count was 1 across the three raw drain tool results.

Sanitized transcript

RUNTIME
PR_HEAD=c4cd8517af0055d0049b01bffd849ac7ac47f9a0
PI_VERSION=0.84.4
CONTEXT_FILES=enabled
PROJECT_AGENTS_LINES=587
MAIN_MODEL=openai-codex/gpt-5.6-sol
MAIN_THINKING=high
BRANCH_MODEL_PIN=openai-codex/gpt-5.6-luna
BRANCH_EFFORT_PIN=medium
EXTENSIONS=disabled (supervision branch absent)
MAIN_USER_TURNS=4
PROVIDER_REQUESTS=8
BRANCH_REQUESTS=0

TURN 1
main prompt: Run bin/fm-session-start.sh exactly once and do not run the wake drain.
main tool: bin/fm-session-start.sh
startup observation: PI_WATCH_EXTENSION: not loaded
assistant: VALIDATION_READY

EXTERNAL CREW EVENT
status bytes: 54
status: done: PR https://example.test/live-mode5 checks green
wake queue bytes: 0
branch outcome store: absent

TURN 2 - FIRST DRAIN
main tool: bin/fm-wake-drain.sh
stdout:
STATUS OUTCOME BACKSTOP (newest captain-facing task event has no covering branch outcome):
live-mode5-keyless done: PR https://example.test/live-mode5 checks green
assistant: FIRST_DRAIN_COMPLETE

TURN 3 - UNCHANGED REPEAT
precondition: same status, 0-byte wake queue, no branch outcome store
main tool: bin/fm-wake-drain.sh
stdout: [empty; Pi rendered "(no output)"]
assistant: REPEAT_DRAIN_COMPLETE

COVERING OUTCOME
command: FM_STATE_OVERRIDE=<ISOLATED_STATE> bin/fm-branch-outcome.sh append --task live-mode5-keyless --verdict captain --summary <SANITIZED_SUMMARY> --wake signal:live-mode5-keyless.status
outcome sequence: 1
outcome statusEndpoint: 54
wake queue bytes: 0

TURN 4 - COVERED DRAIN
main tool: bin/fm-wake-drain.sh
stdout: [empty; Pi rendered "(no output)"]
assistant: COVERED_DRAIN_COMPLETE

ASSERTIONS
BACKSTOP_HEADER_COUNT=1
BACKSTOP_STATUS_COUNT=1
UNCHANGED_REPEAT=EMPTY_STDOUT
COVERED_REPEAT=EMPTY_STDOUT
RESULT=PASS

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 2 issues found → auto-fixed (4) ✅
  • 🚨 bin/fm-wake-drain.sh:290 - The intent requires that already-processed outcomes not be re-presented, but whole-second timestamps cannot establish causal order. A status written at epoch T and handled by a branch outcome later in the same second also has epoch T, so the strict &gt; check resurfaces that already-handled status. Changing this to &gt;= would instead hide a new status appended after an outcome in the same second; a durable causal key or finer-grained ordering is needed, which extends the persisted contract and requires user authorization.
  • ⚠️ bin/fm-wake-drain.sh:224 - The new every-drain path reads the complete append-only branch-outcomes.jsonl, whose documented retention is unbounded, and then launches an awk scan of the per-task result for every status file. Thus drain cost grows with lifetime outcome history and approximately quadratically with task count, contrary to the stated bounded behavior. A bounded per-task outcome index or equivalent persisted summary would require new durable state, so the remedy needs authorization.

🔧 Fix: Index branch outcomes by causal status position
3 errors still open:

  • 🚨 bin/fm-branch-outcome.sh:333 - The outcome row and causal index are not one recoverable transaction. An upgrade with existing outcomes, or a crash after the store append on line 333 but before the index replacement, leaves a valid handled outcome with no index; wake-drain interprets the missing index as “no outcome” and re-presents the covered terminal status indefinitely. The durable fix needs an authoritative recoverable causal record and migration path that does not restore an every-drain history scan; because that changes persisted/recovery machinery, the remedy requires authorization.
  • 🚨 bin/fm-wake-drain.sh:281 - The backstop is not idempotent after successfully resurfacing a genuinely keyless event. With done: shipped and no outcome index, the first main drain prints this line but records no backstop receipt; terminal-only spans also remain unacknowledged by the existing presentation cursor, so an unchanged second drain prints the same line again. This contradicts the authorized requirement to keep the backstop idempotent. A separate durable receipt is needed if delayed signal annotation must remain preserved, so the remedy requires authorization.
  • 🚨 bin/fm-wake-drain.sh:269 - The unconditional exclusion of needs-decision and blocked contradicts the required behavior that a newest “terminal or captain-facing” status without a covering outcome surfaces. For example, blocked [key=bad/value]: credential missing is captain-relevant, but the decision fold rejects its malformed key and this branch also suppresses it, so a lost keyless wake produces no output. Ask whether such non-foldable terminal lines should surface as backstop events without being treated as valid open decisions.

🔧 Fix: Recover outcome indexes and deduplicate resurfaced statuses
2 errors still open:

  • 🚨 bin/fm-branch-outcome.sh:268 - Legacy-index migration can hide a genuinely later same-second status. If legacy outcome A has epoch T and terminal status B is appended afterward during T, the file mtime is still T; mtime &lt;= epoch then indexes the current EOF as covered by A, so wake-drain never resurfaces B. The persisted legacy data cannot reconstruct that causal order, so the migration behavior needs explicit user direction rather than this heuristic.
  • 🚨 bin/fm-classify-lib.sh:886 - The bounded tail reader permanently skips an unbounded captain-facing line longer than 64 KiB. For a single long done: line, skip_first discards the entire tail fragment and finds no event, so every keyless drain remains silent. Status lines are explicitly unbounded elsewhere in the repository, contradicting the required behavior that the newest terminal or captain-facing line surfaces. Preserving both strict boundedness and this guarantee requires authorization for a line-size contract, diagnostic containment, or different bounded metadata.

🔧 Fix: Handle legacy ambiguity and oversized status diagnostics
1 error still open:

  • 🚨 bin/fm-wake-drain.sh:299 - The intent forbids re-presenting routine outcomes, but every over-bound latest line is treated as captain-facing without classification. For example, a single 70 KiB working: routine progress... line makes status_snapshot_latest_event set OVERBOUND, then this branch emits the backstop diagnostic and acknowledges it. The bounded tail cannot reveal that line's leading verb, so deciding whether to add bounded provenance, emit a neutral diagnostic, or accept a miss requires user authorization.

🔧 Fix: Keep unclassifiable oversized statuses silent
✅ Re-checked - no issues remain.

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • bin/fm-test-run.sh tests/fm-wake-drain-outcome-backstop.test.sh
  • Manually ran bin/fm-wake-drain.sh against keyless-done, unchanged-repeat, handled-outcome, and routine-status fixtures.
  • Recorded the end-user CLI transcript and verified temporary worktree fixtures were removed.

✅ No issues found.

  • tests/fm-wake-drain-outcome-backstop.test.sh
  • tests/fm-wake-drain-unread-status.test.sh
  • tests/fm-wake-drain-open-decisions.test.sh
  • tests/fm-branch-supervision.test.sh was non-executable; reran successfully as bash tests/fm-branch-supervision.test.sh
  • Manual end-to-end: ran bin/fm-wake-drain.sh against an empty queue with a keyless done: status, repeated the unchanged drain, then appended a real branch outcome with bin/fm-branch-outcome.sh append and drained again
  • git status --short and transient span-file check confirmed testing left the worktree clean
✅ **Document** - passed

✅ No issues found.

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

✅ No issues found.

@greptile-apps

greptile-apps Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Reviews (6): Last reviewed commit: "no-mistakes(ci): Fixed Behavior portable..." | Re-trigger Greptile

Comment thread bin/fm-wake-drain.sh Resolved
@kunchenguid
kunchenguid force-pushed the fm/fm-pi-drain-resurface-keyless-outcome-r1 branch from fe14bf5 to c6980a9 Compare September 2, 2026 03:54
@kunchenguid kunchenguid changed the title fix(bin): resurface keyless terminal task outcomes fix(bin): resurface task statuses missed by wake handling Sep 2, 2026
…ed-key decisions can no longer bypass the durable decision-fold guard, and status output is prepared and receipt-committed before presentation to prevent repeated one-shot outcomes after later failures. Added a behavioral regression for receipt commit failure and retry. Targeted backstop, correlation-token, decision-cursor, open-decision, unread-status, syntax, and diff checks pass locally. Shard-4 failures appeared unrelated/flaky; the network-parallel test passed locally
Comment thread bin/fm-wake-drain.sh Resolved
…presentation receipts only after prepared output reaches stdout. Added behavioral coverage proving output failure leaves the backstop retryable and receipt failure may duplicate but never lose a presentation. Relevant wake-drain suites and syntax/diff checks pass. The shard-4 Pi extension failure is unrelated to this PR and did not warrant changes
…sh by replacing scheduler-sensitive equal-sleep timing with bounded synchronization between mocked fetch and remote probes. This preserves detection of real serialization while avoiding false failures under CI load. Verified with five consecutive test runs, bash syntax validation, ShellCheck, and git diff checks. The separate Pi stock-rendering failure reproduces locally but is unrelated environment/version drift
…fy-lib.sh and fm-timeout-lib.sh to the broken-root Pi test fixture; fm-branch-outcome.sh now depends on them. Verified the full Pi branch-extension suite with real-Pi checks skipped, the wake-drain outcome-backstop suite, Bash syntax, and git diff checks. Greptile findings are already addressed at HEAD; the no-mistakes attestation failure is external head-SHA state
@kunchenguid
kunchenguid merged commit d977128 into main Sep 2, 2026
16 of 17 checks passed
@kunchenguid
kunchenguid deleted the fm/fm-pi-drain-resurface-keyless-outcome-r1 branch September 2, 2026 07:06
Marcos-Leyva added a commit to Marcos-Leyva/firstmate that referenced this pull request Sep 3, 2026