Repository navigation
Conversation
…unions
message_parser passes these fields through without validating, so a value
missing from the union is one a type checker calls impossible while it
arrives at runtime. Against the TypeScript SDK published alongside the same
CLI, 0.3.292:
- AssistantMessageError had 6 of the 13 in SDKAssistantMessageError
(sdk.d.ts:3698): oauth_org_not_allowed, account_on_hold,
verification_required, overloaded, model_not_found, max_output_tokens and
cloud_credential_error were missing
- RateLimitType had 5 of 6 (sdk.d.ts:5675), missing
seven_day_overage_included
- TaskNotificationOriginSubkind had 2 of 4 (sdk.d.ts:5396), missing
projects-relay and session-inbox
What that costs a caller: retrying only on overloaded does not type check,
error: Non-overlapping equality check (left operand type:
"Literal['authentication_failed', 'billing_error', 'rate_limit',
'invalid_request', 'server_error', 'unknown']",
right operand type: "Literal['overloaded']")
error: Statement is unreachable
and a match over RateLimitType with assert_never silently skips
seven_day_overage_included rather than failing to compile.
AssistantMessageError is reordered to follow sdk.d.ts so the two can be
diffed by eye. Nothing changes at runtime.
anthropics#1069 added the RateLimitType value in June, was approved, and the author
closed it the same day; the value never landed.
This branch has not been deployed
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.
Three
Literalunions intypes.pyare missing values the CLI puts on the wire.message_parser.py:214passes these fields through without validating (error=data.get("error")), so the value arrives at runtime while a type checker says it cannot exist.Checked against the TypeScript SDK published alongside the same CLI,
@anthropic-ai/claude-agent-sdk@0.3.292(CLI 2.1.292):sdk.d.tsAssistantMessageError:3698,SDKAssistantMessageError)oauth_org_not_allowed,account_on_hold,verification_required,overloaded,model_not_found,max_output_tokens,cloud_credential_errorRateLimitType:5675, therateLimitTypeunion)seven_day_overage_includedTaskNotificationOriginSubkind:5396, thesubkindunion)projects-relay,session-inboxAll seven error values are also present as strings in the shipped CLI binary, if you would rather check there than against the TS package.
What it costs a caller. Retrying only on
overloadedcannot be written without acastor an ignore:and an exhaustive
matchoverRateLimitTypeending inassert_nevercompiles while silently not handlingseven_day_overage_included— the arm for it is reported unreachable. That is the failure mode an exhaustive match exists to prevent. After this change the same file type checks and theassert_neverarm becomes genuinely unreachable, which is the point.Nothing changes at runtime.
AssistantMessageErroris reordered to followsdk.d.tsso the two can be diffed by eye when the CLI adds a value next.Prior art, which I only found while checking for duplicates: #1069 added the
RateLimitTypevalue in June with the same reasoning, @aidand-ant approved it, and @sarahdeaton closed it themselves the same day. The value is not onmain, so whatever the reason, it did not land. Credit there for that one line.Two things deliberately left out.
PermissionUpdateDestinationis missingcliArgon the same grounds, but that is already in my #1330 and belongs there rather than here. AndMessageOriginKindcarries a docstring saying newer CLI versions may emit kinds not listed and callers should treat anything unrecognized as "not human" — that is a deliberate open union, so I did not touch it. If the three above are meant to be open in the same way, the fix is that docstring rather than these values, and I will do it that way instead.Tested:
test_literal_unions_cover_what_the_cli_sendsnext to the existingtest_effort_level_is_exported, asserting the exact set for each of the three so the next drift shows up as a failing test rather than a silent gap. It fails onmain. Full suite 1588 passed, 6 skipped.ruff check,ruff format --checkandmypy src/clean.Not run: nothing against a live account, since none of this is runtime behaviour. The two numbers that matter are the union contents, which the test pins, and the type-checker output above, which came from running
mypyover a caller file before and after.