process SDK messages independently of prompt#396
Draft
SteffenDE wants to merge 2 commits intozed-industries:mainfrom
Draft
process SDK messages independently of prompt#396SteffenDE wants to merge 2 commits intozed-industries:mainfrom
SteffenDE wants to merge 2 commits intozed-industries:mainfrom
Conversation
Relates to zed-industries#386. Relates to zed-industries#336.
SteffenDE
commented
Mar 9, 2026
| if (done || !message) { | ||
| if (session.cancelled) { | ||
| return { stopReason: "cancelled" }; | ||
| // Query stream ended |
Contributor
Author
There was a problem hiding this comment.
I assume that this should not normally happen and if it does, the session is done for good? If not, we may need to recursively call process, otherwise we don't handle subsequent messages.
SteffenDE
commented
Mar 9, 2026
| cachedReadTokens: session.accumulatedUsage.cachedReadTokens, | ||
| cachedWriteTokens: session.accumulatedUsage.cachedWriteTokens, | ||
| inputTokens: message.usage.input_tokens, | ||
| outputTokens: message.usage.output_tokens, |
Contributor
Author
There was a problem hiding this comment.
I removed accumulating, since the prompt return usage should reflect "per-turn data" and we only expect one result message for each prompt. This means that usage for background tasks is not included here.
SteffenDE
commented
Mar 9, 2026
Comment on lines
+873
to
+876
| return RequestError.internalError( | ||
| undefined, | ||
| "The Claude Agent process exited unexpectedly. Please start a new session.", | ||
| ); |
Contributor
Author
There was a problem hiding this comment.
Now the question is if we should recurse the loop in case it's not one of these
SteffenDE
commented
Mar 9, 2026
| }; | ||
|
|
||
| // Start the background message processing loop | ||
| // TODO: depending on the error, we might want to recursively call this |
Contributor
Author
There was a problem hiding this comment.
See the other comments.
Contributor
Author
|
Note: I'll need to ensure /compact and /context still work, similar to #400. |
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.
This is a proof of concept of separating the SDK message loop from the prompt promise.
Relates to #386.
Relates to #336.