Skip to content

fix(amber): commit the last runtime stats snapshot on close - #9628

Open
kunwp1 wants to merge 5 commits into
apache:mainfrom
kunwp1:fix/stats-writer-close-race
Open

kunwp1 wants to merge 5 commits into
apache:mainfrom
kunwp1:fix/stats-writer-close-race

Conversation

@kunwp1

@kunwp1 kunwp1 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

Problem. ExecutionStatsService queues each RuntimeStatisticsPersist on its own persist thread, but closes the runtime statistics writer directly on the callback thread when the execution reaches a terminal state. The engine reports the final statistics right before the terminal state, so close() can flush and commit before that last snapshot is written. The snapshot then sits in the writer's buffer and is never committed. The persist executor is also never shut down, so every execution leaves an idle thread behind. A user kill or a fatal error never sends a terminal state at all, so those runs never commit their buffered statistics either, and the service is only torn down at the next run or about 30 s after the last tab disconnects.

Fix. A new commitAndStop runs close() on the persist thread, behind anything still queued, waits for it (up to 60 s, so the commit stays synchronous as before), and then shuts the executor down. It runs once, on whichever comes first: the terminal state, a fatal error, or teardown. A failed run is committed as soon as it fails. A killed run is committed on teardown, in the background, so starting the next run does not wait for it. Statistics that arrive after that are dropped instead of being rejected into the client's error handler.

Before:  final persist -> queued | terminal state -> close() now    -> commit -> final snapshot never committed
After:   final persist -> queued | terminal state -> close() queued -> final snapshot committed -> executor shut down

Not included. ExecutionConsoleService has the same pattern: console messages are written on a single-thread executor, but the writers are closed on the callback thread. That is tracked in #9641 and will get the same fix in a separate PR.

Any related issues, documentation, discussions?

Closes #9627. Found while reviewing #9594.

How was this PR tested?

Three tests were added to ExecutionStatsServiceSpec:

Test Checks
commit a statistics snapshot that is still queued when the execution terminates holds the persist thread so the final snapshot is still queued at the terminal state, then reads it back
stop the persist thread on commit and ignore what arrives after it the executor is shut down, and later statistics and terminal states neither throw nor add rows
commit and stop the persist thread when the engine reports no terminal state a fatal error and unsubscribeAll each commit buffered statistics and shut the executor down

Without the fix, the first test reads back no rows (List() where List("opA") was expected) and the second fails too; the third tests fatal-error and teardown commits that didn't exist before. The existing persistence tests waited for the persist thread before sending the terminal state, which is why they passed.

sbt "WorkflowExecutionService/testOnly org.apache.texera.web.service.ExecutionStatsServiceSpec org.apache.texera.web.service.WorkflowExecutionServiceSpec"
sbt "WorkflowExecutionService/scalafixAll --check" "WorkflowExecutionService/scalafmtCheckAll"

The first command runs 28 tests, and all pass; the second is clean. Across all of org.apache.texera.web.service.*, the only failures are two WorkflowServiceSpec tests that fail the same way on main (a warehouse setting on my machine) and four ResultExportServiceSpec tests that need port 9092, which my local stack holds.

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

Generated-by: Claude Code, Claude Opus 5.5

@Yicong-Huang Yicong-Huang added release/v1.3 back porting to release/v1.3 release/v1.2 back porting to release/v1.2 labels Nov 22, 2026
@github-actions
github-actions Bot requested review from mengw15 and xuang7 November 22, 2026 19:45
@github-actions

github-actions Bot commented Nov 22, 2026 •

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 Already labeled — 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.
🚫 release/v1.2 Label was removed earlier (opt-out); not re-added. Re-add it by hand if this fix should be backported here after all — the branch's release manager then has to approve before this PR can merge.

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

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Benchmark changes need a look

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

Compared against main 8c8cdc8 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 748 0.457 12,064/24,226/24,226 us 🔴 -9.1% / 🔴 +80.9%
🟢 bs=100 sw=10 sl=64 1,892 1.155 52,726/57,516/57,516 us 🟢 -33.0% / 🟢 +42.6%
⚪ bs=1000 sw=10 sl=64 2,146 1.31 463,676/520,940/520,940 us ⚪ within ±5% / 🟢 +57.5%
Baseline details

Latest main 8c8cdc8 from same runner

config metric PR latest main 7d avg Δ latest Δ 7d
bs=10 sw=10 sl=64 throughput 748 tuples/sec 823 tuples/sec 993.83 tuples/sec -9.1% -24.7%
bs=10 sw=10 sl=64 MB/s 0.457 MB/s 0.503 MB/s 0.607 MB/s -9.1% -24.7%
bs=10 sw=10 sl=64 p50 12,064 us 11,895 us 10,119 us +1.4% +19.2%
bs=10 sw=10 sl=64 p95 24,226 us 23,870 us 13,394 us +1.5% +80.9%
bs=10 sw=10 sl=64 p99 24,226 us 23,870 us 16,114 us +1.5% +50.3%
bs=100 sw=10 sl=64 throughput 1,892 tuples/sec 1,869 tuples/sec 1,327 tuples/sec +1.2% +42.6%
bs=100 sw=10 sl=64 MB/s 1.155 MB/s 1.14 MB/s 0.81 MB/s +1.3% +42.6%
bs=100 sw=10 sl=64 p50 52,726 us 52,508 us 79,097 us +0.4% -33.3%
bs=100 sw=10 sl=64 p95 57,516 us 85,830 us 86,335 us -33.0% -33.4%
bs=100 sw=10 sl=64 p99 57,516 us 85,830 us 94,338 us -33.0% -39.0%
bs=1000 sw=10 sl=64 throughput 2,146 tuples/sec 2,156 tuples/sec 1,363 tuples/sec -0.5% +57.5%
bs=1000 sw=10 sl=64 MB/s 1.31 MB/s 1.316 MB/s 0.832 MB/s -0.5% +57.5%
bs=1000 sw=10 sl=64 p50 463,676 us 464,018 us 774,633 us -0.1% -40.1%
bs=1000 sw=10 sl=64 p95 520,940 us 500,350 us 814,584 us +4.1% -36.0%
bs=1000 sw=10 sl=64 p99 520,940 us 500,350 us 858,914 us +4.1% -39.3%
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,267.36,200,128000,748,0.457,12064.01,24225.80,24225.80
1,100,10,64,20,1057.19,2000,1280000,1892,1.155,52725.77,57515.63,57515.63
2,1000,10,64,20,9318.05,20000,12800000,2146,1.310,463675.78,520940.38,520940.38

