Changes
PR #2061 by praxstack: fix(chat): prevent streaming deadlock and unify strategy handling
- Fixed a streaming deadlock in
Chatter.Sendby introducingrecordFirstStreamError(), which uses a non-blockingselect/defaultto safely send only the first error to the buffered error channel, preventing goroutine leaks when both theSendStreamgoroutine and the stream-update loop attempt to write simultaneously. - Unified strategy handling across the CLI and REST API server by passing
StrategyNamethrough toGetChatter()andChatRequest, ensuring the coreChatter.BuildSession()layer handles strategy loading consistently instead of duplicating logic in the server handler. - Removed inline
os.ReadFilestrategy loading from the server handler, which previously bypassed the core Chatter layer, causing strategy prompts to be incorrectly prepended toUserInputrather than the system message. - Replaced raw string concatenation for system message assembly with a new
joinPromptSections()helper that trims whitespace, skips empty sections, and joins strategy, context, and pattern prompts with a single newline separator. - Added regression and unit tests, including a 2-second timeout deadlock test (
TestChatter_Send_StreamingErrorUpdateAndReturnDoesNotDeadlock), a session-assembly validation test (TestChatter_BuildSession_SeparatesSystemSections), and a helper verification test (TestBuildPromptChatRequest_PreservesStrategyAndUserInput).