Repository navigation
fix(jq): bound object-key/index error previews with capped rendering - #2697
Merged
Merged
Conversation
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
bashkit | 68a1bc6 | Commit Preview URL Branch Preview URL |
Oct 12 2026, 04:13 AM |
2 tasks done
chaliy
added a commit
that referenced
this pull request
Oct 12, 2026
…ostile values (#2699) ## What changed Bounds the CPU cost of jq math/index error previews, not just their allocation. ## Why Follow-up to #2697: that PR capped preview *allocation* with the `Capped` sink, but the sink swallowed over-budget writes with `Ok(())`, so `Val`'s `Display` (the `?`-laden `format_val!`/`write_seq!` machinery) kept expanding the full hostile value just to discard the output. For the finding's shared-structure input (`reduce range(0; 40) as $i (1; [., .]) | . + 1`, a ~2^40-element expansion on type-mismatch), the error path still walked the whole expansion. ## Before / After (production entry point, `timeout 120`, direct child timing) Before (by source inspection + failing test `preview_writer_aborts_once_over_budget`): `write!` over a 200 KB value returned `Ok` after walking all of it. After: ``` $ time ./target/debug/bashkit -c 'jq -n '\''reduce range(0; 40) as $i (1; [., .]) | . + 1'\''' jq: error (at <unknown>): array ([[[[[[[[[[[...) and number (1) cannot be added exit=5, 80-byte stderr, 0.012s wall ``` Exit code 5 matches real jq's runtime-error exit; small-value wording is unchanged (`math_errors_use_jq_wording` passes). Also fixed: over-budget previews that aborted before filling the buffer (multibyte char straddling the cut) previously returned without the `...` marker; the marker is now unconditional on over-budget output. Small-value output is byte-identical. ## Validation - `cargo test -p bashkit --lib --features jq builtins::jq`: 357 passed, 0 failed (6 new tests: early-abort, exact-fit, just-over, multibyte, recovery, huge-operand session integration) - `cargo fmt --check`, `cargo clippy --all-targets --features jq`: clean - `just check-okf`: conforms; knowledge note updated in `knowledge/runtimes/jaq-json-vendor.md` ## Checklist - [x] Tests added or updated - [x] Backward compatibility considered (internal code; error-preview bytes for small values unchanged)
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
Error-preview rendering in
crates/bashkit/src/builtins/jq/jaq_json/jqmsg.rsmaterialized huge values before truncating:dump_trunccalledv.to_string()(full render, outside the memory meter) and truncated after.indexinterpolated the raw key string (format!("string {}", r)) into cannot-index errors.A 200 KB string key produced a ~200 KB error string; object keys built by filters (e.g.
{([range(0;200000)]): 1}) transiently rendered megabytes.Fix
dump_truncrenders through a 15-byte cappedfmt::Writesink, then applies the legacy 11-bytes+...cut. Small-value output is byte-identical.dump_trunc.knowledge/runtimes/jaq-json-vendor.md.Proof
cargo test -p bashkit --lib --features jq builtins::jq: 350 passed.cargo fmt --check,cargo clippy --features jq -- -D warnings: clean.Cannot index array with string "a",Cannot use array ([0,1,2,3,4,...) as object key); huge key error is 74 bytes.just check-okf: conformant.