Skip to content

feat(orchestration): flag replies to superseded mail and ask agents not to ack - #51356

Merged
brennanb2025 merged 9 commits into
mainfrom
brennanb2025/agent-mail-stale-reply-warning
Nov 29, 2026
Merged

brennanb2025 merged 9 commits into
mainfrom
brennanb2025/agent-mail-stale-reply-warning

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Agents that message each other sometimes answered an old message after the sender had already sent a newer one, so the answer no longer fit (for example "sign-in in progress" a minute after "signed in"). Agents also woke each other with short "thanks" or "got it" notes. Now a reply to an outdated message still goes through, but the replier is told about the newer message so it can correct itself. Agent-to-agent mail and the worker instructions carry one rule: answer once, only what was asked, with no acknowledgements.

Stacked on #51362; retarget to main once it lands.

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​112 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​112
Prod 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​115 $\color{#cf222e}{\Huge{\mathbf{−}}}$​30 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​85

What Changed

  • orchestration.reply: before storing the reply, look for newer mail from the same sender to the replier that the replier hasn't answered yet. It counts when it is on the same thread, or, for a worker and its coordinator, anywhere on the same Dispatch (mail into its dispatch: mailbox, or worker mail recorded from the same Dispatch), since all of that pair's mail is one task. Other pairs, such as two bots, stay thread-scoped. If found, the receipt's existing warnings list gains a superseded_reply warning that names the newer message and the orchestration inbox command that shows it. The reply is never blocked.
  • AGENT_STATUS_RULE (from fix(bots): record a bot's status to another bot on its item instead of waking it #51362) gains the answering rule: mail another agent only to ask, hand off, answer, escalate or report finished work; answer once and only what it asks; no acknowledgements or thanks; plain sentences. It replaces the worker preamble's separate mail wording, which now also names "finish with one worker_done".
  • Chat mail cards add [Agent mail. <rule>] only on peer agent mail whose answer stays in Orca. Owner item mail and mail whose answer goes to a person's thread never get it. On a card near the size limit the rule is dropped first, so the line saying where the answer goes is kept.

Why

Over three days, 47 replies answered mail that already had a newer message from the same sender, and about 130 acks and self-described FYIs woke their recipients. A receipt warning costs one indexed query per reply and doesn't change delivery.

Linked Issue

N/A (maintainer change)

Visual Proof

N/A: no UI change. The card line is agent-facing text outside the displayed content ranges.

Testing

  • superseded-reply-warning.test.ts (real dispatcher and in-memory DB): warns for newer mail on the same thread even when it was read; stays silent for another thread, mail the other way and mail already answered; counts a worker and its coordinator's newer mail on another thread. The reply tests fail without the change.

  • Real-agent run with Claude and Codex workers and bots: stale replies got the warning ("on this task" and "on this thread") and each worker sent one correction and one worker_done, with no loop. Different-thread mail between non-worker parties gave no warning. FYI mail to Claude and Codex bots drew no acknowledgement. An owner item instruction had no rule line and the bot carried it out. All nine workers reported exactly once.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • Every added test fails without this change and avoids the test anti-patterns

Performance

None, because it adds one indexed SELECT ... LIMIT 1 per local reply and one short line per peer chat mail card.

Risk

A false warning only adds a line to the receipt. Plain revert.

Level: Low

Notes

Cross-platform, remote and mobile: server-side text and a DB read only; paired-server replies take their own path and are unchanged.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

The changes add mail-answer guidance to shared agent rules and worker instructions. Structured mail now selects among sender-specific note variants based on the size limit. The reply path now checks for newer unanswered matching mail and includes any resulting warning in the reply receipt. Tests cover matching and non-matching messages.

Merge Risk: Low · up to 8eecd

Replies still go through. The remaining issues are minor: the new warning can be missed or mislead in some edge cases, and the new mail card names the production launcher in dev builds. Worth fixing before or shortly after merge, but not blocking.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the two main changes: a superseded-reply warning on replies (feat(orchestration)) and a request that agents not send acknowledgements. Both appear in the changeset (superseded-reply-wa…
Description check Passed The description follows the template sections (ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing, Performance, Risk, Notes, Checklist). The Linked Issue section says N/A (maintainer change)…
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 two main changes: a superseded-reply warning on replies (feat(orchestration)) and a request that agents not send acknowledgements. Both appear in the changeset (superseded-reply-warning.ts, reply-method.ts, and AGENT_MAIL_ANSWER_RULE). It is a single line, though at 78 characters it is slightly long and joins two changes in one line.

Full details: Description check

Explanation

The description follows the template sections (ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing, Performance, Risk, Notes, Checklist). The Linked Issue section says N/A (maintainer change), which the template permits for maintainers. The AI Disclosure and Review sections are missing, and the Risk level is filled in. The Performance section is complete. The Testing section gives concrete steps and platform notes. The Agent skill upstream boundary section is also missing. Several template checkboxes are unchecked, including the lint/typecheck/test/build item, which is deferred to CI. The description also has a stacking note about #51362.

Resolution

Optional: add the missing Agent skill upstream boundary checkbox and the Review section, and state which platforms were actually tested (macOS, Linux, Windows, SSH). Consider running pnpm lint, typecheck, test, and build locally before merge.

  • 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: 2

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: 3af3bf31-01a8-420d-82f4-843821146992
Commits

Reviewing files that changed from the base of the PR and between 4660867 and 17fa882.

Files selected for processing: 7

  • src/main/runtime/orchestration/mailbox/structured-mail/structured-mail-source.ts
  • src/main/runtime/orchestration/workers/launch/worker-dispatch-preamble.ts
  • src/main/runtime/rpc/methods/orchestration/messaging/recipient-routing.ts
  • src/main/runtime/rpc/methods/orchestration/messaging/reply-method.ts
  • src/main/runtime/rpc/methods/orchestration/messaging/superseded-reply-warning.test.ts
  • src/main/runtime/rpc/methods/orchestration/messaging/superseded-reply-warning.ts
  • src/shared/orchestration/mailbox/agent-mail-reply-rule.ts

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

@brennanb2025
brennanb2025 force-pushed the brennanb2025/agent-mail-stale-reply-warning branch from e9bfc68 to 45fd44f Compare November 28, 2026 02:51

@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: 9516a7e7-4995-4f51-9f54-8f2b4d2ebf6c
Commits

Reviewing files that changed from the base of the PR and between 17fa882 and 45fd44f.

Files selected for processing: 2

  • src/main/runtime/orchestration/mailbox/structured-mail/structured-mail-source.ts
  • src/main/runtime/rpc/methods/orchestration/messaging/reply-method.ts

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

@brennanb2025
brennanb2025 force-pushed the brennanb2025/agent-mail-stale-reply-warning branch from 45fd44f to 8d54655 Compare November 28, 2026 03:00

@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: 01f88fb4-9d87-4ee9-be0c-cf6cab401411
Commits

Reviewing files that changed from the base of the PR and between 45fd44f and 8d54655.

Files selected for processing: 1

  • src/main/runtime/orchestration/mailbox/structured-mail/structured-mail-source.ts

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

...(structuredAgentSessionBlocksTooLarge(noted) ? whole : noted),
...botItemMailImageBlocks(input.message)
],
blocks: [...(noted ?? whole), ...botItemMailImageBlocks(input.message)],

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

Measure the appended image blocks when selecting the note variant.

The note variant is selected by measuring only its text block. The image-ref blocks are appended after the check. When the text fits alone but text plus image references exceed MAX_PROMPT_BYTES, the host refuses the body. The mail is then parked and retried without success. The new reply rule can cause this by moving selection to a larger guided text. Include the image references in the size check, and append the same images to the chosen blocks.

Suggested fix

--- "a/src/main/runtime/orchestration/mailbox/structured-mail/structured-mail-source.ts"
+++ "b/src/main/runtime/orchestration/mailbox/structured-mail/structured-mail-source.ts"
@@ -181,14 +181,15 @@
         }).text
       : formatted.text
     // The reply rule is dropped first, so a long mail keeps the line saying where its answer goes.
