Repository navigation
fix(go-agent): message double - #17353
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (7)
🚧 Files skipped from review as they are similar to previous changes (5)
📝 WalkthroughWalkthroughAgent responses can now defer execution to downstream Message nodes through runtime-managed streams. Canvas scheduling delays node completion, Message resolves streamed templates with thinking events, duplicate emissions are suppressed, and service-level terminal events account for emitted or suppressed message state. ChangesDeferred streaming runtime
Canvas and Message flow
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant CanvasScheduler
participant AgentComponent
participant RuntimeDeferredStream
participant MessageComponent
participant AgentService
CanvasScheduler->>AgentComponent: pass deferral execution options
AgentComponent-->>RuntimeDeferredStream: return deferred stream
MessageComponent->>RuntimeDeferredStream: open stream
RuntimeDeferredStream-->>MessageComponent: emit reasoning and content deltas
MessageComponent->>AgentService: present canvas message events
AgentService-->>CanvasScheduler: complete deferred node and emit terminal events
Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 8
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/agent/component/agent.go (1)
248-295: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winDon’t stop Agent model streaming after the first chunk.
After
ChatConfig.StreamCallbackis removed,emitAgentModelStreamsis the only delta-forwarding path for Agent components without a directMessagedownstream. Its guard skips all chunks onceAgentMessageEventsEmitted(ctx)becomes true — and the finalinvokeNowconsolidated emission is also skipped becausestreamedis true. The deferred Message-sink path avoids this by checking!HasDeferredAgentMessageSink(ctx), but the eager eino stream loop needs the same per-chunk forward behavior, not a one-shot suppression.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/agent/component/agent.go` around lines 248 - 295, The guard in emitAgentModelStreams must not suppress subsequent Agent model chunks after AgentMessageEventsEmitted(ctx) becomes true. Remove or adjust the one-shot event check so every eligible non-empty assistant message is forwarded through runtime.EmitAgentMessage, while preserving the deferred-sink condition and existing filtering behavior.
🧹 Nitpick comments (1)
internal/agent/component/message_test.go (1)
272-330: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winMissing regression coverage for non-deferred templated refs.
All new tests here use either plain
contentinput (no{{...}}) or a template whose ref resolves to an actual*runtime.DeferredStream. None cover a template referencing an ordinary (non-deferred) state variable, e.g.{{node@field}}wherefieldholds a plain string — which is exactly the case that triggers the double-emission bug flagged ininternal/agent/component/message.go'sresolveDeferredTemplate. Want me to add a test asserting exactly oneWithCanvasMessageEmittercall for that case?🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/agent/component/message_test.go` around lines 272 - 330, The tests lack regression coverage for templated references to ordinary state values. Add a test alongside TestMessage_ConsumesDeferredAgentStream that stores a plain string in a state variable, invokes Message with a template such as {{node@field}}, and uses WithCanvasMessageEmitter to count emissions; assert the rendered content is correct and exactly one emitter call occurs.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/agent/component/agent.go`:
- Around line 713-726: The deferred stream created in AgentComponent.Invoke must
apply a fresh Agent timeout when DeferredStream.Open executes. Update the Open
callback to wrap its received openCtx with the existing Agent-class timeout
mechanism before calling c.invokeNow, preserving the sink attachment and
deferred execution behavior.
In `@internal/agent/component/message.go`:
- Around line 189-201: Update resolveDeferredTemplate and its callers in
Message.Invoke so templated messages with ordinary, non-deferred references are
not emitted during resolution and then emitted again during final rendering.
Track whether the template actually contains a DeferredStream, preserve the
resolved value for non-streamed templates, and ensure EmitCanvasMessage is
called exactly once while retaining the existing deferred-stream behavior.
- Around line 366-401: Update the deferred stream handling around deferred.Open
so finalText uses the completed result["content"] whenever available, preserving
visible.String() only as a fallback when the result has no content. Ensure the
grounded or artifact-annotated content is used for state.SetVar,
CompleteDeferredNode, and the returned output while retaining streamed deltas
for live events.
In `@internal/agent/runtime/context.go`:
- Around line 213-222: Update the WithCanvasMessageEventEmitter doc comment to
remove the compatibility and migration framing, including the reference to
existing plain-content callers. Describe only its current role of installing a
Message presentation callback that supports thinking-boundary-aware
presentation.
- Around line 276-293: Update the EmitCanvasMessageEvent doc comment to remove
the “historical” and “preserving existing component tests and non-streaming
callers” compatibility wording, while retaining a concise description of the
plain-content fallback behavior and leaving the implementation unchanged.
- Around line 233-264: In internal/agent/runtime/context.go:233-264, update
EmitAgentMessage to copy callbacks under sinkState.mu/state.mu, unlock before
invoking sink or state.emit, then re-lock only to update emitted and
agentContent; apply the same pattern in
internal/agent/runtime/context.go:295-330 for EmitCanvasMessage, 375-380 for
FinalizeAgentMessage, and 383-400 for ResetAgentMessageEmission, copying
finalize/reset callbacks before unlocking and performing state updates
afterward.
- Around line 114-122: Update RegisterDeferredNode to preserve existing
callbacks when the same nodeID is registered again by storing a queue or
collection of pending completions per node instead of overwriting the prior
callback. Update CompleteDeferredNode and CompleteAllDeferredNodes to invoke
every queued callback exactly once while retaining existing synchronization and
cleanup behavior.
In `@internal/service/agent.go`:
- Around line 1421-1427: The service-level shouldEmitMessage calculation after
FinalizeAgentMessage must not rely on invocation-scoped
AgentMessageEventsEmitted() or AgentMessageEventsSuppressed() values. Track
whether any Agent node emitted content and whether terminal message emission is
suppressed across the entire run, then use those run-level values to decide
terminal message/message_end events; preserve per-node suppression only for
preventing duplicate aggregation.
---
Outside diff comments:
In `@internal/agent/component/agent.go`:
- Around line 248-295: The guard in emitAgentModelStreams must not suppress
subsequent Agent model chunks after AgentMessageEventsEmitted(ctx) becomes true.
Remove or adjust the one-shot event check so every eligible non-empty assistant
message is forwarded through runtime.EmitAgentMessage, while preserving the
deferred-sink condition and existing filtering behavior.
---
Nitpick comments:
In `@internal/agent/component/message_test.go`:
- Around line 272-330: The tests lack regression coverage for templated
references to ordinary state values. Add a test alongside
TestMessage_ConsumesDeferredAgentStream that stores a plain string in a state
variable, invokes Message with a template such as {{node@field}}, and uses
WithCanvasMessageEmitter to count emissions; assert the rendered content is
correct and exactly one emitter call occurs.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 5c2ac70b-c2e3-4db8-bd4a-83bb126f3e1b
📒 Files selected for processing (12)
internal/agent/canvas/loop_subgraph.gointernal/agent/canvas/node_body.gointernal/agent/canvas/scheduler.gointernal/agent/component/agent.gointernal/agent/component/agent_test.gointernal/agent/component/message.gointernal/agent/component/message_test.gointernal/agent/runtime/context.gointernal/entity/models/llm.gointernal/entity/models/llm_test.gointernal/entity/models/types.gointernal/service/agent.go
💤 Files with no reviewable changes (2)
- internal/entity/models/llm.go
- internal/entity/models/types.go
…z-186/ragflow into fix/agent-Message-double
Summary
Testing
CGO_ENABLED=0 go test ./internal/agent/component ./internal/agent/runtime -count=1