Skip to content

feat(labs): stop a running turn, with "Interrupted by you" and the background count (FIX-2375) - #4939

Merged
jhoffner merged 18 commits into
mainfrom
claude/project-thread-ft4mpv
Nov 8, 2026
Merged

jhoffner merged 18 commits into
mainfrom
claude/project-thread-ft4mpv

Conversation

@jhoffner

@jhoffner jhoffner commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

Requested by Jake · project thread

Builds on FIX-2406's in-process test host and contract matrix (#4942, merged). Spec: specs/issues/FIX-2375/ (#4732).

FIX-2375: Stop a running turn, with clear feedback afterwards

Problem

In the Claude Code-style and Teammates labs, you can't cleanly stop a turn that is running. Even where an abort reaches the server, the conversation doesn't show that the turn was stopped or that stopping is in progress. It also doesn't show that background work the turn started is still running. Before this change, a 409 from the abort route could be mistaken for a successful stop.

What changes

  • @flow-state-dev/ui registry, request-recovery. Adds a stopped look. It reads "Interrupted by you" and, while background work runs, adds "· N background task(s) still running" and a View button. It uses role="status" and data-state="stopped". The existing recovery look is unchanged.
  • Claude Code-style lab.
    • ThreadEntry kind stopped.
    • ThreadView.stopping and ThreadView.backgroundRunning (from the session feed's runs).
    • interrupt aborts the turns that are running when you press Stop.
    • stopping clears once every aborted turn has ended.
    • After a 409, the adapter reads the turn's record. A terminal record means the turn is done. A record still in_progress clears stopping and shows "Not stopped: …".
    • Composer shows Stop/Stopping…. The keys are Esc Esc or Cmd/Ctrl+. (useInterruptKeys).
    • The count appears only on the newest stopped line, and only while no later turn runs. View focuses the tasks pane.
  • Teammates lab. Brings the same behaviour to ConversationView and adds LabAdapter.interrupt.
    • Stop aborts every answering turn except dispatch.
    • A line sent after the press isn't aborted.
    • The count comes from sessionFeed.watchRuns, which reports nothing until the count is known.
  • Both labs install the registry component as a byte copy under src/components/flow-state/.
  • Docs: the registry.json description and each lab's README. The user-docs page and the ui README are left for the release docs pass (packages/ui is private, so there is no changeset; the spec's docs line names the page).
  • Brought up to date with main (via FIX-2406's branch). Teammates' popup Esc fix now rides on the registry's session-overlay, which main moved to; popup-escape.test.tsx runs against it.
  • Each lab's contract suite (FIX-2406's matrix) has rows for stopping a turn. Those rows run each lab's real host in process with a scripted model. The FIX-2375 it.fails gap marks become passing tests.

Evidence

  • After the main merge: ui 387/387, Claude Code-style lab 280/280 (contract 20/20), Teammates lab 290/290 (contract 24/24; one full run had 6 real-host rows time out under load, and they passed alone and on the re-run). Typecheck, check-retired-terms, the vocabulary sweep, fallow:ci and validate-user-docs-scope pass.
  • Registry: pnpm --filter @flow-state-dev/ui test passed 342/342 before the merge. Before the change, the new describe failed 3 of 16.
  • Claude Code-style lab: before the merge, vitest run passed 26 files / 192 tests. Contract red controls:
    • Pre-change adapter: 3 real stop rows fail with "condition never held".
    • Aborted→stopped mapping removed: 3 real rows fail.
    • Any 409 treated as stopped: the refusal row fails ("promise resolved undefined instead of rejecting").
  • Teammates lab: before the merge, vitest run passed 27 files / 207 tests, contract 24/24. Red controls:
    • Pre-change: 5 real rows fail with "lab.interrupt is not a function".
    • Mapping removed: 4 fail.
    • Any 409 treated as stopped: the refusal row fails.
    • Every ended turn mapped to stopped: the completed-turn row fails.
    • Stop using only the view's read of running turns: the new "turn sent just before the press" row fails on the real host, because the second turn runs on.
  • Other checks: typecheck passes for ui and both labs. pnpm fallow:ci is clean. check-new-dead-code against the base reports no issues. check-retired-terms passes.

Not done

  • No browser pass with a real model. This environment has no model key and no browser. The spec's browser pass (both labs: Stop mid-turn, the line, the count, the View button, the keys) still needs a QA run.
  • No changeset: packages/ui is private.
  • Teammates gap, still marked it.fails for the fake column: "stops only the turns answering at the press: a line sent after it runs on" (FIX-2376 owns the mid-turn line).

