Skip to content

fork: report a linked child's pending prompts to its parent (#808 row 1) - #815

Merged
scuttletoby merged 4 commits into
mainfrom
fork/808-remote-pending
Nov 21, 2026
Merged

scuttletoby merged 4 commits into
mainfrom
fork/808-remote-pending

Conversation

@scuttletoby

Copy link
Copy Markdown
Owner

What and why

A delegated task on a linked (remote) machine always reported hasPendingQuestion: false, pendingApproval: null. Those values were hardcoded in the remote read of OrchestratorMcpService.ts ("Its questions and approvals are answered in the environment it runs in"). So the parent never learned that its child was waiting on a question, an approval or a secret, and a blocking wait ran to its timeout.

This change is #808 row 1: report the child's prompts to the parent and wake the parent. Answering them from the parent is a later row.

  • New fork route GET /api/fork/task-prompts?threadId=… (fork/remoteTaskPrompts.ts), on every machine, link token only (a browser session or client token gets 404). For one of its threads it returns the open questions (requestId, runId), the open approval (the same shape as a local child's pendingApproval) and any open secret requests, with label and reason only, never a value.
  • task_status, delegate_task and their waits read that route over the existing link (PeerLinks + HttpClient) through a new fork seat, delegateChecks.remotePrompts. That seat is one spread line in upstream's remote read. A linked child now reports hasPendingQuestion and pendingApproval exactly as a local child does, and next names the requestId and the child's environmentId/threadId.
  • Unknown is never "not waiting": if the link is down, the machine can't be reached within 10 s, the link was forgotten, or the machine runs an older version without the route, the report keeps false/null (the contract has no other value) and next says plainly that it is unknown and why.
  • Wake (fork/remoteTaskPromptWakes.ts): a watcher reads the open linked tasks every 5 s and wakes the parent once per new prompt, the same way upstream's DelegatedTaskQuestionReactor wakes it for a local child's question:
    • If a blocking wait is live, it ends it (a wake-policy change).
    • Otherwise it queues one message.dispatch carrying a delegated_task notification, through the slot gate.
    • Command ids are fixed per parent, machine and prompt, so a re-read or a restarted parent sends no second wake.
    • A prompt answered on the child's machine before the parent took the wake cancels the queued wake.
    • An unknown read changes nothing: no wake, no cancel.

What the contract is missing (not added here)

OrchestratorMcpDelegateTaskResult (packages/contracts/src/orchestratorMcp.ts, an upstream file) has:

  • no field for a pending secret request, and
  • no "unknown" state for hasPendingQuestion/pendingApproval.

Both are therefore reported in next. Real fields would need the seam steps on that file. One effect: a blocking wait does not end on a secret request alone, because upstream's endsTaskWait only sees the question and approval fields. The watcher's wake still reaches the parent.

Upstream file

apps/server/src/mcp/OrchestratorMcpService.ts is a pending file, which may not gain a fork line. The spread line is the only new one. The // Fork: comment about Effect.scoped moves from its own line onto the line it explains, which was already a fork line. The file stays at 35 fork lines and the // Fork: marker count stays 6.

Tests

All new tests are in apps/server/src/fork/.

  • remoteTaskStatus.test.ts runs upstream's real OrchestratorMcpService with a fake machine on the far end. It covers:
    • a question, an approval and a secret (label and reason only);
    • link down, an older machine and a forgotten link, each reading as unknown and never as "not waiting";
    • a prompt answered there (the report clears, and a second read gives the same answer);
    • a restarted parent (the same answer);
    • an ended task (asks nothing);
    • delegate_task wait: a question ends the wait at once, and a later question ends it on the task's wake.
  • remoteTaskPromptWakes.test.ts (the watcher) checks:
    • one wake per question however often it is read, with exactly one command sent;
    • a restart sends no second wake;
    • answered there: the queued wake is cancelled and a new question gets a new wake;
    • unknown reads (unreachable, older, unlinked) and a missing thread there wake no one and clear nothing;
    • an approval and a secret each wake once;
    • a task that ended has its queued wake cancelled;
    • a blocking wait is ended instead of sending a message, also after a restart;
    • a refused wake-policy change falls back to a message.
  • remoteTaskPrompts.test.ts checks the route (real router):
    • the waiting thread's prompts, with no secret value in the body;
    • missing or archived threads give found: false;
    • an unreadable thread gives a 503, read as unknown;
    • browser, client token or no token gets 404;
    • the reader: unlinked, unreachable, timeout, an older app page or bad JSON each read as unknown.
  • delegateChecks.test.ts pins the new seat in the remote read.

Fails on the old code / red checks:

  • Put back the hardcoded false/null (drop the spread line): 9 of 11 tests in remoteTaskStatus.test.ts fail, including "reports its pending question, as a local task's (fails with the fixed false/null)".
  • Each guard in the watcher fails a named test when removed:
    • the per-prompt dedupe fails "is woken once for a question, however often it is read";
    • the wait-receipt check fails "a blocking wait is ended instead: no message, also after a restart";
    • the cancel on answer fails "answered there: its queued wake is cancelled…";
    • the found check fails "a thread there that is gone wakes no one and clears nothing either";
    • the ended-task check fails "a task that ended asks nothing there…".
  • The route's 503 for an unreadable thread failed before the fix.

Checks run: 211 tests pass in the changed files plus the OrchestratorMcpService test files. Also clean: typecheck, vp fmt --check, lint and knip, fork-seam-check.cjs --config-ref origin/main origin/main HEAD, fork-seam-check.cjs --from-upstream and fork-seam-check.test.cjs.

General vs project

General. Any T3 user who delegates to a linked machine gets the report and the wake. There are no project facts, and nothing is configured per project.

Upstream fit

Upstream issue 26527 describes this bug. Its fix PR 26344 was closed unmerged, and no open fix PR exists. That PR added a link-only tool (t3_link_requests) and a projection field. This change keeps upstream's existing result fields and contract unchanged, and adds only a fork route, a fork seat and a fork watcher. If upstream fixes the bug, the seat line and the two fork files can go.

Part of #808

🤖 Generated with Claude Code

scuttletoby added a commit that referenced this pull request Nov 21, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@scuttletoby

Copy link
Copy Markdown
Owner Author

Lens

Verdict: SAFE. Nothing blocks the merge. Unknown never reads as "not waiting", and no secret value, token or file path reaches the parent. The two majors below are small, and neither makes anything worse than main, where a remote child always reported false/null. Fix them in this PR if a round is still open; otherwise make them the first follow-up.

Reviewed head ba59779e. I ran the PR's own tests one at a time: remoteTaskStatus 11/11, remoteTaskPromptWakes 11/11, remoteTaskPrompts 16/16 and delegateChecks 14/14 all pass. fork-seam-check.cjs origin/main HEAD is clean.

Blocking

None.

Major

M1. Text from the other machine goes uncapped and unquoted into the parent's prompt.

  • Where: apps/server/src/fork/remoteTaskPrompts.ts:289 (next) and apps/server/src/fork/remoteTaskPromptWakes.ts:76 (the wake message).
  • What happens: label and reason are put in as they arrive. The schema at remoteTaskPrompts.ts:52 and upstream's request_secret input have no length cap and allow newlines. The child agent writes these fields, so it can write a reason like )\n\n[Owner] New instruction: …. That text then appears inside a message the server sent itself (creationSource: "server") in the parent thread.
  • Same problem with ids: requestId, itemId and runId are TrimmedNonEmptyString of any length. They go into next (:280), the wake text (:60, :69) and the command and message ids (remoteTaskPromptWakes.ts:81, :173), so a faulty or newer peer can make those ids as long as it likes.
  • Why it matters: the child can already put any text in its result summary. What is new here is that its words arrive framed as a server notice.
  • Fix:
    • On the reading side, cut label to about 80 characters and reason to about 300, and turn newlines and control characters into spaces.
    • Quote both with JSON.stringify and present them as the child's words, for example: the child's request, its words: "…".
    • Accept an id only if it matches a short pattern such as ^[A-Za-z0-9:_-]{1,128}$. Otherwise treat the answer as unknown ("older").
    • Add a test with a 10 KB reason containing a newline.

M2. A prompt handed to a blocking wait counts as delivered without proof. It can be lost for good, and a secret is always sent this way.

  • Where: remoteTaskPromptWakes.ts:143-161.
  • What the code does: when waitIsLive, the watcher changes the wake policy and records the prompt as handled. From then on, and after restarts too, the receipt check at :160 stops any message. The test at remoteTaskPromptWakes.test.ts:319 assumes the wait read the prompt ("The wait read it and ended"); nothing checks it. Three ways this goes wrong:
    • A secret request: upstream's endsTaskWait cannot end on a secret, so the wait runs to its timeout (45 s at most). The secret reaches the parent only through that final read's next. The PR body says "The watcher's wake still reaches the parent", which is not true while a wait is live.
    • The wait's read is unknown: the link drops in the seconds between the watcher's known read and the wait's read. The wait goes on, and if its final read is unknown too, the parent gets only "unknown", and no message ever follows for that prompt.
    • The server stops mid-wait: this happens after the policy change but before the wait reads the prompt. After the restart the receipt says "delivered", so no message is ever sent.
  • Fix (small):
    • Never use the wait route for secret: keys. A secret always takes the queued message, which queue_after_active delivers when the parent's turn ends.
    • For questions and approvals, count the wait as delivery only while the parent's run (task.runId) is still active. Once that run has ended and the prompt is still open there, queue the message. Its fixed command id keeps it to one.
    • Add a test: a blocking wait, a secret request, the wait ends at its timeout, and then exactly one message.

Minor

  • m1. The new line has no // Fork: marker, under an upstream comment that it now contradicts. apps/server/src/mcp/OrchestratorMcpService.ts:2129 sits directly below :2126 ("Its questions and approvals are answered in the environment it runs in."). Whoever rebases sees an unmarked line in upstream code, under a comment that says the opposite. Add // Fork: fork/remoteTaskPrompts.ts at the end of that line; it stays one line. Leave the upstream comment as it is, because editing it would lose an upstream line.
  • m2. Every remote wait that the watcher ends logs a false warning. Upstream's upgradeWake (OrchestratorMcpService.ts:2017 / :2027) runs when the wait exits. The decider then refuses an unchanged policy (Orchestrator.ts:10595, "already wakes the parent with completionWake always"), so it logs wake-policy-failed. This is noise only. Note it in the code, or have the watcher go through a fork seat that upstream's exit path recognises.
  • m3. The watcher takes a slot before checking whether the message was already sent. remoteTaskPromptWakes.ts:162: after a restart, every prompt that is still open calls admitSend. That takes a slot and counts it as started into the parent, although the message.dispatch that follows is a duplicate and starts nothing. Check receipts.getByCommandId(WAKE_COMMAND+id) before admitSend.
  • m4. One unreachable machine slows the watcher for every other task. remoteTaskPromptWakes.ts:237 reads tasks one after another, and each read can take up to 10 s. With N open tasks on a machine that is down, one round takes about 10·N s, and wakes for tasks on reachable machines wait behind it. Read with a small concurrency, or skip a machine for the rest of the round after its first "unreachable".
  • m5. A 404 always reads as "older". remoteTaskPrompts.ts:191: a new machine that no longer accepts this link's token also answers 404 (on purpose, :121), so next says it "runs a T3 Code version that does not report it". Say "runs an older version or no longer accepts this link".
  • m6. task_cancel now waits for the remote read. OrchestratorMcpService.ts:2939 calls readTask first, so cancelling a remote task whose machine is down waits up to 10 s before the cancel goes out. This does no harm.

State question

  • Runs again:
    • Re-reads: the per-prompt keys and the fixed command ids give one wake per prompt.
    • A parent restart: no second message (the dispatch is deduplicated by its id; only the slot taken first is extra, m3).
    • The same prompt reaching the parent by two routes (wait and message): the receipt check stops the second, but see M2 for when that is wrong.
  • Stops half-way:
    • Wake queued, then the prompt answered there: the queued wake is cancelled.
    • The task ended: its queued wakes are cancelled.
    • The link drops mid-read: unknown, so nothing is woken or cleared.
    • Parent thread deleted: its entry is dropped once, and a failed cancel is only logged.
    • The gap: a stop between the policy change and the wait's read (M2).
  • Old or empty state:
    • An older peer: 404 or an HTML 200, read as "older", so unknown.
    • No link, or the server runs without PeerLinks/HttpClient: "unlinked", so unknown.
    • A child created before this change: it has remoteChild, so it is read normally.
    • A thread there that is archived or deleted: found: false, so unknown ("gone"), never "not waiting".
  • Bounds: the handled map loses entries once their task is no longer open. Polling is one read per open remote task every 5 s plus the read time, with each read limited to 10 s. I found no wake loop.

Unknown is never "not waiting"

Checked every caller of hasPendingQuestion/pendingApproval: only upstream's OrchestratorMcpService.ts (and tests) read them.

  • endsTaskWait treats an unknown read as "keep waiting", and the result at the timeout carries the unknown next.
  • wait_for has no task kind.
  • t3_thread_wait and task_list do not read these fields.
  • The orchestrator's done check goes through task_status and so sees the same next.
  • A defect inside the read (as opposed to a failure) would fail task_status with an error rather than report false. That is acceptable.

Seam

Folding the Effect.scoped // Fork: comment onto }, Effect.scoped), is within the rule's letter and its intent. It is not a dodge.

  • }, Effect.scoped), was already a fork line: upstream has no Effect.scoped there. The comment line was a fork line on its own.
  • The PR swaps one fork line for one fork line, which docs/fork/updates.md allows by name: "main's ceiling, plus the lines it adds, less the lines it removes".
  • The file's fork footprint and the places a rebase can conflict stay the same.
  • The new line is a one-call seat into a fork file, the shape the rule asks for.

