fix(oauth): enforce max_agents on auto-provisioned agents - #952
Open
AmirF194 wants to merge 1 commit into
Open
Conversation
issueOAuthCodeWithNewAgent created agents via CreateAgentTx with no max_agents check anywhere in the file, unlike POST /v1/agents, which has always called EnforceAgentCreate first. Wire in the same check before the transaction that creates the agent. Fixes tokencanopy#951
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.
Summary
Filed as #951:
issueOAuthCodeWithNewAgent(the OAuth auto-provision path) creates an agent viaCreateAgentTxwith nomax_agentscheck anywhere in the file, unlikePOST /v1/agents, which has always calledEnforceAgentCreatebefore inserting (even before #942's atomicity fix). This wires in the same check, right before the transaction that creates the agent.Client surface checklist
Not applicable: no API or client surface change. The consent flow's response when the cap is already hit changes from a 303 redirect that silently creates the agent anyway to
402 Payment Required, the same status and error shapePOST /v1/agentsalready returns for the identical condition.Operational risk
No schema change. An OAuth consent request that previously created an agent past the cap now gets
402 limit_exceededinstead, matching the REST endpoint's existing behavior for the same account state.Test plan
internal/agent/oauth_consent_test.go,TestHTTP_Consent_Allow_CreateNew_AtAgentCap) drives the real consent HTTP handler withmax_agents: 0. Fails onmain(303, agent created), passes on this branch (402, no agent row, no auth code issued), both against a real Postgres 16 container.go test ./internal/agent/...andgo test ./...(theGo testsjob's own command) both green.gofmt -l .andmake fmt-checkclean.CheckAgentCreatefailing for a reason other than the limit itself (a DB error, say) has no dedicated test here, matching the equivalent branch on the REST path, which is also untested today.Fixes #951