Skip to content

fix(auto-tool-tracking): TOOL_INVOCATION_ERROR_RE misses 'after property value' variant — complete-slice retries instead of pausing on LLM JSON error #3924

@OfficialDelta

Description

@OfficialDelta

Problem

gsd_complete_slice fails with Expected ',' or '}' after property value in JSON at position N when a large narrative parameter causes the agent to emit malformed JSON. GSD does not recognise this as a tool-invocation error, so instead of pausing with a clear message it silently retries the unit — requiring manual user intervention.

Root Cause

TOOL_INVOCATION_ERROR_RE in auto-tool-tracking.js line 86 expects Expected ',' or '}' in JSON but Node.js v18+ emits Expected ',' or '}' after property value in JSON at position N. The extra words "after property value" break the substring match.

// auto-tool-tracking.js:86 — current (broken):
const TOOL_INVOCATION_ERROR_RE =
  /Validation failed for tool|Expected ',' or '\}' in JSON|Unexpected end of JSON|Unexpected token.*in JSON/i;

// Actual error string that should match but doesn't:
// "Expected ',' or '}' after property value in JSON at position 17663 (line 1 column 17664)"

The failed match means recordToolInvocationError() never sets s.lastToolInvocationError. When artifact verification then fails (no SUMMARY.md written), auto-post-unit.js:489 takes the retry path instead of the pause-with-clear-error path — the user sees a silent retry rather than an actionable error message.

Fix

Drop the trailing in JSON from the Expected ',' or '}' branch so it matches all variants:

// auto-tool-tracking.js:86 — fix:
const TOOL_INVOCATION_ERROR_RE =
  /Validation failed for tool|Expected ',' or '\}'|Unexpected end of JSON|Unexpected token.*in JSON/i;

Or equivalently:

  /Validation failed for tool|Expected ',' or '\}'.*in JSON|Unexpected end of JSON|Unexpected token.*in JSON/i;

Expected Behavior

When the LLM emits invalid JSON for gsd_complete_slice (or any GSD tool), GSD should:

  1. Recognise the error via isToolInvocationError()
  2. Set s.lastToolInvocationError
  3. After artifact verification fails, enter the if (s.lastToolInvocationError) branch at auto-post-unit.js:489 and pause auto-mode with a clear notification: "Tool invocation failed for complete-slice: … Structured argument generation failed — pausing auto-mode."

Secondary Symptom (not a separate bug)

After the user manually fixed the JSON and gsd_complete_slice succeeded, the agent showed "Working" until cancelled. The handleCompleteSlice post-write pipeline (renderAllProjectionsrenderStateProjectionderiveState) performs NFS I/O on a hard-mounted NFS share. The idle watchdog (auto-timers.js, interval 15 s, default threshold 10 min) would have recovered the stalled tool after 10 minutes, but the user cancelled first. No code change needed; the watchdog works correctly — the 10-minute threshold just exceeds user patience for a closure unit.

Environment

  • GSD version: 2.67.0
  • Model: claude-haiku-4-5 (complete-slice unit)
  • Unit: complete-slice/M022/S02
  • Milestone: M022, Slice S02

Reproduction Context

  • complete-slice agent calls gsd_complete_slice with narrative > ~15 KB
  • Agent-generated JSON contains a value that causes JSON.parse to throw Expected ',' or '}' after property value in JSON at position N
  • GSD fails to recognise this as a tool-invocation error → retries instead of pausing

Forensic Evidence

  • auto-tool-tracking.js:86TOOL_INVOCATION_ERROR_RE does not match Expected ',' or '}' after property value
  • auto.js:204recordToolInvocationError only sets lastToolInvocationError if isToolInvocationError() returns true
  • auto-post-unit.js:489 — pause branch never reached because lastToolInvocationError is null
  • Activity log 443-complete-slice-M022-S02.jsonl: 22 tool calls, 0 errors, successful completion after user intervention
  • Note: executeCompleteMilestone has a sanitizeCompleteMilestoneParams() call (workflow-tool-executors.js:201) but executeSliceComplete has no equivalent sanitizer — a parallel fix would add one

Auto-generated by /gsd forensics

Metadata

Metadata

Assignees

No one assigned

    Labels

    High PrioritybugSomething isn't workingci-failingLinked PR has failing CI checkscloses-on-mergeWill close automatically when linked PR merges

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions