Repository navigation
feat: manage a chat's wake-ups through the API - #134
Merged
Merged
Conversation
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.
…oder into mike/chat-wakeups-2-worker
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.
… mike/chat-wakeups-3-loop
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.
… mike/chat-wakeups-3-loop
…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.
… mike/chat-wakeups-3-loop
…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.
…ike/chat-wakeups-4-events
…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.
This was referenced Nov 10, 2026
# Conflicts: # coderd/database/forkdb/chat_wakeups.sql.go # coderd/x/chatd/fork_tools.go # coderd/x/chatd/fork_wait_for_events.go # coderd/x/chatd/fork_wait_for_events_internal_test.go # coderd/x/chatd/fork_wakeups.go
…ain on a new UTC day
…t-wakeups-7-pr-events
# Conflicts: # coderd/database/dbauthz/fork_forkdb.go # coderd/database/dbmetrics/fork_forkdb.go # coderd/database/forkdb/forkdbmock/forkdbmock.go # coderd/database/forkdb/querier.go
…t-wakeups-7-pr-events
…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
…' into mike/chat-wakeups-9-api
…t-wakeups-8-loop-archive
…oop-archive # Conflicts: # coderd/x/chatd/fork_wakeups.go
…' into mike/chat-wakeups-9-api
Owner
Author
Merge evidence for head
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #11 (W5 chat wake-ups), stacked on #133.
Adds an API to list a chat's wake-ups and to pause, resume or cancel one. Both routes need the fork-chat-wakeups experiment and are left out of the generated docs.
GET /api/v2/chats/fork/{chat}/wakeupsreturns[]codersdk.ChatWakeup, oldest first, for anyone who can read the chat.eventsis a typed list (type,chat_id,url,on), and internal fields such as the pull request baseline are left out.PATCH /api/v2/chats/fork/{chat}/wakeups/{wakeup}takes{"status": "active" | "paused" | "canceled"}and returns the wake-up.GetChatWakeupByIDForUpdate) and clears the worker's lease, so a worker that finishes its claim in between changes nothing.writeof the chat, withwakeup_id,old_statusandnew_statusin the additional fields.Generated:
coderd/apidoc,docs/reference/api/schemas.md,site/src/api/typesGenerated.ts, and the forkdb query, mock and dbauthz/dbmetrics wrappers for the new lock query.coderd/x/chatd/ARCHITECTURE.mdgets oneTODO(ibetitsmike)line.Tests:
coderd/fork_chat_wakeups_test.gocovers the experiment gate, listing, every status transition (13 cases), refusals and audit. The dbauthz suite covers the new query.UAT: passed on a local dev instance at 1df817c. An invalid
/loop(no prompt, or an interval over 720h) returns 400 "Invalid /loop command." with the reason in the detail. GET lists the chat's wake-ups. PATCH pause, resume and cancel each change the status, and GET shows it. PATCH returns 409 on a finished wake-up and 404 for a wake-up of another chat. Every PATCH, including the refused ones, leaves an audit log entry.