Skip to content

fix(bots): label journal closes from chats that aren't the owner's - #47779

Merged
brennanb2025 merged 13 commits into
mainfrom
AmethystLiang/sta-17041
Nov 24, 2026
Merged

brennanb2025 merged 13 commits into
mainfrom
AmethystLiang/sta-17041

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

A bot keeps a journal of the items it finished. Since the journal became bot-wide, an item the bot finished in a teammate's connector chat (for example, their Slack chat) was written down exactly like the owner's own work, so the bot later remembered it as something its owner did. Now each such line says whom that chat was for, such as "for Dana via Slack, not your owner". When Orca can't tell, the line says the asker is unknown. Lines for the owner's own work read the same as before.

Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​261 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​261
Prod 13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​233 $\color{#cf222e}{\Huge{\mathbf{−}}}$​29 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​204

What Changed

  • When a bot closes an item (bots.items.done, bots.items.cancel, or bots.items.set to a closed status), the host saves whom the closing chat acts for as actsFor on the close's status event. It reads the chat's acts-for record, or, when there is none, its /clear root's first message when that conversation is already open (readFirstMessageActsFor, now shared with bot-recipient), never opening one. Only the person is kept, not where they asked. If the read fails, it saves unknown, never the owner.
  • The journal reads each line's own close in one batched query (closes) among that item's newest events, and labels the line from it: no label for the owner's own close or a chat for the owner; for <name> via <source>, not your owner for anyone else; asker unknown, not known to be your owner when the close saved nothing. A | in a name is replaced so it can't add a field.
  • A new chat the owner opens beside Home Chat now records that it acts for the owner, as Home Chat already does, so a cleared owner chat is never left unattributed.
  • Closes already written at the journal's watermark are skipped before any read, and a deleted bot's watermark is dropped. The close key that dedupes lines ignores the label.

Why

Saving whom the chat acts for at close time, when Orca knows it, keeps the bot-wide journal as it is and costs a fixed read per close, whatever the chat's history. Not covered here: a teammate's request that a bot relays into the owner's Home Chat still reads as owner work, as before. Labeling that needs whom each turn acted for, which follows the shared history reader change in #47878. The teammate's name is now also kept in that item's history and that bot's journal, where the bot and its owner can already see who asked.

Linked Issue

N/A (internal ticket)

Visual Proof

Journal lines after this change
- 2026-11-21 | item #1000 | done | Fix login
- 2026-11-21 | item #1002 | done | Fix login | for Dana via Slack, not your owner
- 2026-11-21 | item #1004 | done | Fix login | asker unknown, not known to be your owner

The first line comes from the owner's own chat (unchanged), the second from a teammate's Slack chat, and the third from a chat Orca can't attribute.

Testing

  • I manually tested these changes locally (not run in the app; covered by the test below)
  • Automated tests added/updated, or explained why not below
  • Every added test fails without this change and avoids the test anti-patterns

bot-memory-journal-attribution.test.ts drives the real item store and journal over:

  • the owner's own closes, from a typed chat and from Slack
  • a teammate's chat, and a chat shared with a teammate
  • the owner closing a teammate's item from the panel
  • a close that saved nothing, and a close through set
  • an item reopened and closed again
  • a repeat pass, which reads no close again
  • a close behind more than the lookup's window of later events

bots-items-close-acts-for.test.ts checks the close-time read: a chat's record is kept naming only the person; with no record, an open root's first message is read; with no record and no open root, the close is unknown and nothing is opened.

With the labels removed, the teammate and unknown lines come out unlabeled, as if they were the owner's work, and the test fails. pnpm check:changed (format, lint, typecheck, unit tests, ratchets) passes on Linux.

Performance

A bot close adds one primary-key read of its chat's record, plus, for a chat with no record, one indexed read of the first message of a conversation that is already open; it never opens or converts a conversation. This doesn't grow with chat history. A journal pass adds one batched close lookup for the lines it writes, capped at each item's newest 200 events; repeat passes skip closes already written. On Linux, the lookup stays at about 32–47 µs from 0 to 100,000 events after a close, and a close costs the same with or without the saved askers (about 26 µs).

Risk

Level: Low. Close events gain an optional actsFor field in their existing JSON data, with no schema change. Older builds ignore it. If the read fails, the close still succeeds and its line says unknown. These also say unknown: closes made before this change but journaled after it (up to a day of catch-up), a close in an older cleared chat that has no saved record, a close behind more than 200 later item events, and an old-format automation chat whose record mixes the owner with unknown. A plain revert backs it out; lines and events already written keep their labels.

AI Disclosure

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

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)

AmethystLiang and others added 13 commits November 23, 2026 11:09
The bot-wide memory journal wrote a close from a teammate's connector chat
the same as the owner's own work. Each line now names whom its chat acted
for (its record, else its first message), and a chat Orca can't attribute
says so; owner-chat lines are unchanged. A failed chat read fails the pass
before anything is written, and the startup lookback is kept across a retry.
Read the closing status event's actor, so a teammate's chat closing an
owner's item is labeled and the owner's own close isn't. A chat whose read
keeps failing is journaled as unknown after three passes instead of holding
back the bot's journal, closes already written at the watermark aren't
re-attributed, records are read as every acts-for check reads them, and a
name can't add a field to a line.
…al from it

