Skip to content

feat(orchestration): answer workers' permission prompts from the coordinator (re-land with fixes) - #41259

Merged
Jinwoo-H merged 11 commits into
mainfrom
jinwoo/worker-approval-reland
Nov 12, 2026
Merged

Jinwoo-H merged 11 commits into
mainfrom
jinwoo/worker-approval-reland

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Why

#40756 let the person answer a worker's permission prompt from the coordinator chat. It's being reverted in #41245 after the first real use went wrong:

  • An Allow that worked was reported as "Closed without an answer Orca can name". Claude took the Allow (its transcript records hook_permission_decision: allow for that call), ran the command, and the command failed with exit 1. Orca credited an allow only when the tool's result was not an error, so it decided the prompt had closed some other way. The card said "No longer open" and the toast said the prompt was no longer open.
  • Cards and receipts sat at the bottom of the chat, below every newer reply, instead of at the time the worker asked.
  • Claude's reason ("Dangerous rm operation not ruled out…") was missing from the card.
  • Closing messages said reasonDelivered: true when there was no reason.

This PR re-lands #40756 with those fixed. Until #41245 merges, the branch carries a copy of the revert so the diff below shows only the fixes; after it merges, this rebases onto it.

What the person sees now

  • Open worker prompts are pinned just above the composer, oldest first, and above the chat's own prompt when it has one. They don't take focus or block typing. Several scroll inside a bounded stack. The "N approvals · Show" strip is gone.
  • Once a prompt is answered, auto-denied or closed, its card leaves the stack and becomes a compact receipt in the transcript at the time the worker asked, with newer replies after it.
  • Allow on the card → "Allowed by you · 3:11 PM", whether the command then succeeds, fails, or is still running. A landed Allow or Deny shows no toast: the receipt says it. A toast appears only when the click could not be applied.
  • A prompt whose worker has ended closes: if the worker's Dispatch stops running (worker_done, stop, abandon, exit, failure, restart), its card becomes "No longer open · worker ended". If a click still races the end, the card turns into that receipt immediately, with an info toast ("worker-name has ended, so this prompt is closed"), not an error.
  • Expiry looks different from an answer: "Auto-denied by Claude after 2:00" is the only expiry. A close Orca can't name reads "Closed without a recorded answer".
  • The card shows Claude's warning as its Reason line.

Final-review changes

  • After a click the card waits on the host. Both buttons turn off and the clicked one shows a spinner until the answer returns (about 0.5 s, most of it Claude recording the decision). Then the host's list turns the card into its receipt. There is no client-side close: if the answer wasn't applied, a toast says so and the host's list decides. A prompt that closed meanwhile becomes its receipt; one still open is answerable again.
  • Outcome where the card was: a prompt that closes while it's shown stays pinned as its receipt for 4 s before it moves to its place in the transcript. One that only the worker's terminal can answer stays pinned.
  • Receipts are history: they no longer drop out after 30 minutes. They're bounded by 100 rows, with still-open prompts kept first, and they come back after a restart.
  • The pinned stack is capped at 40% of the pane and is the first to give way, so the chat's own prompt card keeps its buttons in a short pane (fixture twoOpenWithOwnPromptShort).
  • The stream ignores terminal identity in main too. It watches only the orchestration database's own changes (Runs, Dispatches, mail). Count (worker-approval-stream-wakes.test.ts): 50 terminal-identity notices, which is what every agent status or tab title change sends, cause 0 reads (the earlier wiring did one per notice). A new Run for the chat causes 1.
  • A close no one named, after the worker's Dispatch ended, reads as worker-ended. An unanswered close for an ended worker sends the coordinator no second notice.

Performance

The first version followed the whole crew stream (orchestration.crewSubscribe) from every local native chat, hidden tabs included, to find approvals. That turned back on the crew producer that #37527 and #38045 had switched off for lag. Every agent status change cost one crew read, buildCrewSnapshot and JSON.stringify per open chat in main, plus IPC frames, and it redrew the whole chat pane.

Now:

  • A narrow orchestration.workerApprovalsSubscribe stream per chat party carries only approval rows. It wakes on mail addressed to that party's own mailboxes (itself and its Runs) and on Run/Dispatch changes, never on agent status. It reads the crew (for worker names) only when the approval list itself changed.
  • The pane doesn't hold the approvals. The transcript receipts and the pinned stack each subscribe to the shared per-party feed, so only they redraw.
  • The countdown ticks once a second only for open cards in a visible pane. A hidden coordinator tab still gets its cards: the stream isn't parked while hidden.

Measured in an isolated dev Orca. Five native chats were open, one of them a coordinator with a terminal worker. Each run sent three one-word prompts to the worker, which gave 18 agent transitions. Counters were added temporarily (not in this PR) around buildCrewSnapshot, the crew stream's publish, the renderer's stream frames and the chat pane's render.

Per agent transition Before (29e56c2) After
Crew snapshot builds (main) 10.0 0.06 (one build, when an approval receipt aged out)
Crew stream publishes (main) 0.33 0
IPC frames to the renderer (crew + approvals streams) 1.0 0
Chat pane renders 0.67 0
Approvals SQL reads (main) n/a (inside each crew build) 1.3, coordinator only, on its own Run mail

Every chat also runs one indexed runs lookup by session id, under 1 ms, when a Run or Dispatch changes. On a synthetic 20k-message Run mailbox, the approvals read costs about 4–7 ms CPU. That's why "routing moved" notices without addresses don't trigger it: Orca's approval reports are always inserted with an address.

What changes

  • Who answered comes from Claude's own record. The transcript reader returns the hook decision Claude recorded for that tool call, plus its result. An answer is Orca's when Claude recorded the same decision. For an older Claude that records no decision, it falls back to the result: after an allow, anything except the person's No or the auto-block counts, because a failed command records an error too.
  • PostToolUseFailure counts as "ran", so a Yes typed in the terminal on a failing command closes as "Allowed in the worker's terminal".
  • closedApproval (now in shared, used by main and renderer): state expired only for by: auto; reasonDelivered is false whenever there is no reason.
  • New outcome worker-ended. The approvals read treats an open approval whose Dispatch is no longer pending/dispatched as closed by worker-ended, at the time the Dispatch ended. It does the same for a terminal-only close, since no terminal is left to answer in. A terminal hook that hangs up after its worker's process is gone now closes as worker-ended, not "answer it in the terminal". The coordinator's closing line reads "Closed because its worker ended".
  • Escalation timing: the terminal escalation waits (up to 3 s) for Claude's dialog to paint before reading its countdown and warning. A stop owes a closing line only to an approval whose escalation actually went out.
  • Placement: receipts are timedRows in the message list, drawn after the newest message at or before the ask time. Open cards are NativeChatWorkerApprovalStack above the composer (NativeChatApprovalCard placement="stacked").

Testing

  • Unit:
    • terminal-worker-approval-holds.test.ts, one per outcome: allowed and the command succeeds, fails, or is still running; allowed on a Claude without a decision record; the person's No wins the race; a terminal Yes on a failing command; auto-block; hook gone with the dialog up; worker stopped at the prompt → worker-ended; no closing line for an escalation that never went out.
    • crew-worker-approvals.test.ts: an open approval reads as worker-ended once its Dispatch completes.
    • worker-approval-stream.test.ts: a prompt mailed to a Run the chat started coordinating after it subscribed still arrives.
    • NativeChatWorkerApprovals.test.tsx: after a click both buttons are off and the clicked one shows a spinner until the answer returns; no toast when it lands; an answer that wasn't applied leaves the card answerable for the host list to decide.
    • native-chat-worker-approval-feed.test.ts: a prompt that closes while shown stays pinned as its receipt for 4 s, then moves to the transcript; the transcript's receipt list keeps one array while only pinned prompts change; a terminal-only prompt stays pinned.
    • worker-approval-stream-wakes.test.ts: 50 terminal-identity notices → 0 reads; a new Run for the chat → 1.
  • Fixtures (native-chat/worker-approvals/NativeChatWorkerApprovals, light and dark): oneOpen, twoOpen, openWithOwnPrompt, receiptInPlace and answered.
  • Rig e2e in my own isolated dev Orca. Positions were checked from DOM rects, not text: every open card's bottom (855) is above the composer's top (870).
    • A Claude terminal worker's Allow on a command that exits 3 → "Allowed by you" in place, no toast. The worker reported exit 3. A newer coordinator reply typed while the card was open lands after the receipt.
    • Hidden coordinator tab: the worker started while another chat tab was active. Its card mounted in the hidden pane, with its countdown frozen. On switching back it showed pinned above the composer with live time, and was allowed from there.
    • Worker stopped while its card was open (worker-stop): the card closed to "No longer open · worker ended", and the stored closing line is by: worker-ended.
    • Deny → "Denied by you" in place.
