Repository navigation
Conversation
…e session to still be in last-save.json (#403) The two log lines that fire on a sidecar disagreement both claimed the comparison consulted last-save.json; it only bounded the sidecar against the current run's own transcript line count. An orphaned sidecar (its session evicted from last-save.json, cleanup unlink best-effort and failed) that still fell inside that bound was trusted, resuming from a position the authoritative store no longer recognised and re-summarizing the same span. The check now also requires the session id to be a key in last-save.json's own sessions map, read via bash's fork-free $(< file) substitution so the hot path stays inside its pinned cost budget. Co-Authored-By: Max <noreply>
Self-review (spawned oss:auditor) found the fix landed in the previous commit did a substring match over the WHOLE raw file text, not just last-save.json's "sessions" object. cmd_save_position's payload also always carries the fixed top-level keys "session" and "line" -- so a session id literally equal to one of THOSE field names would false-match and be wrongly trusted even with an empty "sessions" map, the exact failure #403 exists to close. Scope the match to the text between the "sessions" key and its own closing brace (values in that object are always bare integers, never braces, so the object's own closing brace is unambiguous) before testing membership. Reproduced red (session id "session", empty sessions map, false-trusted) then green with a new pinned test; both hot-path cost-budget tests in tests/test_hot_path_cost_pin_330.py still pass. 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 #403.
The #353 position sidecar's hot-path trust check only bounded a sidecar's value against the CURRENT run's own transcript line count -- never against
last-save.jsonitself, even though the two log lines that fire on a disagreement both claimed the comparison consulted it. An orphaned sidecar (its session evicted fromlast-save.json, and the best-effort cleanup unlink inpipeline/shell.py'scmd_save_positionfailed) that still happened to fall inside that bound was silently trusted, resuming from a position the authoritative store no longer recognised and re-summarizing the same span.scripts/post-tool-hook.shnow also requires the session id to be a key inlast-save.json's ownsessionsmap before trusting the sidecar, read via bash's fork-free$(< file)substitution (no subprocess) so the hot path this feature exists to keep cheap stays cheap -- checked against the pinned cost budgets intests/test_hot_path_cost_pin_330.py, both of which still pass.This makes an orphaned sidecar detectable regardless of why it survived eviction -- including the Windows case the issue names as reasoned-not-observed (
os.removeagainst a file another process holds open raisesPermissionError, anOSErrorsubclass the cleanup loop swallows). The fix does not depend on which platform caused the failed unlink; it closes the gap at the read side instead.Self-review found and fixed one real gap
Spawned review (Explore, correctness/cross-platform) returned NO FINDINGS. Spawned audit (oss:auditor) returned two findings against the first commit:
sessionsobject.last-save.json's own schema always carries the fixed top-level keyssessionandlinealongsidesessions, so a session id literally equal to one of those field names would false-match even with an emptysessionsmap. Reproduced red, then scoped the match to thesessionsobject's own text and added a pinned regression test, green.$SESSION_IDcould reach the case pattern unfiltered via the transcript-basename fallback. Traced: the actual gating filter (scripts/post-tool-hook.sh:521) tests the real, final$SESSION_ID(post-fallback-resolution) against[A-Za-z0-9._-]+, not a separate unfiltered variable, and the new code only runs once that filter already passed -- verified empirically that a session id containing a glob metacharacter never reaches the new block at all.Testing
TDD: new tests in
tests/test_position_sidecar_353.py(an orphaned-sidecar-rejected case, its positive control, and a fixed-field-name-collision case) were shown red before each corresponding fix and green after. Both hot-path cost-budget tests intests/test_hot_path_cost_pin_330.pystill pass, confirming the added check stays within the pinned per-tool-call cost budget. Full suite: 1729 passed, 43 skipped, no failures.Docs
No user-facing behavior to document -- this is an internal hot-path correctness fix with no new flag, config or observable output.
README.md(the repo's onlydocs_targetsentry) does not describe the sidecar trust mechanism at all, and still doesn't need to. Changelog fragment:changelog.d/403.fixed.md.