Skip to content

Send a TUI subagent's approval requests to its parent - #2285

Open
fazxes wants to merge 15 commits into
fazxes/send-subagent-approvals-to-parentfrom
fazxes/send-tui-subagent-approvals-to-parent
Open

fazxes wants to merge 15 commits into
fazxes/send-subagent-approvals-to-parentfrom
fazxes/send-tui-subagent-approvals-to-parent

Conversation

@fazxes

@fazxes fazxes commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #2198. Merge after it.

Summary

  • In the interactive app, a subagent's approval request in a turn its parent started now goes to that parent, as in fx ask and ACP after Send a subagent's approval requests to its parent #2198. The run asks through the turn's prompter, so the request is registered, the parent gets one note, and it answers with the subagent tool's approve or deny.
  • The request still waits on the subagent's own worker, so the subagent's screen shows it and the person can answer it there. No instance's screen borrows it, and neither the footer nor the agent list says the subagent needs the person; the list says it is working.
  • When the person answers on the subagent's screen, its registry binding goes, so the parent's later approve reads that nothing waits.
  • A turn the person typed on a subagent's screen keeps the worker's prompter: its requests ask the person and are lent to the instance's screen as before.
  • The approval prompt now owns a copy of its file review. Before, it pointed into a local copy in the tool call's stack frame (tool_admission.zig), so a prompt that outlived its call, such as a lent copy, could read freed memory. That is the crash the first attempt at this change hit. The worker makes the copy under its own lock while the request still waits (WorkerRuntime.copyPendingReview), because an answer can now come from another thread and end the call; the app adopts it once per request, and the snapshot's pointer is only compared.
  • A stop or close of a subagent now first refuses the approval request it waits on, so the call never runs, and then ends the turn as before. The refusal carries a reason ("Your parent stopped you before answering this request. Do not retry it.", and the same for a parent's or the person's close) and a trace line, but the turn ends right after, so the subagent's model does not read it. In fx ask and ACP a stop used to leave the request waiting until the turn ended; in the app it was declined with no reason. ACP's session/cancel still leaves the request waiting. A typed turn's request keeps today's decline.
  • The refusal takes only the registry's mutex and releases it before it answers the worker, and it runs before the stop takes admission, so it cannot deadlock with the note path.

Model

