Repository navigation
perf(decode): skip strings a word at a time and allocate slices once - #158
Conversation
The benchmarks read a corpus of real traffic the way a Connection reads what its peer sends: the scenario fixtures of the Claude and Codex adapters (pinned commits, Apache-2.0, converted to acpwire transcript lines by internal/benchcorpus), the G3 journeys, and the G2 transcripts. - BenchmarkInbound/corpus: every message once per op. - BenchmarkInboundStream: the agent_message_chunk and tool_call_update bursts. - BenchmarkConnectionPipe: session/update notifications through a Connection pair over io.Pipe, and through the client side alone. scripts/bench (make bench BASE=<commit>) builds both sides with the same benchmark file and corpus, checks that both decode every message to the same outcome (TestInboundCorpus), alternates the runs and prints benchstat. It is not part of make test. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
On a shared machine the wall time of a run grows while other processes hold the CPU. The process's user and system time does not, so the benchmarks also report cpu-ns/op (Unix only). --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
The Rust SDK reads an integer of format uint64 as a u64, int32 as an i32, and so on. These tests pin that range at both ends, with a recorded Claude session (claude-g5-1.jsonl) and with the outcomes that the rust-diff probe recorded for agent-client-protocol-schema 1.18.0. On main 13 rows of TestIntegers_ReadTheRangeOfTheirFormat and TestClientSideConnection_ReadsAUint64AboveMaxInt64 fail: a uint64 above 2^63-1 fails to decode or reads as absent, an ErrorCode outside int32 decodes, -0 decodes as 0, and a uint32 out of range in StringPropertySchema or a uint16 out of range in a result decodes. The ten control/integer-* rust-diff cases hold the same values. Part of #141 (items 7 and 8) --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
--- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
--- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
Since #120 an integer of format uint32 or uint64 was an int64, and one of format int32 or uint16 an int, and #138 checked each format's range in Validate and in the lenient shapes. An int64 cannot hold a uint64 above 2^63-1, so a usage_update or a token count that Rust reads failed to decode, and the range lived in two places that each site had to reach: responses, the Other variant of ErrorCode and an optional integer that cannot be null had none. integerType now gives each format the Go type of the Rust type that it names (formatTypes): int32, int64, uint16, uint32, uint64, and int without a format. encoding/json fails a value out of that range, as serde_json does, at every site and in every direction, so Validate and the shapes keep only a minimum or maximum that is narrower than the Go type (ownRange). No schema from 1.18.0 through 1.33.0 has one, so the generated Validate methods lose every range check, and the six lenient decoders that checked a shape only for the range no longer do. shape.go reads a uint64 above math.MaxInt64 as within a range that has no upper bound. The examples and the verification harness clamp the uint32 line and limit through uint64, and MIGRATION_v0.21.md lists each field that changes type, with before and after code. Part of #141 (items 7 and 8) --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
An optional integer whose schema does not allow null is not a pointer, so an absent member reads as 0. Its Go type holds the range of its format, so a value out of it fails to decode, but checkPlan gives the field no minimum or maximum check. No integer of schema 1.18.0 through 1.33.0 has this form, so a synthetic schema stands for one. On the parent commit the four rows with a bound fail: level 11, offset -6 and 6 pass Validate, and so does a value built with level 11. Part of #141 (item 7) --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
checkPlan skipped every optional member whose Go type is not a pointer, because an absent one reads as its zero value. For a struct or union that stays right: a zero value cannot say whether it was sent. An integer can: 0 is the value an absent member reads as, so Validate now checks the minimum and maximum of such an integer when it is not 0, through a nonZero container of the eachHeld walker. An explicit 0 outside the bounds passes as absent, as encoding/json cannot tell the two apart. The range of the integer's format needs no check since the parent commit: its Go type holds it. No schema from 1.18.0 through 1.33.0 has such an integer, so the generated code does not change. Part of #141 (item 7) --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
- scripts/bench stops when the two sides decode a message differently, unless ALLOW_OUTCOME_DIFF=1, because they would not time the same work. - It truncates base.txt and head.txt before the first run, so a reused BENCH_OUT does not mix samples of an earlier run. - The G2 transcripts are optional for the corpus: the module the Go proxy serves leaves out .agents (a module of its own), and TestInboundCorpus must pass there. The corpus digest still tells the corpora apart. - internal/benchcorpus writes a fixture only under a local file name. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
The generated decoders call encoding/json again on each nested value, so the bytes of a deep message are scanned once per level. jsonscan.go reads the members of an object and the items of an array, and skips a value, without decoding it or allocating. It expects JSON that encoding/json accepts and never panics or loops on other input. TestJSONScan_Corpus and FuzzJSONScan compare it with json.Decoder. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
shapeID.accepts decoded every hinted value again into an any (maps, slices, strings) and walked the result with fits. On the inbound benchmark corpus that is 80823 allocations of BenchmarkInbound/corpus. accepts now walks the raw JSON with the scanner in jsonscan.go: scan checks the same rules as fits on the bytes and returns yes, no, or unknown. The rules of a shape combine as the least verdict, anyOf as the greatest, and not swaps yes and no. When scan cannot tell, accepts decodes as before (acceptsDecoded, which the tests also use as the reference). scan cannot tell for a string that a values rule compares when it holds an escape or bytes that are not UTF-8, for an object key that does, for an object with more than 16 members, and past 1000 levels of value and shape. Of duplicate keys it checks only the last, which encoding/json keeps. Every one of the 3756 hinted values that the corpus decodes is a value in its messages, and scan decides all of them without allocating. shape_test.go checks scan and accepts against fits for every value in every corpus message and every shape, for seeds on the edges above, and in FuzzShapeScan.
Each generated union UnmarshalJSON decoded its input into a map[string]json.RawMessage only to read the discriminator or the keys that pick a variant, and then decoded the input again into the variant. It now calls readUnionObject (union.go), which scans the object with the memberIter of jsonscan.go: no map, no copied values, no validation pass. get looks a key up with last-wins, tag reads a plain ASCII discriminator without json.Unmarshal. The scan does not validate. A variant decodes only valid JSON, so input that is not JSON reaches the end of the decoder, where unionError returns the syntax error that the map decode used to return first. An escaped key or an object the scanner cannot read falls back to the map decode. The dead []map decode of the array step is now emitted only for unions with array variants matched by item keys. stablecheck treats unionObject.get and tag as side-effect free, so that a union that gains a discriminator still passes as an addition. TestUnionObject_DecodesLikeAMap and FuzzUnionObject compare every union against the map path (unionsByMap) on the corpus values, changed copies of them, and fuzzed input: same variant, value, encoding, and error.
The generated dispatcher decoded each request's and notification's params with json.Unmarshal, and SendRequest did the same for a response's result. Every one of those types has an UnmarshalJSON method. For such a type json.Unmarshal validates the input, scans the value again to find its end, and only then calls UnmarshalJSON with the value without the whitespace around it. It adds no context to that error at the top level. decodeJSON (decode.go) does the same in one pass. It validates the input with json.Valid, which uses a pooled scanner, trims the whitespace, and calls UnmarshalJSON. Input that is not one JSON value (empty, trailing data, a syntax error) goes to json.Unmarshal, which returns its exact error and leaves the value as it is. So does a type without UnmarshalJSON. Per call this saves the second scan and four allocations: the escaping decodeState and the growth of its scanner's stack. TestDecodeJSON_MatchesUnmarshal, TestDecodeJSON_Corpus and FuzzDecodeJSON compare decodeJSON with json.Unmarshal on edge cases, on every corpus params and result, and on fuzzed input. They check a struct with UnmarshalJSON, unions, a plain struct and json.RawMessage, fresh and already holding data, for the same error (deeply equal) and value.
Every generated UnmarshalJSON called json.Unmarshal on its own input, and each nested type, union variant, and lenient field did it again on its part, so a byte at depth d was validated and decoded about 4d times. Each generated type now has an unexported decodeFast, emitted into decode_fast_gen.go by cmd/generate/internal/emit/fast.go. It walks the object's members once with the scanner of jsonscan.go, decodes each value straight into its field with the helpers of decode_fast.go, and calls the decodeFast of the types it holds. UnmarshalJSON runs it first (tryFast): only on a zero value, for valid JSON without whitespace around it. When decodeFast returns true, the exact decoder, which is unchanged, would return nil with the identical value; on false it runs as before, so every error comes from it. A fast decoder declines a repeated key, an escaped or non-ASCII key, a key that matches a field only in another case, and any value that does not decode. Custom-decoded fields, required members, defaults and additionalProperties follow decodeStmt and emitRequireMembers on the member spans that the walk keeps. Unions select a variant with readUnionObject and the predicates of emitUnion, and decode it with fastOrExact, whose answer is exact, so a variant that fails passes the turn to the next as before. With GOEXPERIMENT=jsonv2 the fast path is off. Tests compare the fast path with the exact one (fastDecode off): every corpus message, every corpus value decoded into a reused value, seeds against all 355 types, and fuzz targets for messages, types and leaves. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
decodeJSON checked its input with json.Valid, whose scanner makes an indirect call per byte. validJSON is a recursive-descent validator that returns exactly what json.Valid returns: the same number grammar, string escapes, control characters invalid, invalid UTF-8 valid, whitespace rules and the 10000-level nesting limit. Strings are most of the bytes of ACP traffic, so it finds the next quote, backslash or control character eight bytes at a time with a zero-byte bit test. Over every message of the inbound corpus validJSON takes 612 us per pass and json.Valid 3458 us (median of 6, -cpu 1), with no allocations. FuzzValidJSON compares the two on arbitrary bytes. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
tryFast checked its input with json.Valid before running a fast decoder. validJSON returns the same answer (FuzzValidJSON) about 5.6 times faster. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
tryFast in decode_fast.go now calls validJSON, so the package that TestWriteTypesJen_* builds from the generated code needs validjson.go next to decode_fast.go. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
The Rust SDK fails an object that holds one of its struct's fields
twice ("duplicate field"), and the Go SDK keeps the last value (#141).
These tests pin the Rust behavior: a repeated property fails the decode
with a *json.UnmarshalTypeError that names the struct, the property
and the field's type; a union whose variant repeats a property selects
no variant; a lenient property reads such a value as its default; an
inbound request gets -32602 without a handler call, a notification is
dropped and logged, and a result fails the call with -32603. Members
that are no property, keys of a map and the discriminator of a
catch-all variant keep the last value, as in Rust.
The fast decoders get seeds with repeated members, so that the fast and
the exact decoders must agree on them, and the Rust probe gets the
dup/... cases: rust-diff fails on them until the fix.
---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
Every generated UnmarshalJSON now checks, in its exact path and after encoding/json has decoded b, that the object holds each property of its struct at most once (rejectDuplicateMembers in duplicate.go). A key counts by its name without escapes. A repeat fails with a *json.UnmarshalTypeError, as a missing member does: json: cannot unmarshal duplicate member into Go struct field SessionNotification.sessionId of type acp.SessionId So a request that repeats a property gets -32602, a notification is dropped and logged, and a result fails the call with -32603, as the Rust SDK fails "duplicate field" (#141). Unions reject through their variant structs, which hold the discriminator; lenient properties read such a value as their default. A member that is no property, a key of a map, and the discriminator of a catch-all variant, which the Rust SDK reads into a map, still keep the last value. The fast decoders are unchanged: they already decline a key that repeats, so a repeat always reaches the exact path. Generator: ElicitationAcceptAction, the one struct with a property and no UnmarshalJSON, gets one. stablecheck keeps a stable property's name in a call's arguments when a nested type of the merged run adds a field with that name, and the range test of the emitter no longer repeats a member to override it. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
skipString stepped through a string one byte at a time and switched on each byte. The fast decoders skip every nested value once per object level, so this loop was the largest share of their CPU time. It now looks for the next quote and then counts the backslashes right before it: the quote ends the string when that run is even. It reads the first two 8-byte words itself, because most strings in ACP traffic are under 16 bytes, and calls bytes.IndexByte for the rest. It returns what the byte loop returned on every input, JSON or not. The tests keep the byte loop as a reference and compare skipString and skipValue with it at every offset of each corpus message, seed and fuzz input. New seeds put escapes and backslash runs at every byte of the words skipString reads. BenchmarkSkipValue skips every corpus value and every value nested in one. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
fastSlice and fastItems (and so fastLenientItems and the patch variants) grew their slice by append from empty, so a slice of n items was allocated about log2(n)+1 times and copied each time. They now collect the items' bytes first, in a 64-entry buffer on the stack (append moves it to the heap past 64), then make the slice at its length and decode each item in place. The scan does the same work as before: the iterator already finds each item's end once, and the items are read from the buffer instead of the iterator. fastItems decodes into the next free place and keeps kept[:n]; fastLenient leaves its place zero on false, which its comment now says. Outcomes are unchanged: [] is an empty non-nil slice, null is nil, a dropped lenient item leaves no gap, a decline returns before *dst is written. Capacity now equals decodeItems' (the item count). TestFastDecode_Slices and FuzzFastDecode_Slices compare fastItems with decodeItems and fastSlice with json.Unmarshal on edge cases, arrays past the buffer, and every array of the corpus. BenchmarkFastSlices reads the corpus arrays of the seven element types the corpus reads most. BenchmarkInbound/corpus: 51858 -> 50683 allocs/op, 4062 -> 3831 kB/op. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
FuzzFastDecode_Leaves requires that a leaf decoder declines only where
json.Unmarshal fails, except for values with an object key, which a map
decoder declines when the key repeats. It recognized a key by the bytes
'":' and so failed on {"" :"","" :{}}: Meta declines the repeated key, as
it should. The check now allows whitespace between the key and its colon.
The input is kept as a seed.
---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
Evidence: the whole stack against main, the limiter, and the hill-climb logFinal: this branch (e9498fd) against main (50da019, the harness of #148)
Stop predicateTarget: at least 40% better than main on the primary metric (total time and allocations of LimiterCPU profile of this branch (4 s, not a reported run): Hill-climb log (
|
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Independent verification of the stack's performance numbers (main 6c4769e → e9498fd): PASS+NOTESEvery claimed number reproduces to within about 2%. Allocation counts match exactly. The H3 and H7 spot checks reproduce. Benchmarks outside the corpus show no regression. Note: the benchmark understates the gain, because it still decodes results the way main's
An out-of-process check agrees: child Noise floor (same decoder code on both sides, 12 runs each): A/A at #158 had no significant difference on any benchmark. Corpus CPU varied ±7%/±2% and medians differed by 0.4%. A/A on main (6c4769e vs 50da019) had none either: corpus CPU ±3%/±2%, Notes
Spot checks of decision.tsv (PR commits,
|
| row | before → after | claimed | measured |
|---|---|---|---|
| H3 fast decoders | f0d4b9c → ea4bf7a | 66.34 → 29.75 ms (−55.2%), 172.7k → 51.86k allocs | 61.27 → 26.18 ms (−57.27%, p=0.000), 172.65k → 51.86k allocs (load ~10). A run at load ~48 gave 77.65 → 32.71 ms (−57.87%). |
H7 validJSON |
ea4bf7a → 41d1177 | 26.67 → 21.51 ms (−19.3%), allocs unchanged | 27.83 → 22.44 ms (−19.34%, p=0.000), allocs unchanged (load ~24 to 48) |
Both kept iterations reproduce in direction and size. Both runs printed "outcomes: every message decodes as on base". Absolute numbers move with host load (+27% for the same commit at load 48 vs 10). Deltas within one alternating run do not.
Benchmarks outside the corpus (main vs e9498fd, 10 alternating runs, -cpu 1)
The only benchmark that exists on both sides is BenchmarkUnmarshalJSON_HintedValues. I added a verifier-only file, not committed, with encode benchmarks (json.Marshal of the corpus's 935 session notifications, and of a PromptRequest) and plain round trips (ClientSideConnection.Prompt and NewSession against an AgentSideConnection over io.Pipe).
| benchmark | main | head | delta |
|---|---|---|---|
| HintedValues/session/new_response | 276.1 µs | 53.5 µs | −80.6% |
| HintedValues/initialize_response | 75.3 µs | 16.7 µs | −77.9% |
| HintedValues/tool_call_update | 44.8 µs | 9.4 µs | −79.1% |
| HintedValues/session_list | 133.8 µs | 30.0 µs | −77.6% |
| HintedValues/plan | 51.6 µs | 10.3 µs | −80.1% |
| HintedValues/agent_message_chunk | 10.5 µs | 2.4 µs | −77.2% |
| Encode/session_notifications (CPU) | 20.68 ms | 20.49 ms | ~ (p=0.28), allocs equal |
| Encode/prompt_request (CPU) | 6.59 µs | 6.39 µs | ~ (p=0.33), allocs equal |
| RoundTrip/prompt (CPU) | 31.50 µs | 17.74 µs | −43.7%, allocs 150 → 107 |
| RoundTrip/new_session (CPU) | 23.55 µs | 13.93 µs | −40.8%, allocs 103 → 77 |
Encoding is unchanged, and every decode path got faster. I found no regression.
Gates and setup
- At e9498fd,
make checkandmake testpassed (10 packages ok). The worktree stayed clean. - Go 1.26.3, GOTOOLCHAIN=local, AMD EPYC 9454P, one shared host. Another verifier was fuzzing at the same time (load 3 to 48 during my runs), so every comparison uses
cpu-sec/opfrom alternating runs. Wall time is shown only where noted. - I did not check decoder correctness beyond the benchmark's outcome comparison. Another verifier covers that.
Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high
A union drops an untitled alternative that is a string, a const, an enum, a number, a boolean or an array, under anyOf and oneOf, so such a value does not decode. Under oneOf, the constructor of a titled string alternative, or of a $ref to a string type, builds a composite literal that does not compile, and a oneOf of consts beside an open string becomes a union instead of an open enum. These tests generate one union per kind of alternative under both keywords, plus the real unions ElicitationContentValue and SessionConfigSelectOptions of schema 1.32.0 with and without titles, and round-trip their G2 transcript values. They fail on main. Part of #141 (item 4) --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
fieldCheckFor returned for a lenient field before mustHoldDefault ran, so a default outside its bounds or format still reached setDefault (Codex r4645610192). Run the check first. load reads a default as a float64, so a default of 2^53 or beyond may be rounded, and planFor would write the rounded fallback (Codex r4645610179). Stop with a message that says so instead of the range error that the rounded value gives. Keeping the exact text would need load to decode numbers as json.Number everywhere, for a form that no schema has. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
fieldCheckFor returns for a const property before mustHoldDefault runs (Codex r4645713059). Expect the panic for it too. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
fieldCheckFor returns early for a const property, so mustHoldDefault missed a const integer's default (Codex r4645713059), as it had missed a lenient one. planFor handles every default, before it writes the fallback that setDefault decodes, so check the default there and drop the call from fieldCheckFor. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
{"const": "a", "allOf": [{"$ref": "#/$defs/Label"}]} is a $ref
alternative (variantRef), and its const is dropped: the union takes
every Label, and its oneOf constructor takes any Label. On main the
old scalarConstOf checked it.
---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
variantRef reads {"const": "a", "allOf": [{"$ref": ...}]} as a $ref
alternative, and values returned none for it, so the union took every
value of the $ref type. unionAlternatives now records the values an
alternative names (named) and the schema of its Go type (value) for a
$ref alternative with its own const too, and values checks both kinds.
---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
mustHoldDefault returns for a default that load did not read as a float64, so "default": "5" or true on an integer passes generation and setDefault leaves 0 (Codex r4645771578). Expect the panic for both. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
mustHoldDefault skipped a default that load did not read as a float64, so "default": "5" or true on an integer generated a fallback that setDefault failed to decode, leaving 0 (Codex r4645771578). Panic on it. planFor passes only a field that holds the integer itself or through a pointer, because the default of an array or a map of integers is not an integer; null never reaches it. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
Arithmetic among changed fields compiles and can now wrap (Size - Used), so the compiler does not report each use of a changed field. A code above MaxInt32 in RequestError reads fine on a 64-bit platform; only Rust and a 32-bit SDK fail. The signed -0 list gains IntegerPropertySchema.maximum and .default. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
A const beside a $ref to {"enum": ["a", "b"]} stops generation, though
main generated it. A number const on a $ref to an integer enum, whose Go
type is a string type, generates code that go vet rejects.
---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
The own const of a $ref alternative was checked against the JSON type of the $defs entry. An entry with an enum is a Go string type whatever its JSON type (jenTypeFor), so a string const on an untyped enum now builds, and a number const on an integer enum fails generation instead of vet. An entry with no JSON type gets its own panic message. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
ErrorCodeOther(70000) stays 70000: it wraps only past int32, so the 4464 example names ProtocolVersion alone. The Rust SDK leaves a -0 IntegerPropertySchema.default unset, as with ResourceLink.size, rather than rejecting it. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
A uint32 minimum above its max, or a signed maximum below its min, now records an out-of-type constant, and the check does not compile. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
A minimum above the greatest value of a field's Go type, or a maximum below its least, left an empty range whose check did not compile. ownRange now panics with the bound and the type. Fixes Codex r4646051333. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
…und panic The guide's wrap example now uses an int variable, since the constant conversion does not compile. The emit README lists the new ownRange panic. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
The panic advised giving the type a JSON type, which does not fit a $ref to a oneOf of consts, the form of every ACP enum. It now names the problem. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
Merges af6272d (main 2a4cf5c with #153) into #159's head 7cbc478, so that #159 lands on the tree main will have once #153 lands. Resolutions: - emit/types.go unionVariant: keep main's fieldType (#149) and #159's isStruct and value. emitUnion keeps fieldType: b.fieldType in the variant literal and #159's isStruct and one-value handling. - emit/README.md: the edits touch different lines. Keep main's name-registration sentence and its alias bullet (#153), #159's open-enum, alternative-kind and constructor sentences, and main's Validate bullet. - #153 x #159: a union alternative that refers to an alias (isRefAlias) now reads the entry that the alias names (aliasTarget). isStruct gives an alias of a struct the struct constructor that main generates, and an alias of a string a value constructor, where main built &LabelAlias{}, which does not compile. An own const on a $ref to an alias is checked against that entry's Go type instead of panicking. Test: PickAlias and PickRefAliasConst in TestWriteTypesJen_UnionKeepsEveryKindOfAlternative, red before the fix (panic, then a constructor that takes the value). The generated files at schema 1.32.0 do not change. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
Merges R159 (af6272d, main 2a4cf5c with #153, then #159) into #150's head 76407db. Resolutions: - emit/types.go integerType: #150's formatType version. #159's wideInteger is gone with formatRange, and the math import stays for #159's values. - #159 x #150, the union fit check: values checks an integer const or enum value against the Go type of its format with the new holdsInteger (ranges.go), instead of #159's int-or-int64 test on formatRange. An int64 or uint64 value above int32 is still taken, an int beyond int32 still panics (it does not compile for GOARCH=386), and a value outside int32, uint16, uint32 or uint64 now panics, where a plain port of wideInteger generated code that does not compile. New rows in TestWriteTypesJen_PanicsOnAValueTheAlternativeCannotHold (uint16 65536, uint32 -1, uint64 enum -1, uint32 $ref 4294967296) fail on that port and pass here; int32 2147483648 panics on both. PickFormatConsts takes each format's limit. - MIGRATION_v0.21.md: #150's "Integer types and ranges" and "Connection constructors and limits" rows and sections, then main's "Log attributes" and "Null in a tool call update", in section order. The sentence that lists the Validate methods of the old range checks goes, as #150 removes those methods. - README.md: #150's Integers bullet before main's Patch fields bullet. - emit/README.md: #150's integer and Validate text merged word by word with main's #149 and #147 edits, and #159's panic list names holdsInteger. types_gen.go is regenerated; its diff from R159 equals #150's own diff. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
Merges R150 (main 2a4cf5c with #153, #159 and #150) into #152's head 6ca095a. #152's own change is 7bc1936..6ca095a, since its stack merged #150 at 7bc1936. Resolutions: - emit/structs.go planFor: main's #149 made fieldType a method that adds a pointer for an indirect member, and planFor already holds that type in p.goType, so mustHoldDefault's check peels p.goType instead of the gone package-level fieldType(field). - emit/ranges_test.go: keep #150's TestWriteTypesJen_PanicsOnABoundNoValueCanMeet (82a9443, newer than #152's base) and #152's optional-integer and default tests; both only add functions after the same test. - emit/README.md: #152's Validate text merged word by word with main's #149 edits and #159's alternative-kind sentence. The generated files at schema 1.32.0 do not change from R150. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
Applies #148's own patch (6c4769e..50da019) onto land/pr152 (d092f3a), which holds main 2a4cf5c plus #153, #159, #150 and #152. Resolutions: - inbound_bench_test.go: #153 made handleCancelRequest take the params of the $/cancel_request (the receive loop finds them with cancelRequestParams), so the harness passes msg.Params instead of &msg. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
Applies #155's own patch (50da019..f0d4b9c) onto the merge of #148 (land/pr148), and regenerates *_gen.go. Resolutions: - connection.go: #153 split SendRequest into sendRequest and sentRequest.wait; wait now returns the raw result, so the decodeJSON call moves to where SendRequest decodes it. - proxy.go: proxyRequest decodes a result as SendRequest does, so it calls decodeJSON too; proxy_gen.go (regenerated) decodes params with decodeJSON through jUnmarshalValidate, as agent_gen.go does. - shape.go: #150 lets an integer shape hold a uint64 above math.MaxInt64 (intRange.holds). scan checked ints with ParseInt alone and said fitNo where fits says yes (FuzzShapeScan seed#16 and TestWriteTypesJen_ValidateChecksIntegerRanges failed), so scan calls holds too. - verify-notification-barrier and verify-session-cancel: both check.sh pass every config; fingerprints re-recorded for SendRequest and the regenerated agent_gen.go cases. The connection.go edit stays on its line (git diff -U0: -1007 +1007), so no SKILL.md line citation moves. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
Applies #156's own patch (f0d4b9c..ce64625) onto the merge of #155 (land/pr155), and regenerates *_gen.go. A fast decoder must decline or read a value exactly as the exact decoder does, so fast.go follows each rule that the exact decoders gained on main. Resolutions: - emit/types.go: #159 replaced isPhantomVariant's branches with alternativeKind: the empty fast decoder goes on nullAlt and emptyAlt, rawAliases gets extensionAlt, and valueAlt declares its fast decoder with the Go type of alt.value. #149 dropped the validated memo map. - emit/fast.go, union alternatives (#159): scalarConst is gone; a value variant takes only its values (unionAlternative.values). takesValue builds that check for the exact decoder and for the fast one, which checks it in the ordered tries only, as the exact decoder does. Before, ErrorCode read 0 and -0 as ParseError. - emit/fast.go, null as unset (#147): a patch field without a clear reads null as absent (absentIfNull, or a present check that leaves out null), as decodeStmt does. Before, the 20 fields read null as PatchNull. - emit/types.go, aliases (#153): an alias of an alias of json.RawMessage is a raw alias too (aliasTarget), or its field would call a decodeFast that json.RawMessage lacks. An alias of a struct shares its methods. - emit/fast.go, integer formats (#150): int32 reads with fastInt, and uint16, uint32 and uint64 with fastUint (decode_fast.go: fastUint, parseUint, which takes no sign, as strconv.ParseUint). They went to fastExact, which is exact but decodes with encoding/json. - #149 members held through a pointer: declType reads p.goType, which holds the pointer, so fastPtr decodes them; no change. - stablecheck: a decodeFast is not compared (fastDecoder). The fast decoder of Tags, once it gains additionalProperties, keeps an unnamed member where the stable one skips it; TestCompare_AllowsAdditions failed on that. What a caller sees changes only in the exact decoder. - decode_fast_test.go: fastTypes lists the decoders of #153's UnstableProxySuccessorNotification and UnstableProxySuccessorRequest. - New tests: decode_fast_semantics_test.go mutates seeds of the types that hold these fields (each member and item replaced by null, integer bounds and one past them, -0, 1e0, 1.5, the ErrorCode codes, or repeated) and compares both decoders; emit/fast_test.go compares them on a schema with recursive pointer members, aliases, scalar alternatives of each kind and every integer format, on amd64 and 386. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
Applies #157's own patch (ce64625..d7908fa) onto the merge of #156 (land/pr156), and regenerates *_gen.go. Resolutions: - emit/types.go: the typesBuilder literal keeps main's fields (#149 dropped validated) and gains #157's repeatable map. - MIGRATION_v0.21.md: the summary table keeps main's rows and adds the Duplicate members row after them; the Duplicate members section follows main's Null in a tool call update section. #157's hunk carried the old "These types get a Validate method" line, which #150 removed; it stays removed. - verify-schema-bump SKILL.md: the cases.jsonl sentence names both the five 141/... null cases (#147) and the dup/... cases (#157); cases.jsonl keeps both sets of cases. - duplicate_member_test.go: UnstableMcpError.code is an int32 since #150, so its repeated-property error names int32. - The fast decoders decline a key that repeats (fastObject.once, skip, keep), so the exact decoder rejects it; no fast.go change. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
Applies #158's own patch (d7908fa..75310bb) onto the merge of #157 (land/pr157), and regenerates *_gen.go. Resolutions: none. The patch applies cleanly, and regenerating changes nothing. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
Verifier verdict for integration
|
| Benchmark | d092f3a | R158 | Change |
|---|---|---|---|
| Inbound/corpus, CPU | 80.24 ms/op | 19.09 ms/op | -76.2% |
| Inbound/corpus, allocations | 306.8k/op | 50.7k/op | -83.5% |
| ConnectionPipe/inbound | 46.56 ms/op | 9.89 ms/op | -78.8% |
Module zip: x/mod/zip CreateFromVCS on a clone, and CreateFromDir, both give 762,477 B, with no testdata/bench file. In the extracted zip, the bench tests skip as intended.
fix(generate): check the bounds of an optional integer that is not null #152: R158 merges with 4bee8a7 with no conflict. The result differs from R158 only in MIGRATION_v0.21.md, where 112 becomes 114. The 114 is right at R158: there are 80 Validate methods at v0.20.0 and 194 at R158.
Notes
go test .in the extracted module zip fails one test,TestUnion_MarshalJSON_RoundTripsTheG2Transcripts. It reads.agents/skills/verify-schema-bump/.../transcripts, which the zip leaves out (that skill has its owngo.mod). This fails the same way at d092f3a, so it comes from main (fix(generate): name the union when MarshalJSON has no variant to encode #143), not from this stack. It does defeat the goal of this PR's zip commits, which is thatgo testpasses in the module zip. A follow-up should skip that test as the bench tests skip.
Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high
Keeps the verified tree of 9d9dbef plus main's changes since 00ce5b0, which do not overlap it. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
Why
Part of #125 (Decoding item 3). After #156 the fast decoders spent most of their time in the scanner skipping strings byte by byte, and every decoded slice grew by doubling. This is the last step of the hill-climb on the recorded traffic of #148; with it the stack reads that traffic 75.8% faster than main with 83.5% fewer allocations.
What changed
jsonscan.go:skipStringfinds the next quote a word at a time (the first 16 bytes) and withbytes.IndexByteafter that, and counts the backslashes before it. Same results as the byte loop on every input, JSON or not.decode_fast.go:fastSliceandfastItemskeep the items' spans in a 64-slot stack buffer and allocate the slice once at its length. Values equal; capacity may differ, as it already could.decode_fast_test.go: the leaf fuzz comparator allows whitespace between a key and its colon ({"" :"","" :{}}failed it althoughMetarightly declines the repeated key).Blast Radius
Every fast decode. No API change.
Verification
BenchmarkInbound/corpusagainst fix(decode)!: reject an object that repeats one of its properties #157: CPU 21.6 ms to 19.0 ms (-12.1%, p=0.000, 10 runs), allocs -2.3%; stream bursts -4%, pipe inbound -11.5%.-cpu 1): CPU median 78.1 ms (range 76.9 to 85.1) to 18.9 ms (18.7 to 19.3), -75.8%; allocs 307.7k to 50.7k, -83.5%; pipe pair 14.2k to 29.9k msgs/s, inbound 21.2k to 93.9k. Every corpus message decodes as on main. Runs, the limiter and the hill-climb log.TestJSONScan_Corpusand the byte-loop reference test at every offset;FuzzJSONScan2.29M execs;FuzzFastDecode_Slicesand the message fuzz target 4.37M execs;FuzzFastDecode_Leaves60 s.make check,make test,go test -race ./...: pass. G2failures.txtequal to main.rust-diff: RUST PASS (73 cases). G3: 15 of 15.Generated with
xum• Model:anthropic:claude-opus-5-5• Thinking:xhigh