Skip to content

post-tool-hook.sh: keep pipeline.shell read-position off the hot path (part 2 of #350) #353

Closed

Description

@fdaviddpt

Split out of #350, which reported two changes. Part 1 — the #227 env-cache fast path — is PR #352. This is part 2, deliberately left out of that PR so it gets its own argument rather than riding a perf win.

What was proposed

Have save-session.sh also write the per-session position to a bash-read-able sidecar (e.g. tmp/position.<session_id>, a plain integer), so scripts/post-tool-hook.sh:304's $PYTHON -m pipeline.shell read-position only runs when the sidecar is missing.

What it is worth

Measured on the #352 branch, macOS 24.3.0 arm64, GNU bash 3.2.57 — observed, and not a claim about Windows, which is the platform the original report was made on:

  • warm tool call, no save yet: 6 spawns / 130 ms
  • warm tool call, once last-save.json exists: 8 spawns / 248 ms

So the sidecar is worth roughly 2 spawns and ~118 ms per warm tool call on that machine, and only on calls after the first save. Real.

Why it is not in #352

last-save.json already holds the position. A sidecar is a second source of truth for the same number, and the two can disagree — a partial write, a session id collision, a save that updated one and not the other, a stale file surviving a crash. A disagreement produces a wrong delta with nothing to notice: the hook silently saves too early, too late, or not at all, and the failure looks exactly like the feature working.

That is the misreports class, traded for latency. It may still be the right trade — but it needs the design that makes the two agree or makes a disagreement loud, and that design is the issue, not the sidecar.

What would have to be true

  • The sidecar is written by whatever writes last-save.json, in an order where a crash between them leaves the sidecar stale-and-detectable rather than wrong-and-plausible.
  • The read path has three states, not two: the sidecar's value, read-position's value, and could not tell — never a silent fallback to zero or to the last delta.
  • A sidecar that disagrees with last-save.json is a loud finding, with a test that pairs "must not fire" against a "must fire" in the same fixture.

Credit to @oguzhanpisgin, who reported both halves in #350 with the measurement matrix.

Activity

  1. added
    cohort-1
    on Aug 27, 2026
  2. self-assigned this
    on Aug 28, 2026
  3. added 5 commits that reference this issue on Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

cohort-1

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions