Repository navigation
Avoid rebuilding JSON arguments for tool invocation fingerprints - #6219
markstuart-oai wants to merge 1 commit into
Conversation
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. |
There was a problem hiding this comment.
Approved after static review and independent review. Returning parsed JSON directly preserves the fingerprint because the final encoder recursively sorts object keys; array order, nested nulls, Unicode, and invalid-constant handling remain unchanged. The exact-builtin scalar shortcut preserves the existing normalization path for subclasses and custom objects. No actionable correctness or approval-identity compatibility findings.
Hosted CI completed: 24 checks passed and 2 were skipped, with no failures. No candidate code, local tests, or benchmarks were executed.
Summary
In an offline test with eight tool calls and 256 records per call, the full run has been dropping from 37.66 to 18.16 ms. A single call with 64 records has been taking 1.95 ms, down from 2.64 ms.
For 32 concurrent streams, the full run has been getting faster but the second batch has been taking 53 ms longer. The garbage collection measurements below have been showing why.
For each approval fingerprint, the SDK has been walking and rebuilding the full tree of JSON arguments after parsing it. The encoder has then been sorting the keys again.
With this change, the SDK has been passing parsed JSON directly to the same encoder. For values from Python objects, it has been handling plain strings, numbers, booleans and nulls before checking for mappings and sequences. Subclasses and custom objects have been keeping the existing conversion path.
The SDK has been computing each fingerprint from the current input. All approval and execution checks have been running as before. No cache or change to stored fingerprints.
Related work in #6191 on parsed JSON. Additional coverage here for plain values in non-JSON inputs and for matching the same nested arguments across representations.
Benchmarks
The separate 30-block replay of eight calls with 256 records each has been reproducing the gain (37.04 to 18.01 ms, −51.48%).
Slower second batch of streams. The second batch has been taking 53 ms longer. The first and third have been taking about 64 and 49 ms less. In a longer test of 12 batches across 24 pairs of processes, only batch two has been getting slower. Including setup, execution, validation and cleanup, time for all 12 has been dropping from 6.43 to 5.83 seconds (−8.80%, 95% interval −11.35 to −7.54%). The slowest batch per process has been getting 9.25% faster.
In a separate check of garbage collection, the full collection in three of four main processes has been landing in setup for batch three, outside the request timer. All four PR processes have been collecting during batch two. Both sides have been doing 12 full collections. The pause has been adding to request latency for that batch.
SQLite writes. The 64-pair repeats have been showing a slowdown for both the small write (+5.62% [2.11, 12.37]) and the large one (+2.29% [0.29, 7.52]). Both intervals have been crossing +3%.
A separate synchronized test has been rotating two copies of main and two copies of the branch across four writer positions in 128 blocks. With matched starts and full checks of the committed data, the small write has been measuring +0.64% [−1.45, +2.91] and the large write −0.02% [−0.50, +0.41]. Both intervals for the same-code controls have been covering zero for each write size. An untimed trace has been recording zero calls to either changed function. The evidence has been pointing to disk timing. The earlier results have been staying in the table.
Regression checks across all 83 comparisons with Codex off. Offline Python SDK workloads on one Linux host with CPython 3.12.16. This change alone against
mainat4e162c79, without network or model latency.Timings and 95% intervals for all 83 comparisons
Test plan and checks
.agents/skills/code-change-verification/scripts/run.sh) including formatting, lint, mypy, Pyright and both pytest phases. 12,865 passed, 30 skipped.