Skip to content

feat(site/src): list, pause and cancel chat wake-ups in the composer - #146

Merged
ibetitsmike merged 134 commits into
mainfrom
mike/chat-wakeups-10-ui
Nov 11, 2026
Merged

ibetitsmike merged 134 commits into
mainfrom
mike/chat-wakeups-10-ui

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

Part of #11 (W5 chat wake-ups), stacked on #134.

Adds a wake-ups pill to the agent chat composer, next to the todo pill, so you can see what a chat is scheduled to do and stop it without asking the agent. The pill needs the fork-chat-wakeups experiment and uses the API from #134.

  • Pill: an alarm clock with the number of open (active or paused) wake-ups. It is hidden while the list loads and when no wake-up is open, and shows a warning pill when the first load fails.
  • Popover: one row per open wake-up with its schedule ("Every 5m", "Cron ... (tz)", "Once", or "Waiting for events" with the child agents, or the pull requests and the events they wait on), the prompt, the next run or a readable pause reason, and the run count. Each row has Pause or Resume and Cancel. While one update is pending, every row's buttons are disabled, and they are also disabled when the composer is. An update error shows on its row as an alert, and a failed refresh shows above the list.
  • Data: GET /api/v2/chats/fork/{chat}/wakeups polled every 30s, because wake-ups have no watch socket and the worker changes them. A PATCH writes the returned wake-up into the cache and refetches when it settles, also after an error.
  • Shared popover: ComposerPillPopover now holds the pill trigger, popover and error pill that ChatTodoPill used inline, and both pills use it.

Tests: ForkComposerSlot.test.tsx checks that no wake-ups request is made while the experiment is off, that todos and wake-ups both load when both experiments are on, that Pause and Cancel send the right PATCH, that a pending update blocks the other rows, and that the pill follows the composer's disabled state. Stories in ForkChatWakeupsPill.stories.tsx cover the collapsed, expanded, mobile, load error, update error, pending, refresh error and last-canceled states.

Left out on purpose after review:

  • A list shell shared with ChatTodoChecklist: the two lists only share markup today.
  • An exit animation for the popover when the last wake-up goes away, and moving focus when that happens.
  • A loading placeholder: the todo pill also renders nothing while it loads.
  • Stopping the poll when no wake-up is open: the poll is how the pill sees a new one.
  • A full prompt view on touch devices: the clamped prompt has a title for hover only.

