Skip to content

fix(context): require word-boundary match for JSON structural-key fidelity check#6611

Merged
bug-ops merged 1 commit into
mainfrom
fix/6575-json-structural-key-check
Jul 20, 2026
Merged

fix(context): require word-boundary match for JSON structural-key fidelity check#6611
bug-ops merged 1 commit into
mainfrom
fix/6575-json-structural-key-check

Conversation

@bug-ops

@bug-ops bug-ops commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Summary

  • check_json_structural_key inside ToolOutputInvariant::verify (crates/zeph-context/src/typed_page.rs) is the FR-003 hard gate that guarantees structural keys survive compaction for JSON-schema ToolOutput pages. It used a raw compacted.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.
  • Added 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.
  • An empty JSON key ({"": ...}) still always passes, preserving the prior permissive behavior for that degenerate case (it carries no structural information to verify).
  • Documented a residual limitation in the doc comment: a short common-English-word key that genuinely appears as a standalone word in unrelated prose (e.g. "the id was ok") still satisfies the check — this closes the subword-substring false-positive class but not the dictionary-word class, consistent with the issue's own framing ("cuts most accidental matches").

Closes #6575

Test plan

  • cargo +nightly fmt --check — clean
  • cargo clippy --profile ci --workspace --all-targets --features "desktop,ide,server,chat,pdf,scheduler,testing" -- -D warnings — clean
  • cargo nextest run --config-file .github/nextest.toml --workspace --features "desktop,ide,server,chat,pdf,scheduler" --lib --bins — 14995 passed
  • RUSTFLAGS="-D warnings" RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc --no-deps --workspace --features "desktop,ide,server,chat,pdf,scheduler" — clean
  • gitleaks protect --staged --no-banner --redact — no leaks
  • New regression tests: substring-only false positive is rejected, whole-word match still passes, UTF-8 boundary adjacency does not panic, empty-key case still passes

@github-actions github-actions Bot added documentation Improvements or additions to documentation rust Rust code changes bug Something isn't working size/M Medium PR (51-200 lines) labels Jul 20, 2026
…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
bug-ops force-pushed the fix/6575-json-structural-key-check branch from 3b1e9ef to 54e72da Compare July 20, 2026 20:16
@bug-ops
bug-ops enabled auto-merge (squash) July 20, 2026 20:17
@bug-ops
bug-ops merged commit ffa501c into main Jul 20, 2026
43 checks passed
@bug-ops
bug-ops deleted the fix/6575-json-structural-key-check branch July 20, 2026 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation rust Rust code changes size/M Medium PR (51-200 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

typed_page ToolOutputInvariant::check_json_structural_key can be trivially satisfied by unrelated compacted text

1 participant