Skip to content

feat: let organization admins configure the daily wake-up caps - #208

Merged
ibetitsmike merged 6 commits into
mainfrom
mike/org-wakeup-caps
Nov 11, 2026
Merged

ibetitsmike merged 6 commits into
mainfrom
mike/org-wakeup-caps

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Nov 11, 2026 •

Copy link
Copy Markdown
Owner

The daily wake-up caps (288 runs per chat, 2,880 per organization, $20 spend per chat, $200 per organization) were constants. With fork-chat-wakeups on, an organization admin can now replace each cap with PUT /api/v2/chats/fork/organizations/{organization}/wakeup-caps and read the stored, default and effective caps with GET. Each cap can go higher or lower than its default, with a minimum of 1. A cap the organization does not set keeps its default. Spend is in millionths of a dollar, like total_cost_micros.

  • A new chatdmig node adds chatd.chat_organization_wakeup_caps: one row per organization, with nullable caps and a check that each set cap is at least 1. forkdb gets Get/UpsertChatOrganizationWakeupCaps, with dbauthz and dbmetrics wrappers. An upsert replaces the whole row, so an omitted cap goes back to its default.

  • wakeupCapReached in coderd/x/chatd/fork_wakeup_caps.go reads the organization row before each wake-up run. The pause notification names the cap in force, for example "the chat reached its daily spend limit of $1.50".

  • The routes use the same RBAC as the organization subagent limits: read and update on ResourceChatModelConfig.InOrg. A member gets 404, and an auditor can read but gets 403 on update.

  • No UI.

  • Tests:

    • TestWakeupCaps has five new cases in which an organization lowers or raises a cap. If wakeupCapReached ignores the organization row (through a -overlay), all five fail.
    • TestForkChatOrganizationWakeupCaps covers defaults, raise and lower, validation, RBAC, and the experiment being off.
    • TestForkQuerier covers the new dbauthz methods.
  • I spliced the apidoc, typesGenerated.ts and the docs/reference/api pages from the generated output. Hand-written code, tests and docs total about 550 lines; the rest is generated.

  • coderd/x/chatd/ARCHITECTURE.md gets one TODO for the new table, for the author to fill in.

Part of #4

Xum opened this PR on behalf of @ibetitsmike.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T20:24:40.241491Z 4139949 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum posted this comment on behalf of @ibetitsmike.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 185de224c8

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

Comment thread coderd/x/chatd/ARCHITECTURE.md Resolved
Comment thread coderd/x/chatd/fork_wakeup_caps.go Resolved
Comment thread coderd/x/chatd/fork_wakeup_caps.go Resolved
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum posted this comment on behalf of @ibetitsmike.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 4139949a8f

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

@ibetitsmike
ibetitsmike merged commit 76f5829 into main Nov 11, 2026
9 checks passed
@ibetitsmike
ibetitsmike deleted the mike/org-wakeup-caps branch November 11, 2026 22:14
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum merged this PR on behalf of @ibetitsmike.

Merged by the pstack parity lead. fork-ci passed on head b6c1593. The Codex review state is clean (has_unresolved_findings=false) on 4139949, and since then the branch has only taken merges from main. 0 threads are unresolved. Ops ran the UAT on a branch build of b6c1593 and it passed:

  • Admin caps: GET returned the defaults, and PUT 1 took effect.
  • Validation: PUT 0 returned 400.
  • Members: GET and PUT returned 404.
  • Wake-up cap: under /loop 1m, one run was delivered, then the wake-up paused with daily_run_cap, and the member got an inbox notification.

Main is ahead of this branch only by #221, which changes site composer files this PR does not touch. Part of #4. Adds an ARCHITECTURE.md TODO for Mike.

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