Skip to content

Claim a screenshot reply's uploads once when its chat hasn't changed - #49572

Merged
brennanb2025 merged 5 commits into
mainfrom
brennanb2025/item-reply-claim-once
Nov 26, 2026
Merged

brennanb2025 merged 5 commits into
mainfrom
brennanb2025/item-reply-claim-once

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When you answer an item with screenshots, Orca reserves those screenshots for the bot's chat when it accepts the reply, then reserved them a second time a moment later when it delivered the reply to the same chat. Now it reserves them once.

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​11 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​10
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​69 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​62

What Changed

  • admitBotItemCommentAttachments now returns which chat it claimed the comment's uploads for (claimed: { sessionId, uploadIds }).
  • The owner-comment RPC records that claim against the open items store after the comment is written (bot-item-comment-admitted-claims.ts, bounded to 64 entries).
  • sendBotItemMail skips its first claim only when that same store recorded exactly these uploads for the same recipient session. It still checks the recipient is current, and any re-resolved recipient, a reopened store (restart), replayed or older mail, or a profile switch claims as before.

Per reply with N screenshot uploads delivered to an unchanged chat, counted from the source: claim passes 2 → 1; sweep lookups, upload-directory reads and ignored inserts on the shared journal writer 2N → N.

Why

#47967 added a delivery-time claim so a reply follows its chat when the chat is replaced between admission and delivery. That claim is needed for recovery and for a changed recipient, but for the common case it repeats exactly what admission just did. Keying the record on the open items store, rather than process memory, means a reopened store always re-claims, which keeps the restart path from #47967 unchanged.

Linked Issue

Tracked in STA-18522

Visual Proof

N/A: no visual change; the reply is delivered the same way.

Testing

  • bots-items-answer-attachments.test.ts drives the real reply RPC, attachment store and mail delivery: changed recipient, restart and expired uploads still claim, and it now asserts a reply delivered to the chat admission claimed for is claimed once (fails on revert).

Performance

Removes N sweep lookups, N synchronous upload-directory reads and N ignored inserts per screenshot reply on the shared journal writer. Adds one in-memory set lookup per delivery.

Risk

Level: Low. The riskiest part is skipping a claim that was needed: that would require the admission's claim row to vanish while the same chat stays the current recipient. Claims are only pruned for chats that are gone, and a gone chat fails the existing recipient check, which re-resolves and claims. Plain revert.

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

Main-process only; same on every platform. Replies from paired phones go through the same RPC. No saved data changes.

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)

Admission already claims an owner reply's uploads for the item's chat, and
delivery to that same chat claimed them all again: N sweep lookups, upload
directory reads and ignored inserts on the shared journal writer. Delivery now
skips the claim when the open items store's admission just made it for the same
chat; a changed recipient, a reopened store or older mail still claims.

Fixes STA-18522
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Attachment admission now returns claim metadata for referenced uploads. A per-store registry retains up to 64 claims, keyed by event ID, session ID, and sorted upload IDs. Owner comment handling records the claim. Mail delivery consumes a matching claim to skip duplicate upload claiming on the first attempt. Retries and attempts without a matching claim still claim uploads. A test checks that delivery to an already-claimed chat does not repeat the claim.

Merge Risk: Minimal · up to 0bf4f

This change avoids claiming screenshot uploads twice when a reply goes to the same chat. Claiming still happens for changed recipients, retries and restarts. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title states the main change: uploads from a screenshot reply are claimed once when the target chat is unchanged. The raw summary shows admission records the claim and delivery skips the duplicate…
Description check Passed The description follows the repository template and covers ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing, Performance, Risk, AI Disclosure, Review, and the checklist. It explains the me…
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 states the main change: uploads from a screenshot reply are claimed once when the target chat is unchanged. The raw summary shows admission records the claim and delivery skips the duplicate claim when the recorded session and upload IDs match, so the title matches the changeset.

Full details: Description check

Explanation

The description follows the repository template and covers ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing, Performance, Risk, AI Disclosure, Review, and the checklist. It explains the mechanism, the scope of the skip, and the rollback path. The Linked Issue section cites STA-18522 rather than a GitHub issue number, and the 'Fixes #' line is left blank. The Testing section also lists only one automated test file and does not state which platforms were manually tested. The AI Disclosure section is empty. These gaps are non-critical, so the check passes.

  • 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: 8fd332be-9e39-4535-b180-037ec057d08b
Commits

Reviewing files that changed from the base of the PR and between 51fef9c and 0bf4f97.

Files selected for processing: 3

  • src/main/bots/bot-items-runtime.ts
  • src/main/runtime/rpc/methods/bots-items-answer-attachments.test.ts
  • src/main/runtime/rpc/methods/bots-items-mail.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: 7fd558ea-015a-46e0-8065-c5e8cd3a76e6
Commits

Reviewing files that changed from the base of the PR and between b7226e3 and a7e87e9.

Files selected for processing: 5

  • src/main/bots/bot-item-comment-admitted-claims.ts
  • src/main/bots/bot-item-comment-attachments.ts
  • src/main/runtime/rpc/methods/bots-items-answer-attachments.test.ts
  • src/main/runtime/rpc/methods/bots-items-mail.ts
  • src/main/runtime/rpc/methods/bots-items-owner-comment.ts

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

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Status (head 0bf4f97): ready for review

Problem. A screenshot reply to an item claimed its N uploads at admission, then claimed them again when it was delivered to the same chat. That doubled the sweep lookups, upload-directory reads and ignored journal inserts on Electron main.

Change. Delivery skips its first claim only when the open items store recorded exactly these uploads for the same recipient. The record is keyed to the reply, so a changed or replaced chat, a retry, a restart, a profile switch and older mail all still claim; delivery never opens an items store to check.

Verified

  • CI is green.
  • bots-items-answer-attachments.test.ts runs the real reply RPC, attachment store, journal and mail delivery through changed-recipient, restart and expired-upload cases. It now asserts that the claim happens once for the admitted chat, and it fails on revert.
  • Regression audit: SAFE. Correctness review: no P0 or P1.

Perf scan: clean.

  • Per reply, journal claim work goes from 2N to N.
  • New in-memory state is at most 64 short keys per items store, held in a WeakMap that is released with the store.
  • No timers, polls, subscriptions or sync I/O are added.

Deferred (no wrong output)

  • A record can outlive its mail, for example when another delivery trigger wins the race. It is capped at 64, and skipping it is still correct because the earlier claim is already durable.
  • When delivery skips, it relies on claimed uploads never being swept, which the sweep guarantees today.
  • If the profile switches during a delivery pass, the lookup misses and delivery claims again. That is one redundant claim, the same as before this change.

@brennanb2025
brennanb2025 merged commit ebdfa52 into main Nov 26, 2026
57 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