Repository navigation
fix(bin): trace context-budget stand-down and notice write failures - #8
Merged
Merged
Conversation
…ing them The block-budget-exhausted stand-down write ignored its own return status, so a failed write left the session-facing message falsely claiming the guard "now stands down for the rest of the session" on every later turn end, with no durable trace anywhere. It now checks the write, corrects the message when it fails, and records the failure once under stage=standdown-unrecorded, mirroring the existing ceiling-unrecorded degrade. The per-episode notice dedup record swallowed its own write failure. If the notice file specifically became unwritable while the rest of state/ stayed writable, stage_enter never deduped again and retraced every threshold crossing on every turn end, reopening the trip-file inflation commit a9fb47f removed. A fallback marker file now carries the same dedup fields when the primary notice file cannot be written, restoring once-per-crossing behavior without ever reading a decision back out of the write-only trip record. The fallback write itself is traced once under stage=notice-unwritable. Both new cases are covered in tests/fm-context-budget.test.sh and documented in docs/context-budget.md.
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
Problem
Fix
Proof
What Changed
bin/fm-context-budget.sh; on write failure, degrade throughstage_enter standdown-unrecordedand swap in a session message that says the stand-down could not be persisted, instead of falsely claiming a durability that never landed.NOTICE_DEGRADED_FILEfallback marker for the per-episode notice dedup fields, consulted only when the primary notice file write fails, so an unwritable notice file traces onenotice-unwritabletrip and keeps deduping crossings instead of retripping on every turn end; the fallback is pruned and reset alongside the other state records.tests/fm-context-budget.test.shand document the fallback file indocs/context-budget.mdand the AGENTS.md state inventory.Risk Assessment
✅ Low: Both degrades are narrowly scoped, preserve the trip record's write-only invariant, dedup correctly across turns via the new fallback marker, and are covered by targeted tests plus updated docs.
Testing
Baseline plus targeted run of tests/fm-context-budget.test.sh passes fully (75 ok, exit 0), and I demonstrated both fixes end-to-end by invoking the real fm-context-budget.sh Stop hook. Scenario A shows the corrected captain message ("could not be persisted ... may recur", with the false "stands down for the rest of the session" claim gone) and a durable stage=standdown-unrecorded trip line next to the ceiling line. Scenario B shows exactly one ceiling line plus one notice-unwritable line across five turn ends (not five), with the fallback dedup marker created. This is a CLI/hook change with no rendered UI surface, so the reviewer-visible evidence is CLI transcripts of the actual systemMessage and persisted trip-record state rather than screenshots. No issues found.
Evidence: Scenario A - stand-down write failure: honest message + durable trip line
systemMessage: "...the block budget is exhausted, but the stand-down could not be persisted and may recur on later turn ends. Run /stow and hand over..." trips: stage=ceiling total=210000 ... stage=standdown-unrecorded total=210000 ... Claims false durability ('now stands down for the rest of the session')? NO (correct)Evidence: Scenario B - unwritable notice file: one ceiling + one notice-unwritable line over 5 turn ends, fallback marker created
trips after 5 turn ends: stage=notice-unwritable total=210000 ... enforce=0 session=sessB stage=ceiling total=210000 ... enforce=0 session=sessB ceiling trip lines: 1 notice-unwritable trip lines: 1 fallback marker .context-budget-notice-degraded-sessB: PRESENTPipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
bash tests/fm-context-budget.test.sh(75 ok, exit 0; includes the two new tests, both ran real assertions, not the mode-400 skip branch)Reproduced Scenario A: enforcing hook with an unwritable block record (mode 400) at the exhausted block budget - captured stdout systemMessage and .context-budget-tripsReproduced Scenario B: warning-only hook run 5 times over one ceiling crossing with an unwritable notice dedup file - counted ceiling vs notice-unwritable trip lines and checked the fallback marker✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.