@codecov-commenter

codecov-commenter commented Nov 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 61.11111% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.67%. Comparing base (8c8cdc8) to head (5fe4b67).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
...che/texera/web/service/ExecutionStatsService.scala 61.11% 6 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #9628      +/-   ##
============================================
- Coverage     91.67%   91.67%   -0.01%     
- Complexity     5135     5144       +9     
============================================
  Files          1304     1304              
  Lines         58093    58106      +13     
  Branches       7582     7588       +6     
============================================
+ Hits          53258    53268      +10     
- Misses         2923     2927       +4     
+ Partials       1912     1911       -1     
Flag Coverage Δ *Carryforward flag
access-control-service 77.44% <ø> (ø) Carriedforward from 518e2a7
agent-service 99.56% <ø> (ø) Carriedforward from 518e2a7
amber 85.75% <61.11%> (-0.01%) ⬇️
computing-unit-managing-service 63.83% <ø> (ø) Carriedforward from 518e2a7
config-service 87.50% <ø> (ø) Carriedforward from 518e2a7
file-service 82.16% <ø> (ø) Carriedforward from 518e2a7
frontend 96.45% <ø> (ø) Carriedforward from 518e2a7
notebook-migration-service 83.77% <ø> (ø) Carriedforward from 518e2a7
pyamber 98.38% <ø> (ø) Carriedforward from 518e2a7
result-service 85.71% <ø> (ø) Carriedforward from 518e2a7
workflow-compiling-service 78.30% <ø> (ø) Carriedforward from 518e2a7

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

@xuang7

xuang7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Removing release/v1.2: not a regression, and it only affects the last statistics snapshot.

@xuang7 xuang7 removed the release/v1.2 back porting to release/v1.2 label Nov 23, 2026
@kunwp1

kunwp1 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

/request-review @bobbai00

@github-actions
github-actions Bot requested a review from bobbai00 November 23, 2026 03:58

@bobbai00 bobbai00 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.

🟡 0 must-fix · 2 advisory · 1 polish: the core fix is correct; the notes cover when killed and failed runs commit, plus two small follow-ups.

Design & architecture (1)

  • ExecutionStatsService.scala:224: failed and killed runs commit only at a later teardown (advisory, see inline)

Conventions (1)

  • ExecutionStatsService.scala:242: the deferred ExecutionConsoleService fix has no tracking issue (advisory, see inline)

Polish: 1 quick touch-up (see inline comments).

Verification trace

Traced the ordering. The persist callbacks and the terminal-state callback both run on the client actor thread (AmberClient.scala:116-144), and the close is submitted to the same single-thread executor as the writes, so it runs after every snapshot queued before the terminal state, and IcebergTableWriter (documented as not thread-safe) is now used from one thread only. A second terminal state, or a teardown after one, is a no-op through the CAS, and the writes rejected after the shutdown were never committed on the base either.

A fatal error ends a run without a terminal state, and the stats service is
only torn down at the next run or on session cleanup, so a failed run's
statistics stayed unreadable until then. Commit them from the FatalError
callback.

The teardown commit no longer waits for the close, so starting the next run
after a kill is not held up by it. Drop the stale note in
WorkflowExecutionServiceSpec about the persist executor leaking, and fold the
two no-terminal-state tests into one.
@kunwp1

kunwp1 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@bobbai00 I addressed all your comments! Can you have one more pass? Thanks.

@bobbai00 bobbai00 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.

🟢 3 resolved · 0 open · 2 new (2 new = 2 newly introduced · 0 late catches)

All three round-1 notes are fixed in the tree; two comments added in this round need a wording touch.

Polish: 2 quick touch-ups (see inline comments).

Take the reviewer's wording for the teardown and fatal-error comments: the
background commit is there so the next run does not wait, and a fatal error
lacks the engine's terminal state rather than a terminal state. Rename the
matching test the same way.

Catch every close failure inside the commit task with ErrorUtils.safely, so a
failed close is always logged and never escapes commit.get. Name the task as
a Runnable, log "Committing runtime statistics." since teardown can run
mid-execution, and fix the comments on rejected persists and the spec header.
@kunwp1

kunwp1 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@bobbai00 I addressed all your comments! Can you have one more pass? Thanks.

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

engine fix release/v1.3 back porting to release/v1.3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Final runtime statistics snapshot can be lost when an execution ends

5 participants