Skip to content

An orphaned position sidecar is trusted, because the hot path bounds it against the transcript rather than against last-save.json #403

Closed

Description

@fdaviddpt

Found by the round-two release audit of v0.22.0..HEAD before tagging 0.23.0. Carry-forward under the two-round cap: non-blocking, ranked misreports.

Symptom

A sidecar whose session has been evicted from last-save.json, and whose unlink failed, is still trusted. The hook resumes from a position the authoritative store no longer recognises, and the span is summarized a second time.

Location

pipeline/shell.py:330-336 -- the evicted-sidecar cleanup:

for evicted_id in evicted:
    try:
        os.remove(os.path.join(sidecar_dir, f"position.{evicted_id}"))
    except OSError:
        pass

scripts/post-tool-hook.sh:539 -- the trust check, which bounds a sidecar only against CURRENT_LINES, this run's own transcript line count.

Mechanism

The two log lines at scripts/post-tool-hook.sh:533 and :540 both say the sidecar "disagrees with last-save.json", but the comparison never consults last-save.json at all. So the eviction cleanup is the only thing keeping an orphaned sidecar out of the trusted path, and it is best-effort by construction -- the code's own comment at pipeline/shell.py:320-329 says so, and that direction was chosen deliberately.

What is not stated is the platform asymmetry. On Windows, os.remove against a file another process holds open raises PermissionError, an OSError subclass caught here -- so the swallowed branch is the ordinary case there rather than the exotic one. Reasoned, not observed: no Windows machine was available, and tests/test_hot_path_cost_pin_330.py and tests/test_position_sidecar_353.py both skip on win32, so no CI leg exercises it.

Nothing is lost -- a span is summarized twice -- which is why this is misreports rather than fails-to-preserve, and why the fix a reviewer is sent to make is at the one rendering seam.

What would settle it

Whether the sidecar trust check should also require the session id to be present in last-save.json. That would make an orphaned sidecar detectable rather than merely improbable, and would make the two log lines true.

Worth deciding at the same time whether the log wording should change if the check does not: a message naming a comparison the code does not perform is its own small defect.

Activity

  1. added
    priority:low
    cohort-2
    on Aug 28, 2026
  2. self-assigned this
    on Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

cohort-2priority:low

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions