Skip to content

fix(amber, v1.2): order worker state by version, not timestamp - #7106

Merged
xuang7 merged 1 commit into
apache:release/v1.2from
Yicong-Huang:backport/6011-order-worker-state-by-version-not-timest-v1.2
Jul 30, 2026
Merged

xuang7 merged 1 commit into
apache:release/v1.2from
Yicong-Huang:backport/6011-order-worker-state-by-version-not-timest-v1.2

Conversation

@Yicong-Huang

Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

Backport of #6011 to release/v1.2, cherry-picked from f521750.

Follows the Direct Backport Push convention; opened as a PR (rather than a direct push) as part of a backport-coverage audit for fixes merged to main since early June that were never labeled for backport.

Any related issues, documentation, discussions?

Backport of #6011. Originally linked #6010.

How was this PR tested?

Release-branch CI runs once the conflicts are resolved and this PR is marked ready for review. The cherry-pick conflicted and was committed with conflict markers.

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

Yes — backport prepared with Claude Code (mechanical cherry-pick; conflicts left as markers for the original author to resolve; the change itself is #6011 by its original author).

@Yicong-Huang Yicong-Huang self-assigned this Jul 30, 2026
@Yicong-Huang
Yicong-Huang requested a review from xuang7 July 30, 2026 03:49
@Yicong-Huang

Copy link
Copy Markdown
Contributor Author

The cherry-pick conflicted and was committed with conflict markers. Resolve the conflicts on this branch, then mark this PR ready for review.

Conflicting files:

  • amber/src/main/scala/org/apache/texera/amber/engine/architecture/deploysemantics/layer/WorkerExecution.scala
  • amber/src/main/scala/org/apache/texera/amber/engine/architecture/worker/DataProcessor.scala
  • amber/src/test/scala/org/apache/texera/amber/engine/architecture/controller/execution/WorkflowExecutionSpec.scala
  • amber/src/test/scala/org/apache/texera/amber/engine/architecture/coordinator/execution/OperatorExecutionSpec.scala

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

@codecov-commenter

codecov-commenter commented Jul 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.39535% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 52.48%. Comparing base (29c3469) to head (304aaaa).

Files with missing lines Patch % Lines
...hitecture/handlers/control/start_worker_handler.py 0.00% 2 Missing ⚠️
...itecture/worker/promisehandlers/StartHandler.scala 50.00% 0 Missing and 2 partials ⚠️
...ecture/deploysemantics/layer/WorkerExecution.scala 91.66% 0 Missing and 1 partial ⚠️
...itecture/worker/promisehandlers/PauseHandler.scala 50.00% 0 Missing and 1 partial ⚠️
...orker/promisehandlers/QueryStatisticsHandler.scala 50.00% 0 Missing and 1 partial ⚠️
...tecture/worker/promisehandlers/ResumeHandler.scala 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@                Coverage Diff                 @@
##             release/v1.2    #7106      +/-   ##
==================================================
- Coverage           52.49%   52.48%   -0.01%     
- Complexity           2498     2502       +4     
==================================================
  Files                1077     1077              
  Lines               42296    42314      +18     
  Branches             4551     4555       +4     
==================================================
+ Hits                22203    22209       +6     
- Misses              18782    18786       +4     
- Partials             1311     1319       +8     
Flag Coverage Δ *Carryforward flag
access-control-service 64.35% <ø> (ø) Carriedforward from 29c3469
agent-service 34.36% <ø> (ø) Carriedforward from 29c3469
amber 52.50% <80.00%> (-0.05%) ⬇️
computing-unit-managing-service 1.65% <ø> (ø) Carriedforward from 29c3469
config-service 56.06% <ø> (ø) Carriedforward from 29c3469
file-service 60.53% <ø> (ø) Carriedforward from 29c3469
frontend 47.32% <ø> (ø) Carriedforward from 29c3469
pyamber 91.01% <84.61%> (+0.04%) ⬆️
python 90.82% <ø> (+0.01%) ⬆️ Carriedforward from 29c3469
workflow-compiling-service 58.69% <ø> (ø) Carriedforward from 29c3469

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

### What changes were proposed in this PR?

A fast **source** operator stayed **orange (RUNNING)** in the editor
after the run finished (issue apache#6010).

**Why it's a bug.** The controller reconstructs each worker's state from
several unordered channels (source `RUNNING` via the `startWorker`
response, non-source `RUNNING` via `workerStateUpdated`,
`COMPLETED`/`PAUSED` via `queryStatistics`/`pauseWorker` responses) and
reconciled them with **last-`System.nanoTime()`-wins** in
`WorkerExecution`. Worker state, however, is single-writer and strictly
ordered causally. For a tiny source the run finishes almost instantly,
so the `startWorker` response — carrying the stale `RUNNING` it sampled
at launch — can reach the controller *after* `COMPLETED` was recorded;
its later receipt timestamp wins and clobbers `COMPLETED`. Results
render fine (separate path), so only the border is stuck.

This PR orders worker state **causally** instead of by wall clock:

| Before | After |
| --- | --- |
| `WorkerExecution.update(nanoTime, state)` — last-write-wins by receipt
time | `updateState(version, state)` — newest **logical version** wins |
| stale late RUNNING clobbers COMPLETED | RUNNING (v2) < COMPLETED (v3)
⇒ COMPLETED kept |
| — | terminal states (COMPLETED/TERMINATED) are absorbing |

- `WorkerStateManager` bumps a monotonic `stateVersion` on every
`transitTo` (its state-machine logical clock).
- The version rides on every state report: `WorkerStateResponse`,
`WorkerStateUpdatedRequest`, `WorkerMetrics` (3 new proto fields).
- The controller applies a state only when its version is newer. Stats
stay timestamp-ordered (monotonic snapshots can share a state version).
- A single per-worker counter ⇒ no cross-process clock-sync assumptions
(why not worker timestamps).
- **pyamber parity:** the Python worker also reports state
(start/pause/resume + query-statistics). Its `StateManager` now bumps
the same monotonic version and the four handlers include it; otherwise
version-0 reports would be dropped after the first and reconfiguration
(RUNNING→PAUSED→RUNNING) would hang.

### Any related issues, documentation, discussions?

Closes apache#6010. The timestamp-based `update` was introduced in apache#3557.

### How was this PR tested?

JDK 17. Scala unit + Scala/Python integration + Python unit:

```
sbt "WorkflowExecutionService/testOnly \
  *WorkerExecutionSpec *WorkerStateManagerSpec *OperatorExecutionSpec \
  *RegionExecutionCoordinatorSpec *WorkflowExecutionCoordinatorSpec \
  *RegionExecutionSpec *WorkflowExecutionSpec"

# Scala-Python reconfiguration end-to-end (spawns Python UDF workers):
sbt "WorkflowExecutionService/testOnly *ReconfigurationIntegrationSpec"   # 3 passed

# Python unit:
cd amber && pytest src/test/python/core/architecture/managers/test_state_manager.py   # 9 passed
```

- `WorkerExecutionSpec`: version ordering (positive +
stale/equal-version negatives), terminal-state absorption,
`forceTerminate`, independent stats-vs-state ordering, and a named
regression for apache#6010 (`COMPLETED` survives a late `RUNNING`). Verified
the regression goes **red** when `updateState` is reverted to
last-write-wins.
- `WorkerStateManagerSpec` / `test_state_manager.py`: version starts at
0, bumps per successful transition, no bump on no-op self-transition or
rejected transition.
- `ReconfigurationIntegrationSpec` reproduced the failure (timeout)
before the pyamber fix and passes after.

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

Generated-by: Claude Opus 4.8 (1M context), via Claude Code

---------

(backported from commit f521750)

Co-authored-by: Claude Fable 5 <[email protected]>
@Yicong-Huang
Yicong-Huang marked this pull request as ready for review July 30, 2026 04:57
@Yicong-Huang
Yicong-Huang force-pushed the backport/6011-order-worker-state-by-version-not-timest-v1.2 branch from 48de983 to 304aaaa Compare July 30, 2026 04:57
@Yicong-Huang

Copy link
Copy Markdown
Contributor Author

Resolved — the conflicts were purely controller→coordinator package-rename drift (that rename is main-only; v1.2 still uses controller/), not a feature dependency. Git rename-detection landed 25 of the files cleanly on v1.2's controller/ paths; I hand-resolved the two source conflicts by keeping v1.2's names and taking the fix's logic:

  • WorkerExecution.scala: kept the controller.execution.WorkerPortExecution import, took the fix's WorkerState.{COMPLETED, TERMINATED, UNINITIALIZED} import set.
  • DataProcessor.scala: kept controllerInterface / mkContext(CONTROLLER), adopted getStateWithVersion + WorkerStateUpdatedRequest(state, stateVersion).

The state_version proto fields and StateManager.getStateWithVersion this fix adds are internal RPC/state-ordering plumbing (invisible to users) — this is a correctness fix for out-of-order worker-state application, not a user-facing feature. Dropped two bits of main-only test scaffolding: the new OperatorExecutionSpec.scala (added by main under coordinator/execution/, no v1.2 counterpart) and two new WorkflowExecutionSpec cases that depend on a regionWithPort helper absent on v1.2. All other test updates (adapting to the new API) applied cleanly and were kept. Release-branch CI does the authoritative compile. Marking ready.

@xuang7
xuang7 merged commit a9fa9bc into apache:release/v1.2 Jul 30, 2026
18 checks passed
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.

3 participants