You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(orchestration): reading the inbox marks the batch handled (auto-ack) - #34754
Reading your orchestration inbox now counts as handling it. A coordinator or worker that forgets --ack no longer gets stuck seeing the same old batch while newer messages pile up behind it.
What Changed
Before: orca orchestration check returned the oldest batch and kept returning that same batch until the caller ran check --ack <delivery_id>. Agents forgot the ack, so newer mail stayed hidden and the wake pointer switched to "…after delivery X, which you have not acknowledged…".
After:
A consuming check (with or without --wait) marks the batch it returns as handled before it returns. The next check returns newer mail. This covers Run inboxes, worker Dispatch mailboxes, federated attachments, and the pre-bind residual Dispatch path.
--peek and --all still never consume.
--ack still works. Acking a batch that is already handled is a no-op, so older CLIs and guides that still ack are fine.
Waiters woken by the same notification share one batch. The waiter registry hands every waiter resolved by one notification a shared wake object. The first of them to take a batch stores it there, and the rest return that exact batch (replayed: true) instead of taking more mail. A forgotten background wait therefore cannot split a wake or swallow the batch the live wait was waiting for. A waiter never falls back to a batch from before its own wake. A waiter that receives a shared batch records its own receipt as soon as it has it, so its --retry-request replays that batch too.
Receipts with a batch now carry deliveryAcknowledged: true. The CLI uses it for mixed versions: with an older runtime that does not set it, text output adds "This Orca version does not acknowledge batches automatically. After handling every message, rerun this check with --ack ."
Updated the worker preamble, the check help text, and the help notes to match.
Mechanism: takeMailboxDelivery / takeRunDelivery select or create the batch, mark it acknowledged, and write the check's complete mutation receipt in one BEGIN IMMEDIATE transaction. They reuse the existing consumer fencing and generation checks and the existing completeMutationReceipt. The held-batch pointer machinery stays, because a batch that an older Orca left outstanding is still served: the next check returns it once and marks it handled.
What "returns it" means (lost responses)
A consuming check is already a durable orchestration mutation keyed by request id. Marking the batch handled and storing the full receipt with that batch now happen in the same database commit. Either both persist or neither does:
Interrupted or closed before mail arrives: nothing is consumed. A cancelled wait returns connectionLost and acks nothing.
Response lost in transit, or the server crashed after the commit: the CLI already prints a --retry-request <id> recovery command for unknown outcomes. Retrying with it replays the stored receipt with the same batch.
Fenced after consuming: a check ends the moment it hands over a batch. Nothing runs after the take, so a later fence check or receipt write can neither withhold the batch nor overwrite its receipt. This covers a nested coordinator whose Run consumer changes after it consumed pre-bind Dispatch mail.
Context lost (brand-new session, compaction, a killed CLI that never printed its request id): the rows are marked read, not deleted. orca orchestration inbox --terminal <run:…|dispatch:…> --limit <n> --full shows them. Name the Run mailbox for a coordinator, and the Dispatch mailbox for a worker, including mail it read before binding a helper Run. check --all is only a recent window, so the help no longer offers it as recovery.
I chose this over "ack the previous batch on the caller's next check". That option drops the same mail if the next check comes from a fresh context, and it brings back the stale-batch state this change removes. The request receipt already gives a precise retry for the one window that matters.
Observers
Consuming checks belong to the agent itself. Help text and notes now say that a script that only watches the inbox must use --peek (including --peek --wait) and must never --ack. No observer leases or script detection were added.
Trade-offs to note
A worker process that took a batch and was then replaced (Dispatch re-attach) no longer gets that batch again automatically. The new process can find it with orchestration inbox --terminal dispatch:<id> --full.
Two plain (non-waiting) checks running at the same moment now split the mail instead of both getting it. Concurrent --wait calls still share a batch.
Why
Missed acks were the main cause of stale-batch bugs. Moving the bookkeeping into Orca removes the "ack until count is 0" loop, the "unacked batch hides newer mail" failure, and the held-batch pointer text in normal use. The design note recommends exactly this (idea 3: reading the inbox advances it).
Real hidden dev builds (ORCA_BACKGROUND_LAUNCH=1, separate /tmp profiles and CDP ports, isolated CLAUDE_CONFIG_DIR). A coordinator terminal runs run-create, receives first-report, never runs --ack, sits as an idle agent while a worker sends second-report, and then checks again.
Before (main): held-batch pointer, and the second check replays first-report, hiding second-report.
You have 1 new orchestration message after delivery delivery_9eda02fad8d9, which you have not acknowledged. If you no longer have it, run `orca-dev orchestration check --run run_c6f67cddbb87` to see it again; once it is handled, run `orca-dev orchestration check --run run_c6f67cddbb87 --ack delivery_9eda02fad8d9`.
$ orca-dev orchestration check
Delivery delivery_9eda02fad8d9
msg_3e61bdf22589 [status] from=term_… "first-report"
After (this branch): normal pointer, and the second check returns second-report.
You have 1 orchestration message. Run `orca-dev orchestration check --run run_e9e659b7ae1f`.
$ orca-dev orchestration check
Delivery delivery_19c85a4c05d5
msg_1f20acbce558 [status] from=term_… "second-report"
Mixed versions (newer CLI, older runtime from the "before" build):
Delivery delivery_9eda02fad8d9
msg_3e61bdf22589 [status] from=term_… "first-report"
This Orca version does not acknowledge batches automatically. After handling every message, rerun this check with --ack delivery_9eda02fad8d9.
Testing
I manually tested these changes locally (macOS, hidden dev builds; before/after above)
Automated tests added/updated
The old tests encoded "replay until ack", so they now assert the new contract instead:
No stale batch hides newer mail: Dispatch mailbox across restart (no --ack in the pointer, next check returns the newer guidance), Run pointer for a never-acking coordinator, residual and Run interleavings.
Concurrent waiters (new check-consumption-safety.test.ts, Run and Dispatch): two parked waits woken by one notification over 51 messages both return the same 50-message batch, leaving one unread. A question-filtered waiter whose wake batch was taken by another consumer returns nothing, never an older status batch. Two same-Run waits over the real socket transport share one batch with one delivery row, and two plain concurrent checks get no duplicates. All new tests fail on the previous head.
Receipt coupling: a take whose receipt write fails rolls back, leaving the mail unread with no delivery. A nested coordinator fenced after consuming residual Dispatch mail returns that batch, and the receipt recorded with the take carries it.
--peek does not consume: peek and filtered peek before a consuming check leave mail unread.
Explicit --ack stays harmless: acking a handled batch returns acknowledged with nothing consumed. Covered over RPC, the built CLI, and a federated attachment across restart.
Mixed versions: an older CLI's --ack against this server is a no-op. The newer CLI prints the ack hint when the receipt lacks deliveryAcknowledged (formatter test, plus the real-app run above).
Lost response: retrying the same request id replays the stored batch.
Held-batch chat nudges are still covered for a batch an older Orca left outstanding.
pnpm check:changed --maxWorkers=2 passes.
Not verified: Windows, Linux, and SSH/remote workers by hand. The change is platform-neutral SQLite/RPC, and the remote path goes through the same check RPC with a federated attachment test.
Guides
skill-guides/orchestration.md and the coordinator-loop, messaging-and-gates, and worker-contract references now say:
A plain check marks the batch it returns as handled.
--ack is gone from the normal loop. It is still accepted, and workers use it only when a batch lacks deliveryAcknowledged (an older Orca).
A lost reply is recovered with --retry-request <id>.
After lost context, the agent reads orchestration inbox --terminal run:<run_id> (coordinator) or dispatch:<dispatch_id> (worker) with --limit 50 --full.
Observer scripts use --peek.
The bundled copies in src/cli/bundled-skill-guides.ts are regenerated.
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.
Mailbox checks now take and acknowledge returned deliveries. Concurrent waiters can share a delivery take. Responses expose acknowledgement state, and waiting checks return empty results when no batch is available. Tests cover restarts, routing, consumer ownership, residual mail, and receipt rollback. CLI help and formatted output describe compatibility acknowledgement and retry behavior.
Priority: Normal
Merge Risk: Moderate · up to 9a3e1
Mailbox auto-acknowledgement works as intended, but the guidance has gaps. Coordinators on older runtimes can reprocess the same batch and miss newer mail. The documented recovery command can miss the oldest messages when more than 50 are queued. Shared waiters may also lose a recoverable batch if a receipt write fails. Resolve these before merging or explicitly accept them.
Pre-merge checks: 3 · 2
Failed checks: 2 warnings
Check name
Status
Explanation
Resolution
Description check
The description is detailed and covers the user impact, implementation, rationale, testing, visual proof, compatibility, and trade-offs. However, the required Linked Issue section uses `Refs #16522, #…
Add an actual linked issue using the required Fixes #<issue-number> format, and complete the omitted template sections or explicitly mark them as not applicable.
Docstring Coverage
Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta…
Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed checks: 3 passed
Check name
Status
Explanation
Title check
The title clearly and concisely describes the main change: consuming an orchestration inbox batch marks it handled automatically.
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Description check
Explanation
The description is detailed and covers the user impact, implementation, rationale, testing, visual proof, compatibility, and trade-offs. However, the required Linked Issue section uses Refs #16522, #21081 instead of an actual linked issue in the required Fixes # format. Several template sections are also omitted, including Review, Agent skill upstream boundary, Notes, and Checklist.
Resolution
Add an actual linked issue using the required Fixes #<issue-number> format, and complete the omitted template sections or explicitly mark them as not applicable.
Full details: Docstring Coverage
Explanation
Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 16 functions across 37 files. (4 skipped: 4 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Finishing Touches: 💡 1
📝 Generate docstrings: 💡
Commit to this branch
Create a new PR
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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Major · Data Integrity & Integration · Heavy lift
Preserve the receipt when a shared waiter receives a batch.
If another waiter takes the batch first, share returns that committed batch to this waiter. Line 289 then writes this waiter's receipt outside the take transaction. If the receipt write fails, this waiter gets an error, but the batch remains acknowledged and a retry cannot recover its messages. The Run wait path has the same sequence at Lines 200–202 of check-run.ts. Coordinate the shared waiters' receipts with the take, or provide a durable recovery path for each waiter. (raw.githubusercontent.com)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Major · Functional Correctness · Quick win
Preserve the coordinator compatibility acknowledgement.
If the runtime is older, it omits deliveryAcknowledged and replays the batch until --ack. The documented --json loop will otherwise process the same batch repeatedly and hide newer mail. Add the conditional acknowledgement used in the worker guidance, including in the messaging reference and bundled guide. (raw.githubusercontent.com)
set -o pipefail
nl -ba src/main/runtime/rpc/methods/orchestration/messaging/message-methods.ts | sed -n '145,205p'
rg -n -F --glob '*.ts''getAllMessagesForHandle' src/main/runtime/orchestration src/main/runtime/rpc
nl -ba src/main/runtime/orchestration/db/messages/message-inbox.ts | sed -n '115,135p;270,310p'
nl -ba src/main/runtime/orchestration/db/messages/mailbox-routing-page.ts | sed -n '1,20p'
nl -ba src/main/runtime/orchestration/mailbox-pointer-eligibility.ts | sed -n '45,65p'
Repository: stablyai/orca
Length of output: 7286
Script executed:
nl -ba src/main/runtime/orchestration/db/messages/message-inbox.ts | sed -n '135,265p'
Repository: stablyai/orca
Length of output: 5491
Do not treat 50 inbox rows as complete recovery.
A consuming check returns the oldest FIFO batch of up to 50 messages. The terminal-scoped inbox command returns only the newest rows and provides no cursor or truncation indicator. With more than 50 messages, it can omit messages from the consumed batch.
Update the Run and Dispatch recovery guidance to require a limit known to exceed the mailbox history, or provide pagination/truncation metadata before presenting the command as complete recovery.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
Reading your orchestration inbox now counts as handling it. A coordinator or worker that forgets
--ackno longer gets stuck seeing the same old batch while newer messages pile up behind it.What Changed
Before:
orca orchestration checkreturned the oldest batch and kept returning that same batch until the caller rancheck --ack <delivery_id>. Agents forgot the ack, so newer mail stayed hidden and the wake pointer switched to "…after delivery X, which you have not acknowledged…".After:
check(with or without--wait) marks the batch it returns as handled before it returns. The nextcheckreturns newer mail. This covers Run inboxes, worker Dispatch mailboxes, federated attachments, and the pre-bind residual Dispatch path.--peekand--allstill never consume.--ackstill works. Acking a batch that is already handled is a no-op, so older CLIs and guides that still ack are fine.replayed: true) instead of taking more mail. A forgotten background wait therefore cannot split a wake or swallow the batch the live wait was waiting for. A waiter never falls back to a batch from before its own wake. A waiter that receives a shared batch records its own receipt as soon as it has it, so its--retry-requestreplays that batch too.deliveryAcknowledged: true. The CLI uses it for mixed versions: with an older runtime that does not set it, text output adds "This Orca version does not acknowledge batches automatically. After handling every message, rerun this check with --ack ."checkhelp text, and the help notes to match.Mechanism:
takeMailboxDelivery/takeRunDeliveryselect or create the batch, mark it acknowledged, and write the check's complete mutation receipt in oneBEGIN IMMEDIATEtransaction. They reuse the existing consumer fencing and generation checks and the existingcompleteMutationReceipt. The held-batch pointer machinery stays, because a batch that an older Orca left outstanding is still served: the next check returns it once and marks it handled.What "returns it" means (lost responses)
A consuming
checkis already a durable orchestration mutation keyed by request id. Marking the batch handled and storing the full receipt with that batch now happen in the same database commit. Either both persist or neither does:connectionLostand acks nothing.--retry-request <id>recovery command for unknown outcomes. Retrying with it replays the stored receipt with the same batch.orca orchestration inbox --terminal <run:…|dispatch:…> --limit <n> --fullshows them. Name the Run mailbox for a coordinator, and the Dispatch mailbox for a worker, including mail it read before binding a helper Run.check --allis only a recent window, so the help no longer offers it as recovery.I chose this over "ack the previous batch on the caller's next check". That option drops the same mail if the next check comes from a fresh context, and it brings back the stale-batch state this change removes. The request receipt already gives a precise retry for the one window that matters.
Observers
Consuming checks belong to the agent itself. Help text and notes now say that a script that only watches the inbox must use
--peek(including--peek --wait) and must never--ack. No observer leases or script detection were added.Trade-offs to note
orchestration inbox --terminal dispatch:<id> --full.--waitcalls still share a batch.Why
Missed acks were the main cause of stale-batch bugs. Moving the bookkeeping into Orca removes the "ack until count is 0" loop, the "unacked batch hides newer mail" failure, and the held-batch pointer text in normal use. The design note recommends exactly this (idea 3: reading the inbox advances it).
Linked Issue
Refs #16522, #21081
Visual Proof
Real hidden dev builds (
ORCA_BACKGROUND_LAUNCH=1, separate/tmpprofiles and CDP ports, isolatedCLAUDE_CONFIG_DIR). A coordinator terminal runsrun-create, receivesfirst-report, never runs--ack, sits as an idle agent while a worker sendssecond-report, and then checks again.Before (main): held-batch pointer, and the second
checkreplaysfirst-report, hidingsecond-report.After (this branch): normal pointer, and the second
checkreturnssecond-report.Mixed versions (newer CLI, older runtime from the "before" build):
Testing
The old tests encoded "replay until ack", so they now assert the new contract instead:
--ackin the pointer, next check returns the newer guidance), Run pointer for a never-acking coordinator, residual and Run interleavings.check-consumption-safety.test.ts, Run and Dispatch): two parked waits woken by one notification over 51 messages both return the same 50-message batch, leaving one unread. A question-filtered waiter whose wake batch was taken by another consumer returns nothing, never an older status batch. Two same-Run waits over the real socket transport share one batch with one delivery row, and two plain concurrent checks get no duplicates. All new tests fail on the previous head.--peekdoes not consume: peek and filtered peek before a consuming check leave mail unread.--ackstays harmless: acking a handled batch returnsacknowledgedwith nothing consumed. Covered over RPC, the built CLI, and a federated attachment across restart.--ackagainst this server is a no-op. The newer CLI prints the ack hint when the receipt lacksdeliveryAcknowledged(formatter test, plus the real-app run above).pnpm check:changed --maxWorkers=2passes.Not verified: Windows, Linux, and SSH/remote workers by hand. The change is platform-neutral SQLite/RPC, and the remote path goes through the same check RPC with a federated attachment test.
Guides
skill-guides/orchestration.mdand the coordinator-loop, messaging-and-gates, and worker-contract references now say:checkmarks the batch it returns as handled.--ackis gone from the normal loop. It is still accepted, and workers use it only when a batch lacksdeliveryAcknowledged(an older Orca).--retry-request <id>.orchestration inbox --terminal run:<run_id>(coordinator) ordispatch:<dispatch_id>(worker) with--limit 50 --full.--peek.The bundled copies in
src/cli/bundled-skill-guides.tsare regenerated.