Skip to content

fix(pyamber, v1.2): disable data sub-queues registered after disable_data - #8093

Merged
xuang7 merged 2 commits into
release/v1.2from
backport/6724-disable-data-sub-queues-registered-after-v1.2
Sep 24, 2026
Merged

xuang7 merged 2 commits into
release/v1.2from
backport/6724-disable-data-sub-queues-registered-after-v1.2

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

Automated backport of #6724 to release/v1.2.

Source: 2173ec5 · automation run

Any related issues, documentation, discussions?

Backport of #6724. Originally linked #6723.

How was this PR tested?

Release-branch CI runs on this branch once the conflicts are resolved and this PR is marked ready for review.

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

No.

@github-actions

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/test/python/core/models/test_internal_queue.py
  • amber/src/test/scala/org/apache/texera/amber/engine/e2e/TestUtils.scala

…6724)

This PR fixes two independent crash bugs in the Python worker's
`InternalQueue`, both of which silently kill a worker thread while the
heartbeat thread stays alive, hanging the execution with no error
reported. It also fixes the reconfiguration test harness, whose
incorrect await order masqueraded as an engine deadlock.

**Fix 1: data leaking out of a paused or backpressured worker.**

Pause and backpressure work by disabling the data sub-queues of
`InternalQueue`. However, `disable_data` only disables the sub-queues
that exist when it is called, while sub-queues are created lazily on a
channel's first `put` and start enabled. A data channel whose first
message arrives during a disable window therefore came up enabled and
was not covered by the disable at all.

This is a bug because the worker can then keep processing data while
reporting PAUSED, and if the leaked `DataElement` is dequeued inside the
pause wait-loop in `main_loop.py`, the control-only pampy `match` raises
an uncaught `MatchError` that silently kills the DP thread while the
heartbeat thread stays alive, so the execution hangs forever with no
error reported. Under backpressure, the leaked channel keeps feeding the
congested downstream, defeating flow control.

The fix in `InternalQueue.put`: when it registers a new data channel
while `_queue_state` is non-empty, the new sub-queue now starts
disabled. The registration is done under the same lock used by
`disable_data`/`enable_data` (with a double-check to avoid duplicate
registration), and the sub-queue is disabled before its first element is
enqueued, so the element never becomes dequeuable during the disable
window. Control channels are never disabled, and `enable_data` needs no
change because it iterates the channel set at release time, which by
then includes channels registered mid-pause.

```mermaid
sequenceDiagram
    participant R as Reader thread
    participant Q as InternalQueue
    participant DP as DP thread

    DP->>Q: disable_data(PAUSE)
    R->>Q: put(): first message on a new channel
    Note right of Q: _queue_state is not empty, so it starts DISABLED
    Note right of Q: messages wait in the queue
    DP->>Q: enable_data(PAUSE) on resume
    Q-->>DP: messages delivered in order, nothing lost
```

An important consequence, pinned by a regression test: ECMs ride data
channels, so an ECM that is such a channel's first message (e.g. a
reconfiguration marker reaching a paused worker) is **delayed until
resume, not dropped** — `enable_data` re-enables the channel and the ECM
is delivered in order. This matches the engine's intended semantics:
reconfigurations submitted while paused only take effect on resume
(`ExecutionReconfigurationService` dispatches them without awaiting),
and the JVM `DPThread` likewise refuses all data-channel traffic, ECMs
included, while paused.

**Harness fix: `TestUtils.shouldReconfigure` awaited the reconfiguration
ack while still paused.**

The three `ReconfigurationIntegrationSpec` failures that earlier looked
like an engine deadlock were the harness deadlocking itself: it called
`Await.result(reconfigureWorkflow(...))` before resuming, but the ack
can only be produced after resume delivers the ECM — a circular wait
that expired at the 30s command timeout. Production never uses this
order. The harness now matches production: dispatch the reconfiguration
without awaiting, await the resume ack (which `ResumeHandler` completes
only once every worker has acknowledged), then await the reconfiguration
ack. This also removes the tests' dependence on source timing. (There is
no RUNNING state event to wait on instead: the engine only pushes
`ExecutionStateUpdate` for PAUSED and terminal states.)

An intermediate revision of this PR instead moved the leak fix to the
dequeue side so ECMs could pass while paused; it was reverted
(`87939215d`) after review established that delivering ECMs during a
pause diverges from the engine's semantics and that the harness order
was the actual culprit.

**Fix 2: the category query methods iterated `_queue_ids` unguarded.**

The six per-category query methods (`is_control_empty`, `is_data_empty`,
`size_control`, `size_data`, `in_mem_size`, `is_data_enabled`) iterated
the live `_queue_ids` set, which `put()` grows on a channel's first
message from a network thread. CPython raises `RuntimeError: Set changed
size during iteration` when a set is mutated mid-iteration, so a query
racing a first-time registration kills the calling thread — e.g. the DP
thread polling `is_data_enabled()` in the main loop — producing the same
silent-hang failure mode as Fix 1 through an unrelated mechanism.

These methods now go through two private helpers, `_control_queue_ids()`
and `_data_queue_ids()`, which take a `tuple()` snapshot of the set and
filter it, so the snapshot is part of the API rather than a convention
each query method has to remember. This keeps the hot-path queries
lock-free: the snapshot copy is a single uninterruptible C-level
operation, and a snapshot at most misses a channel registered mid-call,
which the next poll observes.

