Repository navigation
fix(go-agent): persist canvas session state - #16970
Harry-Hz-Zhang wants to merge 7 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThe change adds DSL history and memory support, separates tool-call memory from conversation history, synchronizes runtime state across workflows, persists session history and partial outputs, and standardizes JSON-style display rendering. ChangesHistory and memory flow
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant AgentService
participant ConversationSession
participant CanvasState
participant Workflow
AgentService->>ConversationSession: load session DSL
AgentService->>CanvasState: seed history and memory
AgentService->>Workflow: invoke workflow
Workflow->>CanvasState: update history and memory
AgentService->>ConversationSession: persist encoded state
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: 5
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/agent/canvas/scheduler.go (1)
154-190: 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy liftReplace length-based state conflict resolution.
A longer slice is not necessarily newer, and equal-length divergent states always discard the local version. Checkpoint restoration or parallel updates can therefore overwrite valid history, memory, or
sys.history. Establish one authoritative direction per lifecycle phase or merge append-only entries using a verified common prefix/version.🤖 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/canvas/scheduler.go` around lines 154 - 190, Replace the length-based conflict resolution in the state synchronization block with lifecycle-aware authoritative selection or append-only merging based on a verified common prefix/version. Apply the same strategy consistently to history, memory, and sys.history, preserving valid local and context updates instead of selecting solely by slice length or discarding divergent equal-length states.
🤖 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/runtime/state.go`:
- Around line 461-474: Update cloneMapSlice to recursively deep-copy each map
value, including nested map[string]any and []any values, while preserving scalar
values and nils. Ensure payload and other nested JSON-compatible structures no
longer share mutable references with the original state.
- Around line 353-366: Update CanvasState.SnapshotPriorHistory so it excludes
the current in-flight turn only when its identity matches the active
prompt/turn, not merely when the latest history entry has role "user". Pass the
current prompt/turn identity or track it separately, while preserving persisted
user turns whose content or identity differs.
In `@internal/service/agent.go`:
- Around line 799-805: Update the session-loading logic in RunAgent around
api4ConversationDAO.GetBySessionID to enforce ownership by comparing the loaded
session.UserID with the authenticated userID, or by using a user-scoped DAO
query. Treat mismatches as not found and do not load or overwrite the other
user’s session data.
- Around line 1319-1334: The persistence logic around the state-handling block
must retain the complete DSL used for the run instead of rebuilding it from an
empty session DSL. Pass that run-time DSL into the relevant function, copy it as
the base, then overlay globals, history, and memory; preserve existing globals
while updating sys.history. Add a regression test covering an API4Conversation
with nil DSL and verify the next run decodes successfully.
- Around line 1167-1169: Update the interrupt handling branch in the run flow
around markRunFailed and persistAgentRunSession to call appendAssistantHistory
with the partial answer before persisting the interrupted session. Ensure this
occurs when answer is non-empty so the assistant response is included in
persisted DSL history and retained for the next run.
---
Outside diff comments:
In `@internal/agent/canvas/scheduler.go`:
- Around line 154-190: Replace the length-based conflict resolution in the state
synchronization block with lifecycle-aware authoritative selection or
append-only merging based on a verified common prefix/version. Apply the same
strategy consistently to history, memory, and sys.history, preserving valid
local and context updates instead of selecting solely by slice length or
discarding divergent equal-length states.
🪄 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
Run ID: 6adcbde0-c470-4d3c-b96b-3caaa7ddc6d0
📒 Files selected for processing (14)
internal/agent/canvas/canvas.gointernal/agent/canvas/decode.gointernal/agent/canvas/decode_history_test.gointernal/agent/canvas/scheduler.gointernal/agent/component/agent.gointernal/agent/component/history_window_test.gointernal/agent/component/llm.gointernal/agent/component/tool_call_memory_test.gointernal/agent/runtime/state.gointernal/agent/runtime/state_test.gointernal/service/agent.gointernal/service/agent_run_e2e_test.gointernal/service/agent_test.gointernal/service/document_test.go
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
internal/service/agent_run_e2e_test.go (1)
1244-1245: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDescribe the Go rendering contract directly.
Avoid coupling this regression test’s rationale to the Python implementation.
Proposed update
- // Python Message._stringify_message_value renders non-string template - // values as JSON, so list references keep commas and quotes. + // Non-string template values use JSON rendering, so list references + // retain commas and quotes.As per coding guidelines, “keep package and documentation comments aligned with the current runtime path rather than migration history” and “do not add compatibility wording to comments or documentation.”
🤖 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/service/agent_run_e2e_test.go` around lines 1244 - 1245, Update the comment in the regression test to describe the Go renderer’s contract directly: non-string template values are rendered as JSON, preserving commas and quotes in list references. Remove the reference to Python’s Message._stringify_message_value and any migration or compatibility wording.Source: Coding guidelines
🤖 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/message_test.go`:
- Around line 50-53: Update the downloads assertion in the test around the
out["downloads"] type check to explicitly verify that the []DownloadInfo slice
is non-nil, while retaining the existing empty-length assertion.
In `@internal/agent/runtime/template.go`:
- Around line 140-143: Remove migration and Python compatibility references from
the comments at internal/agent/runtime/template.go:140-143 and
internal/agent/component/message.go:227-229. In stringifyDisplayValue, describe
the current Go stringification behavior directly; in the message comment,
explain retaining the key using the current architecture, with no direct code
changes required.
---
Nitpick comments:
In `@internal/service/agent_run_e2e_test.go`:
- Around line 1244-1245: Update the comment in the regression test to describe
the Go renderer’s contract directly: non-string template values are rendered as
JSON, preserving commas and quotes in list references. Remove the reference to
Python’s Message._stringify_message_value and any migration or compatibility
wording.
🪄 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
Run ID: 8875de37-e2da-4c52-a463-f81ad42b6c3a
📒 Files selected for processing (8)
internal/agent/component/history_window_test.gointernal/agent/component/message.gointernal/agent/component/message_test.gointernal/agent/runtime/state.gointernal/agent/runtime/state_test.gointernal/agent/runtime/template.gointernal/service/agent.gointernal/service/agent_run_e2e_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
- internal/agent/runtime/state.go
- internal/service/agent.go
Summary
Testing
bash build.sh --test ./internal/agent/runtime ./internal/agent/canvas ./internal/agent/component ./internal/service