Files Added Deleted Net
Test 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​641 $\color{#cf222e}{\Huge{\mathbf{−}}}$​35 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​606
Prod 32 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1162 $\color{#cf222e}{\Huge{\mathbf{−}}}$​426 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​736

@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review
Walkthrough

The change updates terminal approval handling to read hook decisions with tool results and revises how approval closures are classified. Approval records now include an optional ask timestamp. The chat interface uses that timestamp to place approval cards and receipts among transcript messages. Terminal stop reporting now awaits approval lookup and rechecks the worker state before sending a report.

Merge Risk: Low · previous review bcdea

Worker approval prompts can occasionally show a receipt in the wrong place, be missing a receipt, or fail to appear after a transient read error. A rare race can also send a closing note for a prompt the coordinator never saw. These problems are bounded and not severe, but they are worth fixing before or soon after merge.

Pre-merge checks: Passed 3 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Description check Warning The description follows the template's main sections (Why, What changes, Testing, Performance, Visual Proof-style fixtures and rig e2e results) and explains the mechanism, the before/after user experi… Add a linked issue using 'Fixes #' (an actual issue, not a PR reference). Add an ELI5 section in plain language. Add before and after screenshots or videos for the UI changes in the Visual Proof section. Fill in the Risk section with…
Passed Passed checks: 3 passed

Check name Status Explanation
Title check Passed The title names the feature (letting the coordinator answer workers' permission prompts) and the re-land context, which matches the main change in the changeset. It is a single, specific sentence, and…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the feature (letting the coordinator answer workers' permission prompts) and the re-land context, which matches the main change in the changeset. It is a single, specific sentence, and the 'feat(orchestration)' scope is accurate. It is long (97 characters) and the parenthetical 're-land with fixes' is process detail, but the primary change is clear.

Full details: Description check

Explanation

The description follows the template's main sections (Why, What changes, Testing, Performance, Visual Proof-style fixtures and rig e2e results) and explains the mechanism, the before/after user experience, and measured performance data. It is missing a Linked Issue: the template requires 'Fixes #' with an actual issue link, and the description gives only PR references (#40756, #41245), which the template does not accept. The template's ELI5, Risk level, Visual Proof (before/after screenshots or video, or N/A with reason), AI Disclosure, Review, Agent skill upstream boundary checkbox, and the checklist are not filled in. The Risk section lacks a level and a rollback description. The Testing checkboxes are unchecked, and the Visual Proof section gives fixture names and rig results but no before/after attachments despite the UI changes.

Resolution

Add a linked issue using 'Fixes #<issue>' (an actual issue, not a PR reference). Add an ELI5 section in plain language. Add before and after screenshots or videos for the UI changes in the Visual Proof section. Fill in the Risk section with a level (Low, Medium, or High), the riskiest part, affected users or boundaries (saved data, older Claude versions, SSH), and how to back it out. Fill in the Review and Agent skill upstream boundary sections. Check the Testing checkboxes that apply, or state why they do not apply. Complete the Checklist items, including the pnpm lint, typecheck, test, and build status.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Additional comments: 1

src/renderer/src/components/native-chat/conversation/slots/native-chat-timed-rows.ts-32-32: 1

32-32: Minor · Functional Correctness · Heavy lift

Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Place rows before later messages when no earlier message is loaded.

If loaded messages occur at 10:00 and 10:05 and an approval was asked at 09:59, anchor is absent. This branch puts the approval after the 10:05 message, not before the loaded conversation. That case can persist when older history is unavailable. Add a before-first placement for rows earlier than every dated loaded message; retain an end fallback for rows whose time cannot be determined.

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 50dcf8d4-b146-400c-8ca5-2a0d8fddf920
Commits

Reviewing files that changed from the base of the PR and between 1708f1c and 99a0c17.

Files selected for processing: 23

  • src/main/runtime/construction/orca-runtime-agent-transitions.ts
  • src/main/runtime/orchestration/crew/crew-query.ts
  • src/main/runtime/orchestration/workers/approvals/claude-tool-result-close.test.ts
  • src/main/runtime/orchestration/workers/approvals/claude-tool-result-close.ts
  • src/main/runtime/orchestration/workers/approvals/terminal-worker-approval-hold.ts
  • src/main/runtime/orchestration/workers/approvals/terminal-worker-approval-holds.test.ts
  • src/main/runtime/orchestration/workers/approvals/terminal-worker-approval-holds.ts
  • src/main/runtime/orchestration/workers/approvals/worker-approval.ts
  • src/main/runtime/orchestration/workers/turn-stops/terminal-worker-turn-stops.ts
  • src/main/runtime/orchestration/workers/turn-stops/worker-turn-stops.test.ts
  • src/main/runtime/terminal/wait/claude-open-dialog-hold.ts
  • src/renderer/src/components/native-chat/NativeChatMessageList.tsx
  • src/renderer/src/components/native-chat/NativeChatStructuredSession.tsx
  • src/renderer/src/components/native-chat/conversation/slots/NativeChatMessageList.timed-rows.test.tsx
  • src/renderer/src/components/native-chat/conversation/slots/native-chat-timed-rows.ts
  • src/renderer/src/components/native-chat/conversation/slots/use-native-chat-transcript-row-context.ts
  • src/renderer/src/components/native-chat/messages/rows/NativeChatTranscriptRow.tsx
  • src/renderer/src/components/native-chat/viewport/virtualization/NativeChatTranscriptItems.tsx
  • src/renderer/src/components/native-chat/worker-approvals/NativeChatWorkerApprovals.fixture.tsx
  • src/renderer/src/components/native-chat/worker-approvals/NativeChatWorkerApprovals.tsx
  • src/renderer/src/components/native-chat/worker-approvals/worker-approval-card-model.ts
  • src/renderer/src/i18n/locales/en.json
  • src/shared/orchestration/orchestration-crew.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

// One report per approval; the screen shows Claude's own reason for asking.
const approval =
reason === 'needs-input' && before?.target.kind === 'local'
? await this.deps.takeOpenApproval(stop.paneKey, before.target.dispatch.id)

@coderabbitai coderabbitai Bot Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Major · Data Integrity & Integration · Heavy lift

Mark the approval reported only when its opening report is sent.

takeOpenApproval sets hold.reported before this await resumes. If the worker resumes before the final stillStopped check, this function sends no opening report. A concurrent or later hold closure can nevertheless send a closing report because hold.reported is true. Keep the reported state tied to a successful opening report, so the coordinator cannot receive a closure for a card it never received.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 6823ab6. takeOpenApproval now takes a reporting() check that it reads after the dialog wait, right before it marks the hold reported. The caller passes () => this.stillStopped(stop) !== null, and the opening report follows synchronously. A worker that resumed during the wait gets no opening report and is not marked reported, so it owes no closing line. Test: 'owes no closing line to a prompt whose escalation never went out'.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Analysis chain

Script executed:

#!/bin/bash
set -uo pipefail
for f in \
  src/main/runtime/orchestration/workers/approvals/terminal-worker-approval-holds.ts \
  src/main/runtime/orchestration/workers/approvals/terminal-worker-approval-holds.test.ts \
  src/main/runtime/orchestration/workers/turn-stops/terminal-worker-turn-stops.ts \
  src/main/runtime/orchestration/workers/turn-stops/worker-turn-stop-report.ts; do
  echo "===== $f outline ====="
  ast-grep outline "$f" --items all
done
echo '===== relevant references ====='
rg -n -C 7 'takeOpenApproval|hold\.reported|owes no closing line|reportWorkerTurnStop\(' \
  src/main/runtime/orchestration/workers/approvals/terminal-worker-approval-holds.ts \
  src/main/runtime/orchestration/workers/approvals/terminal-worker-approval-holds.test.ts \
  src/main/runtime/orchestration/workers/turn-stops/terminal-worker-turn-stops.ts \
  src/main/runtime/orchestration/workers/turn-stops/worker-turn-stop-report.ts

Length of output: 31027


Script executed:

#!/bin/bash
set -uo pipefail
echo '===== hold lifecycle ====='
cat -n src/main/runtime/orchestration/workers/approvals/terminal-worker-approval-holds.ts | sed -n '45,140p;145,167p;205,315p'
echo '===== report admission ====='
cat -n src/main/runtime/orchestration/workers/turn-stops/worker-turn-stop-report.ts | sed -n '176,270p;312,360p'
echo '===== forwarding and callers ====='
rg -n -C 5 'takeOpenApproval\s*[:(]' src/main/runtime/construction/orca-runtime-agent-transitions.ts src/main/runtime/orchestration/workers

Length of output: 28787


@Jinwoo-H Thanks for the fix. It covers a worker that resumes during the dialog wait, but the original race can still occur.

takeOpenApproval sets hold.reported before its promise resolves. A queued microtask can run before report resumes from the await. If the worker resumes in that interval, the final stillStopped check can suppress the opening report while the hold still owes a closing report.

Also, reportWorkerTurnStop can return without sending when isWaitingForMail is true. The cited test covers a false reporting check, but not these cases.

Please tie hold.reported to a successful opening report and add tests for the await interleaving and a suppressed report. I’m not marking this finding as addressed.


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

You are interacting with an AI system.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Nitpick comments: 1

src/main/runtime/orchestration/crew/crew-worker-approvals.test.ts: 1

111-112: Trivial · Maintainability & Code Quality · Quick win

Assert both timestamps in the dispatch-end test.

This test checks the closed payload but not its at or askedAt values. Assert that at matches the Dispatch completion and that askedAt matches the original escalation. Those values determine where the receipt appears in the chat transcript. (raw.githubusercontent.com)

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5b1fed16-8c6c-4030-86f4-6f349164117a
Commits

Reviewing files that changed from the base of the PR and between 29e56c2 and 6823ab6.

Files ignored due to path filters: 1

  • src/shared/rpc-contract/rpc-params-catalog.generated.ts is excluded by !**/*.generated.*
Files selected for processing: 26

  • src/main/runtime/construction/orca-runtime-agent-transitions.ts
  • src/main/runtime/orchestration/crew/crew-query.ts
  • src/main/runtime/orchestration/crew/crew-source-inputs.ts
  • src/main/runtime/orchestration/crew/crew-worker-approvals.test.ts
  • src/main/runtime/orchestration/crew/worker-approval-stream.test.ts
  • src/main/runtime/orchestration/crew/worker-approval-stream.ts
  • src/main/runtime/orchestration/workers/approvals/terminal-worker-approval-holds.test.ts
  • src/main/runtime/orchestration/workers/approvals/terminal-worker-approval-holds.ts
  • src/main/runtime/orchestration/workers/approvals/worker-approval-report.ts
  • src/main/runtime/orchestration/workers/approvals/worker-approval.ts
  • src/main/runtime/orchestration/workers/turn-stops/terminal-worker-turn-stops.ts
  • src/main/runtime/orchestration/workers/turn-stops/worker-turn-stop-report.ts
  • src/main/runtime/rpc/methods/orchestration/crew-methods.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-approval-answer.ts
  • src/main/runtime/workspaces/persisted-surfaces/crew-operations.ts
  • src/renderer/src/components/native-chat/NativeChatStructuredSession.tsx
  • src/renderer/src/components/native-chat/prompts/NativeChatApprovalCard.tsx
  • src/renderer/src/components/native-chat/worker-approvals/NativeChatWorkerApprovals.fixture.tsx
  • src/renderer/src/components/native-chat/worker-approvals/NativeChatWorkerApprovals.test.tsx
  • src/renderer/src/components/native-chat/worker-approvals/NativeChatWorkerApprovals.tsx
  • src/renderer/src/components/native-chat/worker-approvals/native-chat-worker-approval-feed.ts
  • src/renderer/src/components/native-chat/worker-approvals/worker-approval-card-model.ts
  • src/renderer/src/i18n/en-runtime-required.json
  • src/renderer/src/i18n/locales/en.json
  • src/shared/orchestration/approvals/worker-approval-payload.ts
  • src/shared/orchestration/orchestration-crew.ts
Files with no reviewable changes: 1

  • src/renderer/src/i18n/en-runtime-required.json
Files skipped from review as they are similar to previous changes: 1

  • src/renderer/src/i18n/locales/en.json

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

FROM reports JOIN newest ON newest.sequence = reports.sequence
LEFT JOIN dispatch_contexts d ON d.id = json_extract(reports.payload, '$.approval.worker.dispatchId')
WHERE julianday(reports.created_at) >= julianday(?2)
OR (json_extract(reports.payload, '$.approval.state') = 'open'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor · Functional Correctness · Quick win

Supported by static analysis

Script executed:

sed -n '130,215p' src/main/runtime/orchestration/crew/crew-query.ts

Repository: stablyai/orca

Length of output: 4003


Script executed:

rg -n -F -e 'terminal-only' -e 'closedSince' -e 'readCrewApprovals' -- src/main/runtime/orchestration docs 2>/dev/null || test "$?" -eq 1
rg -n -F -e 'terminal-only' -e 'worker-ended' -- src/main/runtime/orchestration/crew/*.test.ts src/main/runtime/orchestration/*.test.ts 2>/dev/null || test "$?" -eq 1

Repository: stablyai/orca

Length of output: 1879


Select terminal-only approvals whose dispatch ended recently.

Terminal-only approvals are converted to worker-ended when their dispatch ends, as line 197 does for open approvals. The SQL selection admits only 'open' approvals in the dispatch-based branch. A terminal-only report older than the freshness window is therefore never selected, so its conversion never runs, and its receipt is omitted. Add a clause for terminal-only reports whose dispatch ended within the window. The clause requires an ended dispatch so that old terminal-only reports do not appear while their dispatch still runs.

Suggested fix

--- "a/src/main/runtime/orchestration/crew/crew-query.ts"
+++ "b/src/main/runtime/orchestration/crew/crew-query.ts"
@@ -178,11 +178,14 @@
           COALESCE(d.completed_at, reports.created_at) AS ended_at
         FROM reports JOIN newest ON newest.sequence = reports.sequence
         LEFT JOIN dispatch_contexts d ON d.id = json_extract(reports.payload, '$.approval.worker.dispatchId')
         WHERE julianday(reports.created_at) >= julianday(?2)
           OR (json_extract(reports.payload, '$.approval.state') = 'open'
             AND (d.status IS NULL OR d.status IN ('pending', 'dispatched')
               OR julianday(COALESCE(d.completed_at, reports.created_at)) >= julianday(?2)))
+          OR (json_extract(reports.payload, '$.approval.outcome.by') = 'terminal-only'
+            AND d.status IS NOT NULL AND d.status NOT IN ('pending', 'dispatched')
+            AND julianday(COALESCE(d.completed_at, reports.created_at)) >= julianday(?2))
         ORDER BY reports.sequence DESC LIMIT ${CREW_APPROVAL_ROWS}`)
         .all(JSON.stringify(aliases), closedSince)
     )
   const shown: { approval: WorkerApprovalPayload; at: string; askedAt: string }[] = []

Comment on lines +53 to +59
} catch {
// Read again on the next change rather than show a partial list.
mailboxes = undefined
mailed = true
previous = undefined
readMailboxes = undefined
return

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor · Stability & Availability · Quick win

Retry an approval read that fails during subscription.

If the initial approvals() or workers() read throws, this catch emits no frame and schedules no retry. If no later watched change occurs, the coordinator never receives the pending approval. The renderer keeps its empty initial feed. Schedule a bounded retry or end the stream so the client can reconnect. (raw.githubusercontent.com)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d6eaa7e7-54a0-4707-87f9-dcf70bf86b42
Commits

Reviewing files that changed from the base of the PR and between 7eec497 and bcdeaa3.

Files selected for processing: 3

  • src/renderer/src/components/native-chat/worker-approvals/NativeChatWorkerApprovals.test.tsx
  • src/renderer/src/components/native-chat/worker-approvals/NativeChatWorkerApprovals.tsx
  • src/renderer/src/components/native-chat/worker-approvals/native-chat-worker-approval-feed.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

This reverts commit 818055f.

The feature misbehaves in real use: an Allow on a worker's approval card
was recorded as closed without an answer, and closed approval cards render
at the bottom of the coordinator chat, below newer messages.

Removed: the Claude PermissionRequest hook hold and its 130 s timeout,
the approval card in the coordinator chat, `orchestration deny`, the
approval payload on stop escalations, and the held-delivery lines on send
receipts. Escalation text goes back to its pre-#40756 wording.

Kept from later commits:
- #40983 (lost-worker alerts): its `lost` reason, cause/leftover/settled
  fields, turnStartedAt and the rejected-report check stay; only the
  approval branches around them are removed.
- #41158 (owner moves) and the test cleanups (#41151, #41175, #41177)
  only touched approval code that is now deleted.
…ord and place each worker card at its time

- An Allow that Claude took is answered by the person even when the command then fails or is still running; a failed command's PostToolUseFailure counts as ran.
- Expired means the agent's own timeout only; a close Orca can't name is not an expiry, and reasonDelivered is true only with a reason.
- Escalations wait for the dialog to paint and read Claude's warning even when a long command hides the top of its box.
- Worker cards and receipts render after the message they followed in time, not after the whole conversation; the toast says what happened.
…pen cards, close cards whose worker ended

Native chats no longer subscribe to the crew stream for worker approvals. A
narrow orchestration.workerApprovalsSubscribe stream per chat party wakes only
on that party's own mail and on Run/Dispatch changes, never on agent status,
and reads the crew only when the approval list itself changes. The pane no
longer redraws for approvals: the transcript receipts and the pinned stack
each hold the feed themselves.

Open worker prompts are pinned above the composer (above the chat's own
prompt), oldest first, in a bounded scrolling stack; the transcript keeps only
receipts, at the time the worker asked. The countdown ticks only for open
cards in a visible pane.

An approval whose Dispatch is no longer running reads as closed ("No longer
open · worker ended"); a hook that hangs up after its worker is gone closes as
worker-ended rather than "answer it in the terminal"; and a click that finds
the prompt or Dispatch already gone turns the card into its receipt at once.

Also carries over: a stop owes a closing line only to an approval whose
escalation went out.
…t's own prompt does

The card turns into 'Allowed by you' at once and Claude's confirmation runs behind it; only an answer
Claude did not take changes it to the real outcome, and a failure reopens the card.
@Jinwoo-H
Jinwoo-H force-pushed the jinwoo/worker-approval-reland branch from bcdeaa3 to ec37d69 Compare November 12, 2026 00:58
- A click that gets approval_not_open no longer hides the card: the host's list decides, so a
  prompt the host still holds stays answerable. Only dispatch_inactive closes it locally.
- The approvals stream watches only the orchestration database's own changes (Runs, Dispatches,
  mail), not terminal identity notices, so agent status and title changes cost it nothing in main.
- Receipts are the chat's history: no 30-minute window, bounded by 100 rows with still-open
  prompts kept first.
- The pinned stack is capped against the pane and gives way first, so the chat's own prompt keeps
  its room; a prompt that closes while shown stays pinned as its receipt for 4 s, and one only the
  worker's terminal can answer stays pinned.
- A close no one named, after the worker's Dispatch ended, reads as worker-ended, and an
  unanswered close of an ended worker sends the coordinator no second notice.
- The transcript's receipts keep one array until a receipt changes.
… a click instead of answering ahead of it

Both buttons turn off and the clicked one shows a spinner until the answer returns; the host's list
then turns the card into its receipt. Drops the client-side close and its reconciliation.
@Jinwoo-H
Jinwoo-H merged commit b8950a4 into main Nov 12, 2026
51 checks passed
audichuang pushed a commit to audichuang/orca that referenced this pull request Nov 13, 2026
…dinator (re-land with fixes) (stablyai#41259)

* revert: worker permission approvals (stablyai#40756)

This reverts commit 818055f.

The feature misbehaves in real use: an Allow on a worker's approval card
was recorded as closed without an answer, and closed approval cards render
at the bottom of the coordinator chat, below newer messages.

Removed: the Claude PermissionRequest hook hold and its 130 s timeout,
the approval card in the coordinator chat, `orchestration deny`, the
approval payload on stop escalations, and the held-delivery lines on send
receipts. Escalation text goes back to its pre-stablyai#40756 wording.

Kept from later commits:
- stablyai#40983 (lost-worker alerts): its `lost` reason, cause/leftover/settled
  fields, turnStartedAt and the rejected-report check stay; only the
  approval branches around them are removed.
- stablyai#41158 (owner moves) and the test cleanups (stablyai#41151, stablyai#41175, stablyai#41177)
  only touched approval code that is now deleted.

* feat(orchestration): answer workers' permission prompts from the coordinator (re-land of stablyai#40756)

* fix(orchestration): credit an approval from Claude's own decision record and place each worker card at its time

- An Allow that Claude took is answered by the person even when the command then fails or is still running; a failed command's PostToolUseFailure counts as ran.
- Expired means the agent's own timeout only; a close Orca can't name is not an expiry, and reasonDelivered is true only with a reason.
- Escalations wait for the dialog to paint and read Claude's warning even when a long command hides the top of its box.
- Worker cards and receipts render after the message they followed in time, not after the whole conversation; the toast says what happened.

* fix(native-chat): place timed rows without a memo the compiler skips

* perf(orchestration): feed chat approvals from their own stream, pin open cards, close cards whose worker ended

Native chats no longer subscribe to the crew stream for worker approvals. A
narrow orchestration.workerApprovalsSubscribe stream per chat party wakes only
on that party's own mail and on Run/Dispatch changes, never on agent status,
and reads the crew only when the approval list itself changes. The pane no
longer redraws for approvals: the transcript receipts and the pinned stack
each hold the feed themselves.

Open worker prompts are pinned above the composer (above the chat's own
prompt), oldest first, in a bounded scrolling stack; the transcript keeps only
receipts, at the time the worker asked. The countdown ticks only for open
cards in a visible pane.

An approval whose Dispatch is no longer running reads as closed ("No longer
open · worker ended"); a hook that hangs up after its worker is gone closes as
worker-ended rather than "answer it in the terminal"; and a click that finds
the prompt or Dispatch already gone turns the card into its receipt at once.

Also carries over: a stop owes a closing line only to an approval whose
escalation went out.

* fix(native-chat): no toast when a worker approval answer lands; the card's receipt says it

* fix(native-chat): a worker approval card answers on click, as the chat's own prompt does

The card turns into 'Allowed by you' at once and Claude's confirmation runs behind it; only an answer
Claude did not take changes it to the real outcome, and a failure reopens the card.

* fix(orchestration): keep main's stop-report index for the open-approval sweep after the re-land

* fix(orchestration): final-review fixes for chat worker approvals

- A click that gets approval_not_open no longer hides the card: the host's list decides, so a
  prompt the host still holds stays answerable. Only dispatch_inactive closes it locally.
- The approvals stream watches only the orchestration database's own changes (Runs, Dispatches,
  mail), not terminal identity notices, so agent status and title changes cost it nothing in main.
- Receipts are the chat's history: no 30-minute window, bounded by 100 rows with still-open
  prompts kept first.
- The pinned stack is capped against the pane and gives way first, so the chat's own prompt keeps
  its room; a prompt that closes while shown stays pinned as its receipt for 4 s, and one only the
  worker's terminal can answer stays pinned.
- A close no one named, after the worker's Dispatch ended, reads as worker-ended, and an
  unanswered close of an ended worker sends the coordinator no second notice.
- The transcript's receipts keep one array until a receipt changes.

* refactor(native-chat): a worker approval card waits on the host after a click instead of answering ahead of it

Both buttons turn off and the clicked one shows a spinner until the answer returns; the host's list
then turns the card into its receipt. Drops the client-side close and its reconciliation.

* fix(native-chat): let the compiler memoize the worker approval answer handler

(cherry picked from commit b8950a4)
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