Cleanup in the same file: the unreachable `InternalMarker` entry in the
isinstance tuple is removed (`InternalMarker` does not subclass
`InternalQueueElement`, so it can never reach that branch) and the two
identical dispatch branches are merged.

Fixes #6723. The regression tests extend the `InternalQueue` spec added
by #6444.

Two pre-existing bugs found while tracing the reconfiguration failure
will be filed separately, as neither is needed for this suite to pass:
`_check_and_process_control` processes ECMs under a stale
`current_input_channel_id`, and `PauseManager.resume` re-enables
ECM_PAUSE channels before checking `_global_pauses` (the Scala
`PauseManager` has the correct order).

`amber/src/test/python/core/models/test_internal_queue.py` passes with
34 passed and 1 xfailed (the xfail documents a pre-existing
`LinkedBlockingMultiQueue` priority bug from #6444, unrelated to this
PR).

For Fix 1: the late-channel leak test (fails without the fix), release
via `enable_data`, stacked pause+backpressure disables, control channels
staying unblocked mid-pause, pre-registered and normally-registered
baselines, two threaded stress tests racing first-time registrations
against disable/enable toggles with exact element counts, and a new test
pinning the delayed-ECM semantics (an ECM as a mid-disable channel's
first message is not dequeuable while a reason is active and is
delivered after `enable_data`, under both PAUSE and BACKPRESSURE).
Deleting the born-disabled block turns 5 tests red, including both
parametrized cases of the new ECM test.

For Fix 2: 6 deterministic parametrized tests (a sentinel key
interleaves a real first-time `put()` into each query's iteration) plus
a threaded stress test racing 800 first-time registrations against all
six queries; all fail with the `RuntimeError` when the snapshot is
reverted.

For the harness fix, the flip is the evidence: with the engine
byte-identical, `ReconfigurationIntegrationSpec` fails 3 of 3 under the
old await order and passes 3 of 3 on repeated clean local runs under the
production order; `ReconfigurationSpec`, which shares
`shouldReconfigure`, passes 2 of 2.

The wider `amber/src/test/python/core` tree was run before and after
with identical pass/fail sets apart from the new tests (the only
failures need a live Iceberg catalog). `scalafmtCheck` and `scalafix
--check` pass on the touched Scala scope.

Co-authored by: Claude Code (Claude Fable 5)

---------

Co-authored-by: Yicong Huang <[email protected]>
(cherry picked from commit 2173ec5)
@xuang7
xuang7 force-pushed the backport/6724-disable-data-sub-queues-registered-after-v1.2 branch from 8da10d9 to 896ef13 Compare September 18, 2026 03:59
@github-actions

Copy link
Copy Markdown
Contributor Author

Automated Reviewer Suggestions

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

  • Contributors with relevant context: @Yicong-Huang, @Ma77Ball
    You can notify them by mentioning @Yicong-Huang, @Ma77Ball in a comment.

@xuang7
xuang7 marked this pull request as ready for review September 18, 2026 04:01
@xuang7

xuang7 commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Resolved by re-cherry-picking onto the current release/v1.2. test_internal_queue.py did not exist on this branch, so it is brought over in full from the source commit; internal_queue.py is now byte-identical to main's, so the whole suite applies. TestUtils.scala was adapted to this branch's API (controllerInterface, Duration.fromSeconds timeouts).

@codecov-commenter

codecov-commenter commented Sep 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 53.13%. Comparing base (5a5ff9a) to head (4fa321c).
⚠️ Report is 2 commits behind head on release/v1.2.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@                Coverage Diff                 @@
##             release/v1.2    #8093      +/-   ##
==================================================
+ Coverage           53.09%   53.13%   +0.03%     
+ Complexity           2565     2564       -1     
==================================================
  Files                1078     1078              
  Lines               42360    42367       +7     
  Branches             4562     4562              
==================================================
+ Hits                22493    22510      +17     
+ Misses              18549    18538      -11     
- Partials             1318     1319       +1     
Flag Coverage Δ *Carryforward flag
access-control-service 64.35% <ø> (ø) Carriedforward from 896ef13
agent-service 34.36% <ø> (ø) Carriedforward from 896ef13
amber 53.48% <ø> (-0.02%) ⬇️
computing-unit-managing-service 1.65% <ø> (ø) Carriedforward from 896ef13
config-service 56.06% <ø> (ø) Carriedforward from 896ef13
file-service 61.72% <ø> (ø) Carriedforward from 896ef13
frontend 47.36% <ø> (ø) Carriedforward from 896ef13
pyamber 93.32% <100.00%> (+0.24%) ⬆️
python 90.93% <ø> (+0.04%) ⬆️ Carriedforward from 896ef13
workflow-compiling-service 58.69% <ø> (ø) Carriedforward from 896ef13

*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 enabled auto-merge September 19, 2026 19:09
@xuang7
xuang7 added this pull request to the merge queue Sep 19, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 19, 2026
@xuang7
xuang7 added this pull request to the merge queue Sep 21, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 21, 2026
@xuang7
xuang7 added this pull request to the merge queue Sep 24, 2026
Merged via the queue into release/v1.2 with commit de23d2a Sep 24, 2026
18 checks passed
@xuang7
xuang7 deleted the backport/6724-disable-data-sub-queues-registered-after-v1.2 branch September 24, 2026 19:32
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