Skip to content

Treat a local batch that exits 0 before its app is detected as finished - #7816

Closed
pan3793 wants to merge 2 commits into
apache:masterfrom
pan3793:kyuubi-flaky-batch-recovery
Closed

pan3793 wants to merge 2 commits into
apache:masterfrom
pan3793:kyuubi-flaky-batch-recovery

Conversation

@pan3793

@pan3793 pan3793 commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Why are the changes needed?

A local (JPS) batch that exits with code 0 can be marked ERROR with job failed: Some(ApplicationInfo(null,null,NOT_FOUND,...)).

In submitAndMonitorBatchJob, the submit process is polled every kyuubi.batch.application.check.interval (default 5s). A short client-mode app (e.g. SparkPi on local) can start and finish between two polls, so its id is never observed and appStarted stays false. JPS does not keep the state of finished apps, so NOT_FOUND here is indistinguishable from "never started", and the zero exit code is the only trustworthy signal.

This makes batch sessions recovery in BatchesV1ResourceSuite/BatchesV2ResourceSuite flaky, e.g. https://github.com/apache/kyuubi/actions/runs/40693174724/job/122832955449

The fix only fails on a missing app id when the app operation persists app state (YARN, Kubernetes) or no app operation matches, keeping existing behavior for those.

How was this patch tested?

Added local batch finished before the application is detected to BatchesResourceSuite. It hides the batch JVMs from jps (-XX:-UsePerfData) so the app is never detected, then asserts FINISHED. It fails without the fix ("[ERROR]" did not equal "[FINISHED]") and passes with it.

build/mvn test -pl kyuubi-server -am -Pspark-3.5 -Dtest=none \
  -DwildcardSuites=org.apache.kyuubi.server.api.v1.BatchesV1ResourceSuite,org.apache.kyuubi.server.api.v1.BatchesV2ResourceSuite

Was this patch assisted by generative AI tooling?

Assisted-by: Claude Opus 5.5

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The regression test can pass with the fix reverted because the immediate application lookup may set appStarted to true, leaving the new branch untested.

1 open issue
What changed in this PR

This PR lets local batches finish successfully when their submit process exits with code 0 before JPS detects the application, addressing intermittent batch-recovery failures.

Changes:

  • Accept a missing application ID after successful exit when the application operation does not persist state.
  • Preserve existing failure behavior for persistent-state operations and unmatched operations.
  • Add a regression test using a long polling interval.
File Description
kyuubi-server/​src/​test/​scala/​org/​apache/​kyuubi/​server/​api/​v1/​BatchesResourceSuite.scala Adds coverage for a local batch finishing before application detection.
kyuubi-server/​src/​main/​scala/​org/​apache/​kyuubi/​operation/​BatchJobSubmission.scala Conditions missing-ID failure on application-state persistence support.

Review effort: Balanced

Comment on lines +545 to +548
// a long check interval lets the process exit before the app is ever polled
val requestObj = newSparkBatchRequest(Map(
"spark.master" -> "local",
BATCH_APPLICATION_CHECK_INTERVAL.key -> "PT1M"))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid. Fixed in 8d9cd55: the test now hides both the launcher and spark-submit JVMs from jps via -XX:-UsePerfData (kyuubi.engineEnv.SPARK_LAUNCHER_OPTS / SPARK_SUBMIT_OPTS), so the lookup returns NOT_FOUND through process exit, and asserts appId is null and appStartTime is 0 before asserting FINISHED. Fails 3/3 with the fix reverted.

@pan3793 pan3793 self-assigned this Oct 30, 2026
@pan3793 pan3793 added this to the v1.10.4 milestone Oct 30, 2026
@pan3793 pan3793 closed this in ab07bdf Oct 30, 2026
pan3793 added a commit that referenced this pull request Oct 30, 2026
…ected as finished

### Why are the changes needed?

A local (JPS) batch that exits with code 0 can be marked ERROR with `job failed: Some(ApplicationInfo(null,null,NOT_FOUND,...))`.

In `submitAndMonitorBatchJob`, the submit process is polled every `kyuubi.batch.application.check.interval` (default 5s). A short client-mode app (e.g. SparkPi on `local`) can start and finish between two polls, so its id is never observed and `appStarted` stays false. JPS does not keep the state of finished apps, so `NOT_FOUND` here is indistinguishable from "never started", and the zero exit code is the only trustworthy signal.

This makes `batch sessions recovery` in `BatchesV1ResourceSuite`/`BatchesV2ResourceSuite` flaky, e.g. https://github.com/apache/kyuubi/actions/runs/40693174724/job/122832955449

The fix only fails on a missing app id when the app operation persists app state (YARN, Kubernetes) or no app operation matches, keeping existing behavior for those.

### How was this patch tested?

Added `local batch finished before the application is detected` to `BatchesResourceSuite`. It hides the batch JVMs from jps (`-XX:-UsePerfData`) so the app is never detected, then asserts `FINISHED`. It fails without the fix (`"[ERROR]" did not equal "[FINISHED]"`) and passes with it.

```
build/mvn test -pl kyuubi-server -am -Pspark-3.5 -Dtest=none \
  -DwildcardSuites=org.apache.kyuubi.server.api.v1.BatchesV1ResourceSuite,org.apache.kyuubi.server.api.v1.BatchesV2ResourceSuite
```

### Was this patch assisted by generative AI tooling?

Assisted-by: Claude Opus 5.5

Closes #7816 from pan3793/kyuubi-flaky-batch-recovery.

Closes #7816

8d9cd55 [Cheng Pan] Hide the batch JVMs from jps to make the test deterministic
64b7646 [Cheng Pan] Treat a local batch that exits 0 before its app is detected as finished

Authored-by: Cheng Pan <pan3793@gmail.com>
Signed-off-by: Cheng Pan <chengpan@apache.org>
(cherry picked from commit ab07bdf)
Signed-off-by: Cheng Pan <chengpan@apache.org>
pan3793 added a commit that referenced this pull request Oct 30, 2026
…ected as finished

### Why are the changes needed?

A local (JPS) batch that exits with code 0 can be marked ERROR with `job failed: Some(ApplicationInfo(null,null,NOT_FOUND,...))`.

In `submitAndMonitorBatchJob`, the submit process is polled every `kyuubi.batch.application.check.interval` (default 5s). A short client-mode app (e.g. SparkPi on `local`) can start and finish between two polls, so its id is never observed and `appStarted` stays false. JPS does not keep the state of finished apps, so `NOT_FOUND` here is indistinguishable from "never started", and the zero exit code is the only trustworthy signal.

This makes `batch sessions recovery` in `BatchesV1ResourceSuite`/`BatchesV2ResourceSuite` flaky, e.g. https://github.com/apache/kyuubi/actions/runs/40693174724/job/122832955449

The fix only fails on a missing app id when the app operation persists app state (YARN, Kubernetes) or no app operation matches, keeping existing behavior for those.

### How was this patch tested?

Added `local batch finished before the application is detected` to `BatchesResourceSuite`. It hides the batch JVMs from jps (`-XX:-UsePerfData`) so the app is never detected, then asserts `FINISHED`. It fails without the fix (`"[ERROR]" did not equal "[FINISHED]"`) and passes with it.

```
build/mvn test -pl kyuubi-server -am -Pspark-3.5 -Dtest=none \
  -DwildcardSuites=org.apache.kyuubi.server.api.v1.BatchesV1ResourceSuite,org.apache.kyuubi.server.api.v1.BatchesV2ResourceSuite
```

### Was this patch assisted by generative AI tooling?

Assisted-by: Claude Opus 5.5

Closes #7816 from pan3793/kyuubi-flaky-batch-recovery.

Closes #7816

8d9cd55 [Cheng Pan] Hide the batch JVMs from jps to make the test deterministic
64b7646 [Cheng Pan] Treat a local batch that exits 0 before its app is detected as finished

Authored-by: Cheng Pan <pan3793@gmail.com>
Signed-off-by: Cheng Pan <chengpan@apache.org>
(cherry picked from commit ab07bdf)
Signed-off-by: Cheng Pan <chengpan@apache.org>
pan3793 added a commit that referenced this pull request Oct 30, 2026
…ected as finished

### Why are the changes needed?

A local (JPS) batch that exits with code 0 can be marked ERROR with `job failed: Some(ApplicationInfo(null,null,NOT_FOUND,...))`.

In `submitAndMonitorBatchJob`, the submit process is polled every `kyuubi.batch.application.check.interval` (default 5s). A short client-mode app (e.g. SparkPi on `local`) can start and finish between two polls, so its id is never observed and `appStarted` stays false. JPS does not keep the state of finished apps, so `NOT_FOUND` here is indistinguishable from "never started", and the zero exit code is the only trustworthy signal.

This makes `batch sessions recovery` in `BatchesV1ResourceSuite`/`BatchesV2ResourceSuite` flaky, e.g. https://github.com/apache/kyuubi/actions/runs/40693174724/job/122832955449

The fix only fails on a missing app id when the app operation persists app state (YARN, Kubernetes) or no app operation matches, keeping existing behavior for those.

### How was this patch tested?

Added `local batch finished before the application is detected` to `BatchesResourceSuite`. It hides the batch JVMs from jps (`-XX:-UsePerfData`) so the app is never detected, then asserts `FINISHED`. It fails without the fix (`"[ERROR]" did not equal "[FINISHED]"`) and passes with it.

```
build/mvn test -pl kyuubi-server -am -Pspark-3.5 -Dtest=none \
  -DwildcardSuites=org.apache.kyuubi.server.api.v1.BatchesV1ResourceSuite,org.apache.kyuubi.server.api.v1.BatchesV2ResourceSuite
```

### Was this patch assisted by generative AI tooling?

Assisted-by: Claude Opus 5.5

Closes #7816 from pan3793/kyuubi-flaky-batch-recovery.

Closes #7816

8d9cd55 [Cheng Pan] Hide the batch JVMs from jps to make the test deterministic
64b7646 [Cheng Pan] Treat a local batch that exits 0 before its app is detected as finished

Authored-by: Cheng Pan <pan3793@gmail.com>
Signed-off-by: Cheng Pan <chengpan@apache.org>
(cherry picked from commit ab07bdf)
Signed-off-by: Cheng Pan <chengpan@apache.org>
@pan3793

pan3793 commented Oct 30, 2026

Copy link
Copy Markdown
Member Author

Merge Summary:

Posted by merge_kyuubi_pr.py

@wForget

wForget commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

CI failed on branch-1.10 https://github.com/apache/kyuubi/actions/runs/41022327580/job/123952278548, appOperation was introduced in #7033

[ERROR] [Error] /home/runner/work/kyuubi/kyuubi/kyuubi-server/src/main/scala/org/apache/kyuubi/operation/BatchJobSubmission.scala:306: not found: value appOperation
Error occurred in an application involving default arguments.

@wForget

wForget commented Nov 3, 2026

Copy link
Copy Markdown
Member

CI failed on branch-1.10 https://github.com/apache/kyuubi/actions/runs/41022327580/job/123952278548, appOperation was introduced in #7033

[ERROR] [Error] /home/runner/work/kyuubi/kyuubi/kyuubi-server/src/main/scala/org/apache/kyuubi/operation/BatchJobSubmission.scala:306: not found: value appOperation
Error occurred in an application involving default arguments.

Backport #7033 to branch-1.10: #7832

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.

4 participants