Refusing such swaps would need the checker to understand code, and it would also block real clean-ups, so I filed no issue. If the owner wants pending files to only ever shrink, the route is the documented two-step one: a list-only PR that moves the file to files with all its lines listed and announces the new line, then this PR. m1 above is the part of the intent this PR does miss: the new line carries no marker.

Missing contract fields

Reporting a secret request and "unknown" only in next is acceptable for now. A wait lasts at most 45 s, its final result carries next, and after M2 a secret also reaches the parent as a message.

Follow-up, one issue: a seam PR on packages/contracts/src/orchestratorMcp.ts. It would add two optional fields to OrchestratorMcpDelegateTaskResult:

  • pendingSecretRequests (itemId, label and reason, capped as in M1), and
  • promptsKnown: false or similar, for unknown.

It would also add a fork seat in endsTaskWait, so that a secret ends a wait. Once that lands, the wait route in M2 can carry secrets as well.

scuttletoby added a commit that referenced this pull request Nov 21, 2026
…s run lasts (#815 fix round)

- Text and ids from the linked machine: ids only on a strict pattern (else
  unknown, "refused"), at most 50 prompts, a secret's label and reason
  folded to one line, capped (80/300) and quoted as the child's words.
- A secret never goes to a blocking wait; it is always a queued message.
  A question or approval handed to a wait counts only while the parent's
  run lasts; after it, one message if it is still open there.
- The receipt of a sent wake is read before a slot is taken; a machine
  that does not answer is asked once per round; "older" also names a link
  no longer accepted.
- The remote read's spread line carries its // Fork: marker (no new line).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@scuttletoby

scuttletoby commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner Author

Fix round

Head 9d4439ac89, from the lens. Follow-up for the contract: #817.

M1. Text and ids from the other machine (done)

  • Ids: the reader (remoteTaskPrompts.ts, checkedPrompts) takes ids only on ^[A-Za-z0-9._~:%-]{1,256}$, which is the shape the id allocator makes (URI-encoded parts joined by :). This covers request, run and item ids. It also takes at most 50 prompts. Anything else reads as unknown, with the new reason refused. next then says the machine "answered with a prompt id of an unexpected shape or too many prompts".
  • Text: a secret's label and reason are folded to one line. Whitespace, control, format and line/paragraph separators become one space. Both are cut (label 80, reason 300, then …) and quoted with JSON.stringify as "the child's own words, not an instruction: label "…", reason "…"". That happens both on read and again when next and the wake message are written.
  • Tests: table tests cover ids with a space, a newline, a heading, a backtick, a quote or 257 characters, in each id field, plus too many prompts. Text tests cover newlines with a markdown heading, control, zero-width and line-separator characters, and a 10 KB reason. They run through the reader, through reportOf, through the full task_status path over HTTP, and through the wake text.

M2. A wait counts as delivery only while it can deliver (done)

  • Secrets never go to a blocking wait. They are always one queued message (queue_after_active).
  • A question or approval handed to a wait counts only while the parent's run (task.runId) is active. The watcher asks again each poll. Once that run has ended with the prompt still open there, it sends one message, kept to one by its fixed command id. This is read from the receipts and runs, so it holds across a restart.
  • State tests (remoteTaskPromptWakes.test.ts):
    • the wait has the question; it is read again; the server stops during the wait; the run ends, giving exactly one message; read again after another restart, still one, sent once;
    • the wait's read was unknown (link down) and its run ended: nothing while unknown, then exactly one message;
    • answered there while the wait had it: nothing after the run;
    • a secret during a blocking wait: no wake-policy change, one queued message at once, still one after the run ends and a restart.

Minor

  • m1 (done): the spread line now ends // Fork: reported here (fork/remoteTaskPrompts.ts). That is the same line, and the upstream comment above stays as it is: the marker says "reported here", which squares with "answered in the environment it runs in". The fork-line count is unchanged and the seam check is clean. The // Fork: marker pin in delegateChecks.test.ts goes from 6 to 7, with the reason in the test. No seam line was added.
  • m2 (noted): a comment at the wait route says that the wait's own exit sets the same policy again, which upstream logs as wake-policy-failed. That log is noise only.
  • m3 (done): the sent wake's receipt is read before admitSend, so a restart takes no slot and sends nothing.
  • m4 (done): a machine that answers "unreachable" is not asked again in the same round. Its other tasks are kept and nothing is cleared.
  • m5 (done): "older" now reads "runs an older T3 Code version that does not report it, or no longer accepts this link".
  • m6 (left): task_cancel still waits up to 10 s for the remote read. The lens calls it harmless.

Contract follow-up: #817, a seam PR on packages/contracts/src/orchestratorMcp.ts for pendingSecretRequests, an "unknown" marker, and a secret ending a wait.

Checks

  • Old code: 27 of the 75 tests in the four changed test files fail against the old fork files.
  • Each fix line, removed: a named test fails each time (12 of 12):
    • id pattern: 11 tests;
    • prompt cap: 1;
    • fold on read: 3;
    • refused-as-unknown: 15;
    • JSON quoting: 1;
    • fold when quoting: 2;
    • secret not to a wait: 1;
    • wait only while its run lasts: 2;
    • wait not counted as sent: 1;
    • m3 receipt check: 2;
    • m4 skip: 1;
    • m1 marker: 1.
  • Clean: 241 tests across the changed files and the OrchestratorMcpService test files; typecheck (apps/server); vp fmt --check; lint on the changed files; knip; fork-seam-check.cjs --config-ref origin/main origin/main HEAD; fork-seam-check.test.cjs.

scuttletoby and others added 3 commits November 21, 2026 20:09
A delegated task on a linked machine always reported
hasPendingQuestion false and pendingApproval null, so its parent never
learned the child was waiting.

- New fork route GET /api/fork/task-prompts on each machine: the open
  questions, approval and secret requests (label and reason only, never
  a value) of one of its threads. Link token only.
- task_status, delegate_task and their waits read it over the existing
  link through the fork seat remotePrompts (one spread line in the
  remote read). An unreachable or older machine reads as unknown in
  next, never as "not waiting".
- A watcher wakes the parent once per prompt, the way a local child's
  question does: it ends a blocking wait if there is one, else it queues
  one wake message, and cancels that message if the prompt is answered
  there first. Wake ids are fixed, so a restart sends no second wake.
- OrchestratorMcpService.ts is a pending file and may not gain a fork
  line: the Effect.scoped comment moves onto the (already fork) line it
  explains, which frees the line the seat takes. Still 35 fork lines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s run lasts (#815 fix round)

- Text and ids from the linked machine: ids only on a strict pattern (else
  unknown, "refused"), at most 50 prompts, a secret's label and reason
  folded to one line, capped (80/300) and quoted as the child's words.
- A secret never goes to a blocking wait; it is always a queued message.
  A question or approval handed to a wait counts only while the parent's
  run lasts; after it, one message if it is still open there.
- The receipt of a sent wake is read before a slot is taken; a machine
  that does not answer is asked once per round; "older" also names a link
  no longer accepted.
- The remote read's spread line carries its // Fork: marker (no new line).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@scuttletoby
scuttletoby force-pushed the fork/808-remote-pending branch from 9d4439a to ede78af Compare November 21, 2026 20:09
@scuttletoby
scuttletoby merged commit 102e23a into main Nov 21, 2026
38 checks passed
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