Skip to content

Fix: path-aware reset in canvas.run() to preserve cross-run outputs - #14600

Merged
wangq8 merged 2 commits into
infiniflow:mainfrom
wanghualoong:fix/canvas-path-aware-reset
May 8, 2026
Merged

wangq8 merged 2 commits into
infiniflow:mainfrom
wanghualoong:fix/canvas-path-aware-reset

Conversation

@wanghualoong

Copy link
Copy Markdown
Contributor

Summary

  • When an agent workflow has multiple UserFillUp pause points, canvas.run() calls reset(True) on all components at the start of each run. This clears outputs from components that completed in prior runs, so downstream references like {Agent:XXX@content} resolve to None.
  • This fix only resets components on the current execution path (self.path), preserving outputs from previously completed components.

Problem

In a multi-step agent (e.g. draft email → user confirms → send email):

  1. First run(): Agent drafts content, UserFillUp pauses for user input → Agent output is saved
  2. Second run(): User submits input, but reset(True) clears all components including the Agent that already completed
  3. Email component references {Agent:XXX@content} → gets None instead of the draft

This affects all agents that reference upstream component outputs after a UserFillUp pause point.

Fix

# Before: reset ALL components
for k, cpn in self.components.items():
    self.components[k]["obj"].reset(True)

# After: only reset components on current execution path
path_set = set(self.path)
for k, cpn in self.components.items():
    if k in path_set:
        self.components[k]["obj"].reset(True)

self.path already tracks the current execution path. For agents without UserFillUp (single run), path contains all components, so behavior is unchanged.

Test plan

  • Agent with single UserFillUp: outputs from prior components are preserved after resume
  • Agent with multiple UserFillUp: each resume preserves all previously completed outputs
  • Agent without UserFillUp: behavior unchanged (all components in path, all reset)
  • Webhook-triggered agents: unaffected (path includes all components on first run)

🤖 Generated with Claude Code

When an agent workflow contains multiple UserFillUp pause points,
canvas.run() previously called reset(True) on ALL components at the
start of each run. This cleared outputs from components that had
already completed in prior runs, causing downstream references
(e.g. {Agent:XXX@content}) to resolve to None.

This fix builds a set from self.path (which tracks the current
execution path) and only resets components that are part of that
path. Components completed in earlier runs retain their outputs,
allowing cross-run variable references to work correctly.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. 🌈 python Pull requests that update Python code 🐞 bug Something isn't working, pull request that fix bug. labels May 6, 2026
@coderabbitai

coderabbitai Bot commented May 6, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The Canvas.run method now resets only components currently in the active execution path instead of unconditionally resetting all components. This optimization narrows the scope of component reset operations by building a set of active path IDs and conditionally applying reset logic to matching components.

Changes

Canvas Component Reset Optimization

Layer / File(s) Summary
Core Logic
agent/canvas.py
Component reset in Canvas.run (lines 382–385) is scoped to active path: a path ID set is constructed, and only components matching those IDs are reset, replacing prior unconditional reset of all components.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

Down the canvas paths we swiftly hop,
Resetting wisely, we don't stop.
Just the active nodes we touch,
Efficiency means so much! 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main behavioral change: implementing path-aware reset logic to preserve cross-run outputs in canvas.run().
Description check ✅ Passed The description fully covers the required template sections: problem statement, type of change (Bug Fix), detailed context, root cause analysis, and comprehensive test plan.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
agent/canvas.py (1)

382-385: ⚡ Quick win

Add debug logging for the new path-scoped reset flow.

The new branch at Line 382–Line 385 changes reset semantics but emits no trace, which makes resume-path state issues hard to debug. Please log task ID, path size, and reset component IDs/count at debug level.

Proposed patch
         path_set = set(self.path)
+        logging.debug(
+            "Canvas.run path-scoped reset: task_id=%s path_size=%d",
+            self.task_id,
+            len(path_set),
+        )
         for k, cpn in self.components.items():
             if k in path_set:
                 self.components[k]["obj"].reset(True)
+        logging.debug(
+            "Canvas.run reset complete: task_id=%s reset_count=%d",
+            self.task_id,
+            len(path_set),
+        )

As per coding guidelines, "**/*.py: Add logging for new flows".

🤖 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 `@agent/canvas.py` around lines 382 - 385, Add debug-level logging around the
new path-scoped reset branch: before computing path_set/logging, capture task id
(self.task_id or similar), path size (len(self.path)), and then collect the
list/count of component ids that will be reset (those k in self.components
intersecting path_set). Log a concise debug message including task id, path
size, reset count and component ids right before calling
self.components[k]["obj"].reset(True) (or immediately after identifying them) so
resume-path state changes are traceable; use the existing logger instance used
elsewhere in this class (e.g., self.logger or the module logger) to maintain
consistent logging.
🤖 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.

