Skip to content

feat(site/src): show the wake-up tools as chat tool cards - #149

Merged
ibetitsmike merged 147 commits into
mainfrom
mike/chat-wakeups-11-tool-cards
Nov 11, 2026
Merged

ibetitsmike merged 147 commits into
mainfrom
mike/chat-wakeups-11-tool-cards

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

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

Shows the three wake-up tools as chat tool cards rather than the generic tool fallback. The cards need the fork-chat-wakeups experiment; with it off, the tools render as before.

  • schedule_wakeup: "Scheduled a wake-up every 5m" (or "on cron ... (tz)", "in 5m"), with the prompt, and the next run, run limit and expiry, one per line. While the call runs, the label already shows the schedule from the args.
  • wait_for_events: "Waiting for 2 child agents and a pull request", with a link to each child chat, a link to the pull request that lists the events it waits on, and when the wait stops.
  • notify_user: "Sent a notification" with the message.
  • Failed calls show the tool's error. A result that the card cannot parse falls back to the generic tool card.
  • Icons: an alarm clock, an hourglass and a bell. The tool showcase fixture has a row for each tool.

To share code, ForkChatLink now exports its link row class for the pull request link, and wait_for_events reuses the child entry parser of search_chats.

Tests: ForkWakeupTools.stories.tsx covers interval and cron schedules, the running and failed schedule cards, the experiment off, wait_for_events with children and a pull request, with only a pull request, failed, and with an unparsable result, and notify_user sent and failed.

Left out on purpose, to stay under 500 lines: running stories for wait_for_events and notify_user (header only), and a story for the delay schedule label.

UAT: passed on 2026-11-10 against the fork UI UAT server (backend main 4b0b4a0) at 7e33800, in a real browser. The schedule_wakeup card ("Scheduled a wake-up every 1h", prompt and local next-run time) and the notify_user card (title and message) render collapsed and expanded, and their headers toggle with Enter and Space. The wait_for_events card was checked in its error state ("Failed to wait for events" with the server's reason); its success state needs a child chat or a linked PR and was not exercised.

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.
@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 6ab1c0d1f2

ℹ️ 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-10-ui to main November 11, 2026 00:41
…tool-cards

# Conflicts:
#	site/src/testHelpers/forkChatWakeups.ts
@ibetitsmike
ibetitsmike merged commit cd0ba56 into main Nov 11, 2026
9 checks passed
@ibetitsmike
ibetitsmike deleted the mike/chat-wakeups-11-tool-cards branch November 11, 2026 00:56
@ibetitsmike

Copy link
Copy Markdown
Owner Author

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

Merge evidence for head 75f0802dbdf7d8b91c0ebb00549f8305b6b8a228:

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