fix(claude): read nested JSON objects regardless of key order - #24
Merged
Merged
Conversation
The status line's json_obj captured a nested object only up to its first closing brace, on the assumption that every object lists its scalars ahead of any object of its own. Key order is not guaranteed: the extras spec encodes its payload with vim.json.encode, whose order varies by build, and on one CI runner context_window came out with current_usage ahead of used_percentage. The percentage then fell outside the capture, the token-sum fallback rounded 61500/200000 down to 30%, and the spec failed on the stable job alone while v0.10.4 and nightly passed. The match now spans one level of nesting and cuts the inner objects out of the body before any scalar lookup, so a recurring key such as used_percentage still resolves against the right object. Every caller reads from the top-level payload, so nothing depended on the inner objects surviving. Generated scripts rebuilt for all five variants. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WAKpAw1biNtpxi3VEb37Nw
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.
π What broke
CI on main failed in the extras spec, on the stable Neovim job only:
renders the Claude Code status line from a payloadreportedmissing 31%for every variant while v0.10.4 and nightly passed. The same commit had passed on its PR run minutes earlier.π Why
The status line parses its JSON with bash regex helpers.
json_objcaptured a nested object up to its first closing brace, assuming every object lists its scalars before any object of its own. The spec encodes its payload withvim.json.encode, whose key order varies by build, and on the stable runnercontext_windowcame out withcurrent_usageahead ofused_percentage. The percentage landed outside the capture, the token-sum fallback rounded 61500/200000 down to 30%, and the assertion on31%failed.Claude Code's real payload carries the same risk, since nothing guarantees its key order either.
π οΈ The fix
json_objnow matches one level of nesting and strips the inner objects from the body before any scalar lookup, so a key that recurs across objects (used_percentagelives in bothcontext_windowand the rate limit objects) still resolves against the right parent. All ten call sites read from the top-level payload, so none of them depended on inner objects surviving. The five generated scripts underextras/claude/are rebuilt from the template.β Verification
current_usagefirst: 30% before the fix, 31% after.make testgreen, and the status line spec rerun twelve times in a loop with no failures.bash -non all five generated scripts, shellcheck unchanged from before.π€ Generated with Claude Code
https://claude.ai/code/session_01WAKpAw1biNtpxi3VEb37Nw