mirror of
https://github.com/CopilotKit/CopilotKit.git
synced 2026-09-14 16:26:20 +08:00
d0f5fd772f
The spring-ai integration stashed inbound x-* headers in an InheritableThreadLocal (AimockHeaderContext) on the Tomcat request thread, but the AG-UI Java SDK's LocalAgent.runAgent dispatches the LLM call via CompletableFuture.runAsync onto a pre-existing ForkJoinPool.commonPool() worker. InheritableThreadLocal only copies the parent value at thread creation, so a reused pooled worker snapshots an empty/stale map and the outbound RestClient/WebClient interceptor drops x-aimock-context. aimock strict mode then 503s, yielding an empty assistant message and a conversation-error on d5/d6 agentic pills. Add explicit propagation: AimockHeaderContext.capture()/runWith() snapshot the headers on the request thread and re-establish them on whatever worker thread runs the agent. A new PropagatingLocalAgent base class wires these around the runAsync boundary; all six LocalAgent subclasses now extend it. This mirrors the AsyncLocalStorage shim used by the TypeScript integrations (e.g. mastra's _header_forwarding.ts).