Skip to content

fix(llm): recover bare arrays and truncated JSON from gateway content (#253) - #269

Closed
Frankie-Xu wants to merge 4 commits into
trailhq:mainfrom
Frankie-Xu:fix/253-recover-bare-array-truncated
Closed

Frankie-Xu wants to merge 4 commits into
trailhq:mainfrom
Frankie-Xu:fix/253-recover-bare-array-truncated

Conversation

@Frankie-Xu

@Frankie-Xu Frankie-Xu commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Recover bare synth/crux item arrays and complete payload items from truncated gateway content when a local model ignores forced tool calling.
  • Truncation recovery now verifies the cut belongs to the recovered payload array. A complete object inside an unfinished trailing node's links or metadata cannot cause that node to be accepted.
  • Reject wrong-tool envelopes before nested bracket fallback, including prefixed or truncated single-object envelopes. Existing tool wrappers, JSON fences and real toolCalls precedence remain covered.

Opt-in raw-content diagnostics from #253 remain separately scoped. Recovery changes are in src/ai/llm/recover-tool.ts and test/llm-ops.test.ts. The CodeQL initialization pin is also aligned with the existing analysis pin (4.38.1), allowing scans to start after current main introduced mismatched action versions.

Addresses #253

Validation

  • npm run build passed after a normal merge of current main (fe30ead39d5e6f0c921018d364da2bdbc9d4b3ad).
  • Node 24.18.1: node --import tsx --test --test-concurrency=1 test/llm-ops.test.ts — 18 passed, zero failed or skipped.
  • The nested-item and rejected-tool regressions both reproduced on the previous PR head; independent local code review has no outstanding findings.
  • git diff --check upstream-live/main...HEAD passed.
  • CodeQL pins statically match the official 4.38.1 tag and package version; updated remote CI verifies the scan.

Local macOS validation used an exact-lock npm ci --ignore-scripts install plus a matching cached Kotlin 0.3.8 native binary copied into the isolated dependency directory and verified on Node ABI 137. Tests use a fake model with no external model calls. Linux and Windows validation is left to the updated GitHub CI run.

github-actions Bot added a commit that referenced this pull request Aug 30, 2026
@github-actions

github-actions Bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

🌱 graft blast radius

1 area changed → 1 area can be affected. 4 dependent symbols, depth 2.
Tests: 1 area updated its tests.
Tag: @anirudhkumar-nanonets — Code Synthesis · @shhdwi — Code Synthesis

flowchart TB
  A0(("Code Synthesis<br/>4 symbols"))
  classDef reached fill:#D9EDF3,stroke:#3AA7C9,stroke-width:1.5px,color:#0E313C;
  class A0 reached;
Loading
Can be affected Symbols Nearest hop Reached from
Code Synthesis 4 src/ai/crux.ts:L159-L172 argsFromResponse — calls, depth 1 LLM Tool Recovery
Who knows this code — 2 people across 2 areas
Area Who knows it
Code Synthesis · affected @anirudhkumar-nanonets — 5 commits, last 3mo ago · @shhdwi — 2 commits, last 2mo ago
LLM Tool Recovery · changed only you — nobody else has touched these files

Ownership is git history over each area's own files, weighted towards recent work (120-day half-life). Merge commits and bots are dropped, and you are dropped from your own PR. A name with no @ has no GitHub handle in its commit email — tag them by hand, or add a .mailmap entry. A suggestion from history, not a CODEOWNERS rule.

All 4 dependent symbols, grouped by area

Code Synthesis — 4 symbols in 2 files

  • src/ai/crux.ts:L159-L172 — argsFromResponse (calls, depth 1)
    166: const recovered = recoverToolArgsFromContent(res.text, {
  • src/ai/synthesize.ts:L158-L171 — nodesFromResponse (calls, depth 1)
    165: const recovered = recoverToolArgsFromContent(res.text, {
  • src/ai/crux.ts:L180-L202 — describeFile (calls, depth 2)
  • src/ai/synthesize.ts:L132-L151 — synthesize (calls, depth 2)
Test signal per changed area — 1 ✓

Reached = a node under a test path has a resolved edge into the changed symbol. It undercounts anything called indirectly — through a CLI, a spawned process or a dynamic import — so read a low ratio as “look here”, never as a coverage gate.

  • ✓ LLM Tool Recovery — 1 of 4 reached · 1 test file changed here: test/llm-ops.test.ts
    • not reached: closersFor, tryRepairedPayload, asPayload

⚠️ 1 changed file not in the graph (.github/workflows/codeql.yml) — no parser claims the extension, or the index predates the file.

graft blast · origin/main...HEAD · depth 2 · 3 changed files

Open the interactive graph → — click an area to see its dependent symbols at file:line.

@Frankie-Xu
Frankie-Xu force-pushed the fix/253-recover-bare-array-truncated branch from 9b8f87b to 0e7cf16 Compare August 31, 2026 17:44
@Frankie-Xu
Frankie-Xu marked this pull request as ready for review August 31, 2026 17:45
@Frankie-Xu

Copy link
Copy Markdown
Contributor Author

Kept this as Draft while the review queue was full.

Rebased onto main at aa1e2bb (release: 0.16.0). Follow-up to #216: recover a bare item array and truncated JSON from gateway content (#253), linear scan only (no backtracking regex). Real toolCalls still win; empty recoveries are not treated as a successful cache (#177).

Closes #253.

@Frankie-Xu

Copy link
Copy Markdown
Contributor Author

Rebased onto main after #277 so the stale not-ok-197 checks could re-run — all checks green now.

@Frankie-Xu
Frankie-Xu force-pushed the fix/253-recover-bare-array-truncated branch from 0a644c9 to 9afde32 Compare September 11, 2026 12:25
@Frankie-Xu

Copy link
Copy Markdown
Contributor Author

CI is green on current main. Ready for review.

github-actions Bot added a commit that referenced this pull request Oct 7, 2026
shhdwi pushed a commit that referenced this pull request Nov 9, 2026
…#253) (#269)

Re-landed from #269 with the conflicts against main resolved; the contributor's fork couldn't take the merge commit.

Co-Authored-By: Shrish Dwivedi <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-actions Bot added a commit that referenced this pull request Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant