Skip to content

fix: stop stalled Claude turns after inactivity - #327

Open
LucaLow wants to merge 1 commit into
yc-software:mainfrom
LucaLow:fix/claude-inactivity-watchdog
Open

fix: stop stalled Claude turns after inactivity#327
LucaLow wants to merge 1 commit into
yc-software:mainfrom
LucaLow:fix/claude-inactivity-watchdog

Conversation

@LucaLow

@LucaLow LucaLow commented Aug 11, 2026

Copy link
Copy Markdown

Summary

  • enforce a five-minute model inactivity deadline while waiting for Claude SDK activity
  • pause the deadline during tool and subagent execution and local event processing
  • abort stalled initialization and iteration cleanly while preserving user cancellation semantics

Verification

  • Claude harness turn tests
  • ESLint and Prettier on affected files
  • TypeScript typecheck
  • independent correctness review

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Copilot AI lite review requested due to automatic review settings August 11, 2026 02:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a model-inactivity watchdog to the Claude harness turn runner to prevent indefinitely stalled Claude SDK turns, while pausing the watchdog during tool/subagent execution and local processing.

Changes:

  • Introduces a default 5-minute Claude model inactivity deadline (modelInactivityMs override) while awaiting SDK initialization and stream activity.
  • Pauses the inactivity deadline during bridged tool execution and Claude subagent task execution, and resumes/reset logic around SDK next() waits.
  • Adds harness-turn tests covering inactivity timeouts, reset behavior, and pausing semantics.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/harness/claude-harness.ts Implements the inactivity timer and pause/reset logic around SDK initialization/iteration and tool/subagent execution.
test/claude-harness-turn.test.ts Extends the SDK mock and adds turn tests to validate inactivity timeouts, resets, and pause behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

queue.close();
await sdkQuery.interrupt().catch(() => undefined);
controller.abort();
await sdkQuery.interrupt().catch(() => undefined);
Comment on lines +314 to +326
await new Promise((resolve) => setTimeout(resolve, 15));
yield assistantMessage("msg_A", "working", {
input_tokens: 1,
output_tokens: 1,
cache_read_input_tokens: 0,
cache_creation_input_tokens: 0,
});
await new Promise((resolve) => setTimeout(resolve, 15));
yield resultMessage("done");
};

const harness = createClaudeHarness({ modelInactivityMs: 25 });
const { turn } = harnessTurn();
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.

2 participants