Repository navigation
feat(coderd): wake a chat on pull request activity - #131
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.
# 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
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d8b3d03d1a
ℹ️ 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".
|
@codex review
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9ccfcfc2b5
ℹ️ 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".
Closing and reopening only to make GitHub recompute the merge ref against current main ( |
The merge ref now points at current main ( |
Merge evidence for head
|
Part of #11 (W5 chat wake-ups), stacked on #115.
A chat can now wait for activity on a pull request.
wait_for_eventstakes an optionalpull_request_urlandpull_request_events(any ofreview,comment,checks,closed). The wake-up worker polls the pull request through the chat owner's linked git account every 60 s and wakes the chat when requested activity from someone other than the owner shows up.- and N more.closedwakes on close or merge. A pull request that closes whenclosedwas not requested stays pending until the wake-up expires.Commits 1 to 4 are the GitHub activity reader from #121, cherry-picked because this stack's base predates it. They are already in
mainand will drop out when the stack is rebased ontomain.Hot files:
coderd/coderd.go(1 line, setsForkPullRequestActivityin the chatd config) andcoderd/x/chatd/chatd.go(3 small hunks for the config field).Tests: table tests at the worker boundary in
fork_pull_request_events_internal_test.goand a coderd boundary test for provider and token resolution. Negative controls were run on each assertion (27 breaks, all caught).UAT: passed on
3f6e2f05d0against a local server with a linked GitHub account and a throwaway draft PR (#129, closed). The Codex bot comment woke acommentwatch once, listing the bot and the comment URL with no body; the owner's own comments woke nothing over 3 polls; closing the PR woke aclosedwatch in 15 s; a merged PR, a non-PR URL and a missing repo were refused at the tool call;next_run_atadvanced by 60 s per poll. A baselinechecks_stateofsuccessturned out to be three completed check runs on the head, not a zero-check rollup (zero checks read asnone).