Skip to content

feat(agent,cli): reclaim oversized run journals; wait for the remote verdict - #1367

Merged
huichen merged 2 commits into
mainfrom
pr/huichen
Oct 26, 2026
Merged

huichen merged 2 commits into
mainfrom
pr/huichen

Conversation

@huichen

@huichen huichen commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Frozen snapshot of dev-huichen at e7ea4222 (rebased onto current origin/main; 0 behind).

  • run-journal reclaim (b30ac356): journal_compaction.rs retired a run's raw journal only when it fit under SNAPSHOT_BYTE_BUDGET (4 MiB) and otherwise returned Ok(0) — permanently. Since streamed tool_delta events land one row each, every long run exceeded it and was never reclaimed: measured 1,668,496 run_events rows / 392.5 MB on one machine, growing ~25 MB/hour, which filled a disk and took a remote desktop down for 30 minutes. Now an oversized journal is reclaimed in bounded slices (journal_reclaim.rs), with replay equality asserted per run; verified on a real DB copy: 21/21 reclaimed runs replay identically (e.g. 136,298 events → 1,375-event snapshot, 250 tool calls, EQUAL).
  • hasMore fix: it used to mean "some run still has a raw journal", so an unreclaimable run made the CLI repeat itself — 1,042 duplicate refusals measured on a real DB copy. It now means "this scan still has work", with at least one run handled per call and a 256-slice cap.
  • remote start refusal (e7ea4222): the CLI waits for the remote's verdict instead of a fixed 30 s window; acceptance recorded in docs/testing/remote-start-refusal-wait-2026-10-26.md.

Verification reported by the implementing session: agent 2498 + cli 1313 tests pass, fmt/clippy/check-docs clean; the 3 agent test failures and 2 Windows clippy errors reproduce on the untouched baseline and are unrelated. Its one honest gap: a >4 MiB live run was not exercised end-to-end (no model configured in its isolated instance) — covered by unit tests at the same call site plus the real 17 MiB→4.6 MiB reclaim.

No RPC contract change beyond additive fields; no compaction threshold touched; no destructive schema migration.

huichen and others added 2 commits October 26, 2026 13:07
… them

A settled run's raw journal was retired only if its folded snapshot fit 4 MiB
*and* the run held at most 65,536 rows. Over either limit the compactor
returned `Ok(0)` and never looked again, so `run_events` only grew. Measured on
a 1 GiB `agent.db`: 1.6M raw rows / 375 MiB, of which 1,213,282 rows sat in 15
runs whose only disqualifier was the row count, plus one run whose folded
projection was 4.5 MiB. The automatic trigger is also in-process only, so a run
that settled under an older build is never retried at all.

- Retire raw rows in bounded 32,768-row transactions after publishing the
  snapshot; the first slice stays in the publishing transaction, so a crash
  still leaves either the whole journal or (snapshot + inert leftover rows).
- Publish a snapshot above the 4 MiB target instead of abandoning the run. It
  is counted in `journal.oversize_publishes` and logged once per run, and it is
  still 6–17x smaller than the journal it replaces; the delivered projection is
  the same fold a client already receives from the raw path.
- Record why a journal was kept (`journal.skipped.<reason>`) and the durable
  reclaim counters in `storage_meta`, so "nothing happened" is diagnosable.
- Add sessionless `get_journal_stats` / `reclaim_run_journals` and
  `future session journal [--reclaim [--yes]]`: a report, a plan, and an
  explicit resumable sweep. Off unless asked for, bounded per call, prints rows
  and bytes before/after, and gates on `quick_check`.
- The sweep reports `hasMore` only for work it can still do, retires inert
  leftovers of an interrupted retirement, always attempts at least one run per
  call, and skips (rather than aborts on) a journal it cannot represent.

Replay equivalence is unchanged: the snapshot is the same folded projection of
the same journal, covered by a test that compares what a client renders (text
in order, tool arguments, tool results) before and after reclamation.
`a_broker_that_refuses_the_credential_is_reported` failed on Windows CI
(run 40267289153 attempt 1) because its 30 s window also contained the
child's own startup: the embedded agent's prologue took 26.2 s and no
`Remote:` line had appeared when the window closed, so the refused
connection had not even been attempted. Attempt 2 of the same run on the
same commit passed, which is why the rerun hid it.

The claim is *that* the refusal is reported, not *when*, so the wait now
ends on an outcome: the line appears, the child ends, or a 300 s backstop
against a hang expires. `Verdict` names which, so a timeout is reported as
a timeout instead of a bare `false`, and a child that never reports is
killed rather than blocking `wait()` forever. Every assertion is unchanged.

Three more waits in the same file had the same shape (a line that cannot
exist before the child's first start attempt, budgeted from `spawn` at
30-40 s) and are converted with it; the recorded survey lists the 27 waits
left alone and why. The accompanying record has the runner's log, the
prologue measurements and two falsification experiments: a 45 s prologue
is red before (49.25 s) and green after (49.84 s), and a child that never
reports fails at 300.27 s naming the timeout.
@huichen
huichen enabled auto-merge (squash) October 26, 2026 05:08
@huichen
huichen merged commit eeb47ca into main Oct 26, 2026
55 of 58 checks passed
@huichen
huichen deleted the pr/huichen branch October 26, 2026 05:29
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