fix(agent/copilot): map reasoning deltas to EventThinking#1512
Open
zhengweixing wants to merge 3 commits into
Open
fix(agent/copilot): map reasoning deltas to EventThinking#1512zhengweixing wants to merge 3 commits into
zhengweixing wants to merge 3 commits into
Conversation
Copilot CLI streams thinking/reasoning content as `assistant.reasoning_delta`
(streaming, with `deltaContent`) and `assistant.reasoning` (final, with
`content`). The copilot adapter had no case for either, so these events
fell through to the default handler and never emitted an event — meaning
reasoning could be misrouted or lost, and `thinking_messages=false` could
not suppress it because nothing was tagged as thinking.
Captured the real wire format by probing `copilot --stdio`: reasoning
deltas carry `{"reasoningId":"...","deltaContent":"..."}`, mirroring the
message delta shape, so they reuse `copilotEventText`.
Changes:
- handleSessionEvent: add `assistant.reasoning_delta` and
`assistant.reasoning` cases, emitting `core.EventThinking`.
- normalizeCopilotEventType: normalize `assistant_reasoning` /
`assistant_reasoning_delta` underscore variants.
- Add tests for reasoning delta and final reasoning -> EventThinking.
With this, `thinking_messages=false` correctly suppresses Copilot
reasoning and it no longer mixes into the answer text.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
When cc-connect bridges Copilot CLI through the generic ACP adapter
([projects.agent] type = "acp"), Copilot streams its reasoning/thinking
content as session/update frames whose sessionUpdate discriminator is
`agent_thought_chunk` (captured live via ACP probing against
`copilot --acp --stdio`; payload is '{"content":{"type":"text","text":"..."}}',
e.g. "The user needs to check the health status of their PaaS microservices...").
The reasoning whitelist in mapSessionUpdateFallback only listed
"reasoning", "reasoning_chunk", "thinking", "agent_thinking_chunk" — note
`agent_thinking_chunk` (gerund) vs the actually-emitted `agent_thought_chunk`
(past tense). So `agent_thought_chunk` missed the case and fell into the
default branch, which extracts content.text and emits it as EventText.
Because it was never tagged EventThinking, `thinking_messages=false` could
not suppress it, and the reasoning text leaked into the chat reply.
This is the ACP-adapter counterpart to the copilot-adapter fix in chenhg5#1512.
The earlier PR only patched agent/copilot/session.go (assistant.reasoning_delta
-> EventThinking), which is unused when type = "acp"; the production paas-ops
project uses the generic ACP path, so reasoning still leaked there.
Changes:
- mapSessionUpdateFallback: add `agent_thought_chunk` to the reasoning
discriminator whitelist so it maps to core.EventThinking.
- Add TestMapSessionUpdate_agentThoughtChunk regression test asserting
`agent_thought_chunk` with content.text -> core.EventThinking.
With this, `thinking_messages=false` (e.g.
CC_CONNECT_DISPLAY_THINKING_MESSAGES=false) correctly suppresses Copilot
reasoning over the ACP path and it no longer appears inline in the reply.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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
When bridging GitHub Copilot CLI through cc-connect to a chat platform (e.g. Feishu),
Copilot's thinking/reasoning content leaks into the answer text and
thinking_messages=falsecannot suppress it. This PR maps Copilot reasoning events to
core.EventThinkingso theexisting thinking-display toggle works.
Root cause
Copilot CLI streams reasoning as two distinct
session.eventtypes (captured by probingcopilot --stdiodirectly):assistant.reasoning_delta(streaming):{"reasoningId":"...","deltaContent":"..."}assistant.reasoning(final aggregated):{"reasoningId":"...","content":"..."}The copilot adapter (
agent/copilot/session.go) had no case for either — they fell intothe
defaultbranch and were dropped. Because reasoning was never taggedEventThinking,thinking_messages=false(which only filtersEventThinking) had no effect. Since thedeltaContentfield name matches ordinary message deltas, reasoning could also be misroutedas answer text and concatenated into the reply.
Confirmed absent on upstream
main(a23fb90) and base commit (e2bbe5f):assistant.reasoningoccurs 0 times in
agent/copilot/session.gobefore this PR.Type of change
Fix
handleSessionEvent: addassistant.reasoning_deltaandassistant.reasoningcases,both emitting
core.EventThinking(reusingcopilotEventText, which already readsdeltaContent/content).normalizeCopilotEventType: normalizeassistant_reasoning/assistant_reasoning_deltaunderscore variants.
Testing
Automated tests added in this PR
TestHandleSessionEvent_ReasoningDeltainagent/copilot/session_test.go— assertsassistant.reasoning_deltawithdeltaContentmaps tocore.EventThinking.TestHandleSessionEvent_ReasoningFinalinagent/copilot/session_test.go— assertsassistant_reasoning(final,content) maps tocore.EventThinking.For bug fixes only — regression test
TestHandleSessionEvent_ReasoningDeltaassistant.reasoning_deltahits thedefaultbranch (no event emitted),so the test fails on pre-fix code and passes on the fixed code (verified by code inspection
of the
defaultbranch one2bbe5f).Critical User Journeys (CUJ) impact
go test ./core/ -run TestCUJpasses locally.Manual / user-visible behavior change
With
thinking_messages=false(e.g.CC_CONNECT_DISPLAY_THINKING_MESSAGES=false), Copilotreasoning no longer appears in the chat reply. With it enabled, reasoning is shown as a
separate thinking preview rather than mixed inline with the answer.
Checklist (reviewer will verify)
go build ./...passesgo test ./...passes (copilot package; concurrency untouched, so no-raceneeded)core/Related