tests/tla/subagent/TuiParentApproval.tla, with 13 configs in check.sh. The step-3b trial (lend a parent-routed request) breaks NoStaleLent, and design a (main's answer off the loop, the call frees its review) breaks NoStalePrompt; a2, b and c pass. Design c is this change: NoStalePrompt holds for it because the prompt reads its own copy, taken under the worker's lock while the request waits; the OwnedReview and copyPendingReview unit tests prove the copy is taken only then and outlives the call. Three planted defects each break their rule (NoPersonPromptForParentRouted, NoStalePrompt, TypedStaysWithPerson), and two simulation runs pass. ParentApproval.tla's Stop already drops the request; its comment now says the stop refuses it first.

Tests

  • Unit: OwnedReview keeps its rows after the source review is freed, in computed and fallback mode and at the fallback limit; the two approval-prompt tests that asserted the borrow now assert the copy and read it after the source is freed; a stop refuses the child's waiting request once with the reason; a close refuses it with the reason of who closed it; a stop or close with nothing waiting refuses nothing; a refused stop answer ends a child's permission wait with the reason.
  • E2E, tui-host-switch.test.ts: the parent approves (the write lands) and denies (nothing written), and main's screen never shows "needs permission"; the person answers on the subagent's screen first and main is told nothing waits; a typed turn's approval is still lent; two subagents wait at once and main answers both; the status and agent-list tests each have a typed form with their old assertions and a main-started form (main reads "waiting for an approval", the footer stays quiet, the list says working); main's stop refuses a subagent's request and its command never runs.
  • E2E, tui-host-instances.test.ts: the 17 grant tests (always and one-time answers, kept, sibling, nested, lead, instance scope, main's running turn, /permissions reset, fx mcp call, auto mode) keep every assertion with the subagent's turn typed by the person, since a main-started subagent no longer asks the person; a launched instance's subagent still asks on that instance's screen in a typed turn; new: a launched instance's subagent asks that instance's agent, not the person or main.
  • E2E, sessions.test.ts: main's stop refuses a subagent's request in fx ask, and nothing runs.
  • E2E, tui-command-permissions.test.ts and gateway-stream-lifecycle.test.ts: "interactive child approval uses the normal parent prompt" and "subagent search recovers when its target disappears during approval" keep their assertions with the subagent's turn typed; new tests cover main denying through the note, and main's approve refused once the target is gone.
  • Unit, worker_runtime.zig: the worker copies a pending review only while the request waits, and the copy outlives its source.
  • Test changes: tests that held a main-started subagent's approval on main's screen now type the subagent's turn, so they keep their assertions; their fakes answer by content instead of counting main's turns, because main now gets a note turn. Two rows of the typed list test name the last completed work, because a typed turn has no named work; each asserts the whole exact row. The report-while-prompt tests count only the reports a typed turn sends, and instead check that the approved write landed; the question and out-of-credits variants keep covering the writer's report.

Merges

The branch merges #2198's head four times: for its fix of the ACP reload tests (with a follow-up that removed a duplicate import that merge left), for its fix of a registry-owner lock cycle, for the single-check route pin that replaced that fix's give-back, and for a one-line std.mem.print fix in a test. The SDK budget for fx-term.wasm rises from 4,254,000 to 4,270,000 bytes: this change adds 6,798 bytes (4,253,179 on the base, 4,259,977 at its first head), as sdk/AGENTS.md allows for a change that has to grow the package.

Checks

  • bin/check reports removed-assert for the tests that pinned syncReview or the prompt's own review pointer. Each one has a replacement: adoptReview(alloc, id, &review, owned copy) in approval_screen.zig, approval_prompt.zig and app_render_runtime.zig, and the two null cases; review_source == &review and == &replacement_review in app_worker_runtime.zig. The prompt's and the projection's pointer equality became pointer inequality plus content checks (currentReview() != &review, the row count, the viewport), because the prompt now holds its own copy. In tui-host-switch.test.ts, the status and row assertions now pin indexed status lines and the full row text. None was dropped (R7.4).
  • agents_menu/ and turn_clock/ stay as they are (R7.2). The list's label comes from the worker's turn phase, and a parent-routed approval is still a turn in flight. The clock's wait condition and edges are unchanged; only who owns the review copy changed.
  • Fuzz: switch_order, agents_menu_selection, queue_placement and diff_rows, the four targets this change reaches directly, each ran one 60 s round with no reproducer.
  • Thread Sanitizer on the approval, review-copy, refusal and lock tests (-OReleaseSafe -fsanitize-thread): 0 warnings in 40 tests, none in a changed file.
  • The new waits in the E2E tests use held promises, not Bun.sleep polls (R7.3).

Docs

The subagents page on fx.sh: vercel-labs/fx-web#365, stacked on vercel-labs/fx-web#357.

Rules: R3.8, every withdrawn or refused request leaves a trace line with counts and ids, never content; R3.9, the prompt owns its review and frees it; R4.1 and R4.2, the parent's answer never grants more than its own check; R7.1, each new test fails without its part of the change; R7.2, the model above; R7.4, no assertion was loosened.

In the interactive app, a run its parent started now asks through that
turn's prompter, as `fx ask` and ACP do: the request is registered, the
parent gets one note, and the parent answers with `approve` or `deny`.
The request still waits on the subagent's own worker, so its own screen
shows it, but no instance's screen borrows it, and neither the footer
nor the agent list says the subagent needs the person. A turn the person
typed on a subagent's screen keeps the worker's prompter and stays with
the person, lent to the instance's screen as before. When the person
answers on the subagent's own screen, its registry binding goes, so the
parent's later answer reads that nothing waits.

The approval prompt now owns a copy of its file review instead of
pointing into the tool call's stack frame, so a prompt that outlives its
call can no longer read freed memory.

Tests that held a main-started subagent's approval on main's screen now
type the subagent's turn, so each keeps its assertions; new tests cover
the parent's approve and deny, the person answering first, two
subagents at once, the quiet footer and list, and an instance's
subagent asking that instance's agent.
A stop or close of a subagent now first refuses the approval request it
waits on, with a reason it can read: its parent stopped it, its parent
closed it, or the person closed it. The call is refused and nothing runs.
In fx ask and ACP a stop used to leave the request waiting until the
turn ended; in the app it was declined without a reason.

The refusal takes only the registry's mutex and releases it before it
answers the worker, and it runs before the stop takes admission, so it
cannot deadlock with the note path. ACP's session/cancel still leaves
the request waiting. A turn the person typed keeps today's decline.
The fake approved writer first whenever any note was in the history. When helper's note reached main first, main approved writer before it waited, fx answered that nothing waited, and writer's later note found both approve calls already made, so writer was never approved. The fake now approves the agent the newest note names, approves again an agent whose approval came too early, and says both were answered only after both approvals were allowed.
tests/tla/subagent/TuiParentApproval.tla checks the designs for Part 2: the step-3b trial breaks NoStaleLent and design a breaks NoStalePrompt, while a2, b and c pass. Design c is the code in this change: the prompt owns a copy of its review, so NoStalePrompt holds by construction, and a request its parent answers is never lent. Three planted defects each break their rule, and two simulation runs cover ideal and non-ideal conditions.
Both branches added the same import to approval_registry.zig, and the merge kept both lines, which does not compile.
@fazxes fazxes added type: feature Adds a new user-facing capability ci:macos Run macOS arm64 checks on this PR labels Nov 24, 2026
@vercel-internal-security-reviewer

Copy link
Copy Markdown

Security review details

The terminal build now carries the approval prompt's own copy of its file review, the routing of a subagent's request to its parent, and the refusal on stop and close. That code adds 6,798 bytes to fx-term.wasm: CI's SDK job measured 4,253,179 bytes on the base and 4,259,977 with this change, over the 4,254,000-byte budget.
The app copied the approval prompt's review from a pointer it read in the
worker's snapshot, after the worker's lock was released. The review lives
in the tool call's frame, and in this change an answer can come from
another thread, the parent's approve or a stop's refusal, so the call
could end and free the review before the copy was made. The worker now
makes the copy itself under its lock while the request still waits, and
the prompt adopts it once per request; the snapshot's pointer is only
compared.

Also: the main-started form of the agent-list test asserts the team row
again, the instance tests wait on the pane instead of polling with a
sleep, and a test that ignored closeChild's error now checks it.
"interactive child approval uses the normal parent prompt" and "subagent search recovers when its target disappears during approval" held a main-started subagent's request on main's screen, which now goes to main as a note. Each keeps its assertions with the subagent's turn typed by the person; a typed turn sends no report, so the wait for main's report turn is replaced by the child's own evidence. Each also gets a new test for the note path: main denies, and main's approve is refused once the target is gone.
The restored command and search approval tests, and their note-path
versions, sampled a variable every 25 ms to see what the fake recorded.
They now await a promise the fake resolves when it records it, bounded
by a deadline. Selecting an agent uses the list's search box and waits
for its one-row header, instead of stepping the highlight and sampling.
The app copies a waiting request's file review through the worker; when
that copy fails, the prompt shows no review for that pass and the next
pass tries again. It now leaves a trace line with the request id and the
error, so the dropped copy is visible.
The note shows a shell command's permission label cut to one activity
line. On macOS the temp workspace path is long, so the cut falls before
the marker's name, and the note test failed there. The test now checks
that the note's action is the real label, or the label's own head
ending in a cut marker, and checks the marker's name only when the label
is whole.
@fazxes
fazxes marked this pull request as ready for review November 25, 2026 04:41

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:macos Run macOS arm64 checks on this PR type: feature Adds a new user-facing capability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant