Repository navigation
Conversation
#450) `save-session.sh` advanced the saved position past a span it never actually read whenever ExtractResult.envelope came back "unrecognised" -- a 0-exchange quiet session and a 0-exchange failure-to-read were saved identically, so a later build that could finally parse the envelope (as #443 did for Codex) found the span already behind the marker. The position still advances unconditionally on an unrecognised envelope -- leaving it in place re-triggers the save path forever (#147) -- but the span is now also quarantined in a sidecar next to last-save.json (pipeline.extract.mark_unread_envelope / read_unread_envelope), at the earliest point not yet actually read. The next extraction for that session resumes from the quarantine point instead of the advanced position, and cmd_save_position clears the entry once a save with a recognised envelope lands. `save-position` gains two optional, backward-compatible arguments (envelope, skip_lines); omitted, they leave any existing quarantine alone. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
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.
What
scripts/save-session.shadvanced the saved read position past a span it never actually read wheneverExtractResult.envelopecame back"unrecognised"-- a genuinely quiet 0-exchange session and a 0-exchange failure to read were saved the same way, so once a later build could finally parse that envelope (as #443 did for Codex), the span was already behind the marker and did not come back.The design call (this was most of the issue)
Not advancing has its own failure mode: #147, where a permanently-unreadable session re-triggers the save path forever and never clears its cooldown. So the saved position still advances unconditionally on an
"unrecognised"envelope -- that is what keeps #147's loop closed -- but the span is now also quarantined, in a new sidecar (unread-envelope.json, next tolast-save.json, same directory, same bounded/evicted shape as the existing_POSITION_SLOTSposition store) at the earliest line not yet actually read.The next extraction for that session consults the quarantine and, when one exists, resumes from the quarantine point instead of the (already-advanced) saved position -- so a build that can now parse the envelope actually re-reads the missed span.
pipeline.shell.cmd_save_positiongained two new optional arguments,envelopeandskip_lines: passingenvelope="unrecognised"marks/keeps the quarantine (set-if-absent, so the point never creeps forward across repeated failed runs); passing any other envelope clears it, because a save with a recognised envelope means the span has now actually been read; andenvelope=None(every existing caller, including the plainpipeline.shell save-position last.json id 99form) leaves any quarantine another, envelope-aware caller set completely untouched -- so an old-style call can never silently erase it.The three-reasons-for-zero question the issue raised: a genuinely quiet session (envelope recognised, 0 exchanges) is unaffected and still just advances, never quarantined -- pinned by a must-fire positive control in the new tests. A file this build's envelope sniffing cannot classify at all (
sniff_file_envelopenever finds a parseable first line, or finds one it does not recognise) is the case this quarantines. Corrupt/truncated JSON within an otherwise-recognised envelope was left alone:extract_messagesalready skips unparseable lines one at a time and keeps going, so a torn tail of an otherwise-normal Claude-Code or Codex transcript is not conflated with the unrecognised-envelope case at all -- it was never advancing past content it could parse.Tests
tests/test_unread_envelope_450.py-- red (ImportError against the pre-fix tree) then green, six tests: the core quarantine-then-recover round trip, a must-fire positive control (quiet + recognised envelope advances and is never quarantined), quarantine monotonicity (earliest point wins), back-compat (envelope=Nonecannot erase another caller's quarantine), and eviction parity with the existing position-store bound.tests/test_shell.pyupdated for the two new optionalsave-positionCLI arguments (one pre-existing assertion had to change to match the new default kwargs; a second test added for the populated-argument case).Full suite: 1834 passed, 43 skipped (platform-gated, expected), 0 failed.
Closes #450.
Deferred, not fixed here
The self-review auditor found that
read_unread_envelopecollapses "the quarantine sidecar is corrupt or unreadable" and "nothing was ever quarantined for this session" into the same empty-dict return -- a torn write tounread-envelope.json(crash mid-write, disk fault) would silently re-lose an already-quarantined span, the same failure class this diff exists to close. This is real and reachable, but fixing it honestly needs a design decision (how to plumb a distinct "quarantine unreadable" signal throughcmd_extract's existing KEY=VALUE shell bridge and into a bash-visible log line, given this python module's own stderr is discarded in the normal backgrounded save path) and would meaningfully widen this diff rather than ride along inside it. Reported for filing, not fixed here -- see the accompanying report'sadjacentitem.