Repository navigation
feat(api): every closed set is an enum; credential and sign-in reasons are coded - #176
Merged
Merged
Conversation
…s are coded
The rest of the fixed-vocabulary `String` fields in tw-api are enums now,
with the same wire words (serde renames; ts-rs exports string-literal
unions): Billing, Protocol, Dialect, ProxyKind, OnProxyFail, ModelSource,
Health, BreakerState, ProxyState, AuthState, FailureSource, GuardMode,
SecurityOutcome, ContentMatch, SecretKind, HiddenKind, LoginStatus,
ChatgptLoginMode, ZaiFamily, ConfigOrigin, ConfigStage, PricingSource,
ProbeClass, ProbeMode, ConditionField, SetField, ServeSkip, DryRunOutcome,
RuleVerdict, RuleEffect, ScanSource, Verification, FieldOp, McpOp.
`slug_enum!` also gives them Display and comparison with their word.
Internal enums map to them through exhaustive `From` impls (tw-config's
and tw-gateway's `wire` modules). A value outside a set is now a
request-body error (422 control.request_rejected), so the hand-written
"unknown value" checks and their codes are gone.
Credential errors are coded end to end. OauthError has a code per variant
(gw.oauth.*, backoff per cause), `${ENV}` failures have config.secret.*,
RotateError has its own codes, and headers_for / oauth_token_for /
headers_after_401 return `Msg`. Where a reason sits inside a larger
context (which upstream, which proxy, which sign-in step), the new
`Msg::in_context` keeps the reason's code and adds the context as an
argument, instead of wrapping English text in a `{detail}` code; the
gw.credentials.failed / control.credentials_failed / gw.models.credentials
/ control.provider_test.credentials / *.proxy_password wrappers are gone.
CredentialRotated/CredentialExpired.detail, OAuthView.failure, the
ChatGPT and Z.ai sign-in errors (status and event), ConfigRejected.message
and RuleTrace.error are `Msg`.
CONTROL_API_VERSION is 15.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Sep 24, 2026
Merged
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.
Follow-up to #174, which did the first eight sets. This covers the rest of the closed-set strings in tw-api and makes the credential and sign-in errors coded all the way through.
Closed sets → enums (same wire words)
New
slug_enum!types, exported to TypeScript as string-literal unions:Billing,Protocol,Dialect,ProxyKind,OnProxyFail,ModelSource,Health,BreakerState,ProxyState,AuthState,FailureSource,GuardMode,SecurityOutcome,ContentMatch,SecretKind,HiddenKind,LoginStatus,ChatgptLoginMode,ZaiFamily,ConfigOrigin,ConfigStage,PricingSource,ProbeClass,ProbeMode,ConditionField,SetField,ServeSkip,DryRunOutcome,RuleVerdict,RuleEffect,ScanSource,Verification,FieldOp,McpOp(andDryRunResult.strategyusesGroupKind).Fromimpls (tw-config/src/wire.rs,tw-gateway/src/wire.rs), so a new variant on either side fails to compile.RequestRow.billing/TurnRow.billing/SecurityEvent.actionare typed.control.request_rejected), so the hand-written checks go away:security.unknown_mode,security.unknown_match,control.unsupported_value,control.unsupported_action,control.unknown_signin_mode,control.unknown_account_family,control.rule.unknown_condition.slug_enum!also gives each typeDisplayand comparison with its wire word.Left as strings on purpose: names and ids the user or an upstream chooses (proxy names, client ids, rule/category names in
SecurityRuleView.kind,QuotaWindow.window/status,ResetCreditViewfields),auth_header(a header name),DryRunRequest.intent(empty means a real request).Credential and sign-in reasons →
MsgOauthErrorhas a code per variant (gw.oauth.{unreachable,status,no_token,expired}, andgw.oauth.backoff.{unreachable,status,no_token}for a backoff by cause);${ENV}failures haveconfig.secret.{env_missing,unterminated,empty_name}(replacing the passthroughconfig.credential.env);RotateErrorhasconfig.rotate.*.headers_for/oauth_token_for/headers_after_401returnMsg.Msg::in_context(name, value, lead): keeps the reason's code, adds the context (upstream, proxy, sign-in step) as an argument and prefixes the English. It replaces the{detail}wrapper codesgw.credentials.failed,control.credentials_failed,gw.models.credentials,control.provider_test.credentials,gw.config.proxy_password,l1.config.proxy_password.Msg:CredentialRotated.detail(control.rotation.written,gw.oauth.rotation_{queue_full,no_manager}, or the write-back error's own code),CredentialExpired.detail,OAuthView.failure,ChatgptLoginStatus.error/ZaiLoginStatus.error/LoginFinished.error(control.chatgpt_login.*,gw.chatgpt.token_*,control.zai_login.*, Z.ai call failures keep theircontrol.account_service_*codes with astepargument),ConfigRejected.message,RuleTrace.error.CONTROL_API_VERSION14 → 15.msg-codes.txtupdated.Local: fmt, clippy (
--all-targetsand--lib), workspace tests, and thetssteps (clippy, tests, export,tsc --strict).🤖 Generated with Claude Code