Repository navigation
fix(bots): label journal closes from chats that aren't the owner's - #47779
Conversation
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.
…iling chats together
…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.
…ip closes already journaled
…e; bound the close lookup
…for a closing chat
… chat attribution
|
Performance check on this head, compared with main:
No regression against main found. |
|
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:
Not covered here, unchanged from main:
|
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
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.
What Changed
bots.items.done,bots.items.cancel, orbots.items.setto a closed status), the host saves whom the closing chat acts for asactsForon 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 withbot-recipient), never opening one. Only the person is kept, not where they asked. If the read fails, it saves unknown, never the owner.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 ownerfor anyone else;asker unknown, not known to be your ownerwhen the close saved nothing. A|in a name is replaced so it can't add a field.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
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
bot-memory-journal-attribution.test.tsdrives the real item store and journal over:setbots-items-close-acts-for.test.tschecks 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
actsForfield 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
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)