UAT: passed on 2026-11-10 against the fork UI UAT server (backend main 4b0b4a0, fork-chat-wakeups on), frontend at 7e33800 (contains this head's diff), as a member user in a real browser. A /loop 10m message showed the wake-ups pill with its schedule, prompt and next run; pause, resume and cancel each sent one PATCH and the list API agreed; a chat with no wake-ups shows no pill; the pill and popover work by keyboard (Tab, Enter, Escape returns focus). Flag-off was not testable on that server and stays covered by the ForkComposerSlot tests. The pill picks up a new wake-up on its 30 s poll, not immediately after send.

Xum opened this PR on behalf of @ibetitsmike.

Adds the fork-chat-wakeups experiment and the storage for chat wake-ups: a
chatdmig node with chatd.chat_wakeups and chatd.chat_wakeup_runs, forkdb
queries to create, list, pause, cancel and claim due wake-ups with a lease
(FOR UPDATE SKIP LOCKED), run records unique per occurrence and daily run
counts, with their dbauthz and dbmetrics wrappers.

Refs #11.
…ke-up

InsertChatWakeupRun now selects chat_id and organization_id from the
wake-up and authorizes on the wake-up's chat, so a caller cannot record
a run of one chat's wake-up against another chat. Adds the chatd
architecture TODO for the new state.
chat_wakeups gets organization_id, copied from the chat by
InsertChatWakeup, so organization-scoped lists and caps need no join.
A wake-up run now takes its organization from the wake-up.
…chema

# Conflicts:
#	coderd/database/dbauthz/fork_forkdb.go
#	coderd/database/dbmetrics/fork_forkdb.go
#	coderd/database/forkdb/forkdbmock/forkdbmock.go
#	coderd/database/forkdb/querier.go
#	coderd/database/forkdb/sqlc.yaml
… hook denial

Start the worker to prove the hook line runs the wake-up loop on start and
on each poll tick, cover all three busy statuses, an expired wake-up, a
hook denial that pauses the schedule, and assert that concurrent workers
never queue a duplicate prompt behind the turn the first delivery starts.
Insert the delivered run and end the claim inside SendMessage's
transaction, so a chat that turned busy, an occurrence that already ran,
or a canceled or taken-over claim rolls the message back. Hook dispatch
failures no longer pause the wake-up, and each claimed row uses the time
it is processed.
… mike/chat-wakeups-3-loop

# Conflicts:
#	coderd/x/chatd/chat_mutations.go
…occurrences

Busy chats are no longer claimed, so their rows cannot fill the claim batch.
A full queue keeps the occurrence due like any other busy race, and a failed
send records its run only after the worker proves it still holds the lease.
…wake-up

The wake-up ID derives from the tool call, so a call replayed after a worker
restart finds the wake-up it created instead of adding a second one.
A paused chat, or an errored chat with a non-empty queue, would queue the
wake-up prompt, so its due rows filled the claim batch on every poll.
Delivery times now also count the time the claim query took.
…mpossible cron

- schedule_wakeup takes the ID of the tool-call occurrence, since providers
  can reuse a call ID in a later step.
- A replayed call returns its wake-up before the first run is recomputed.
- A cron schedule that never occurs is refused.
- user_prompt_submit hooks see the /loop command as submitted.
- A /loop wake-up is attributed to the user who sent it.
…s to the loop

A /loop command as the first message of a new root chat now creates its
wake-up in the transaction that inserts the chat, through a ForkAfterInsert
hook on chatstate.CreateChatInput. A subagent first message is never parsed,
since its parent model wrote it. When a user_prompt_submit hook replaces the
prompt, the loop runs the replacement.
…orker

# Conflicts:
#	coderd/database/forkdb/chat_wakeups.sql.go
#	coderd/database/forkdb/querier.go
#	coderd/database/forkdb/queries/chat_wakeups.sql
…NoKeyUpdate

The busy-chat filter in ClaimDueChatWakeups skipped an archived errored
chat with a queued message forever, so the worker never canceled its
wake-up. Archived chats are now always claimed.

Also restores the LockChatForNoKeyUpdate querier method that the merge
with main dropped.
…flake the per-child tick

Add TestWakeupEventsUnknownAndInvalidEvents: an event type the worker does not know sends nothing and does not hold the wake-up open, and events that are not a JSON array pause it with reason invalid_events.

TestWakeupEventsDeliversOncePerChild advanced its clock by exactly the poll interval, but the worker adds the time it spent since the claim to the next poll, so under load a tick came microseconds before the wake-up was due and skipped a delivery. Tick one second past the interval.
…nd schedule from admission

A wake-up that resumes a finished child now carries the message_agent
resume marker, so the family live subagent limit applies. The next run is
computed from the admission time, so a hook that delays admission past
the next slot does not leave an already-due schedule. A failed run is
recorded in the transaction that ends the claim.
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum posted this on behalf of @ibetitsmike.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 311a531b26

ℹ️ 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".

# Conflicts:
#	coderd/database/dbauthz/fork_forkdb.go
#	coderd/database/dbmetrics/fork_forkdb.go
#	coderd/database/forkdb/forkdbmock/forkdbmock.go
#	coderd/database/forkdb/querier.go
…r-events

# Conflicts:
#	coderd/x/chatd/fork_wait_for_events.go
#	coderd/x/chatd/fork_wakeups.go
…nto mike/chat-wakeups-8-loop-archive

# Conflicts:
#	coderd/exp_chats.go
#	coderd/x/chatd/fork_family_lock.go
…oop-archive

# Conflicts:
#	coderd/x/chatd/fork_wakeups.go
Base automatically changed from mike/chat-wakeups-9-api to main November 10, 2026 22:36
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum (AI agent) closed and reopened this on behalf of @ibetitsmike.

Closing and reopening only to make GitHub recompute the merge ref against current main (50e9121c3b) and run fork-ci on it. The head is unchanged.

@ibetitsmike ibetitsmike reopened this Nov 10, 2026
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum (AI agent) closed and reopened this again on behalf of @ibetitsmike.

The merge ref now points at current main (50e9121c3b), but the run started by the first reopen was queued against the old merge ref. This second reopen starts fork-ci on the recomputed merge. The head is unchanged.

@ibetitsmike ibetitsmike reopened this Nov 10, 2026
@ibetitsmike
ibetitsmike merged commit 3839333 into main Nov 11, 2026
21 of 28 checks passed
@ibetitsmike
ibetitsmike deleted the mike/chat-wakeups-10-ui branch November 11, 2026 00:41
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum (AI agent) merged this on behalf of @ibetitsmike.

Merge evidence for head 7eab07b5c3b0353f7b9ddf177572e7f5911f4b27:

  • fork-ci pull_request run 42926886110 passed; its build job checked out Merge 7eab07b5c3 into 50e9121c3b (current main). Run 42916314978 had also passed on this head against 4b0b4a0706. All checks green.
  • Codex: no major issues on 311a531b26 (comment 6773291567). This head only merges main; limited to this PR's 9 files, its diff has the same patch ID as 311a531b26's. 0 of 29 review threads unresolved; the declined findings (focus and accessibility edge cases, polling every wake-up, truncated prompt hover, the shared error pill announcement, disabled controls with no model) were declined with reasons.
  • UI UAT on :3100 (backend 4b0b4a0706, fork-chat-wakeups on) with the frontend at feat(site/src): show the wake-up tools as chat tool cards #149's head, which contains this diff unchanged, as a member user: no pill without wake-ups; after /loop 10m the pill and its popover showed the schedule, prompt and next run, matching the API; pause, resume and cancel each sent one PATCH that returned 200, with the API agreeing; Tab, Enter and Escape moved and returned focus. The pill appears on the 30 s poll, not right after send; accepted as is. Cleanup verified by Fork ops.
  • No migration.

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