Skip to content

fix(invoke): resolve signalDone grace period race condition#258

Merged
jlia0 merged 1 commit intomainfrom
jlia0/fix-signaldone-kill
Mar 24, 2026
Merged

fix(invoke): resolve signalDone grace period race condition#258
jlia0 merged 1 commit intomainfrom
jlia0/fix-signaldone-kill

Conversation

@jlia0
Copy link
Collaborator

@jlia0 jlia0 commented Mar 24, 2026

Description

Fix a race condition in runCommandStreaming where the signalDone grace period handler kills the subprocess with SIGTERM, which triggers the close event with exit code 143 before the delayed settle(0) can run. This causes a spurious rejection and the agent returns a generic error message instead of the successfully streamed result.

Changes

  • Call settle(0) before child.kill('SIGTERM') so the promise resolves successfully and the subsequent close event (code 143) is a no-op
  • Remove the unnecessary nested setTimeout(() => settle(0), 2000) since settling now happens synchronously before the kill

Testing

  • Reviewed the control flow to confirm settle guards on settled flag, so the close event after kill is safely ignored

Checklist

  • PR title follows conventional commit format (type(scope): description)
  • I have tested these changes locally
  • My changes don't introduce new warnings or errors
  • I have updated documentation if needed

The SIGTERM kill triggers a `close` event with code 143 before the
delayed settle(0) can run, causing a spurious rejection. Settle
successfully before killing the process so the close event is a no-op.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jlia0 jlia0 merged commit afd2730 into main Mar 24, 2026
@jlia0 jlia0 deleted the jlia0/fix-signaldone-kill branch March 24, 2026 19:26
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