Repository navigation
Repair create_schema JSON keys corrupted by a leaked Gemma quote token (closes #1926) - #1929
Conversation
closes #1926) Grammar-constrained decoding was observed emitting Gemma 4's literal quote-token text (<|"|>) inside a create_schema call's fields array, corrupting a key like "type" into "<|"|>type<|"|>" — syntactically valid JSON with a garbled key, so no parse-failure guard caught it; the tool rejected the call for a missing "type" field, and scenario 8b regressed from 3/3 to 0/3. First attempt stripped the leaked token at the streaming-delta layer in nlp-engine (mirroring how content already handles it), and looked correct against unit tests reproducing the exact corrupted string — but failed live: the token can straddle a delta boundary, and a per-delta substring strip can't match a token split across two separate deltas. Content has boundary-carry handling for exactly this reason; tool-call arguments never did. Fixed instead with repair_leaked_special_token_keys, a sibling to the existing repair_over_quoted_keys (#1876), operating on the fully accumulated, already-parsed argument value — immune to delta boundaries since the corrupted key already exists as one complete string by the time it runs. Wired in alongside repair_over_quoted_keys at both call sites: the real execution path and canonical_args, so a malformed call and its repaired retry share one duplicate-guard identity. Validated: 3-rep full matrix gate (isolated daemon, purged DB per rep) scores 10, 10, 10 — mean 10.0/12, fully deterministic. Scenario 8b passes all 3 reps with zero JSON corruption in the daemon log across 9 create_schema executions. Remaining failures (scenario 6, 8c) are pre-existing, separately tracked, and unaffected by this change. Co-Authored-By: Claude <[email protected]>
Code Review SummaryClean, well-scoped bug fix. I independently re-ran the 4 new tests ( FindingsCritical IssuesNone. Suggested Improvements
Nitpicks
Verification Notes (independently checked, not just accepted from the PR description)
Recommendation: APPROVE |
malibio
left a comment
There was a problem hiding this comment.
Review recommendation: APPROVE (self-approval blocked by GitHub — same account authored the PR). Full findings posted above. No blockers; net positive, safe to merge.
The review on PR #1929 traced that repair_leaked_special_token_keys's collision guard checks against the live, mutating object on each loop iteration rather than a frozen snapshot — correct by construction (the first-processed corrupted key repairs cleanly, a second key that would collide with it backs off untouched), but not covered by an explicit test. Adds a test with two distinct corrupted keys that both repair to the same clean name within one object, asserting the first wins and the second is left in its original form rather than overwritten or discarded. Verified it actually catches the regression by temporarily removing the collision guard and confirming the test fails, then reverting. Co-Authored-By: Claude <[email protected]>
Address reviewAddressed the review's one substantive suggestion: The other suggestion (scope: only the one observed leaked token,
Re-Review DecisionDecision: NO RE-REVIEW NEEDED Rationale: One additive unit test, no production code changed, no logic altered — the fix itself was already reviewed and approved. Low-risk, straightforward addition per the skill's own criteria for skipping re-review. Ready for merge, pending your go-ahead. |
Summary
Closes #1926. Scenario 8b regressed 3/3 → 0/3 after the history-compaction fix (#1925) — root-caused to a pre-existing, unrelated bug the compaction fix merely exposed: grammar-constrained decoding was observed emitting Gemma 4's literal quote-token text (
<|"|>) insidecreate_schema'sfieldsarray, corrupting a key like"type"into"<|"|>type<|"|>". That's syntactically valid JSON with a garbled key, so no parse-failure guard caught it — the tool rejected the call for a missingtypefield.What was tried and didn't work (documented for the record)
The obvious fix — the codebase already strips this exact leaked token from plain-text
contentviastrip_gemma_special_tokens— is to apply the same stripping to tool-callargumentsat the streaming-delta layer (nlp-engine::emit_oai_delta). This passed unit tests reproducing the exact corrupted string from the issue's daemon-log evidence, but failed live: the token can straddle a delta boundary (one streamed chunk ending<|, the next starting"|>), and a per-delta substring strip can't match a token split across two deltas. Confirmed via a genuinely clean-rebuilt binary — the corruption still appeared verbatim in the daemon log.The actual fix
repair_leaked_special_token_keys, a sibling to the existingrepair_over_quoted_keys(#1876's fix for a related-but-distinct key-corruption shape — the model over-quoting its own keys). Operates on the fully accumulated, already-parsed argumentValue— immune to delta boundaries since the corrupted key already exists as one complete string by the time it runs. Wired in alongsiderepair_over_quoted_keysat both call sites: the real execution path andcanonical_args(so a malformed call and its repaired retry share one duplicate-guard identity, same rationale as the existing repair).Test plan
canonical_args. Verified each catches its regression by temporarily reverting the fix.cargo test -p nodespace-agent --lib— 434 passed, 0 failedcargo clippy --all-targets -- -D warnings -D clippy::unused-async— cleanbun run quality:fix— clean (0 errors/warnings)args_previewshows the correctly-repaired"type"key, schema persistedcreate_schemaexecutions. Remaining failures (scenario 6 — documented model-capability limit; scenario 8c — update_node resolves the correct node but persists no properties on state-change requests (scenario 6 residual gap) #1927) are pre-existing, separately tracked, and unaffected by this change.test:all+cargo build --bin nodespaced+test:e2e) passedFull investigation trail on #1926's comments.
Co-Authored-By: Claude [email protected]