Skip to content

feat(runtime): a read sub-agent no longer blocks its parent (AP4.1) - #244

Merged
lg2m merged 4 commits into
fix/eng-1002-compaction-tool-historyfrom
feat/eng-1004-ap4-nonblocking-delegation
Oct 5, 2026
Merged

lg2m merged 4 commits into
fix/eng-1002-compaction-tool-historyfrom
feat/eng-1004-ap4-nonblocking-delegation

Conversation

@lg2m

@lg2m lg2m commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

Linear: ENG-1004. ADR-0054 § 4, slice AP4.1. Base: #242, which is stacked on #240 and #238.

What changes for users

A read sub-agent no longer blocks the agent that started it. Over 30 days of real use, runs that delegated spent 40 % of their wall time blocked on spawn_agent. The v0.1.6 planning run was blocked for 209 of its 267 minutes.

  • The spawn returns immediately. spawn_agent returns as soon as the child is durably admitted, with its session id. The parent keeps working.
  • Answers arrive later, once. The child's answer reaches the parent at a later turn as a runtime notice, exactly once. The notice is the final reply, a labelled interim report, or the reason the child stopped plus its latest report.
  • A reply without tool calls waits. If the parent replies without tool calls while children are still out, the run does not settle. It waits for the next answer, or for steering, then runs another turn. Cancellation, the run deadline and a budget-final turn still settle it: the children are cancelled and what they left is delivered to the session.
  • An interrupting steer stops the parent's turn, not its children.
  • Still blocking, unchanged:
    • write children (one write slot; parent and child never edit at once);
    • audits;
    • every spawn in a run with a finite token or cost limit, because each child is granted the parent's whole remainder.

Not in this PR: wait_agents, cancel_agent and interim-report delivery. They are slice AP4.2, which also bumps DESCRIPTOR_VERSION. The "waiting for sub-agents" UI is AC14.

Design

  • Exactly-once delivery. Store schema 41 adds child_deliveries. Admission inserts the child's row in the same transaction that creates the child.
    • At the top of every parent turn, one transaction stamps every settled, undelivered row: the notice text, the parent turn whose request carries it, and a delivery ordinal.
    • The notice joins the live context only after that commit. Each row is stamped once (delivered_at_ms IS NULL, exactly one row changed).
    • A parent that settles first gets the answers with its own settlement, placed after its run. A child settling after its parent, or a grandchild unblocking a child's spend, delivers up the ownership chain at once. Recovery delivers the rest.
  • Replay matches live. Assembly places stored notices after the boundary's steering and before the turn notice, exactly where the live loop put them. In-run compaction drops them with the summarized span, like steering.
  • Spend is charged at delivery, once. An answer from a child that answered is a progress event. A notice that the child failed, was cancelled or paused is not, exactly as a blocking spawn's error result is not. The admission receipt is not either.
  • Bounds. Each answer is bounded like a tool result. The answers delivered at one boundary share one turn's tool-output budget and count against max_tool_output_bytes. A cut names the child session that keeps the whole answer.
  • Waiting races "a child settled" against "steering arrived". It ends only after something was added to the context, so a request never has two assistant messages in a row. An empty waiting reply takes the empty-turn placeholder.
  • The prompt says so: prompt version 15 → 16. The spawn tool says the sub-agent runs in the background and its answer comes later as a notice. The golden test undoes exactly those two bullets and the description, then checks the AP1 hashes.

Verification

  • Tests: 2084 workspace tests and the soak pass; clippy and fmt are clean. The delegation, progress and nonblocking suites passed six runs in a row under load. New tests in sessions/tests/nonblocking.rs:

    • three children while the parent keeps working, with each answer delivered once and spend charged once;
    • steering inside the wait;
    • cancel inside the wait, then the next run sees the answer;
    • the deadline ends a wait;
    • an interrupt does not stop detached children;
    • an empty waiting reply stays valid;
    • a bounded parent still blocks;
    • a budget-final turn cancels and delivers;
    • a restart between child settlement and delivery delivers once;
    • a grandchild settling late;
    • the receipt window;
    • a poisoned registry;
    • bounded long answers;
    • only an answered child resets the parent's stall count. This test fails if every notice counts as progress.

    Each of the last three regression tests fails with its fix reverted.

  • Replay identity: each scenario compares the last live request with the follow-up run's assembled context, message for message, and checks the joined loader against the reference loader, which now reads deliveries. The in-run compaction splice is pinned. A write child still blocks, and the one-write-slot test is unchanged.

  • Independent review: the first review requested changes (2 blocking, 9 should-fix), all fixed. The re-review approved, and its should-fixes are done too. Details are in the ledger.

  • Benchmarks. Medians against the base branch; the machine was loaded.

    • child_admission: its children answer instantly, so detaching cannot shorten wall time. Unbounded runs take one more parent turn (spend 30 → 35); peak concurrency is unchanged.

      Case Before After
      unbounded-read 140.1 ms 140.6 ms
      unbounded-read-overlap 114.0 ms 126.2 ms
      finite-read 164.9 ms 168.4 ms
      depth-two 102.7 ms 111.7 ms
    • turn_overhead and context_assembly are within noise. The per-turn check is an in-memory flag, so a run without detached children makes no store call.

    • The real measure is the AP0 blocked share (target: under 20 %). It needs real use and is recorded in AP5.

Compatibility

  • Store schema 40 → 41. The migration adds an empty table, and existing sessions assemble exactly as before. Older builds refuse a schema-41 store, as with every schema bump.
  • Agent prompt 15 → 16.
  • No PROTOCOL_VERSION change. Delivered answers reach clients through the child session's own events, and the notice is ordinary model context.
  • Behaviour change for blocking spawns too: a child that stopped short (cancelled, failed, paused, budget) now also returns its latest report, because blocking and delivered answers share one function.

