Skip to content

save-session.sh advances the read position past lines it failed to read, so a later fix cannot recover them #450

Closed

Description

@fdaviddpt

Reported out of the #443 lane's review and routed here rather than fixed in that diff, which judged the semantics too large for its own footprint. That judgement is correct and the reason is in this body.

Symptom

Lines that were never successfully read are marked as read. A user who upgrades to a build that can read them gets nothing back — the exchanges are behind the saved position, and nothing re-reads behind it.

Location

scripts/save-session.sh, the position write that runs when EXCHANGE_COUNT is 0. Observed live on a Codex session (#443):

07:04:00 [extract] 0 exchanges (0 human)
07:04:00 [extract] 0 exchanges, skip -- position -> 15

All 15 lines of that transcript were unreadable by the then-current extractor. All 15 were marked consumed.

Mechanism

The advance is unconditional on the reason the count was zero, and there are three reasons that are not the same:

  1. A genuinely quiet session — advancing is correct.
  2. Corrupt or truncated JSON — pre-existing.
  3. An envelope the extractor does not recognise — which extract.py cannot read a Codex rollout transcript, so a Codex session silently saves zero memory #443 has now made a distinct, loudly-reported state (ExtractResult.envelope), so the code can finally tell this case apart from case 1 and still advances past it.

This is this project's own defect class with the loss attached: an absence produced by the tool, recorded as an absence in the world, and then made permanent.

Why it is not a one-line fix, which is the actual content of this issue

Not advancing has its own failure mode, and it is the one the current behaviour exists to prevent: #147, where a session that cannot be read keeps re-triggering the save path and never clears its cooldown. So the design questions are real ones:

  • Should an unread line block the advance, or should it advance while recording that it did so unread?
  • If it blocks, for how long — what breaks the loop when the lines are permanently unreadable rather than temporarily unsupported?
  • Do the three cases above get the same answer? Case 3 is recoverable by a future release; case 2 usually is not.

A plausible shape, offered as a starting point rather than a decision: advance, but record the skipped range alongside the position, so a later build can re-read behind the marker exactly once. That keeps #147 closed and makes case 3 recoverable, at the cost of a sidecar that has to survive rotation.

What would settle it

A test that feeds a transcript the extractor cannot read, asserts the position does not silently consume it, and pairs that with a positive control — a genuinely quiet session where the advance must happen — because an assertion that the position stayed put also passes when the save path never ran. tests/test_position_store.py and tests/test_position_sidecar_353.py are the existing surface.

Part of the same family as #443, not closed by it.

Metadata

Metadata

Assignees

Labels

bugpriority:medium

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions