Skip to content

fix(connectors): tell no new turn from an ended turn's own status row - #48604

Merged
brennanb2025 merged 9 commits into
mainfrom
brennanb2025/item-434-turn-starts
Nov 25, 2026
Merged

brennanb2025 merged 9 commits into
mainfrom
brennanb2025/item-434-turn-starts

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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.

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​299 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​299
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​176 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​172

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.

  • New 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-date observe() accepts as the same turn (send to handover, after an answered prompt), and dates from adopt() or prompt adoption.
  • A re-date counts only while the host still runs the turn that the same message opened, so the host's next turn is never taken for the previous one. A turn taken over with an unreadable opener takes no re-dates.
  • When the turn ends, its dates become the ended turn's. ChatTurns.observe() doesn't open a turn for a working row showing one of them. turnOf() (used by adopt()) and the snapshot's working flag don't report it as running.
  • If a newer turn is told before the last turn's end is heard, that end closes the older turn's dates. A start told under the opener the host still runs (a waiting message that joined the turn) stays that turn.
  • Ended dates outlive a watch gap, so the next watch's snapshot gets this too. Dates are kept only for chats still linked: dropped when a chat closes or unlinks, at a watch's start for chats gone meanwhile, and on an account reset.

Why

At a turn's end startedAt is 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's stateStartedAt stays 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

  • I manually tested these changes locally (not in the app: the race needs a status row that lags its turn's end, so the tests drive ChatTurns through each event order instead)
  • Automated tests added: external-conversation-turn-start-after-end.test.ts drives ChatTurns through a turn's send, handover and end, then rows read after the end, in both orders of row and end:
    • The ended turn's row tells no turn, a real next turn is told (also one handed over before the last end), and the next watch neither adopts nor snapshots the ended turn as working.
    • A turn joined at its prompt, a turn taken over mid-run (opener readable or not), a waiting message that joins the turn, a newer turn told before the last end, and a watch gap all stay in step.
    • Dates are kept only for chats still linked.
  • src/main/external-conversations and src/main/connector-cloud suites (243 tests), pnpm typecheck (full, on a Linux runner), oxlint and oxfmt pass.
  • Every added test that targets the change fails without it and avoids the test anti-patterns.

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

  • Not applicable.

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

  • This PR is small and focused
  • I explained what changed and why
  • I stated the risk
  • N/A with reason for visuals
  • Self-reviewed for correctness, security, and performance
  • Cross-platform and SSH impact considered: none, main-process logic only
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred): lint, typecheck and the connector suites ran; CI covers the rest

@brennanb2025
brennanb2025 force-pushed the brennanb2025/item-434-turn-starts branch from 91c6c7d to 1b17f02 Compare November 25, 2026 01:17
@brennanb2025 brennanb2025 changed the title fix(connectors): tell no new turn from an ended turn's status row fix(connectors): tell no new turn from an ended turn's own status row Nov 25, 2026
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
@brennanb2025
brennanb2025 force-pushed the brennanb2025/item-434-turn-starts branch from 4b613b6 to 0e134e3 Compare November 25, 2026 02:13
… 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.
@brennanb2025
brennanb2025 marked this pull request as ready for review November 25, 2026 02:24
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change adds TurnDates to track open, replaced, and ended turn dates and opener identities. ChatTurns updates this state during turn events and uses it when determining turn starts. ConversationEvents retains date state for linked panes and uses it to determine snapshot working status. Tests cover turn starts, handovers, watch gaps, joined deliveries, and pane retention.

Merge Risk: Minimal · up to 4380d

This change stops Slack threads from being told a new turn started when a status row still says working after its turn ended. No concrete merge-blocking risk was identified in the supplied change.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a fix in connectors so that a status row from an already-ended turn is not reported as a new turn. The raw summary shows the TurnDates tracking and the observe() chang…
Description check Passed The description follows the repository template and covers each required section. It has an ELI5, a before/after account of the change, the mechanism, the reason for the approach, testing notes with t…
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: a fix in connectors so that a status row from an already-ended turn is not reported as a new turn. The raw summary shows the TurnDates tracking and the observe() change that do this, and the tests cover the same case. The title is specific and matches the changeset, and the 69-character length is within a reasonable limit for a single-sentence title.

Full details: Description check

Explanation

The description follows the repository template and covers each required section. It has an ELI5, a before/after account of the change, the mechanism, the reason for the approach, testing notes with the automated test file named, a performance line, a risk level with a revert path, and checklist items. Two gaps remain. The Linked Issue section reads 'None (maintainer)' with no issue reference, which the template says should not be left out for outside contributors. The Visual Proof section is marked N/A with a reason, which the template accepts. The 'I manually tested' box is left unchecked with an explanation, which is acceptable. Overall the description is mostly complete.

  • 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: 51cd7454-f4cf-42e7-b6fd-b592a391061b
Commits

Reviewing files that changed from the base of the PR and between 5f0a5cc and 4380dce.

Files selected for processing: 1

  • src/main/external-conversations/external-conversation-turn-start-after-end.test.ts

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

@brennanb2025

Copy link
Copy Markdown
Contributor Author

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 ChatTurns through both orders of status row and turn end, including takeover, joined messages and watch gaps (each fix's test failed on the head before it). The external-conversations and connector-cloud suites (243 tests), full typecheck and the changed-code checks pass, and CI is green. No app run: the race needs a status row lagging its turn's end, which the tests drive directly. In-memory only, with no saved data or wire change.

@brennanb2025
brennanb2025 merged commit 658f310 into main Nov 25, 2026
55 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