fix(context): require word-boundary match for JSON structural-key fidelity check#6611
Merged
Merged
Conversation
…elity check check_json_structural_key inside ToolOutputInvariant::verify (the FR-003 hard gate for compacted JSON ToolOutput pages) used a raw substring test against top-level JSON keys, so short common keys like "id" or "ok" were satisfied by unrelated prose (e.g. "idea", "okay") without the field's actual content surviving compaction. Add key_appears_as_word, requiring the key to appear JSON-quoted or as a standalone word. Empty keys still always pass, preserving prior permissive behavior for that degenerate case. Document the residual: a dictionary-word key genuinely present as a standalone word in unrelated prose still satisfies the check. Closes #6575
bug-ops
force-pushed
the
fix/6575-json-structural-key-check
branch
from
July 20, 2026 20:16
3b1e9ef to
54e72da
Compare
bug-ops
enabled auto-merge (squash)
July 20, 2026 20:17
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.
Summary
check_json_structural_keyinsideToolOutputInvariant::verify(crates/zeph-context/src/typed_page.rs) is the FR-003 hard gate that guarantees structural keys survive compaction for JSON-schemaToolOutputpages. It used a rawcompacted.contains(key)substring test, so short common keys like"id"or"ok"were trivially satisfied by unrelated prose (e.g. "the idea was okay" satisfies"id"/"ok") without the field actually surviving compaction.key_appears_as_word(haystack, key), which requires the key to appear either JSON-quoted ("key") or as a standalone word (checks that characters immediately before/after a match are not alphanumeric/_). No regex dependency added.{"": ...}) still always passes, preserving the prior permissive behavior for that degenerate case (it carries no structural information to verify).Closes #6575
Test plan
cargo +nightly fmt --check— cleancargo clippy --profile ci --workspace --all-targets --features "desktop,ide,server,chat,pdf,scheduler,testing" -- -D warnings— cleancargo nextest run --config-file .github/nextest.toml --workspace --features "desktop,ide,server,chat,pdf,scheduler" --lib --bins— 14995 passedRUSTFLAGS="-D warnings" RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc --no-deps --workspace --features "desktop,ide,server,chat,pdf,scheduler"— cleangitleaks protect --staged --no-banner --redact— no leaks