Feature flow

flowchart LR
  A["Unbounded read child is durably admitted"] --> B["Return session receipt; parent continues"]
  B --> C["Child settles"]
  C --> D["Commit one delivery and its spend"]
  D --> E["Add notice at a parent turn boundary"]
  E --> F{"Child answered?"}
  F -->|Yes| G["Reset stall progress"]
  F -->|Failed or cancelled| H["Keep notice as context"]
Loading

Combined-source validation — 2026-10-04

This exact PR head was composed locally with #227, #231, #238, #239, #240, #242, #243 and #244 at 8dcf7a7270a8ac936a74e2f07d4aca7a8ccfb8c4 (tree 13816472ac53b0e117f042b74d8c6f23b435e9ec). Non-author interaction review accepted compaction/child-delivery ordering and the ADR merge. 307 relative links in changed Markdown resolve.

  • Actual pinned Rust/Cargo 1.97.1: formatting and all-workspace/all-target/all-feature Clippy with -D warnings passed.
  • cargo test --locked --workspace -- --test-threads=2: 2,087 passed, 0 failed, 12 ignored.
  • Minimal provider profile: 210 passed, 0 ignored.
  • Explicit isolated process_kill_preserves_the_side_effect_without_reexecution: 1 passed; each of two kill/reopen cycles preserved one journalled side effect without reexecution. The child environment is cleared and only local scripted providers/temporary SQLite are used.
  • cargo build --locked --workspace passed after an observed ENOSPC in this task's default-debug incremental output. Only owned build artifacts were removed; the successful remaining build/minimal/recovery checks used CARGO_INCREMENTAL=0 and local dev/test debug symbols disabled. Source/features/optimization were unchanged. The original failure and environment differences are retained.

These are local source/runtime-fixture checks. Required hosted CI is verified separately on each individual PR head; the local composition has no hosted CI receipt. Existing per-PR performance evidence is reused, with no new combined performance or real-provider claim. Real model sessions, AP5 blocked-share qualification and the integrated paid customer journey remain unaccepted.

lg2m added 3 commits October 2, 2026 18:16
Before, spawn_agent held the parent's turn until the child settled: over
30 days, delegating runs spent 40 % of their wall time blocked on it
(ADR-0054 § 4).

Now a read spawn returns as soon as the child is durably admitted, with
its session id, and the parent keeps working. Its answer (final reply,
labelled interim report, or the reason it stopped plus its latest report)
reaches the parent at a later turn boundary as a runtime notice:

- Exactly once: admission inserts a child_deliveries row, and one
  transaction stamps it with the notice and the parent turn it precedes
  before that request is built. A parent that settles first gets the
  answer with its own settlement; recovery delivers to parents settled
  before their child. The next run assembles the notice from the row,
  so live and replayed context match.
- Spend is charged once, at delivery. A delivered answer is progress;
  the admission receipt is not.
- A reply without tool calls while children are outstanding waits for
  the next answer or steering and runs another turn. Cancellation, the
  deadline and a budget-final turn still settle the run; teardown
  cancels the children and the settlement delivers what they left.
- Interrupts and the audit drain stop only blocking work; detached
  children keep reading.
- Write children, audits, and runs with a finite token or cost bound
  still block (each child gets the whole remainder).

Store schema 40 -> 41 (child_deliveries); agent prompt 15 -> 16. No
protocol change. wait_agents, cancel_agent and interim-report delivery
are AP4.2 with the descriptor bump.

Linear: ENG-1004
…wers

Fixes from the independent review of the non-blocking delegation slice:

- A tool-free reply that the run continues past (waiting for
  sub-agents, or steering) is never an empty assistant message: it takes
  the empty-turn placeholder, as replay does.
- The reference assembly loader knows child_deliveries. New tests compare
  each run's last live request with the follow-up's assembled context,
  pin the in-run compaction splice of delivered answers, and cover the
  deadline, an interrupt, an empty waiting reply, and a grandchild
  settling after its parent.
- Delivered answers share one turn's tool-output budget per boundary,
  are stored as cut, and count against max_tool_output_bytes.
- An answer that waits on an unsettled descendant is delivered when that
  descendant settles, not at the next restart.
- DeliveryError keeps its store error; a poisoned child registry fails
  loudly instead of skipping the wait; a spawn call dropped while the
  receipt is in flight no longer cancels its detached child.

Linear: ENG-1004
…ests, one budget per boundary

The receipt-window test fails when the waiter cancels unconditionally on
drop. A boundary the wait already delivered for is not delivered again
with a fresh budget, and its cut names the child session that keeps the
whole answer.

Linear: ENG-1004
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-04T02:29:24.185627Z f0b67e4 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 70286ed484

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/qq-core/src/lib.rs Resolved
@lg2m
lg2m added this pull request to stack #241 October 3, 2026 07:21
Codex review on #244 read 'a delivered answer is a progress event' as
covering failure notices too. The rule, matching the blocking path and
ADR-0054 § 1, is that only a child that answered restarts the parent's
stall count: a cancelled, failed, or paused child's notice is context
and spend, not output, so a parent spawning children that fail still
reports. The docs now say so, and a test pins it; the test fails with
every notice counted as progress.

Linear: ENG-1004
@lg2m
lg2m merged commit fc97fab into main Oct 5, 2026
6 checks passed
@lg2m
lg2m deleted the feat/eng-1004-ap4-nonblocking-delegation branch October 5, 2026 02:56
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