The journal worked out whose work a close was chat by chat, after the
fact, so a teammate request relayed into Home Chat still read as the
owner's, and its chat reads needed retries. A bot's close now saves whom
its turn acted for (the turn read Slack posts already use); the journal
labels from that and reads no chats. A close that saved nothing is
labeled unknown, never the owner's.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Performance check on this head, compared with main:

  • A bot closing an item adds one primary-key read of its chat's record, plus one indexed first-message read when the chat has no record and is already open. Nothing is opened or converted, and the cost doesn't grow with chat history or with the number of automations. A close write costs the same as on main (about 26 µs on Linux).
  • A journal pass adds one batched lookup for the closes it writes, done in the items database worker and capped at each item's newest 200 events. On Linux it takes about 32–47 µs from 0 to 100,000 later events. Closes already written are skipped before any read.
  • Deleted bots don't leave journal state behind.

No regression against main found.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Problem: the bot-wide memory journal wrote an item closed in a teammate's connector chat exactly like the owner's own work.

Change: a bot's close now saves whom its chat acts for, and each journal line for a close made for anyone other than the owner says so ("for Dana via Slack, not your owner", or "asker unknown" when Orca can't tell). Owner lines are unchanged.

Verified:

  • unit tests on the real item store and journal, plus one on the close-time attribution read
  • format, lint, typecheck, tests and ratchets pass on Linux
  • the close-path and journal-pass cost, measured against main

Not covered here, unchanged from main:

  • A teammate request handed into the owner's Home Chat is still journaled as owner work. It needs turn-level attribution, which follows the shared reader change in perf(journal): a window of a chat's newest turns reads only the sends it can hold #47878.
  • A second close of the same item on the same day is still dropped by the journal's existing date and item dedupe.
  • Old-format automation chats whose record mixes the owner with an unknown asker are labeled "asker unknown".

@brennanb2025
brennanb2025 marked this pull request as ready for review November 24, 2026 01:30
@coderabbitai

coderabbitai Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Close operations now resolve and store asker attribution in status events. Bot item reads expose close metadata, and bot memory journal entries can label the person or people for whom an item was closed. The journal also tracks item numbers at its timestamp watermark to filter repeated reads. Session starts record owner attribution, and first-message attribution lookup is shared with bot turn processing.

Merge Risk: Low · up to b4804

Close attribution is added to the bot memory journal and is mostly well covered by tests. In the rare case where an item is closed twice in the same millisecond, the earlier close can be shown with the later closer's attribution. This is a small labeling inaccuracy that does not need to block the merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the journal now labels closes made from chats that do not belong to the owner. It matches the summarized changes, which add close-time attribution (actsFor) and journa…
Description check Passed The description follows the repository template closely. It has ELI5, What Changed, Why, Linked Issue (N/A, internal ticket), Visual Proof (journal line examples), Testing with the checklist items tic…
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 main change: the journal now labels closes made from chats that do not belong to the owner. It matches the summarized changes, which add close-time attribution (actsFor) and journal labels such as 'for <name> via <source>, not your owner' and 'asker unknown'. It follows the conventional type(scope): summary format and is specific, though it omits the close-time capture and the new chat-to-owner recording.

Full details: Description check

Explanation

The description follows the repository template closely. It has ELI5, What Changed, Why, Linked Issue (N/A, internal ticket), Visual Proof (journal line examples), Testing with the checklist items ticked, Performance with a concrete measurement, Risk with level Low and a revert path, and the checklist. Gaps: the 'Fixes #' issue line is replaced by 'N/A (internal ticket)', which the template's outside-contributor rule may not accept, and the AI Disclosure and Review sections are empty. The Testing section also leaves the manual-testing box unchecked while the text says it was not run in the app.

Resolution

Confirm the 'N/A (internal ticket)' linked issue meets the repository's rule for linked issues. Fill in or explicitly mark the empty AI Disclosure and Review sections.

  • 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: ec05e433-890d-4ec7-afcb-79d4f4b6f27e
Commits

Reviewing files that changed from the base of the PR and between 71e7c31 and b4804d4.

Files selected for processing: 15

  • src/main/bots/bot-item-dispatch-link-refs.ts
  • src/main/bots/bot-items-edits.ts
  • src/main/bots/bot-items-input.ts
  • src/main/bots/bot-items-ops.ts
  • src/main/bots/bot-items-reads.ts
  • src/main/bots/bot-items-writes.ts
  • src/main/bots/bot-memory-journal-attribution.test.ts
  • src/main/bots/bot-memory-journal-runtime.ts
  • src/main/bots/bot-memory-journal.ts
  • src/main/runtime/rpc/methods/bots-items-close-acts-for.test.ts
  • src/main/runtime/rpc/methods/bots-items-close-acts-for.ts
  • src/main/runtime/rpc/methods/bots-items-write-methods.ts
  • src/main/runtime/rpc/methods/bots.ts
  • src/main/runtime/rpc/methods/orchestration/messaging/bot-first-message-acts-for.ts
  • src/main/runtime/rpc/methods/orchestration/messaging/bot-recipient.ts

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

@brennanb2025
brennanb2025 merged commit 3a53a93 into main Nov 24, 2026
87 of 88 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.

2 participants