Repository navigation
Conversation
Every coderd instance now scans for due schedule automations at start and every 30 seconds. The scan reads due rows without locks, decides the chat-automations experiment once per owner, and treats occurrences older than a 60 second grace window as missed: it moves the cursor to the next cron time and publishes nothing. Other occurrences are published with the observed schedule revision and cursor. The admission callback rechecks both under the chat and automation locks, reads the clock after the locks, and moves the cursor in the same transaction, so exactly one instance accepts each occurrence. Refusals (busy chat with skip, full queue or automation share, hook denial, lost permission, experiment off, expired occurrence) skip the occurrence with the same conditional cursor write; other errors retry within the grace window. Publish now checks the experiment for every publisher, and new chats of schedule automations are titled in the schedule's time zone. Part of CODAGT-1211.
The schedule loop's guarded cursor write is now authorized like other object writes: the dbauthz wrapper loads the automation and requires update on it. The chatd subject gains update on chat_automation (read already existed); owner-only changes stay in the chatd automation service, and chatd still cannot create or delete automations. The cursor now only moves forward, and a comment explains why clock skew between instances cannot accept an occurrence twice or replay one. The schedule tests run their servers through dbauthz, so they exercise the chatd subject's real permissions. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
…chat' into tk/codagt-1211-automations-schedules # Conflicts: # coderd/x/chatd/automations_publish.go
|
@codex review |
…chat' into tk/codagt-1211-automations-schedules
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
A chat created through the chat API or by a webhook event records an audit entry. A chat that a new_chat schedule creates now records one too, as created by the automation owner, with the automation and input ids in the additional fields. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0787d0896b
ℹ️ 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".
…refusals The scan read one page of 500 due schedules per tick. Rows that stay due, such as those of owners with the experiment off, stayed first in every page and could hide all other schedules, and a large burst could wait past the grace window. The scan now pages by (cursor, id) until a page comes back short. A Publish refusal because the experiment is off for the owner no longer skips the occurrence: the evaluator also reports a failed read as off, so the cursor stays for a retry within the grace window, and the next scan drops an owner whose experiment really is off. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d35563001a
ℹ️ 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".
A scan published due occurrences one at a time, so an occurrence that waited for a chat lock or a slow hook held back every later schedule, which could then expire past the grace window. The scan now publishes up to eight occurrences at once and returns when all are done. A chat that a new_chat schedule creates is now titled with its occurrence's scheduled time, which does not depend on how long hooks and locks take before acceptance. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
GitHub created no pull_request runs for the last two pushes while the PR mergeability stayed unknown. This commit changes no files. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
|
CI note: GitHub has not created Local gates on every pushed head: Generated with |
|
CI evidence for the exact head d483cd5: Why workflow_dispatch: GitHub creates no pull_request runs for this pushed stacked PR, and its mergeable state stays UNKNOWN. Attempt 1 failed only in Generated with |
…agt-1211-automations-schedules No conflicts. make gen produced no diff. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
|
sync with main d9c13dc: no content conflicts; make gen produced no diff
Generated with |
…agt-1211-automations-schedules No conflicts. make gen produced no diff. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
|
sync with main 35abc22: no content conflicts; make gen produced no diff
Generated with |
ibetitsmike
left a comment
There was a problem hiding this comment.
Xum (an AI coding agent) prepared and posted this review on behalf of Mike. Each finding came from automated review passes and was re-verified against the code; please push back on anything that looks wrong.
The schedule scanner matches the CODAGT-1211 scan requirements for this layer: an unlocked keyset-paged due read, per-owner experiment evaluation, a guarded forward-only cursor write, the skip versus retry split, and fake-clock tests for every required check. go test ./coderd/x/chatd -run TestAutomationSchedule passes locally at this head (all 19 TestAutomationScheduleScan subtests, nested ones included, plus TestAutomationScheduleLoopScansAtStart). Only small nits remain.
Verdict: no blocking issues
Severity: P0 0, P1 0, P2 0, P3 2 (1 inline, 1 below)
Nits:
coderd/x/chatd/automation_schedules.go:135-137:scanAutomationSchedulesonly forwardsautomationScheduleBatchSizetoscanAutomationSchedulePagesso tests can pass a smaller page. The worker already handles this with an option and a default (ArchiveBatchSize, and this PR'sAutomationScheduleInterval). AnAutomationScheduleBatchSizeoption would remove the wrapper and follow that pattern.
Review coverage
- code-review Standards: 3 findings. 1 kept (detached doc comment), 1 folded as a nit (batch size wrapper), 1 dropped (ARCHITECTURE.md section: AGENTS.md says reviewers treat changes to that document as the owner's work, and the PR body says the author asked for the prose)
- code-review Spec: 1 finding, dropped (the same ARCHITECTURE.md point); all scan requirements and required checks for layer 7a are met, and Run now is in #30166
- frontend-review: skipped, no files under site/
- coder-frontend-review: skipped, no files under site/
- Existing Codex threads (6, all resolved): fixes verified at this head; CODAGT-1234 tracks the deferred hook double-dispatch
| // clock that runs ahead can skip the occurrences within d of true time. | ||
|
|
There was a problem hiding this comment.
P3: Blank line detaches the doc comment from checkAutomationOccurrence
The blank line at 73 separates the 15-line comment from the function, so go/doc and editors do not treat it as the function's doc comment. Hovering checkAutomationOccurrence then hides the clock-skew argument that the PR body points reviewers to. This is still the case at the top of the stack (#30220).
Fix: Delete the blank line.
| // clock that runs ahead can skip the occurrences within d of true time. | |
| // clock that runs ahead can skip the occurrences within d of true time. |
There was a problem hiding this comment.
Fixed in 67db54f: the blank line is gone, so the comment documents checkAutomationOccurrence again. The same commit replaces the batch-size wrapper with an AutomationScheduleBatchSize worker option (default 500), matching AutomationScheduleInterval and ArchiveBatchSize.
Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high
…agt-1211-automations-schedules Resolved two conflicts. ARCHITECTURE.md: kept main's new auto-archive paragraphs under the Auto-archive loop heading and this layer's Automation schedule loop section after them. options.go: kept this layer's AutomationScheduleInterval and main's HeartbeatRenewalTimeout and HeartbeatLockTimeout. make gen produced no diff. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
…option Replace the scanAutomationSchedules batch-size wrapper with a worker option, AutomationScheduleBatchSize, defaulting to 500, and attach the checkAutomationOccurrence doc comment to its function. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
|
sync with main d11809f: merged #30134 (resolved ARCHITECTURE.md and options.go next to main's heartbeat options); attached the checkAutomationOccurrence doc comment and made the schedule batch size a worker option (Mike's review)
Generated with |
ibetitsmike
left a comment
There was a problem hiding this comment.
Xum re-reviewed this PR on behalf of @ibetitsmike using GPT-6.1 Sol (high) Exec subagents.
Both prior Mike nits are fixed; the doc thread is still marked open, and duplicate hooks remain acknowledged and deferred.
New findings: Standards 1 nonblocking P3, Spec 0, Frontend 0 (no own-layer site changes).
Verified fresh delta logs pass schedule/startup, cursor authorization, shared webhook, selected heartbeat/archive/chatstate, and three-repeat concurrency/paging tests.
No extra suites or race run were performed; custom worker/tick coverage remains source-only, and fresh required CI completion is not captured (Pixel pending).
| @@ -0,0 +1,699 @@ | |||
| package chatd //nolint:testpackage // Runs the unexported schedule scan directly. | |||
There was a problem hiding this comment.
[P3] Remove the prohibited internal-test suppression
.claude/docs/TESTING.md:58-65 explicitly prohibits //nolint:testpackage; the existing _internal_test.go suffix already exempts this file. This adds a redundant per-file lint exception contrary to the documented convention, not a runtime defect. Keep package chatd and remove the directive and its justification.
There was a problem hiding this comment.
…agt-1211-automations-schedules No conflicts. make gen produced no diff. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
…ule scan test The _internal_test.go suffix already exempts the file from testpackage, and .claude/docs/TESTING.md prohibits the per-file directive. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
|
sync with main a328bee: merged #30134; removed the testpackage suppression from the schedule scan test (Mike's review)
Generated with |
ibetitsmike
left a comment
There was a problem hiding this comment.
Xum validated this PR and approved it on behalf of @ibetitsmike.
The reported test-package suppression is removed. The current layer preserves the earlier fixes and explicitly accepted follow-ups.
Validation: the previously completed, uncached schedule scan/startup and schedule authorization tests passed on this exact unchanged head. I rechecked the live layer diff and scope. The author-triggered CI rerun now passes, including test-go-race-pg and required.
This approval covers this layer at the pinned commit, not unresolved findings elsewhere in the stack. No new remote UAT or full local suite was run during this follow-up.
…agt-1211-automations-schedules No conflicts. make gen produced no diff. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
|
merged #30134
Generated with |
…agt-1211-automations-schedules No conflicts. make gen produced no diff. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
|
merged #30134
Generated with |
…agt-1211-automations-schedules No conflicts. make gen produced no diff. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
Generated with |
…tions-schedules Brings main ff158c0 into this layer. No conflicts. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
…tions-schedules Brings the new_chat automation title source fix from #30134. Resolved automations_publish.go: this layer's automationNewChatTitle call keeps the new TitleSource line. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
ibetitsmike
left a comment
There was a problem hiding this comment.
Xum validated this PR and approved it on behalf of @ibetitsmike.
Revalidated head 549f50621744 against base 7f5d2aa18e6b. Independent Standards and Spec renewal found no new blockers; the original accepted exclusions remain unchanged.
Re-reviewed scheduler contracts and the inherited title-source change. Schedule, scheduler-grant and authorization checks passed; the concurrency regression passed under race with count=3.
Approval is scoped to this layer and the reviewed inherited interactions. No full-repository suite, fresh Pixel screenshots or remote UAT claimed.
Part of CODAGT-1211. Part of CODAGT-1135.
Schedule automations now run. Every coderd instance scans for due schedules at start and every 30 seconds, and publishes each occurrence through the existing
Publishpaths (existing_chatSendMessage(queue)and new_chatCreate, with theirAdmitInTxcallbacks). There is no second admission path.How a scan works
schedule_next_run_at) is due, in pages of 500 by (cursor, id) until a short page. It leaves out inactive or deleted owners and existing_chat targets that are gone or archived.chat-automationsexperiment is evaluated once per owner per tick, outside any callback. Owners with it off are dropped without a cursor write.Publishchecks the experiment for the owner again before the transaction (webhooks map that refusal to 404, like the handler's own check).Publishruns (up to eight occurrences at once, so one slow hook or lock wait does not hold back the rest) with the observed revision and cursor. The pre-check refuses a stale or expired occurrence before any hook runs. Under the chat and automation locks, the callback requires the same revision and cursor, reads the clock after the locks, requires the occurrence to be due and within grace, and moves the cursor to the first cron time after that read in the same transaction.skip, a full queue or automation share, a hook denial, lost permission, or an occurrence that expired while waiting for a lock skips the occurrence with the same guarded write and an info log. A stale, disabled, or deleted automation is left alone. Other errors keep the cursor, so the next scan retries within grace. That includes an experiment-off refusal fromPublish, because the evaluator also reports a failed read as off.New chats created by a schedule are titled with the occurrence's scheduled time in the schedule's time zone, for example
Tokyo digest 2026-09-30 08:14 JST(the ticket says acceptance time; the two differ by at most the grace window, and the scheduled time cannot drift across a minute while hooks or locks run). Webhook titles stay in UTC. Each such chat gets an audit entry as created by the automation owner, with the automation and input ids, like the chats the webhook endpoint creates.Decisions reviewers should check
now(). The ticket also requires fake-clock tests, and the lower layers already read the clock after locks. Exactly-once rests on the revision and cursor tuple, not on time. Inter-instance clock skew cannot cause a double acceptance or a replay: an acceptance commits only together with the conditional cursor write under the automation lock, and every cursor write moves the cursor strictly forward (advanceAutomationSchedulerefuses a next run at or before the cursor). A clock that is off bydonly shifts the acceptance window to[cursor-d, cursor+grace+d]in true time; a clock that runs ahead can skip occurrences withind. See the comment oncheckAutomationOccurrenceand theCursorOnlyMovesForwardtest. Swapping inclock_timestamp()later is a one-line change.AdvanceChatAutomationScheduleCursorfollows the object pattern ofConsumeChatAutomationWebhookByIDandUpdateChatAutomationByID: the dbauthz wrapper loads the automation and authorizesupdateon it. The scanner and the callback call it as chatd, so the chatd subject gainsupdateonchat_automation(it already hadread). This is the smallest grant; chatd still cannot create or delete automations (pinned inTestAsChatd), and owner-only changes stay in the chatd automation service. No 1207 migration is touched.schedule_next_run_atandupdated_at, guarded byid,kind = 'schedule',enabled, the observedschedule_revision, and the observed cursor. It never touches owner-controlled fields or the revision.user_prompt_submithook before one loses under the lock; only one message or chat commits. This matches the lower layer's best-effort unlocked pre-check for webhooks. A claim-first cursor move would break the ticket's retry-within-grace rule or the forward-only cursor, so a lease column is proposed as a follow-up.Tests
coderd/x/chatd/automation_schedules_internal_test.gouses a mock clock, real Postgres, and a second connection that holds row locks (waiting onpg_stat_activity): two instances accept one occurrence (existing_chat, and new_chat with no orphan chat); busyskip, automation share full, and queue full each advance the cursor once; a cron edit rolls back an in-flight acceptance; restart after missed intervals publishes nothing, restart within grace accepts once; previews match accepted runs; an occurrence that expires while waiting for a lock is not accepted; a DST change keeps 09:00 wall-clock time; the experiment off gets no run (scan and Publish); the cursor only moves forward; the loop scans at start.Dogfood UAT ran on a real dev instance through Coder Agents and passed: a one-minute schedule delivered one message per minute with no browser open, a busy chat skipped its occurrence, disable stopped runs and re-enable did not replay, new_chat titles used Asia/Tokyo, two coderd instances produced no duplicates, and downtime was not replayed.
Size
About 994 hand-written lines (about 560 of them tests). Generated:
queries.sql.go,querier.go,dbmetrics,dbmock(181 lines).ARCHITECTURE.md prose was drafted by an agent at the user's request; the user will review it.
Generated with
xum• Model:anthropic:claude-opus-5-5• Thinking:high