fix: remove chatd usage limit enforcement by johnstcn · Pull Request #27535 · coder/coder · GitHub
Skip to content

fix: remove chatd usage limit enforcement - #27535

Merged
johnstcn merged 5 commits into
mainfrom
cj/rm-chatd-usage-limit-enforcement
Jul 28, 2026
Merged

fix: remove chatd usage limit enforcement#27535
johnstcn merged 5 commits into
mainfrom
cj/rm-chatd-usage-limit-enforcement

Conversation

@johnstcn

Copy link
Copy Markdown
Member

This PR surgically removes enforcement of Agents spend limits:

  • Adjusts the relevant function that checks usage to always return nil
  • Deletes tests that expect a usage limit error.

This PR surgically removes enforcement of Agents spend limits:
- Adjusts the relevant function that checks usage to always return nil
- Deletes tests that expect a usage limit error.
@johnstcn johnstcn self-assigned this Jul 27, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

observation: this actually tests the interaction between compaction and usage limit.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we adapt these tests to integrate with AI Gateway? Not now, but as a potential follow-up.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

100% yes, this was just where the knife landed.

Comment thread coderd/x/chatd/chatd.go Outdated

@ssncferreira ssncferreira left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM 👍

require.Equal(t, []string{"hello", "queued", "later queued"}, userTexts)
}

func TestEditMessageRejectsWhenUsageLimitReached(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Interesting test...I haven't used the edit functionality in agents, I assume this just creates a new message (based on the edited message), which means a new request in AI Gateway, so the spend is accumulated. Should work without any problems I would say 🤔

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yep, that's how editing works!

})
}

func TestCompactChat(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we adapt these tests to integrate with AI Gateway? Not now, but as a potential follow-up.

@johnstcn
johnstcn marked this pull request as ready for review July 28, 2026 14:44
Copilot AI review requested due to automatic review settings July 28, 2026 14:44
@coderagents

coderagents Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Documentation Check

checkUsageLimit remains a no-op at every call site (create chat, send message, edit message, regenerate title, compaction, subagent spawn), so chatd no longer enforces chat spend limits. Config, per-user/per-group overrides, spend status, and cost tracking still exist. New in 97e909a1: the code comment states enforcement now lives in AI Gateway ("Budgets"). No docs changes in this PR yet, so the Spend Management pages still describe chatd-side blocking.

Updates Needed

  • docs/ai-coder/agents/platform-controls/usage-insights.md - The ### Enforcement section (lines 34-42) no longer matches the code: messages are not blocked, and no 409 Conflict is returned when spend meets or exceeds the limit. Rewrite or remove it.
  • docs/ai-coder/agents/platform-controls/usage-insights.md - Intro to ## Usage limits (lines 10-12): "Usage limits cap how much each user can spend ... the system checks the user's current spend before processing each chat message" is no longer true. Reword to reflect tracking without chatd-side enforcement.
  • docs/ai-coder/agents/platform-controls/index.md - ### Spend management (line ~119): "Administrators can set spend limits to cap LLM usage per user" implies chatd enforcement. Adjust to match the new behavior.
  • docs/ai-coder/agents/platform-controls/usage-insights.md - New (per 97e909a1): document that spend enforcement is now performed by AI Gateway budgets, and cross-link to Cost Controls. Note that page is still a stub (TODO(AIGOV-476)), so readers currently have no documented path to configure the enforcing control. If enforcement behavior differs (thresholds, error surfaced to users, per-group resolution), the differences should be called out explicitly rather than left implied.

Not flagged: docs/reference/api/* (auto-generated), and the deleted tests.


Automated review via Coder Agents

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR removes server-side enforcement of chat usage/spend limits in chatd by turning the limit check into a no-op and deleting tests/mocks that assert the previous rejection behavior.

Changes:

  • Make (*Server).checkUsageLimit(...) always return nil, effectively disabling limit enforcement in chatd.
  • Remove chatd unit tests that expected UsageLimitExceededError during create/edit/compaction flows.
  • Remove gomock expectations for GetChatUsageLimitConfig in internal chat title tests now that the limit check no longer queries it.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
coderd/x/chatd/chatd.go Disables usage limit enforcement by making checkUsageLimit always succeed.
coderd/x/chatd/chatd_test.go Removes tests that asserted chat operations are rejected when usage limits are reached.
coderd/x/chatd/chatd_internal_test.go Removes unused DB mock expectation for usage limit config lookup.
coderd/x/chatd/title_override_internal_test.go Removes unused DB mock expectation for usage limit config lookup.
coderd/exp_chats_test.go Deletes HTTP/API tests and helper that expected “usage limit exceeded” responses.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread coderd/x/chatd/chatd.go
Comment thread coderd/x/chatd/chatd.go
@johnstcn
johnstcn merged commit 75fd7bc into main Jul 28, 2026
27 of 28 checks passed
@johnstcn
johnstcn deleted the cj/rm-chatd-usage-limit-enforcement branch July 28, 2026 16:14
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 28, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants