Skip to content

fix(bots): route --item mail and its files to the Home Chat once the item's chat is closed - #52378

Merged
nwparker merged 1 commit into
stablyai:mainfrom
yeong-chae:yeong-chae/bots-item-mail-closed-chat
Nov 29, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
yeong-chae:yeong-chae/bots-item-mail-closed-chat

Conversation

@yeong-chae

@yeong-chae yeong-chae commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When you message a bot about one of its items, Orca sends the message to the chat where the item was made. If that chat was closed, for example after the bot started a fresh Home Chat, the message was refused. Now it goes to the bot's current Home Chat, which is where the item's other updates already go. Any files you attach go there too.

What Changed

Before: orca orchestration send --to bot:<name> --item <n> fell back to the Home Chat only when the item's chat record had been deleted. A closed chat keeps its record (an older Home Chat replaced by bot new-chat, or a side chat whose tab was closed), so the mail was addressed to that closed chat and refused with has ended: its chat was closed. No message was sent. With --file, it was refused earlier with This item's chat was deleted, so files can't be attached here.

After: both sends go to the Home Chat, and the files are claimed for the Home Chat.

How it works:

  • bot-chat-address.ts chatForItem: uses the item's chat only while it takes mail (botChatTakingMail). Otherwise it returns no chat, so the mail goes to bot:<name>, which is the Home Chat.
  • bot-item-mail-files.ts withItemMailFiles: now takes the chat routeBotMail chose and claims the files for that same chat, so files and mail can never end up in different chats. For the Home Chat it uses botHomeMailSession.
  • bot-mail-chat.ts: the Home Chat half of botMailSession is split out as botHomeMailSession, so nothing is reimplemented.
  • peer-mail-files.ts and the local --file refusal now say the files go to the item's chat, or the Home Chat once that chat is closed.

--chat <id> is unchanged: mail sent to a closed chat by id is still refused. If the item's chat closes after it was chosen but before its files are claimed, the send is refused, as on main.

Why

The item's own change mail and owner comments already pick their chat with botMailSession: the item's chat while it takes mail, else the Home Chat. #47967 moved the sidebar's item replies with screenshots onto that rule. --item mail was the last path still on the old rule. This puts it on the same rule and reuses the existing Home Chat lookup.

Linked Issue

Fixes #52377

Visual Proof

N/A. This changes which chat a CLI orchestration send --item is routed to. There is no UI change.

Testing

  • 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

No test is committed. The routing test from the first revision was dropped during review. The behavior was checked with a throwaway probe that runs routeBotMail against a real chat record store and attachment store, with only delivery mocked:

Case main this PR
item's side chat open that chat that chat
item's chat is a replaced (closed) Home Chat closed chat, delivery refused: has ended: its chat was closed bot:Nightly (Home)
same, with --file refused: This item's chat was deleted bot:Nightly, file claimed for Home
item's chat record deleted, with --file refused bot:Nightly, file claimed for Home
item's chat closes after routing, before file claim refused refused, nothing claimed for Home
  • Re-ran the probe on this commit rebased onto current main. Results match the table.
  • Targeted vitest: bot-items-runtime, bot-group-mail-root, bots-items-self-echo-mail, bots-items-worker-origin, remote-owned-route, send-params, agent-session-attachment-sweep (7 files, 19 tests) pass.
  • oxfmt, anti-slop oxlint, code-quality oxlint, ast-grep and the changed-code quality gate are clean on the 4 changed files.
  • Platforms: macOS, unit level. There is no platform-specific code.

Performance

None that matters. This only runs on orchestration send --item, a one-off CLI request, never on a hot path. It adds one chat-record lookup (botChatTakingMail) while routing. Probe benchmark per send: 0.002 ms on main and 0.010 ms here with 10 chats, and 0.002 ms vs 0.057 ms with 2000 chats. Main's number is the early refusal, so it is not a like-for-like comparison. Either way the cost stays far below 1 ms, with no new polling, subprocess or sync disk work.

Risk

Level: Low

  • If an item's chat can't take mail for another reason (it runs on another host, its /clear lineage can't be verified, or it was a Look around run), its --item mail now goes to the Home Chat instead of being refused. Item change mail already behaves this way.
  • Files are claimed for the Home Chat before the mail is stored. If a bot new-chat lands in that window, the files stay claimed for the old Home Chat.
  • Mixed versions: the change is host-side routing only. A paired Orca still uploads files the same way, and only the refusal text changed.
  • Back out with a plain revert. No saved data or settings change.

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Original fix by @yeong-chae in #52378. Their authorship is kept as a co-author on the squashed commit.

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)

@greptile-apps

greptile-apps Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge, with no new actionable issues found.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with no new actionable issues found.

Summary

Routes --item mail to the item's chat while it takes mail, otherwise to the bot's Home Chat.

  • Bot item messages go to the Home Chat when their chat closes.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["Send mail with --item"] --> B{"Item's chat takes mail?"}
  B -->|Yes| C["Choose item's chat"]
  B -->|No| D["Choose Home Chat"]
  C --> E["Claim files for chosen chat"]
  D --> E
  E --> F["Route mail"]
Loading

Reviews (4) · Last reviewed commit: "fix(bots): route --item mail and its fil..." · Reviewed by Greptile

@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Item mail now uses the item’s recorded chat only while that chat takes mail. Otherwise, routing selects the bot’s Home Chat. Attachment claims use the selected chat or the Home mail session when no chat was selected. The refusal messages now describe the Home Chat destination.

Severity of issue fixed: Medium

Merge Risk: Low · up to 45e53

Item mail now falls back to the Home Chat when the item's chat is closed, as the linked issue requests. One rare case remains: if the Home Chat is replaced during a send, attached files may stay claimed for the old Home Chat. The author has acknowledged this.

Pre-merge checks: Passed 4

Check name Status Explanation
Linked Issues check Passed Issue #52377 requires orchestration send --to bot:<name> --item <n> to reach the bot's current Home Chat when the item's chat is closed, with --file attachments following the same destination. At …
Out of Scope Changes check Passed Each changed area ties to #52377. bot-chat-address.ts changes the routing condition and passes the chosen chat to the file step. bot-item-mail-files.ts takes the chat as a parameter and claims fil…
Title check Passed The title names the main change: when an item's chat is closed, --item mail and its files go to the bot's Home Chat. It also states the fix type and scope. It matches the raw summary and the PR obje…
Description check Passed The description follows the repository template and fills every required section. It has an ELI5, a before/after in What Changed, the mechanism per file, a Why, a linked issue (Fixes #52377), N/A visu…
Full details: Linked Issues check

Explanation

Issue #52377 requires orchestration send --to bot:&lt;name&gt; --item &lt;n&gt; to reach the bot's current Home Chat when the item's chat is closed, with --file attachments following the same destination. At head 45e53ce, chatForItem in bot-chat-address.ts returns the item's chat only when it is not gone and botChatTakingMail accepts it. Otherwise it returns undefined, so mail goes to bot:&lt;name&gt;. routeBotMail passes the chosen chat to withItemMailFiles in bot-item-mail-files.ts, which claims files for that chat, or for botHomeMailSession when no item chat is chosen. This removes the commentChatDeleted refusal for closed item chats. The new bot-chat-address.test.ts covers the closed-chat mail and file cases. Explicit --chat &lt;id&gt; handling is unchanged. The PR discloses a known gap: if the Home Chat is replaced between file claim and mail storage, files stay on the old chat. The issue does not state a requirement for that case. The test suite was not run during this assessment; the conclusion rests on source inspection and the PR's reported test results.

Full details: Out of Scope Changes check

Explanation

Each changed area ties to #52377. bot-chat-address.ts changes the routing condition and passes the chosen chat to the file step. bot-item-mail-files.ts takes the chat as a parameter and claims files for the same destination as the mail. bot-mail-chat.ts extracts botHomeMailSession from botMailSession. Source diff confirms the refactor keeps behavior: the original chat session is returned when it takes mail, and otherwise the Home Chat session is returned. The extracted function is needed for the Home claim. peer-mail-files.ts changes only the refusal message text for the --file path, which describes the new fallback. The new test file tests the changed behavior. No unrelated paths, configuration, or interfaces change.

Full details: Title check

Explanation

The title names the main change: when an item's chat is closed, --item mail and its files go to the bot's Home Chat. It also states the fix type and scope. It matches the raw summary and the PR objectives, which both describe routing to the Home Chat when the item's chat stops taking mail.

Full details: Description check

Explanation

The description follows the repository template and fills every required section. It has an ELI5, a before/after in What Changed, the mechanism per file, a Why, a linked issue (Fixes #52377), N/A visual proof with reason, detailed testing with a case table, a performance line, and a risk section with level and back-out plan. The AI Disclosure section is left empty, which is acceptable for an internal contributor. Some template comment text was kept only in the unchanged form, and the Review heading is empty, but these are non-critical.

  • 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

Recent 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: 949e663e-27fa-44bf-971c-ddc2f98c45da
Commits

Reviewing files that changed from the base of the PR and between 1246e1d and 45e53ce.

Files selected for processing: 3

  • src/main/runtime/rpc/methods/orchestration/messaging/bot-chat-address.ts
  • src/main/runtime/rpc/methods/orchestration/messaging/bot-item-mail-files.ts
  • src/main/runtime/rpc/methods/orchestration/messaging/peer-mail-files.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.

@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: f9592f1c-3870-4671-b977-3f83fa5d8eba
Commits

Reviewing files that changed from the base of the PR and between 044dc58 and da330d3.

Files selected for processing: 3

  • src/main/runtime/rpc/methods/orchestration/messaging/bot-chat-address.test.ts
  • src/main/runtime/rpc/methods/orchestration/messaging/bot-chat-address.ts
  • src/main/runtime/rpc/methods/orchestration/messaging/bot-item-mail-files.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.

…item's chat is closed

`orchestration send --to bot:<name> --item <n>` fell back to the Home Chat
only when the item's chat record was deleted. A closed chat (a Home Chat
replaced by `bot new-chat`, or a side chat whose tab was closed) keeps its
record, so the mail was addressed to it and refused, and `--file` was
refused with "This item's chat was deleted".

chatForItem now uses the item's chat only while it takes mail
(botChatTakingMail), else the Home Chat, the rule item change mail already
follows via botMailSession. routeBotMail passes that choice to
withItemMailFiles so the files are claimed for the same chat the mail goes
to; the Home Chat lookup is split out of botMailSession as
botHomeMailSession.

Fixes stablyai#52377

Co-authored-by: yeong-chae <[email protected]>
@nwparker
nwparker force-pushed the yeong-chae/bots-item-mail-closed-chat branch from 1246e1d to 45e53ce Compare November 29, 2026 09:10
@nwparker nwparker changed the title fix(bots): send --item mail and its files to the Home Chat once the item's chat closed fix(bots): route --item mail and its files to the Home Chat once the item's chat is closed Nov 29, 2026
@nwparker
nwparker merged commit 7294c7c into stablyai:main Nov 29, 2026
58 of 59 checks passed
@yeong-chae
yeong-chae deleted the yeong-chae/bots-item-mail-closed-chat branch November 29, 2026 09:31
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.

[Bug]: orchestration send --item is refused once the item's chat is closed, instead of going to the Home Chat

2 participants