Skip to content

feat: prevent LoopStart state variable collision - #8126

Open
VuMartin wants to merge 8 commits into
apache:mainfrom
VuMartin:fix/7248-loop-state-variable-collision
Open

VuMartin wants to merge 8 commits into
apache:mainfrom
VuMartin:fix/7248-loop-state-variable-collision

Conversation

@VuMartin

@VuMartin VuMartin commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

Fixes LoopStart state variables being silently overwritten by upstream state. LoopStart now detects collisions between existing loop variables and incoming state variables and raises an error instead of overwriting the loop variable.

Upstream state can still introduce new loop variables when they do not already exist in the LoopStart state, but it cannot overwrite existing loop variables.

The loop back-edge state is now stamped with the LoopStart ID and restored directly on re-entry. This means variables removed during a loop iteration remain removed in the next iteration instead of being reintroduced.

Before:
Screenshot 2026-08-27 at 6 39 29 PM

Screenshot 2026-08-28 at 12 14 43 AM

After:
Screenshot 2026-08-28 at 12 03 05 AM

Screenshot 2026-08-28 at 12 07 52 AM

Any related issues, documentation, discussions?

Fixes #7248

How was this PR tested?

Added a unit test verifying that LoopStart rejects incoming state that attempts to overwrite an existing loop state variable.

Ran the targeted pytest test successfully: 1 passed.

Was this PR authored or co-authored using generative AI tooling?

Generated-by: ChatGPT (5.5 mini)

@github-actions

github-actions Bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Automated Reviewer Suggestions

Based on the git blame history of the changed files, we recommend the following reviewers:

  • Contributors with relevant context: @carloea2, @eugenegujing, @aglinxinyuan
    You can notify them by mentioning @carloea2, @eugenegujing, @aglinxinyuan in a comment.

@VuMartin VuMartin changed the title Fix LoopStart state variable collision fix: prevent LoopStart state variable collision Aug 30, 2026
@Yicong-Huang Yicong-Huang added the release/v1.2 back porting to release/v1.2 label Aug 30, 2026
@github-actions
github-actions Bot requested a review from xuang7 August 30, 2026 08:01
@github-actions

Copy link
Copy Markdown
Contributor

Backport auto-label report

This fix: PR was checked against each actively-supported release branch. release/* labels drive the post-merge backport, so add or remove one to change where this fix lands.

Release branch Analysis
⚠️ release/v1.3 Not labeled automatically — none of the files this PR modifies exist on this branch (amber/src/main/python/core/models/operator.py, amber/src/test/python/core/models/test_operator.py). The fix may target code that isn't on this release, or the files were moved/renamed after the branch was cut. Please check and add release/v1.3 by hand if this fix should be backported here.
✅ release/v1.2 Change detected on this branch — label added; this fix is queued to backport here. Requested review from @xuang7.

Auto-label run.

@github-actions

github-actions Bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Benchmark changes need a look

🟢 2 better · 🔴 5 worse · ⚪ 8 noise (<±5%) · 0 without baseline

Compared against main 9cf43f2 benchmarked on this same runner, so the delta is largely free of cross-runner hardware noise. The "7d avg" column still reflects the gh-pages dashboard. Treat <±5% as noise unless repeated.

Dashboard · Run

config throughput MB/s latency max Δ latest / 7d
🔴 bs=10 sw=10 sl=64 379 0.231 25,555/32,762/32,762 us 🔴 +14.9% / 🔴 +109.1%
🔴 bs=100 sw=10 sl=64 795 0.485 123,208/172,755/172,755 us 🔴 +9.7% / 🔴 +61.7%
⚪ bs=1000 sw=10 sl=64 924 0.564 1,069,077/1,184,436/1,184,436 us ⚪ within ±5% / 🔴 +15.7%
Baseline details

Latest main 9cf43f2 from same runner

config metric PR latest main 7d avg Δ latest Δ 7d
bs=10 sw=10 sl=64 throughput 379 tuples/sec 406 tuples/sec 782.27 tuples/sec -6.7% -51.6%
bs=10 sw=10 sl=64 MB/s 0.231 MB/s 0.248 MB/s 0.477 MB/s -6.9% -51.6%
bs=10 sw=10 sl=64 p50 25,555 us 22,245 us 12,538 us +14.9% +103.8%
bs=10 sw=10 sl=64 p95 32,762 us 36,011 us 15,667 us -9.0% +109.1%
bs=10 sw=10 sl=64 p99 32,762 us 36,011 us 19,058 us -9.0% +71.9%
bs=100 sw=10 sl=64 throughput 795 tuples/sec 817 tuples/sec 1,010 tuples/sec -2.7% -21.3%
bs=100 sw=10 sl=64 MB/s 0.485 MB/s 0.499 MB/s 0.616 MB/s -2.8% -21.3%
bs=100 sw=10 sl=64 p50 123,208 us 118,805 us 100,043 us +3.7% +23.2%
bs=100 sw=10 sl=64 p95 172,755 us 157,490 us 106,848 us +9.7% +61.7%
bs=100 sw=10 sl=64 p99 172,755 us 157,490 us 121,073 us +9.7% +42.7%
bs=1000 sw=10 sl=64 throughput 924 tuples/sec 938 tuples/sec 1,041 tuples/sec -1.5% -11.2%
bs=1000 sw=10 sl=64 MB/s 0.564 MB/s 0.572 MB/s 0.635 MB/s -1.4% -11.2%
bs=1000 sw=10 sl=64 p50 1,069,077 us 1,057,550 us 980,364 us +1.1% +9.0%
bs=1000 sw=10 sl=64 p95 1,184,436 us 1,187,212 us 1,023,796 us -0.2% +15.7%
bs=1000 sw=10 sl=64 p99 1,184,436 us 1,187,212 us 1,046,281 us -0.2% +13.2%
Raw CSV
config_idx,batch_size,schema_width,string_len,num_batches,total_ms,total_tuples,total_bytes,tuples_per_sec,mb_per_sec,lat_p50_us,lat_p95_us,lat_p99_us
0,10,10,64,20,527.67,200,128000,379,0.231,25555.04,32762.42,32762.42
1,100,10,64,20,2517.10,2000,1280000,795,0.485,123208.28,172754.98,172754.98
2,1000,10,64,20,21645.08,20000,12800000,924,0.564,1069077.44,1184435.62,1184435.62

@codecov-commenter

codecov-commenter commented Aug 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.61%. Comparing base (9cf43f2) to head (eacce0b).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
amber/src/main/python/core/models/operator.py 50.00% 1 Missing and 1 partial ⚠️
amber/src/main/python/core/runnables/main_loop.py 50.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #8126      +/-   ##
============================================
- Coverage     92.61%   92.61%   -0.01%     
+ Complexity     5061     5059       -2     
============================================
  Files          1258     1258              
  Lines         53778    53783       +5     
  Branches       6706     6709       +3     
============================================
+ Hits          49808    49809       +1     
  Misses         2316     2316              
- Partials       1654     1658       +4     
Flag Coverage Δ *Carryforward flag
access-control-service 77.38% <ø> (ø) Carriedforward from fd25ce8
agent-service 99.16% <ø> (ø) Carriedforward from fd25ce8
amber 88.09% <ø> (-0.02%) ⬇️ Carriedforward from fd25ce8
computing-unit-managing-service 60.48% <ø> (ø) Carriedforward from fd25ce8
config-service 87.37% <ø> (ø) Carriedforward from fd25ce8
file-service 82.00% <ø> (ø) Carriedforward from fd25ce8
frontend 96.59% <ø> (ø) Carriedforward from fd25ce8
notebook-migration-service 83.73% <ø> (ø) Carriedforward from fd25ce8
pyamber 98.50% <50.00%> (-0.03%) ⬇️
workflow-compiling-service 72.43% <ø> (ø) Carriedforward from fd25ce8

*This pull request uses carry forward flags. Click here to find out more.

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

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@chenlica

chenlica commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

@aglinxinyuan Do you want to chime in?

@aglinxinyuan
aglinxinyuan self-requested a review September 6, 2026 03:46

@aglinxinyuan aglinxinyuan 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 — right fix, and the loop e2e passing confirms it. Two small doc asks inline.

# and never mutates the State it is handed.
for key, value in state.items():
if key in self.state:
raise ValueError(f"Loop state variable cannot be overwritten: '{key}'")

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.

With the back-edge stamped, this only sees outside state — nice. One note for the PR body: outside state can still add new loop variables, just not overwrite them.

# The back-edge fires only after the matching LoopEnd consumed at
# loop_counter == 0, so the next iteration's input starts at depth 0.
writer.put_one(executor.state.to_tuple(0))
writer.put_one(executor.state.to_tuple(0, self._loop_start_id))

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.

Stamping the back-edge is the key move — it's what makes the rest safe. LGTM.

# This is this LoopStart's own back-edge state. Restore the loop
# variables directly instead of routing the state through
# process_state(), which is reserved for external/first-entry state.
executor.state = state

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.

This replaces the state instead of merging it, so a variable deleted in update stays deleted next iteration. I think that's better than before — just mention it in the PR body. Optional: merge the two stamped branches into one if/else.

@aglinxinyuan aglinxinyuan changed the title fix: prevent LoopStart state variable collision feat: prevent LoopStart state variable collision Sep 6, 2026
@aglinxinyuan
aglinxinyuan removed the request for review from xuang7 September 6, 2026 04:08
@aglinxinyuan aglinxinyuan removed the release/v1.2 back porting to release/v1.2 label Sep 6, 2026
@aglinxinyuan

Copy link
Copy Markdown
Contributor

It's not a fix. It's a change to the original behavior.

@VuMartin

VuMartin commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review! Updated the PR description to clarify the external state behavior and the back-edge state replacement behavior. Also simplified the stamped LoopStart state routing.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale because it has
not had any activity for 30 days. It will be closed in 7 days if no
further activity occurs.

If this PR is still relevant, please:

  • Push new commits or rebase onto the latest main, or
  • Comment with a status update, or
  • Address any open review feedback.

To exempt this PR from auto-close, a maintainer can add the pinned label.
Thank you for your contribution to Apache Texera (incubating)!

@github-actions github-actions Bot added the stale label Oct 12, 2026
@github-actions github-actions Bot removed the stale label Oct 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale because it has
not had any activity for 30 days. It will be closed in 7 days if no
further activity occurs.

If this PR is still relevant, please:

  • Push new commits or rebase onto the latest main, or
  • Comment with a status update, or
  • Address any open review feedback.

To exempt this PR from auto-close, a maintainer can add the pinned label.
Thank you for your contribution to Apache Texera (incubating)!

@github-actions github-actions Bot added the stale label Nov 23, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stateful operator upstream of a Loop Start silently overwrites loop variables

5 participants