Skip to content

Conversation

@BowTiedSwan
Copy link

@BowTiedSwan BowTiedSwan commented Jan 13, 2026

Summary

This PR introduces a new hook json-error-recovery to address Issue #735.

Problem

When a tool call fails due to a JSON parse error (e.g., "Expected '}'"), the agent often retries the exact same malformed payload, leading to an infinite retry loop that wastes tokens and stalls the session.

Solution

The new json-error-recovery hook detects specific JSON error patterns in tool outputs:

  • "JSON Parse error"
  • "SyntaxError: Unexpected token"
  • "Expected '}'"
  • "Unexpected EOF"

When detected, it injects a high-priority system reminder into the tool output, instructing the agent to:

  1. Stop and read the error.
  2. Correct the JSON syntax.
  3. Retry with valid JSON (instead of repeating the error).

Changes

  • Added src/hooks/json-error-recovery/index.ts
  • Updated src/hooks/index.ts and src/index.ts to register the new hook.
  • Updated src/config/schema.ts to include the new hook name.
  • Added verification tests in tests/json_recovery.test.ts.

Verification

  • Ran new tests with bun test tests/json_recovery.test.ts -> PASSED.

Summary by cubic

Adds a json-error-recovery hook to stop infinite retry loops when tool calls fail with JSON parse errors by instructing the agent to fix and resend valid JSON. Fixes #735.

  • Bug Fixes
    • Detects common JSON errors: "JSON Parse error", "SyntaxError: Unexpected token", "Expected '}'", "Unexpected EOF".
    • Appends a high-priority reminder at tool.execute.after to halt repeats and correct JSON.
    • Registers the hook in schema and index; adds tests for JSON recovery and edit recovery.

Written for commit b54a235. Summary will update on new commits.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 13, 2026

All contributors have signed the CLA. Thank you! ✅
Posted by the CLA Assistant Lite bot.

@BowTiedSwan
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 6 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

renekris added a commit to renekris/oh-my-glm that referenced this pull request Jan 13, 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.

[Bug]: Tool call JSON parse error causes infinite retry loop (Write/JSONC)

1 participant