Repository navigation
fix(connectors): tell no new turn from an ended turn's own status row - #48604
Conversation
91c6c7d to
1b17f02
Compare
A chat's status row can read working for a moment after its turn ended, under a date that turn already showed (its send, then its handover). With the turn's start cleared at its end, that row was told to the conversation as a new turn that never ran. ChatTurns now keeps the dates each turn's row showed, its identity on the row, and a working row showing one of the ended turn's dates is that turn: no new start, and not running on a new watch. A real next turn shows a date of its own and is told as before, even when it was handed over before the last turn ended.
A turn joined or adopted at its prompt runs under a new date once the prompt is answered; that date is the turn's too. The ended turn's dates now outlive a watch gap (cleared on an account reset), so the next watch's snapshot neither adopts nor reports as working the ended turn's row. The told start stays when a turn's dates are capped.
…s that turn If the host ends a turn and begins the next before the end is heard, the row reads working under the next turn's date while the ended turn is still open. That date was recorded as the ended turn's, so the next turn was never told. A re-date now joins a turn's dates only while the message that opened the turn on its host is unchanged.
…told first When the next turn's row is told before the last turn's end is heard, that end is the older turn's. It no longer marks the newer turn's dates as ended, so the newer turn stays running for Stop, replies and the next snapshot.
… across a watch gap A turn taken over mid-run (a watch's snapshot, a chat linked mid-turn, an adopted prompt) now records the message that opened it, so the host's next turn is never absorbed into it. A watch gap drops open and replaced turns, as it drops their starts, keeping only ended turns. A turn told again under its own date stays that turn, so the next end is never one turn behind.
…ble opener; keep a replaced turn across a watch gap
4b613b6 to
0e134e3
Compare
… that turn A start told while a delivery waits, under the same opener the host still runs, is the running turn re-dated: its dates join that turn, so the turn's one end closes them all and no false start comes back after it.
A watch's start drops the turn dates of chats closed or unlinked while nothing watched, and an unlinked chat's dates go with its link, so they never outlive the chat.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
Status: ready for review Problem. Right after a bot answered in a Slack thread, the app could tell the thread that a new turn had started, though nothing ran. The thread waited on it, and a restart then showed a "lost track" line under the finished answer. Change. A turn is identified by the start dates its own status row showed, counted only while the host runs the turn the same message opened. After the turn ends, a row still showing one of those dates is not announced as a new turn, and it isn't reported as running by a later watch or its snapshot. A real next turn shows its own date and is announced as before, including one handed over before the last turn ended. Fixed during review. A turn joined at its prompt; the host's next turn read before the last end; a newer turn told before the last end; a waiting message that joined the running turn; a turn taken over mid-run with an unreadable opener; dates across a watch gap; dates of chats closed while unwatched. Deferred. Two existing behaviors, unchanged by this PR: an end that arrives after the next turn was told carries the newer turn's id, and a message's claim on its chat is cleared at a turn's end. Edge case left as-is: a turn the host starts with no new message, told while the previous turn is still open, takes that turn's opener. Verified. 14 tests drive |
ELI5
Right after a bot finished answering in a Slack thread, the app could tell the thread that a new turn had started, though nothing was running. The thread kept waiting on that turn, and an Orca restart then showed a "lost track" line under the finished answer. Now a turn that just ended is never announced again as a new one. A real next turn is still announced right away.
What Changed
Before: once a chat's turn ended, a status row that still read "working" for a moment was announced to the linked thread as a new turn. After: that row is recognized as the turn that just ended, and only a real next turn is announced.
TurnDates(external-conversation-turn-dates.ts) holds, per linked chat, the lead dates its open turn's status row showed: the told start, each re-dateobserve()accepts as the same turn (send to handover, after an answered prompt), and dates fromadopt()or prompt adoption.ChatTurns.observe()doesn't open a turn for a working row showing one of them.turnOf()(used byadopt()) and the snapshot'sworkingflag don't report it as running.Why
At a turn's end
startedAtis cleared, so the existing "same turn, re-dated" guard no longer applies. If the status row reads working once more before it reads done, its date was told as a new turn-started. A lead'sstateStartedAtstays pinned for a working run, so the dates a turn's row showed identify that turn. A real next turn shows its own date, even one handed over before the last turn ended (a message that waited to join the turn and then ran as its own turn). A clock cutoff at the last end would miss that turn, so the change matches dates exactly.Linked Issue
None (maintainer).
Visual Proof
N/A: no UI change. A linked chat sends no turn start for its ended turn's row.
Testing
ChatTurnsthrough each event order instead)external-conversation-turn-start-after-end.test.tsdrivesChatTurnsthrough a turn's send, handover and end, then rows read after the end, in both orders of row and end:src/main/external-conversationsandsrc/main/connector-cloudsuites (243 tests),pnpm typecheck(full, on a Linux runner), oxlint and oxfmt pass.Performance
None, because it adds one set lookup per status-row change of a linked chat, at most 16 dates per chat, and one pass over linked chats when a watch starts. No timers, IO or subprocesses.
Risk
Level: Low. The riskiest part: a real next turn whose row shows exactly a date the ended turn's row showed, under the same opener, would not be announced. A running turn's row shows its own turn's dates, so a new turn shows new ones. A plain revert backs it out.
Review
Reviewed with independent code reviews and a blinded regression audit on the final head.
Agent skill upstream boundary
Notes
Security, cross-platform (Linux, Windows, Mac), Remote SSH, mobile and backwards compatibility: no impact. The change is in-memory main-process bookkeeping, cleared on restart, with no saved data or wire format change.
Checklist
N/Awith reason for visualspnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred): lint, typecheck and the connector suites ran; CI covers the rest