Skip to content

Take Running off a routine's list row when its run ends - #3979

Merged
backnotprop merged 5 commits into
mainfrom
fix/routine-row-stuck-running
Nov 24, 2026
Merged

backnotprop merged 5 commits into
mainfrom
fix/routine-row-stuck-running

Conversation

@backnotprop

Copy link
Copy Markdown
Owner

A routine's row in the Inbox list kept its animated Running mark for hours after the run ended. Opening the thread fixed it at once.

Cause

  • The row reads state === 'running' from the routines store (packages/inbox/scheduled/rowLook.tsx:35). The server derives that state from the run's launch line (packages/server/inbox-scheduled.ts:114,123, launch.runOfMessage → runOfRoot), which is the same line the open thread shows.
  • A run ends when its session answers and goes idle. Nothing is written to the store when that happens. Only the launch line moves, and that moves launch.signature() (packages/server/inbox-launch.ts:2672), so the window gets event: deliveries (packages/server/inbox.ts:5076).
  • The routines store re-read on that frame only while the Routines page was open: event === null ? pages > 0 (packages/inbox/scheduled/store.ts:68 on main). The agent's reply does not carry scheduled_run, so it never triggered a re-read either. The row stayed on the value read when the run's divider arrived.
  • Opening the thread "fixed" it because POST /threads/:id/seen → store.markSeen (packages/shared/inbox/store.ts:3965) rewrites the thread's root. That root is the first run's divider and carries scheduled_run, so its message record made the store read again.

This affected every run that ended (replied, stopped, or failed) while the window was on the list. Separately, a deliveries frame that went out while the stream was down (laptop asleep, Inbox restart) is never replayed, and nothing re-read the routines on reconnect or when the window was shown again.

Fix

packages/inbox/scheduled/store.ts:

  • When a deliveries frame arrives, the store reads again while the Routines page is open or a routine is running. While nothing runs, nothing extra is read: a run's start already arrives as its divider record.
  • It reads again on every reconnect: scheduledFrame('connect') from the hello frame in packages/inbox/eventFrames.ts, which reaches every tab, shared-stream followers included.
  • It reads again when the window becomes visible while a run is under way (visibilitychange, attached only while something uses the store).

Nothing new on screen. Reads happen at most once per deliveries frame (at most one per second, and only when a launch line moves), and only while a run is under way. That is the same pace as the list's own re-read.

Tests

  • packages/inbox/scheduled/rowRunEnds.test.tsx (DOM): the real InboxList and the real dispatchInboxFrame. A deliveries frame takes Running off. A stopped or failed run turns to the warn mark. hello reads again. Visibility reads again. Nothing running means no read. Against main, 4 of these 5 fail; the "no read" guard passes there too.
  • tests/e2e/inbox-routine-row-run-ends.spec.ts: the compiled binary with fake Claude Code (hold). It makes a routine and runs it, and checks Running on a wide window and a phone-sized one. It then lets the turn answer, and checks that both windows drop Running with no thread or Routines page opened.

Docs: docs/agent-guides/inbox-routines.md.

e2e: inbox-routine-row-run-ends.spec.ts inbox-routine-editor.spec.ts

A run's end writes no store line: only its launch's run line moves, which the
window hears as event: deliveries. The routines store read again on that frame
only while the Routines page was open, so a list row kept Running for hours,
until opening the thread rewrote its root (a run divider) and the store read
again. Read again on deliveries while a run is under way, on every reconnect,
and when the window is shown again while a run is under way.
@backnotprop backnotprop added the ci:e2e Run the full browser suite (Inbox window e2e) on this PR label Nov 24, 2026
@backnotprop
backnotprop marked this pull request as ready for review November 24, 2026 07:55
@backnotprop
backnotprop merged commit ce9338a into main Nov 24, 2026
39 checks passed
backnotprop added a commit that referenced this pull request Nov 24, 2026
…es CI checks

Merged main's routine re-reads (#3979: a run under way, a reconnect, the window shown again) into the store with this
branch's linked-computer reads. Resolved by hand: packages/inbox/scheduled/store.ts, packages/core/inbox-types.ts,
packages/server/inbox-machines.ts, packages/server/inbox.ts, tests/e2e/slice-rules.ts, tests/e2e/shard-times.json and
apps/mobile/contract/parity/surface.json; the ledger and Wire.swift taken from main, then the mobile contract regenerated.

- The routines-machines e2e gives each computer the fake claude on its launch PATH and the plugin in its agent home,
  as a sandboxed Inbox needs (as inbox-routine-row-run-ends.spec.ts): without them a Run there never started. The
  fake's turn holds, so the run stays Running.
- The door table test fills a routine's id (sch_1), so the scheduled/:id routes are checked against their own entries.
- The linked test expects the far switches read's own words (held, away, read_at).
- rowRunEnds' stand-in answers the window's read with ?machines=1, as a server does.
- A forward test: Run once now with that computer online goes there at the press, keyed, with the window's mark.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:e2e Run the full browser suite (Inbox window e2e) on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant