Skip to content

feat: replay budget, bash counted by effect, replay in stats (0.0.75) - #95

Merged
okisdev merged 7 commits into
mainfrom
replay-budget
Nov 15, 2026
Merged

okisdev merged 7 commits into
mainfrom
replay-budget

Conversation

@okisdev

@okisdev okisdev commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

summary

  • the inline guard prices each main loop turn at the context tokens it replays, read from the assistant message that holds the tool call, and one replay budget of 2,000,000 tokens replaces the five write budget and the five turn read streak. this acts on a usage review of one host (seven days of transcripts, 115 main sessions): the main loop took 78% of weighted token cost and its cache reads alone 57%, half of those from turns above 500,000 tokens of context, while a turn at 800,000 and one at 80,000 both counted as one. a session at 80,000 tokens now reads for about 25 turns before the advisory and one at 800,000 for 3. a turn with no context reading prices at 400,000 tokens, where the budget equals the old count of five.
  • a Bash command counts by its effect. an in place edit, a redirect or tee into a workspace file, and an inline interpreter script that writes a workspace path are writes: counted, advised, and denied in strict past the budget. a failed Bash write keeps its charge, because a command can write and then exit non zero. the guard saw none of them, and 834 of 1066 main loop edit turns went through Bash against 232 through Edit and Write. the read classifier accepts echo, cut, sort, uniq, diff, newlines, ||, more git and gh read subcommands, and a git -C prefix; one echo separator between two reads used to reset the streak.
  • every priced turn is logged as a replay audit event with its kind (read, write, verify, settle, dispatch, other), and /fusion:stats reports the main loop replay of dispatching sessions per accepted package with its split by kind, after the verification evidence lines. replay events carry no repository, so only sessions with a worker record in the report's scope count, and only packages accepted since the first counted event. the coercion ledger counts a sprawl in replayed tokens for events that carry them and keeps the write count rule for older events.
  • where to read: lib/guard/replay.mjs (pricing and budget math), lib/guard/bash-effect.mjs (the two classifiers), lib/guard/turn.mjs (one turn record per hook call); write-events.mjs and read-streak.mjs switch their thresholds to tokens. rules-manifest.json is generated output.
  • the codex deadline test waits for the detached worker's history gc before its sandbox is removed. the worker writes history-gc-stamp.json and a lock into the data directory after the job record turns done, and the linux runner lost that race with ENOTEMPTY here twice and once on main.
  • release 0.0.75 across every plugin and the marketplace, with a changelog entry.

breaking changes

  • FUSION_INLINE_WRITE_BUDGET is gone. FUSION_INLINE_REPLAY_BUDGET_TOKENS sets the budget in both postures.
  • in strict a session with a small context writes for more turns before the denial and one with a large context for fewer; the tail allowance and the zero dispatch relief are unchanged.
  • hook message text changes for the read streak advisory, the unverified advisory, and the write budget lines; their digests stay.

test plan

already verified

  • npm test -> 2141 tests, 2136 pass, 3 skipped, 2 fail under full suite load (Codex monitor keeps A announced when B vanishes after the snapshot, background timeout marks the record error and result reports the failure, neither in a touched file); node --test tests/codex-jobs-monitor.test.mjs tests/task-lifecycle.test.mjs then passed 90 of 90 three times in a row. 1967 passed before the change
  • claude plugin validate passes for codex, grok, cursor, devin, fusion, and the marketplace root
  • node plugins/fusion/scripts/generate-rules-manifest.mjs -> 60 template versions
  • the guard against a live session transcript: it read 320,305 tokens of context from the message holding the tool call, logged sed -n 1,5p README.md; echo ---; grep -n fusion package.json as a read turn, then raised the same turn to write for a python heredoc that appends to README.md and logged the write with its path
  • node plugins/fusion/scripts/fusion-stats.mjs --all over those events printed the replay headline and replay by kind: write 100% (1 turn) (run before the headline gained in dispatching sessions)

#- [x] an adversarial review of the branch returned 17 findings with probes. 15 are fixed here with a failing test each: Bash write forms the classifier missed (newline boundaries, NAME=value prefixes, >& file, several in place operands, dotfile and extensionless targets), read commands with an output option (sort -o, git diff --output, gh api -f), quoted operators read as redirects, a failed sibling write erasing a shared turn charge, a held lock leaving a write priced on the previous turn, two known message ids merged inside 1500 ms, and the stats scope and coverage of the per package figure. rerunning the reviewer's 21 command probe returns the expected class for every line. one is the documented limit below (MCP and skill turns are not priced), and one was already true on main and is fixed with it (a passing verification now clears the advisory dedupe)

reviewer should verify

  • after refreshing the plugin cache, /fusion:smoke passes, and a session past 500,000 tokens of context gets the read advisory within four consecutive read only turns
  • /fusion:stats shows the two main loop replay lines once a session has run on the new build

notes

  • rules checklist: Locus follows the package gains two sentences saying locus also follows the price of the seat; nothing is removed. A read only stretch longer than a few turns becomes the stretch that would replay the budget, with the two worked figures, which is stricter at a large context and looser at a small one by design. the runtime guard paragraph names the replay budget in place of the two counts and adds the Bash effect sentence; the write budget is a hard floor becomes the replay budget is a hard floor for writes. no invariant in CONTRIBUTING.md changes.
  • accepted packages in the replay headline counts accepted implementation packages only, so consult and review packages do not lower the figure. sessions that never dispatched are left out of the replay section.
  • replay events cover the tools the guard sees (reads, searches, edits, Bash, dispatches). MCP calls, skills, and turns with no tool call are not priced.
  • the Bash write classifier reads the command text: a target held in a variable or with no visible path is not counted, and git apply, mv, and cp are left out on purpose because they are how a peer's work is merged back.

@okisdev
okisdev merged commit a68d341 into main Nov 15, 2026
6 of 7 checks passed
@okisdev
okisdev deleted the replay-budget branch November 15, 2026 03:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant