fix(claude): handle async background task notifications in remote mode#354
Open
xyzhang626 wants to merge 4 commits intotiann:mainfrom
Open
fix(claude): handle async background task notifications in remote mode#354xyzhang626 wants to merge 4 commits intotiann:mainfrom
xyzhang626 wants to merge 4 commits intotiann:mainfrom
Conversation
The test was failing in CI because Claude CLI is not installed in the CI environment. Mock the path utility to avoid the dependency. via [HAPI](https://hapi.run) Co-Authored-By: HAPI <noreply@hapi.run>
| logger.debug(`${debugPrefix} scheduleNextMessage start fetchId=${fetchId}`); | ||
| void (async () => { | ||
| try { | ||
| const next = await opts.nextMessage(); |
There was a problem hiding this comment.
[MAJOR] Unhandled rejection risk from fire-and-forget nextMessage. Detached async call has no catch, so any rejection bypasses the outer try/catch and becomes unhandled. Evidence: cli/src/claude/claudeRemote.ts:190.
Suggested fix:
void (async () => {
try {
const next = await opts.nextMessage();
if (!next) {
inputEnded = true;
messages.end();
logger.debug(
`${debugPrefix} nextMessage resolved null fetchId=${fetchId} elapsedMs=${Date.now() - startedAt}; input ended`
);
return;
}
mode = next.mode;
messages.push({ type: 'user', message: { role: 'user', content: next.message } });
logger.debug(
`${debugPrefix} nextMessage resolved fetchId=${fetchId} elapsedMs=${Date.now() - startedAt} ` +
`messageLength=${next.message.length} permissionMode=${next.mode.permissionMode}`
);
} catch (e) {
inputEnded = true;
messages.end();
logger.debug(`${debugPrefix} nextMessage error fetchId=${fetchId}`, e);
} finally {
nextMessageFetchInFlight = false;
logger.debug(`${debugPrefix} scheduleNextMessage done fetchId=${fetchId}`);
}
})();
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
pendingNextInputeven when async task results arrived, causing notifications to be silently droppedProblem
When Claude executes a background task (e.g.
say hi after 10 secs), the task notification arrives asynchronously after the main response completes. The remote stream handler was waiting forpendingNextInputto resolve before processing new messages, which caused these async notifications to never be delivered to the user.Reproduce
Changes
claudeRemote.ts: Refactor stream processing to not block onpendingNextInputwhen async task results arrive. Add debug traces for task notification lifecycle.claudeRemoteLauncher.ts: Add debug logging for incoming messages in the launcher bridge.claudeRemote.test.ts: Add test cases covering the async notification flow.Test plan
bun test claudeRemote.test.ts