-    const noted = withConversationNotes(guided, from, input).find(
-      (blocks) => !structuredAgentSessionBlocksTooLarge(blocks)
-    )
+    const images = botItemMailImageBlocks(input.message)
+    const noted = withConversationNotes(guided, from, input).find(
+      (blocks) => !structuredAgentSessionBlocksTooLarge([...blocks, ...images])
+    )
     return {
       body: {
         kind: 'message',
         role: 'user',
-        blocks: [...(noted ?? whole), ...botItemMailImageBlocks(input.message)],
+        blocks: [...(noted ?? whole), ...images],
         from: {
           ...from,
           orchestration: {

@brennanb2025
brennanb2025 force-pushed the brennanb2025/agent-mail-stale-reply-warning branch from 238c88f to 8b53bfd Compare November 28, 2026 03:48
@brennanb2025
brennanb2025 changed the base branch from main to brennanb2025/agents-update-own-status November 28, 2026 03:48
@brennanb2025
brennanb2025 force-pushed the brennanb2025/agent-mail-stale-reply-warning branch 7 times, most recently from 7eb3f8c to 20a3a10 Compare November 29, 2026 22:05
@greptile-apps

greptile-apps Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge; the two previous warning gaps remain non-blocking.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the two previous warning gaps remain non-blocking.

Findings

  1. P2 Old questions get no warning ▶
  2. P2 Unrelated threads trigger stale warnings ▶

Summary

Adds a receipt warning when an agent replies to mail that has newer, unanswered mail.

  • Replies point agents to newer unanswered mail.
  • Agent mail now asks for one direct answer without acknowledgements.

Reviews (5) · Last reviewed commit: "refactor(orchestration): give the send w..." · Reviewed by Greptile

Comment on lines +178 to +179
// Read before the reply is stored, so a reply to one's own mail never counts as newer mail.
const supersededWarning = supersededReplyWarning(db, original)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Old questions get no warning

supersededReplyWarning runs only for ordinary mail. Replies to worker questions return earlier through the helper or run branches. If a worker asks a question and then asks a newer question on the same Dispatch, answering the older question sends no warning. This leaves part of the stale-reply problem unchanged. Run the check before storing local question answers too, and include it in their receipts.

AND newer.type <> 'heartbeat'
AND (
COALESCE(newer.thread_id, newer.id) = ?4
OR ?5 = 1

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Unrelated threads trigger stale warnings

Mail to any dispatch: mailbox skips the thread check, even when the sender is not that worker's coordinator. When one helper sends another two unrelated questions on separate threads, replying to the first warns that the second supersedes it and suggests a correction. That can cause needless follow-up mail.

Check that the sender coordinates the recipient before allowing a different thread to match.

@brennanb2025
brennanb2025 force-pushed the brennanb2025/agent-mail-stale-reply-warning branch from 96438c5 to ac50261 Compare November 29, 2026 22:31
@brennanb2025
brennanb2025 changed the base branch from brennanb2025/agents-update-own-status to main November 29, 2026 22:37
@brennanb2025
brennanb2025 force-pushed the brennanb2025/agent-mail-stale-reply-warning branch from ac50261 to 8eecd19 Compare November 29, 2026 22:38

@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: 4

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: b53e5026-4354-48ea-a15e-3fbe8dfb4fd1
Commits

Reviewing files that changed from the base of the PR and between 8d54655 and 8eecd19.

Files selected for processing: 8

  • src/main/runtime/orchestration/mailbox/structured-mail/structured-mail-source.ts
  • src/main/runtime/orchestration/workers/launch/worker-dispatch-preamble.ts
  • src/main/runtime/rpc/methods/orchestration/messaging/recipient-routing.ts
  • src/main/runtime/rpc/methods/orchestration/messaging/reply-method.ts
  • src/main/runtime/rpc/methods/orchestration/messaging/send-recipient-warning.ts
  • src/main/runtime/rpc/methods/orchestration/messaging/superseded-reply-warning.test.ts
  • src/main/runtime/rpc/methods/orchestration/messaging/superseded-reply-warning.ts
  • src/shared/orchestration/mailbox/agent-status-rule.ts

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

if (sender === BOT_ITEM_MAIL_SENDER || bound?.answersThere) {
return [placed]
}
const rule = `[Agent mail. ${AGENT_STATUS_RULE}]`

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

Use cliCommand for the reply command in the agent-mail rule card.

The [Agent mail.] card builds its rule from AGENT_STATUS_RULE, which hard-codes orca orchestration reply --id <msg>. The reply banner in the same function uses ${cliCommand}. In dev builds, cliCommand is orca-dev, so the card directs the agent to plain orca. The repository guide states that plain orca targets an installed production Orca, not the dev runtime that owns the message. The reply can then fail or reach the wrong runtime.

The correct banner does not cover this case. It appears only when the answer stays in the bound conversation. That branch never includes the rule, and the rule-bearing variant names no launcher.

Build the reply command for this card from cliCommand, so dev builds get orca-dev orchestration reply.

runtime.getTerminalPaneKey(replyFrom) ?? undefined
)?.id
// Read before the reply is stored, so a reply to one's own mail never counts as newer mail.
const supersededWarning = supersededReplyWarning(db, original)

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

Add the superseded-reply check to question answers.

Answers to questions skip the superseded-reply warning. The helper and run branches return before the lookup at line 191, so their receipts never include superseded_reply.

A worker can hold more than one open question. With wait: false, ask returns while the question stays open, and a new question is created without checking for an open one. A newer open question from the same Dispatch matches the superseded query. If the older question is answered through either branch, the warning is not returned, even though the worker-to-coordinator question channel is the case this lookup targets.

Compute supersededReplyWarning(db, original) before answerQuestion in both branches. Add the result to the receipt's warnings when present. Apply this to the federated return in the run branch as well. The warning is advisory and does not block the answer, so delivery is unaffected.

Comment on lines +30 to +33
OR ?5 = 1
OR EXISTS (
SELECT 1 FROM message_dispatch_provenance provenance
WHERE provenance.message_id = newer.id AND provenance.dispatch_id = ?6

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

Limit the cross-thread provenance match to mail with the Dispatch's coordinator.

The message_dispatch_provenance branch matches on Dispatch identity alone. A worker that sends to a peer agent on two threads gets provenance rows for the same Dispatch on both messages. A later reply to the first message can then match the second message, and the warning says "on this task". The helper's doc comment limits cross-thread matching to a worker and its coordinator, so this match is outside the stated contract.

The dispatch: mailbox branch has the same gap. It matches any sender to a worker mailbox across threads without checking that the sender is the coordinator.

Require that cross-thread matches apply only when the recipient is the coordinator of the original sender's Dispatch. Keep same-thread matching unchanged.

return {
code: 'superseded_reply',
recipient: original.from_handle,
message: `${newer.id} from ${original.from_handle} ${where} is newer than the message you answered; read it with \`${localOrchestrationCliCommand()} orchestration inbox --terminal ${original.to_handle} --limit ${newer.rows_since} --full\`, and send a correction if your reply no longer fits.`

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

The superseded-reply command can omit the named message when the original mail is self-addressed.

The warning counts recipient mail before the reply is stored. For self-addressed mail, the stored reply lands in the same mailbox. The inbox returns the newest --limit rows, so the reply uses one slot and pushes the named message out of the window. When rows_since is 1, the command shows only the reply.

Read mail does not cause this. The inbox history read includes read messages, and the limit is passed through without a clamp.

The count must cover the reply when the reply lands in the same mailbox. Either compute the limit after the reply is stored, or add one to the limit for self-addressed mail. The choice is open. Either way, the command must return the named message.

@brennanb2025
brennanb2025 merged commit fc52494 into main Nov 29, 2026
58 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