Skip to content

perf(session): wait for control admission and share the group commit across store lanes (H20) - #9

Merged
lg2m merged 4 commits into
mainfrom
perf/h20-control-admission
Sep 9, 2026
Merged

lg2m merged 4 commits into
mainfrom
perf/h20-control-admission

Conversation

@lg2m

@lg2m lg2m commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

H20: wake-driven control admission and shared commit across store lanes

Spec: docs/plans/speed-first-extensible-agent-harness.md#d8--control-admission-and-shared-commit-h20-implemented
ADR: docs/adr/0011-shared-commit-across-lanes.md
Ledger: docs/plans/progress/speed-first.md (2026-09-09 entries)

What changed

Admission (ab6de6f). Every store call the runtime makes on behalf of
already-admitted work (cancellation reads, reserved starts, compaction
load/start/commit, reserved reloads, history search, all settlement paths,
prompt identity, review context, final text, the scheduler's claim) now uses
Priority::AwaitControl and waits for a control_slots permit. The thirteen
sleep(1 ms) loops that polled Overloaded in execution.rs,
scheduler.rs, and subagents.rs are deleted, along with the 64-attempt
history-search cap. Overloaded remains the immediate answer for new client
commands, feed attachment, replay pages, and snapshots, so admission control at
the boundary is unchanged. Bug fixed along the way: a full control lane during
reserve_next_run_at_depth previously failed the whole runtime; it now waits.

Shared commit (d05e474). Attribution showed the eight-stream output gap
is fsync-bound, not wake-bound: each service round paid one output-group
commit plus one ~3 ms fsync per interleaved control write (command,
start_reserved_run), and the scheduler's claim read closed 17 of 18 forming
groups at one or two jobs. Control-lane jobs now declare worker::Joins:

  • OutputGroup — writes join a forming output group as savepoints and settle
    on its single commit; a write dequeued with nothing open opens a group, so
    consecutive writes share an fsync. Replies still wait for durability.
  • Never — client reads run alone and close a forming group; they are
    answered right after that commit and never observe uncommitted state.
  • AfterGroup — the scheduler's claim read runs alone after the group but
    does not cut it short (it is a wakeup, not a waiting client).

At most one read is held per group and no further control message is dequeued
once one is, so the control lane stays FIFO. Persist-before-publish is
unchanged.

Docs (acf2f9d). ADR-0011 (supersedes D8's admission-only framing),
architecture.md § Persistence amended, plan status/task index/Phase 6
acceptance updated, ledger receipt and probe attributions, decisions #5
resolved.

How verified

  • cargo test --workspace — 1220 passed / 3 ignored
  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo build --workspace
  • New/converted regressions:
    • store::tests::lifecycle_store_calls_wait_for_capacity_while_client_commands_are_rejected
    • store::tests::a_waiting_control_write_joins_the_output_group_and_a_read_does_not
    • sessions::tests::saturated_cancellation_read_and_start_wait_without_failing_the_runtime
    • sessions::tests::saturated_prepared_rejection_settles_and_keeps_priced_accounting_known_zero
    • sessions::tests::saturated_reserved_reload_waits_after_auto_compaction
      (the three saturated_* tests saturate the real 256-slot control lane
      behind a held worker instead of injecting Overloaded; the injected-failure
      hooks that can no longer fire were removed)

Measurements

Eight-streams focused fixture, 30 interleaved A/B pairs, release workers,
host I/O pressure 13–21% some avg10. Median / p95.

Gate Baseline 804e254 Candidate d05e474 Budget
Completion 283.7 / 310.1 ms 209.8 / 228.4 ms —
Control latency upper bound 19.69 / 24.16 ms 15.89 / 18.44 ms —
Cancellation to finished 25.92 / 29.81 ms 23.14 / 27.23 ms ≤100 ms
Max output service gap 24 / 28 ms 20 / 33 ms ≤50 ms executable; 20 ms target
Peak temporary RSS 8.82 / 9.32 MiB 8.64 / 9.52 MiB +25%
Shell completion (15 pairs) 96.6 / 114.1 ms 98.4 / 117.7 ms —
Fan-out ack 1/8/32 (median) 3.27 / 3.13 / 3.17 ms 3.25 / 3.33 / 3.30 ms ≤15 ms

27 of 30 gap samples are 18–22 ms; the p95 is three outliers at 33–38 ms that
a 15-pair same-binary A/A (20 / 21–23 ms) does not reproduce. The median meets
the carried 20 ms target; the executable budget stays at 50 ms until a
quiet-host recording qualifies p95. A lone command still costs exactly one
fsync (fan-out ack medians unchanged). Raw reports, worker binaries by SHA,
and pressure snapshots are under target/qq-perf/h20-2026-09-09/ (untracked).

Compatibility

  • PROTOCOL_VERSION 16, DESCRIPTOR_VERSION 5, store schema 25: unchanged.
  • No public API change. Store::call_write / call_after_group are
    pub(super).
  • Behavioral: a control write's reply may now wait for up to fifteen sibling
    savepoints (sub-millisecond of SQL) before the shared fsync — still less
    than its own fsync was.

Follow-ups / decisions needed

  • Qualify gap p95 ≤20 ms on a quiet host, then tighten
    benchmarks/perf/budgets-v1.json from 50 ms to 20 ms (ledger row H20).
  • The 50 ms cancellation polls in qq-mcp, hosts/embedded.rs, and
    tools/shell.rs poll an Arc<AtomicBool> and never touch the store;
    converting them to a Notify changes ExternalToolHost::call and is
    moved to H22.
  • Next slice per the plan: H21 (behavioral settlement — RunIdentity,
    RunSettlement, PersistenceFault).

lg2m added 4 commits September 9, 2026 14:08
…loaded

Run-lifecycle store calls made on behalf of already-admitted work
(cancellation reads, reserved starts, compaction load/start/commit,
reserved reloads, history search, every settlement path, the scheduler's
claim, prompt-identity, review-context and final-text reads) now use
`Priority::AwaitControl`, which waits for a `control_slots` permit. The
thirteen `sleep(1 ms)` retry loops that polled `Overloaded` from those
calls in `execution.rs`, `scheduler.rs`, and `subagents.rs` are deleted,
along with the 64-attempt history-search cap.

`Overloaded` remains the immediate answer for new client commands, feed
attachment, replay pages, snapshots, and child creation, so admission
control at the boundary is unchanged.

The scheduler's `reserve_next_run_at_depth` previously failed the whole
runtime when the control lane was full during a claim; it now waits.
Regression: `saturated_cancellation_read_and_start_wait_without_failing_
the_runtime`, `saturated_prepared_rejection_settles_and_keeps_priced_
accounting_known_zero`, and `saturated_reserved_reload_waits_after_auto_
compaction` saturate the real control lane (256 slots behind a held
worker) instead of injecting `Overloaded`; `lifecycle_store_calls_wait_
for_capacity_while_client_commands_are_rejected` pins the lane split at
the store. The injected-`Overloaded` test hooks that can no longer fire
are removed.

Part of H20 (speed-first plan, D8). No protocol, descriptor, or schema
change.
…er wakeups

Attribution of the eight-stream output service gap showed it is fsync
bound, not admission bound: each service round paid one group commit plus
one fsync per interleaved control write (`command`, `start_reserved_run`,
~3 ms each on ext4/NVMe), and the scheduler's claim read
(`reserve_next_run_at_depth`, issued after every settlement) closed almost
every forming group at one or two jobs.

Control-lane jobs now declare how they relate to a forming output group
(`worker::Joins`):

- `OutputGroup` (writes: commands, child creation/cancellation, run
  starts, settlements, prompt identity, recovery) join the group as
  savepoints and settle on its single commit. A control write dequeued
  when no group is open opens one, so consecutive writes share an fsync.
  The reply still waits for durability; persist-before-publish is
  unchanged.
- `Never` (client reads: snapshots, replay pages, cancellation reads)
  runs alone and closes a forming group, so it is answered right after
  that commit and never observes uncommitted state.
- `AfterGroup` (the scheduler's claim read) runs alone after the group
  commits but does not cut the group short; it is a wakeup, not a
  waiting client.

At most one read is held per group and no further control message is
dequeued once one is, so control-lane FIFO order is preserved.

Interleaved A/B, 30 pairs, eight-streams focused fixture, medians / p95:
completion 283.7/310.1 -> 209.8/228.4 ms; control latency upper bound
19.7/24.2 -> 15.9/18.4 ms; cancellation 25.9/29.8 -> 23.1/27.2 ms; output
service gap 24/28 -> 20/33 ms (27 of 30 samples 18-22 ms; three outliers
33-38 ms; a 15-pair same-binary A/A shows 20/21-23 ms). RSS unchanged.

Regression: `a_waiting_control_write_joins_the_output_group_and_a_read_
does_not`. Part of H20 (speed-first plan, D8). No protocol, descriptor, or
schema change.
- ADR-0011: one commit discipline across store lanes; wakeups do not close
  groups. Supersedes D8's admission-only framing.
- architecture.md § Persistence: describe `Joins`, the two admission modes,
  and that commands, starts, and settlements share the stream's fsync.
- speed-first plan: status block, D8 collapsed to its receipt and remaining
  acceptance, task index (H20 in review, H21 next), Phase 6 acceptance
  progress, cancel polls moved to H22.
- Ledger: baseline, slice 1 A/B, the two probe attributions (fsync per
  control write; scheduler claim closing groups), and the H20 receipt with
  A/B and A/A tables. decisions-needed #5 resolved; root ADR allocation
  updated.
@lg2m
lg2m merged commit 151fe94 into main Sep 9, 2026
3 checks passed
@lg2m
lg2m deleted the perf/h20-control-admission branch September 9, 2026 23:36
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