fix: 9 critical bugs for robustness and reliability#2
Merged
Conversation
4e627ec to
c3f81d5
Compare
1. Context compaction message tracking: After compaction truncates the messages array, REPL/CLI lost track of new messages. Added inputMessageCount to LoopResult so consumers can correctly slice new messages regardless of compaction. 2. Missing isError on IMessage type: The agent loop sets isError on tool error messages but IMessage didn't declare the field. Added optional isError to the type definition. 3. Ollama done emission: Stream could end without chunk.done=true, leaving no done event emitted. Added fallback emission after loop. 4. MCP server transport race: Transport was registered AFTER handleRequest, so concurrent requests couldn't find the session. Now registered before handling, with cleanup on error. 5. Google provider empty parts: Empty message content produced an empty parts array that Gemini API rejects. Now ensures at least one part per message. 6. toolTimeout on middleware: Tool timeout was applied to all middleware chains including compaction (which makes provider.chat calls). Removed timeout from middleware chains — only actual tool executions are timed out now. 7. SIGINT/SIGTERM error handling: Async shutdown errors in signal handlers could become unhandled rejections. Added try/catch for best-effort cleanup. 8. HTTP body validation: parseBody didn't validate that messages was an array or handle missing fields. Added proper type checking. 9. Tilde path resolution: Config and middleware loader matched bare ~ (e.g., ~username/path) instead of only ~/. Fixed to check ~/ specifically. https://claude.ai/code/session_019Ey19uR78tJQ98Ue2vrgKf
c3f81d5 to
3dec70e
Compare
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.
Context compaction message tracking: After compaction truncates the messages array, REPL/CLI lost track of new messages. Added inputMessageCount to LoopResult so consumers can correctly slice new messages regardless of compaction.
Missing isError on IMessage type: The agent loop sets isError on tool error messages but IMessage didn't declare the field. Added optional isError to the type definition.
Ollama done emission: Stream could end without chunk.done=true, leaving no done event emitted. Added fallback emission after loop.
MCP server transport race: Transport was registered AFTER handleRequest, so concurrent requests couldn't find the session. Now registered before handling, with cleanup on error.
Google provider empty parts: Empty message content produced an empty parts array that Gemini API rejects. Now ensures at least one part per message.
toolTimeout on middleware: Tool timeout was applied to all middleware chains including compaction (which makes provider.chat calls). Removed timeout from middleware chains — only actual tool executions are timed out now.
SIGINT/SIGTERM error handling: Async shutdown errors in signal handlers could become unhandled rejections. Added try/catch for best-effort cleanup.
HTTP body validation: parseBody didn't validate that messages was an array or handle missing fields. Added proper type checking.
Tilde path resolution: Config and middleware loader matched bare ~ (e.g., ~username/path) instead of only ~/. Fixed to check ~/ specifically.
https://claude.ai/code/session_019Ey19uR78tJQ98Ue2vrgKf