Repository navigation
refactor(stop): cost-tracker shares one usage-record def and one sentinel row (#379) - #386
Merged
Merged
Conversation
…inel row (GH #379) raw_records and scan_transcript each carried a copy of the usage-record builder (they differed only in t: and f:), and emit_rows and the orchestrator path each built the jq_failed sentinel. Now usage_def (def usage_rec($t; $f)) sits beside adv_def, and jq_failed_row <stream> <files> builds the sentinel. Byte-identical costs.jsonl, marker, stdout, stderr and rc against the develop copy on 316 real sessions (1,531 rows) plus 8 hand-made sessions (61 rows, both sentinel paths), under bash 3.2 and bash 5. Timing unchanged (193 subagents: 3783 -> 3783 ms, bash 3.2). Test phase 6: the same two-iteration 1h line in main and in a subagent splits cw/cw1h alike, and each stream writes the same sentinel shape. Red on a develop copy whose raw_records copy drifts; 10 mutants killed.
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.
Refs #379 (item 3 of 3; items 1 and 2 merged in #380 and #384).
What
raw_records(subagent files) andscan_transcript(main transcript) each held a copy of the usage-recordbuilder. The copies differed only in
t:andf:, and a past cw1h fix had to edit both. That builder isnow one
def usage_rec($t; $f)inusage_def, next toadv_def. Both readers call it.emit_rowsand the orchestrator path each built thejq_failedsentinel row. Now both calljq_failed_row <stream> <files>.is untouched.
Proof
Equivalence. The develop copy (with #384 merged) was frozen and both copies ran on the same inputs.
Each run had a throwaway
HOME, settle 0, and adateshim. Every run comparedcosts.jsonl, the marker,stdout, stderr and the exit code byte for byte. The only normalization: bash's
<script path>: line N:prefix.
Tests. Phase 6 of
test-cost-tracker.sh:file. Both rows must be cw 300 / cw1h 700. No test covered the subagent path's split before.
usage: "not-an-object"line in each stream must give each stream the exact sentinel row (all keys)and its stderr line.
Red on a develop copy whose
raw_recordscopy alone drifts (ignores iterations), which is the bug classthis removes. It passes on the develop copy and on the new code under bash 3.2 and 5. Mutants killed
(across test-cost-tracker.sh and test-session-stop.sh), 10 of 10:
tdropped orfwrong at either call sitetfixed to nullfilesemptiedstreamkey droppedTiming. Whole hook, 20 interleaved runs, medians (p90): unchanged, as expected for a refactor. At
193 subagents: 3,783 (3,968) -> 3,783 (4,044) ms on bash 3.2, 3,891 (4,248) -> 3,847 (4,059) ms on bash 5.
At 6 subagents: 155 -> 157 / 176 -> 176 ms.
Skipped: single-pass codex tally
emit_codex_invocationsre-reads the subagent files thatraw_recordsalready read. On the 193-subagentsession that second read costs about 1.15 s (5 runs, 1,122-1,197 ms), about 30% of the hook. Folding it
into
raw_recordswould merge two failure domains: today a malformed subagent line gives a sentinel row,and the codex tally still counts. Keeping them apart needs the per-field try/catch that
scan_transcriptuses. The local corpus has 0 subagent files with a codex call, so only hand-made fixtures could cover it.
Left as a follow-up rather than mixed into this refactor.