Notes for review

  • Teammates count rows file Coder tasks. Researcher tasks don't show up in runs; they come back as onMessageReceived turns, and Stop aborts those turns while they wait, per the spec's "everything but dispatch".
  • Tests simulate the 409-while-running case at the transport, because the real host can't race a turn on cue.
  • The two labs decide which turns Stop aborts in different ways:
    • The Claude Code-style lab reads the running turns when you press Stop.
    • The Teammates lab uses what the view shows answering, plus a fresh read of running requests at the press, so a turn sent just before Stop is stopped too.

https://claude.ai/code/session_01NczDiF6MmQeZ9KUe2E41Up


Generated by Claude Code

claude added 10 commits November 4, 2026 22:13
A turn the person stopped leaves a quiet status line, Interrupted by you,
with the live count of background work still running and a View.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NczDiF6MmQeZ9KUe2E41Up
…th the live background count (FIX-2375)

The adapter reads the session's recent turns, not only running ones, and puts
a stopped entry after the last entry of each aborted turn. The thread view
gains stopping (from the press until every turn it aborted has ended) and
backgroundRunning (the session stream's unfinished runs). The Stop button
waits while stopping, and a refused stop says why beside it. The dead
interrupted entry is now the registry's request-recovery stopped line, and
the contract matrix's stop rows check it on the real adapter (the FIX-2375
gap mark is gone).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NczDiF6MmQeZ9KUe2E41Up
…ecord (FIX-2375)

A 409 means the turn already ended, or an answer resumed it first and it runs
on. The adapter reads the record: still running, the stop was refused, and
the view clears Stopping and says so beside the button. The contract matrix
gains that row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NczDiF6MmQeZ9KUe2E41Up
…e live background count (FIX-2375)

The adapter gains interrupt: it aborts each answering turn the view shows
running at the press (never the board's dispatch passes), and a 409 is read
against the turn's record. The conversation view gains stopping and
backgroundRunning, and a stopped entry follows the last entry of each
aborted turn. The composer shows Stop beside Send; Esc Esc and Cmd/Ctrl+.
stop from anywhere, and the session popup spends its own Esc. The contract
matrix gains the turn-stop rows on both columns, and the fake follows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NczDiF6MmQeZ9KUe2E41Up
…ery copies' unused reason (FIX-2375)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NczDiF6MmQeZ9KUe2E41Up
…t the view hasn't read yet (FIX-2375)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NczDiF6MmQeZ9KUe2E41Up
@vercel

vercel Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
flow-state-dev-docs Ready Ready Preview Nov 8, 2026 4:18pm UTC
2 Skipped Deployments
Project Deployment Actions Updated
flow-state-dev-ui Ignored Ignored Preview Nov 8, 2026 4:18pm UTC
flow-state-dev-build-site Skipped Skipped Nov 8, 2026 4:18pm UTC

Request Review

@linear-code

linear-code Bot commented Nov 8, 2026

Copy link
Copy Markdown

FIX-2375

@jhoffner jhoffner assigned jhoffner and unassigned Copilot Nov 8, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-08T16:20:13.781450Z 1bcd23c New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

jhoffner commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator Author

Second look + architecture notes

Read the diff against the base (37a6244a..2bbe9b5b), plus both adapters and the registry copies. Nothing here blocks. The approach (stop = abort the turns running at the press, stopped derived from the request record, the 409 resolved by reading the record) is sound and the red controls in the description cover the right failure modes. Notes are ordered by value; the first two are the only ones I'd act on in this PR.

1. The same stop lifecycle is hand-written twice (worth extracting, modestly)

labs/claude-code-style/src/adapter.ts and labs/teammates/src/adapter.ts each carry a near-identical block:

  • a stops map, a stopWatchers map, wake, and a done() that clears the stop and wakes the views;
  • the abort loop with the same .catch that treats a 409 as "ended meanwhile" unless a re-read of the record still says in_progress, in which case it throws the same "The turn went on before the stop reached it. Press Stop again." message.

That 409-versus-record rule is the subtle part of this change (it's the bug the PR exists to fix), and it now has two copies that must stay in lockstep. A small shared helper, e.g. abortTurns(client, flow, ids, readRecord) plus a tiny createStopTracker() in a lab-shared module (or @flow-state-dev/client if FIX-2376 / Kitchen Sink will want it), would put the rule and its error text in one place and let the contract matrix test it once. If you'd rather wait for a third consumer, add a comment in each copy pointing at the other so they don't drift. I'd lean towards extracting now, since the logic is not lab-specific.

2. Teammates' runningNow / answeringTurnsOf may be redundant with the fresh read

interrupt takes the union of "what the view showed answering" and a fresh sessions.requests({status:"in_progress"}) read. The view-side set exists because "the list trails the items", but the fresh read happens at the press, after the view's data, so it is by construction at least as current. If the fresh read alone passes the "turn sent just before the press" row, runningNow, the per-conversation map cleanup, and answeringTurnsOf can go, and the two labs would then decide "which turns Stop aborts" the same way (the description flags that they currently differ). If the row only passes with the union, keep it and note why in the header comment (an in-flight message item can exist before the request row is listed). Please confirm which with the red control rather than the reasoning.

3. Stop-end detection can stick on a turn that leaves the read window

Both labs clear stopping only when every aborted id appears in the latest request read with a non-in_progress status (limit: 50 in Claude Code-style, limit: 20 in Teammates). An id absent from the window makes the every(...) false forever and the composer shows "Stopping…" indefinitely. Unlikely for a just-aborted turn, but a long-lived session with many quiet/dispatch turns makes it possible. Cheap guard: treat an id missing from a read that is already full-window as ended, or end the stop on a timeout. At minimum, add a test row for the missing-id case.

4. Two implementations of "insert a line after a turn's last entry"

withStopped (Claude Code-style, via a lastOf map and flatMap) and the endOf + reverse splice in Teammates' toEntries do the same job differently. These are different entry shapes so a shared one isn't free, but the Teammates version (count-and-splice from the end, with a grew check that compares the last entry by identity) is the harder one to read and verify. Consider mirroring the lastOf/flatMap approach, or tracking requestId on entries as the Claude Code-style lab does so the line can be placed without counting.

5. Byte-copied registry component, and the .fallowrc.json cost

The request-recovery.tsx copies are identical to the registry source (verified with diff), which matches the existing convention for error.tsx and connection-screen.tsx. The cost shows up as two more .fallowrc.json suppressions for the unused reason constant. That's consistent with the current pattern, so no change requested, but it's the third and fourth such entries for this reason; if the registry exports only what a consumer reads, those entries go away.

Not flagging

  • Counting backgroundRunning from the feed's runs with null meaning unknown, and showing it only on the newest stopped line, looks right.
  • The build() cache in the Claude Code-style thread (rebuild only on items/turns change, not on runs-only changes) is a reasonable use of the opportunity while touching this code.
  • No browser pass is listed as not done; fair, but this is UI-layer, so it does still need the QA run from the spec before merge.

Generated by Claude Code

Comment thread labs/teammates/src/adapter.ts Resolved
Comment thread labs/teammates/src/adapter.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2bbe9b5bed

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread labs/teammates/src/adapter.ts Resolved
…e outlives the recent-requests read (FIX-2375)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NczDiF6MmQeZ9KUe2E41Up
…he stop keys see it (FIX-2375)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NczDiF6MmQeZ9KUe2E41Up
…t alone (FIX-2375)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NczDiF6MmQeZ9KUe2E41Up

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 815410b1ea

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread labs/teammates/src/adapter.ts Resolved
…en when its read answers late (FIX-2375)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NczDiF6MmQeZ9KUe2E41Up

jhoffner commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator Author

Process guards: check-retired-terms collection-row (16 lines). The failure comes from the stack's base, not from this change. None of the 16 lines is in a file this PR edits. They come from an older main that this branch picked up through the merged FIX-2375/FIX-2376 spec branch: they are absent from the base (claude/project-thread-76q4pb, FIX-2406's branch, forked earlier) and current main has already renamed them. The fix is to bring main into the stack. I've asked FIX-2406's thread to merge main into its branch first, so the harness files get resolved once. I'll then merge it here and resolve the labs conflicts with main (FIX-2479, FIX-2354, FIX-2578). Until then this check stays red, and the other checks were cancelled by the review-fix pushes.


Generated by Claude Code

Keeps main's renames, the failed turn and Retry, the shared session
overlay and the lead wording, with FIX-2375's stop behaviour on top.
The Teammates popup's Esc handling now lives in the registry overlay.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NczDiF6MmQeZ9KUe2E41Up
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NczDiF6MmQeZ9KUe2E41Up
… (FIX-2375)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NczDiF6MmQeZ9KUe2E41Up
The registry's stopped look is described in the registry entry and the lab
READMEs; the site page and the ui README change in the release docs PR.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NczDiF6MmQeZ9KUe2E41Up
@gitar-bot

gitar-bot Bot commented Nov 8, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 3 closed / 3 findings

🟡 Medium risk · Adding Stop to both labs aborts active turns while spawned tasks continue, so users could lose an in-progress response while background work remains.

Adds a stop control to the Claude Code-style and Teammates labs that interrupts running turns, shows an "Interrupted by you" line with a background task count, and handles 409 aborts by reading the turn's record. Resolved this session: stale half-written turns no longer leave Stopping… stuck, the stopped line persists after its request leaves the read window, and Esc in the ⌘K switcher closes the popup beneath it instead of the switcher. No open issues found.

✅ 3 closed
✅ Bug: Old half-written turns get into Stop's ids and leave Stopping… stuck

📄 labs/teammates/src/adapter.ts:830-835 📄 labs/teammates/src/adapter.ts:1075 📄 labs/teammates/src/adapter.ts:1079 📄 labs/teammates/src/adapter.ts:1018-1021 📄 labs/teammates/src/adapter.ts:1038
answeringTurnsOf takes every message/tool_output item that still says in_progress, unless its request is in ended. But ended is built only from the last 20 requests (client.sessions.requests(sessionId, { limit: 20 })), and dispatch passes count toward those 20. answeringOf already warns that a crashed or aborted turn leaves its half-written item that way for good, which is why it only trusts the newest request. answeringTurnsOf has no such limit. Once such a turn drops out of the 20-request window, it lands in runningNow, and every later interrupt adds it to stop.ids.

The abort then gets a 409. The record lookup also reads only 20 requests, finds nothing and treats the turn as stopped. emit clears the stop only when every id is in ended, which never happens for this one. The result: stopping stays true, the button stays disabled on Stopping…, and useInterruptKeys stays off until the page reloads. Fix: apply the same newest-request rule here that answeringOf uses, so only the newest request or one the list names counts.

✅ Edge Case: "Interrupted by you" disappears once its request leaves the read window

📄 labs/teammates/src/adapter.ts:1117 📄 labs/claude-code-style/src/adapter.ts:223 📄 labs/claude-code-style/src/adapter.ts:602-605 📄 labs/claude-code-style/src/adapter.ts:1036
Both adapters build the stopped lines only from a bounded list of recent requests. Teammates uses the same limit: 20 read, which also counts dispatch passes. Claude Code-style uses recentTurns with RECENT_TURNS = 50. After enough later requests, the aborted turn drops out of that list, so it is no longer in stopped, and its line silently vanishes from the thread even though its items are still loaded. That breaks the spec's promise that the line survives a reload because it is read from the turn's record. Fix: keep a set of aborted ids that only grows for the life of the view, or ask for aborted requests directly (status: "aborted") when building the stopped set.

✅ Bug: Esc in the ⌘K switcher now closes the popup under it, not the switcher

📄 labs/teammates/src/components/SessionPopup.tsx:33-44
Moving the popup's keydown listener to the document capture phase puts it on the same node and phase as Radix's Esc listener. ownEscape (lib/keys.ts:99) calls stopPropagation() there so popups and sheets underneath never see the Esc, but stopPropagation doesn't stop other listeners on the same node, so it no longer shields the popup. ⌘K still opens the Switcher while a SessionPopup is open (useLabKeys lets ⌘K act inside a dialog). The popup's listener was registered first, so it runs first: it calls preventDefault() and onClose(). Radix's DismissableLayer then sees defaultPrevented and skips its own dismiss. The result is that Esc closes the hidden popup and leaves the Switcher, or KeysSheet, open on top. Before this change, the bubble-phase listener was cut off by ownEscape's capture-phase stopPropagation. A fix: skip the Esc in the popup handler when the event target is outside the popup's own dialog, or when another dialog is open above it. Add a test that opens the Switcher over a popup and presses Esc.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@jhoffner
jhoffner added this pull request to stack #4944 November 8, 2026 16:22
Base automatically changed from claude/project-thread-76q4pb to main November 8, 2026 16:25
@jhoffner
jhoffner added this pull request to the merge queue Nov 8, 2026
Merged via the queue into main with commit 9469293 Nov 8, 2026
27 checks passed
@jhoffner
jhoffner deleted the claude/project-thread-ft4mpv branch November 8, 2026 16:25

This branch was successfully deployed

1 active deployment
Preview – flow-state-dev-docs — 1bcd23cf Deployed Nov 8, 2026 by vercel[bot]
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.

3 participants