Nitpick comments:
In `@agent/canvas.py`:
- Around line 382-385: Add debug-level logging around the new path-scoped reset
branch: before computing path_set/logging, capture task id (self.task_id or
similar), path size (len(self.path)), and then collect the list/count of
component ids that will be reset (those k in self.components intersecting
path_set). Log a concise debug message including task id, path size, reset count
and component ids right before calling self.components[k]["obj"].reset(True) (or
immediately after identifying them) so resume-path state changes are traceable;
use the existing logger instance used elsewhere in this class (e.g., self.logger
or the module logger) to maintain consistent logging.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 87f91823-bac4-46af-8f7c-b17d1adcc8c3

📥 Commits

Reviewing files that changed from the base of the PR and between 3e396c0 and 464b4f0.

📒 Files selected for processing (1)
  • agent/canvas.py

@wangq8
wangq8 requested a review from Magicbook1108 May 8, 2026 05:45
@wangq8 wangq8 added the ci Continue Integration label May 8, 2026
@wangq8
wangq8 marked this pull request as draft May 8, 2026 05:50
@wangq8
wangq8 marked this pull request as ready for review May 8, 2026 05:50

@Magicbook1108 Magicbook1108 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@codecov

codecov Bot commented May 8, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.16%. Comparing base (a82ae4a) to head (a6d8908).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14600   +/-   ##
=======================================
  Coverage   94.16%   94.16%           
=======================================
  Files          10       10           
  Lines         703      703           
  Branches      112      112           
=======================================
  Hits          662      662           
  Misses         25       25           
  Partials       16       16           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wangq8
wangq8 merged commit decb5dc into infiniflow:main May 8, 2026
1 check passed
pekar9781 pushed a commit to pekar9781/ragflow that referenced this pull request May 8, 2026
…nfiniflow#14600)

## Summary

- When an agent workflow has multiple `UserFillUp` pause points,
`canvas.run()` calls `reset(True)` on **all** components at the start of
each run. This clears outputs from components that completed in prior
runs, so downstream references like `{Agent:XXX@content}` resolve to
`None`.
- This fix only resets components on the **current execution path**
(`self.path`), preserving outputs from previously completed components.

## Problem

In a multi-step agent (e.g. draft email → user confirms → send email):

1. First `run()`: Agent drafts content, UserFillUp pauses for user input
→ Agent output is saved
2. Second `run()`: User submits input, but `reset(True)` clears **all**
components including the Agent that already completed
3. Email component references `{Agent:XXX@content}` → gets `None`
instead of the draft

This affects **all** agents that reference upstream component outputs
after a UserFillUp pause point.

## Fix

```python
# Before: reset ALL components
for k, cpn in self.components.items():
    self.components[k]["obj"].reset(True)

# After: only reset components on current execution path
path_set = set(self.path)
for k, cpn in self.components.items():
    if k in path_set:
        self.components[k]["obj"].reset(True)
```

`self.path` already tracks the current execution path. For agents
without UserFillUp (single run), `path` contains all components, so
behavior is unchanged.

## Test plan

- [x] Agent with single UserFillUp: outputs from prior components are
preserved after resume
- [x] Agent with multiple UserFillUp: each resume preserves all
previously completed outputs
- [x] Agent without UserFillUp: behavior unchanged (all components in
path, all reset)
- [x] Webhook-triggered agents: unaffected (path includes all components
on first run)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: wanghualoong <[email protected]>
Co-authored-by: Claude Opus 4.6 <[email protected]>
Ricardo-M-L pushed a commit to Ricardo-M-L/ragflow that referenced this pull request Aug 17, 2026
…nfiniflow#14600)

## Summary

- When an agent workflow has multiple `UserFillUp` pause points,
`canvas.run()` calls `reset(True)` on **all** components at the start of
each run. This clears outputs from components that completed in prior
runs, so downstream references like `{Agent:XXX@content}` resolve to
`None`.
- This fix only resets components on the **current execution path**
(`self.path`), preserving outputs from previously completed components.

## Problem

In a multi-step agent (e.g. draft email → user confirms → send email):

1. First `run()`: Agent drafts content, UserFillUp pauses for user input
→ Agent output is saved
2. Second `run()`: User submits input, but `reset(True)` clears **all**
components including the Agent that already completed
3. Email component references `{Agent:XXX@content}` → gets `None`
instead of the draft

This affects **all** agents that reference upstream component outputs
after a UserFillUp pause point.

## Fix

```python
# Before: reset ALL components
for k, cpn in self.components.items():
    self.components[k]["obj"].reset(True)

# After: only reset components on current execution path
path_set = set(self.path)
for k, cpn in self.components.items():
    if k in path_set:
        self.components[k]["obj"].reset(True)
```

`self.path` already tracks the current execution path. For agents
without UserFillUp (single run), `path` contains all components, so
behavior is unchanged.

## Test plan

- [x] Agent with single UserFillUp: outputs from prior components are
preserved after resume
- [x] Agent with multiple UserFillUp: each resume preserves all
previously completed outputs
- [x] Agent without UserFillUp: behavior unchanged (all components in
path, all reset)
- [x] Webhook-triggered agents: unaffected (path includes all components
on first run)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: wanghualoong <[email protected]>
Co-authored-by: Claude Opus 4.6 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration 🌈 python Pull requests that update Python code size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants