Skip to content

fix(frontend): stop opening a y-websocket connection on every compile - #9200

Open
aglinxinyuan wants to merge 1 commit into
apache:mainfrom
aglinxinyuan:fix/compile-websocket-leak
Open

aglinxinyuan wants to merge 1 commit into
apache:mainfrom
aglinxinyuan:fix/compile-websocket-leak

Conversation

@aglinxinyuan

Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

Every debounced workflow edit (500 ms) opened a new y-websocket connection that was never closed.

WorkflowCompilingService compiled a filtered copy of the graph: ValidationWorkflowService.getValidTexeraGraph() returned new WorkflowGraph(validOperators, validLinks, ...). The WorkflowGraph constructor always builds a SharedModel, and that always opens a WebsocketProvider to a fresh rtc/<uuid> room. The copy was only read to build the logical plan, and nothing destroyed it. So each edit left one more socket behind, retrying forever while the server was unreachable, along with its Y.Doc, two 3 s intervals and its listeners.

This PR stops building the copy:

  • WorkflowCompilingService now plans the live graph with ExecuteWorkflowService.getLogicalPlanRequest, then keeps only the valid operators and the links between them.
  • ValidationWorkflowService.getValidTexeraGraph() becomes getValidOperatorIDs(), which only returns the set of operator IDs that pass validation.
  • The compile subscription now stops when the service is destroyed (@UntilDestroy() and untilDestroyed(this), as in ValidationWorkflowService).

The plan sent to /compile is unchanged. With no target operator, getSubDAG returns every enabled operator and link of a DAG, so filtering the plan afterwards keeps the same operators and links as filtering the graph first. The only difference is a cycle with no terminal operator, which execution already leaves out of its plan too.

Any related issues, documentation, discussions?

Fixes the per-edit leak ("Leak B") of #6239. The other half of that issue ("Leak A", SharedModel.destroy() calling disconnect() instead of destroy()) is fixed in #9198, which also lists this leak as tracked separately. #6240 was an earlier attempt at both and was closed without merging.

How was this PR tested?

Added three tests to workflow-compiling.service.spec.ts:

  • "opens no websocket when it compiles" stubs the global WebSocket and runs two debounced compiles. On main it fails, recording two ws://localhost:3000/rtc/<uuid> sockets, one per compile. With this PR it records none.
  • "stops compiling once the service is destroyed" fails on main (the service has no ngOnDestroy) and passes here.
  • "leaves an invalid operator, and the links touching it, out of the logical plan" passes on both, showing the compiled plan is unchanged.

The validation and menu specs are updated for the renamed method.

Commands, run on Node 24 (required since #9125):

  • ng test --watch=false --include=src/app/workspace/service/compile-workflow/workflow-compiling.service.spec.ts --include=src/app/workspace/service/validation/validation-workflow.service.spec.ts --include=src/app/workspace/component/menu/menu.component.spec.ts: 3 files, 232 tests passed.
  • The new compile spec against main's production code: 2 failed (the two above), 48 passed.
  • Full frontend suite, ng test --watch=false: 244 files, 6921 passed, 1 skipped.
  • yarn format:ci: clean.

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

Generated-by: Claude Code (Opus 5.5)

Each debounced compile planned a filtered copy of the graph, built by
ValidationWorkflowService.getValidTexeraGraph() as a new WorkflowGraph.
Its SharedModel opened a WebsocketProvider to a fresh rtc/<uuid> room
that nothing ever closed, so every edit left one more socket retrying
forever.

The compile now plans the live graph and keeps only the valid operators
and the links between them; getValidTexeraGraph() becomes
getValidOperatorIDs(). The compile subscription also stops when the
service is destroyed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 27, 2026 23:35

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@github-actions github-actions Bot added fix frontend Changes related to the frontend GUI labels Oct 27, 2026
@Yicong-Huang Yicong-Huang added release/v1.3 back porting to release/v1.3 release/v1.2 back porting to release/v1.2 labels Oct 27, 2026
@github-actions
github-actions Bot requested review from mengw15 and xuang7 October 27, 2026 23:36
@github-actions

Copy link
Copy Markdown
Contributor

Backport auto-label report

This fix: PR was checked against each actively-supported release branch. A release/* label nominates a backport target; the branch's release manager approving this PR is what sends the fix there. The required Backport Approvals check stays red until every label below is approved, so each manager either approves or removes their own label — which is why the labels left on a merged PR are exactly the branches it reached.

Release branch Analysis
✅ release/v1.3 Change detected on this branch — label added; this fix is queued to backport here. @mengw15 decides: approving sends the fix here, removing this label declines it. The merge waits on one or the other. Review requested.
✅ release/v1.2 Change detected on this branch — label added; this fix is queued to backport here. @xuang7 decides: approving sends the fix here, removing this label declines it. The merge waits on one or the other. Review requested.

Auto-label run.

@github-actions

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: @kz930, @kunwp1
    You can notify them by mentioning @kz930, @kunwp1 in a comment.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.98%. Comparing base (c57e6b0) to head (2973287).

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #9200      +/-   ##
============================================
- Coverage     91.98%   91.98%   -0.01%     
  Complexity     5084     5084              
============================================
  Files          1281     1281              
  Lines         55806    55799       -7     
  Branches       7076     7076              
============================================
- Hits          51333    51326       -7     
  Misses         2732     2732              
  Partials       1741     1741              
Flag Coverage Δ *Carryforward flag
access-control-service 77.44% <ø> (ø) Carriedforward from c57e6b0
agent-service 99.16% <ø> (ø) Carriedforward from c57e6b0
amber 86.43% <ø> (ø) Carriedforward from c57e6b0
computing-unit-managing-service 63.52% <ø> (ø) Carriedforward from c57e6b0
config-service 87.50% <ø> (ø) Carriedforward from c57e6b0
file-service 82.29% <ø> (ø) Carriedforward from c57e6b0
frontend 96.53% <100.00%> (-0.01%) ⬇️
notebook-migration-service 83.77% <ø> (ø) Carriedforward from c57e6b0
pyamber 98.54% <ø> (ø) Carriedforward from c57e6b0
workflow-compiling-service 74.25% <ø> (ø) Carriedforward from c57e6b0

*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.

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

Labels

fix frontend Changes related to the frontend GUI release/v1.2 back porting to release/v1.2 release/v1.3 back porting to release/v1.3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants