Repository navigation
Conversation
…as landed (#353) save-session.sh (via pipeline.shell save-position) now also writes a per-session, bash-`read`-able position sidecar (tmp/position.<session_id>), written strictly after last-save.json is committed so a crash between the two writes can only leave it stale, never ahead of the truth. post-tool-hook.sh's hot path bounds the sidecar's value against the transcript's own line count and falls back to read-position -- loudly logging the disagreement, never silently trusting a bad sidecar or defaulting to 0 -- on any mismatch. Part 2 of #350, split from the #352 latency fix so the sidecar's own misreports risk gets its own argument. Credit to @oguzhanpisgin, who reported both halves in #350 with the measurement matrix. Co-Authored-By: Max <noreply>
…rage Self-review (Explore reviewer + oss:auditor) on the first #353 commit found two real gaps in the sidecar mechanism itself: - last-save.json evicts the oldest session past _POSITION_SLOTS (#140), but the sidecar mirror was never cleaned up on eviction -- a stale sidecar still <= the current transcript's line count would be silently TRUSTED by post-tool-hook.sh's bounds check, which has no way to see that last-save.json itself has forgotten the session. cmd_save_position now removes the evicted session's sidecar in the same call, pinned by a new test that reproduces the eviction and asserts the sidecar is gone. - the non-numeric-sidecar test asserted the fallback spawn but never the loud-warning log line its sibling (out-of-range sidecar) already checked, so a regression that silently dropped just that warning would have shipped green. Added the missing assertion. Also: the header docstring's Binaries/COST sections and the block heading above the read-position block still described the pre-#353 shape (python3 spawned unconditionally once a save had landed) -- updated to describe the sidecar as the common path and read-position as the fallback, marking the projected spawn/latency drop as REASONED rather than re-measured. Co-Authored-By: Max <noreply>
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.
Closes #353
Part 2 of #350, split from the #352 latency fix so the sidecar's own misreports risk gets its own argument.
What changed
save-session.sh, viapipeline.shell save-position(pipeline/shell.py::cmd_save_position), now also writes a per-session, bash-read-able position sidecar undertmp/position.<session_id>.scripts/post-tool-hook.sh's per-tool-call hot path reads it with a bashreadbuiltin (no spawn) instead of forkingpython3 -m pipeline.shell read-positionon every warm tool call once a save has landed for that session.The disagreement design (the actual point of #353 being split out)
The sidecar is written strictly after
last-save.jsonis committed viaos.replace, never before -- so a crash between the two writes can only leave the sidecar holding the previous position, never a value ahead of the truth. That ordering is what makes a sidecar value greater than the current run's own transcript line count self-evidently wrong (corruption or a session-id collision, never a legitimate crash window), so the hot path bounds the sidecar against that count and treats any excess -- or a non-numeric value -- as a loud, logged disagreement, falling back to the pre-existingread-positionspawn rather than trusting it or defaulting to a silent 0.An mtime-based staleness check (bash
-nt) was considered and rejected: this repo's owntests/test_hot_path_cost_pin_330.pyalready documents-ntas one-second granularity on macOS system bash 3.2.57, and the sidecar write lands in the same wall-clock second aslast-save.jsonfar too often for that to be a reliable signal on the very runs this feature is meant to help. Full reasoning in the maintainer's notes for this branch.Self-review
An
Explorereviewer andoss:auditorboth ran against the first commit. Two real gaps they found were fixed in a follow-up commit on this branch: sidecar files were not being removed whenlast-save.json's own bounded eviction (_POSITION_SLOTS, #140) dropped a session, which could let a stale-but-in-bounds sidecar be trusted after the authoritative store had forgotten that session --cmd_save_positionnow removes an evicted session's sidecar in the same call, pinned by a new test; and the non-numeric-sidecar test was missing the log assertion its out-of-range sibling already had, so a regression dropping just that warning would have shipped green -- assertion added.Below the bar, not filed: the auditor also flagged that the
SESSION_IDcase guard gating the sidecar path (scripts/post-tool-hook.sh:502-505) has no test exercising its rejection arm. Confirmed the only call path:SESSION_IDis always the basename of a transcript file the hook itself just found on disk, or the already-validatedSTDIN_SESSION_ID-- never raw untrusted text here -- and the identical shape already exists untested a few lines up in the same file. No reachable caller would exercise the rejection arm, so this is left as-is rather than filed.Tests
tests/test_position_sidecar_353.py(new, 9 tests): the write-side ordering guarantee (reproduced by forcing the secondos.replaceto fail, simulating a crash between the two writes), the per-session isolation, the eviction cleanup, and the read-side hot path against the real hook binary -- an agreeing sidecar skips the spawn, a missing/non-numeric/out-of-range sidecar all fall back toread-positionand (for the latter two) log a loud disagreement. Every "must not fire" assertion is paired with a "must fire" control in the same fixture.Full suite: 1684 passed, 43 skipped, twice (once per commit on this branch).