Skip to content

feat(java): operator admin surface - #558

Merged
kartikeya-27 merged 4 commits into
masterfrom
feat/java-admin-surface
Jul 27, 2026
Merged

feat(java): operator admin surface#558
kartikeya-27 merged 4 commits into
masterfrom
feat/java-admin-surface

Conversation

@pratyush618

@pratyush618 pratyush618 commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

Closes #524.

Ports the operator admin surface to the Java SDK. Java had none of the five APIs the other SDKs expose.

What's added

API Notes
requeueJob(jobId)boolean Forces a stuck running job back to pending, releasing its execution claim. The only new native surface.
predicateStats()PredicateStats allowed / skipped / deferred / rejected / errors. One count per gated enqueue — the decision that won, not per gate evaluated.
analyzeArguments(taskName, payload)InterceptionAnalysis Dry-runs the interceptor chain without enqueuing. A chain that would reject reports rejected instead of throwing.
reloadResources() / reloadResources(names)Map<String, Boolean> Hot-reload: dispose what is cached, rebuild dependency-first.
shutdown() Closes every worker started from the client — the programmatic SIGINT/SIGTERM.

Implementation notes

requeueJob goes over the existing Storage::requeue_stuck: a new Java_..._NativeQueue_requeueJob in crates/taskito-java/src/queue/admin.rs, then NativeQueueQueueBackend (defaults to UnsupportedOperationException) → JniQueueBackendInMemoryQueueBackend. The double-execution caveat is surfaced in the API reference and the troubleshooting guide.

reloadResources needed real runtime work. Java's ResourceRuntime is two-level: the client runtime holds definitions and counters, and forWorker() forks a child that holds the live caches. A client-level reload() therefore fans out to the live children and ANDs their results — reloading on the client runtime itself would build orphan instances in a cache nothing tears down. Children publish themselves on acquireWorker()'s first lease and unpublish in disposeWorker(), so a builder that is never started leaves no reload target behind.

Selective disposal required keying the shared LIFO teardown stack (Deque<Runnable>Deque<Teardown>), so one resource's entries can be pulled out without disturbing the rest. Dependency ordering comes from a workerDeps edge map recorded by a per-build workerContext(name).

Per scope: WORKER disposes and rebuilds eagerly under the resource's build lock (so a factory that now fails reports false rather than surfacing on some later task); THREAD drops every per-thread instance so each thread rebuilds on next use; POOLED drops the pool; TASK/REQUEST are a successful no-op since nothing is cached.

Java has no resource options bag, so reloadable is a fifth ResourceDefinition record component — the existing 4- and 3-arg constructors are kept, so this stays source- and binary-compatible — plus withReloadable(boolean), reached through a new Taskito.resource(name, ResourceDefinition) escape hatch instead of another resource(...) overload.

shutdown adds a WorkerLifecycle interface (started/closed) wired by Taskito.worker(); DefaultTaskito keeps a Set<Worker>. It closes (drains) each worker rather than only halting dispatch, because Worker.close() is Java's full, already-idempotent teardown.

analyzeArguments takes a payload rather than an args array, since Java interception is payload-level. The interceptor loop was extracted out of dispatchEnqueue into applyInterceptors(taskName, payload, outcomes), so the dry run is literally the enqueue path; a rejection reports the original input plus the partial outcome list.

Tests

12 new: core/RequeueTest (3), resources/ResourceReloadTest (6 — rebuild, reloadable sweep, unknown name, no running worker, dependency ordering, failing factory), worker/ShutdownTest (3), plus new cases in core/PredicateTest and core/InterceptionTest.

Full Gradle suite green. cargo check --workspace, cargo clippy -p taskito-java, cargo fmt --check, spotless, checkstyle, and javadoc all clean; pnpm --dir docs typecheck and lint clean.

Summary by CodeRabbit

  • New Features
    • Added Java admin APIs to recover stuck running jobs, shut down client-started workers, hot-reload resources, and inspect predicate outcomes.
    • Added dry-run argument analysis to preview interception results without enqueueing.
    • Added support for registering pre-built resource definitions and marking resources as reloadable.
  • Documentation
    • Expanded Java API references and the “jobs stuck in running” troubleshooting guide with recovery and admin usage details.
  • Bug Fixes
    • Requeued jobs return to pending while preserving retry budget, and stale requeue attempts no longer publish results.
  • Tests
    • Added coverage for requeue, shutdown, resource reload, and predicate stats/analysis.

requeueJob, predicateStats, analyzeArguments, reloadResources, and shutdown — the recovery and introspection APIs the other SDKs already expose.
@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: eab07bc0-9557-4083-a47f-afe54086ac8f

📥 Commits

Reviewing files that changed from the base of the PR and between 6b7185d and 7a8023a.

📒 Files selected for processing (1)
  • sdks/java/test-support/src/main/java/org/byteveda/taskito/test/InMemoryQueueBackend.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • sdks/java/test-support/src/main/java/org/byteveda/taskito/test/InMemoryQueueBackend.java

📝 Walkthrough

Walkthrough

The Java SDK adds administrative APIs for stuck-job recovery, predicate inspection, interceptor analysis, resource hot reload, and client-wide worker shutdown. JNI, resource runtime, lifecycle wiring, tests, and Java documentation are updated.

Changes

Java operator administration

Layer / File(s) Summary
Stuck job recovery
sdks/java/src/main/java/org/byteveda/taskito/..., crates/taskito-java/src/queue/admin.rs, sdks/java/test-support/..., sdks/java/src/test/.../RequeueTest.java, docs/...
Adds requeueJob, propagates it through the Java backend and JNI to storage, fences stale worker outcomes, and documents and tests running-to-pending recovery semantics.
Interception analysis and predicate metrics
sdks/java/src/main/java/org/byteveda/taskito/..., sdks/java/src/test/.../InterceptionTest.java, sdks/java/src/test/.../PredicateTest.java, docs/.../queue/resources.mdx
Adds dry-run interceptor analysis, immutable analysis results, thread-safe predicate counters, and corresponding API documentation and tests.
Resource hot reload
sdks/java/src/main/java/org/byteveda/taskito/resources/*, sdks/java/src/main/java/org/byteveda/taskito/DefaultTaskito.java, sdks/java/src/test/.../ResourceReloadTest.java, docs/.../resources.mdx
Adds reloadable resource definitions, dependency-ordered rebuilds across live workers, teardown handling, result reporting, and coverage for reload behavior.
Client worker shutdown
sdks/java/src/main/java/org/byteveda/taskito/worker/*, sdks/java/src/main/java/org/byteveda/taskito/DefaultTaskito.java, sdks/java/src/test/.../ShutdownTest.java, docs/.../queue/workers.mdx
Adds worker lifecycle callbacks, tracks client-created workers, and closes them through Taskito.shutdown() with lifecycle and disposal tests.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Taskito
  participant JniQueueBackend
  participant NativeQueue
  participant QueueStorage
  Taskito->>JniQueueBackend: requeueJob(jobId)
  JniQueueBackend->>NativeQueue: requeueJob(handle, jobId)
  NativeQueue->>QueueStorage: requeue_stuck(id, now)
  QueueStorage-->>Taskito: return success or false
Loading

Possibly related PRs

Suggested labels: storage, tests

Suggested reviewers: kartikeya-27

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 44.59% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately summarizes the Java operator admin surface added in this PR.
Linked Issues check ✅ Passed The PR implements the requested Java admin APIs and documents the requeueJob caveat called out in issue #524.
Out of Scope Changes check ✅ Passed All code and docs changes support the Java operator admin surface; no unrelated changes stand out.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/java-admin-surface

Comment @coderabbitai help to get the list of available commands.

@pratyush618
pratyush618 requested a review from kartikeya-27 July 27, 2026 02:44
@pratyush618 pratyush618 self-assigned this Jul 27, 2026

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 3

🧹 Nitpick comments (1)
sdks/java/src/main/java/org/byteveda/taskito/resources/ResourceRuntime.java (1)

369-390: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Reload's dependency ordering doesn't cover POOLED resources that depend on a WORKER resource.

workerContext (Lines 375-390) records a dependency in workerDeps only when a WORKER-scoped factory resolves another resource. The pre-existing pooledContext.use() (unchanged, Lines 92-102) calls resolvePooledDependency without recording anything into workerDeps. So reloading a WORKER resource that a POOLED resource depends on won't rebuild/refresh already-checked-out or idle pooled instances — they keep the stale dependency until the pool itself is reloaded or a pooled instance's maxLifetime expires. This is a real gap in the "dependency-first" guarantee for the pooled+worker combination; worth a short caveat in the reload Javadoc/docs, or extending workerDeps tracking to pooled dependencies if that combination is expected to be common.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@sdks/java/src/main/java/org/byteveda/taskito/resources/ResourceRuntime.java`
around lines 369 - 390, Extend pooled dependency tracking so pooled resources
that resolve WORKER resources participate in reload ordering. Update
pooledContext.use() and its resolvePooledDependency flow to record WORKER
dependencies in the same tracking structure used by workerContext, while
preserving existing handling for other scopes.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@sdks/java/src/main/java/org/byteveda/taskito/DefaultTaskito.java`:
- Around line 1453-1474: Make worker lifecycle coordination in DefaultTaskito
atomic by adding a shutdown state guarded by the same synchronization mechanism
used when registering workers. Update WorkerLifecycle.started() to reject and
close workers once shutdown begins, while adding accepted workers to liveWorkers
atomically; update shutdown() to mark shutdown before draining the set and
continue closing workers until no accepted workers remain. Preserve normal
registration before shutdown and ensure workers starting concurrently cannot
remain running after shutdown completes.

In `@sdks/java/src/main/java/org/byteveda/taskito/resources/ResourceRuntime.java`:
- Around line 253-326: Coordinate worker reloads with terminal teardown in
recreateWorker, resolveWorker, and disposeWorker so cache and teardown mutations
cannot race. Add an atomically coordinated disposed state or shared monitor, and
re-check disposal while holding each worker’s lock before building or caching an
instance. Ensure disposeWorker marks the runtime disposed while clearing caches
and draining teardown entries, and make reload against a disposed runtime return
false without creating new resources.

In
`@sdks/java/test-support/src/main/java/org/byteveda/taskito/test/InMemoryQueueBackend.java`:
- Around line 152-164: Update InMemoryQueueBackend and InMemoryWorker to
associate each worker token with a claim/attempt generation rather than only
jobId. Increment or invalidate the generation when requeueJob makes a running
job pending and on later claims, then ignore complete, fail, or cancel outcomes
whose token generation no longer matches the job’s current generation.

---

Nitpick comments:
In `@sdks/java/src/main/java/org/byteveda/taskito/resources/ResourceRuntime.java`:
- Around line 369-390: Extend pooled dependency tracking so pooled resources
that resolve WORKER resources participate in reload ordering. Update
pooledContext.use() and its resolvePooledDependency flow to record WORKER
dependencies in the same tracking structure used by workerContext, while
preserving existing handling for other scopes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 05ed9743-91f7-4c69-a6ce-b7789bbfecbb

📥 Commits

Reviewing files that changed from the base of the PR and between 8f8a34f and 41e03d1.

📒 Files selected for processing (26)
  • CHANGELOG.md
  • crates/taskito-java/src/queue/admin.rs
  • docs/content/docs/java/api-reference/queue/queues.mdx
  • docs/content/docs/java/api-reference/queue/resources.mdx
  • docs/content/docs/java/api-reference/queue/workers.mdx
  • docs/content/docs/java/api-reference/resources.mdx
  • docs/content/docs/resources/changelog.mdx
  • docs/content/docs/shared/guides/operations/troubleshooting.mdx
  • sdks/java/src/main/java/org/byteveda/taskito/DefaultTaskito.java
  • sdks/java/src/main/java/org/byteveda/taskito/Taskito.java
  • sdks/java/src/main/java/org/byteveda/taskito/interception/InterceptionAnalysis.java
  • sdks/java/src/main/java/org/byteveda/taskito/internal/JniQueueBackend.java
  • sdks/java/src/main/java/org/byteveda/taskito/internal/NativeQueue.java
  • sdks/java/src/main/java/org/byteveda/taskito/predicates/PredicateMetrics.java
  • sdks/java/src/main/java/org/byteveda/taskito/predicates/PredicateStats.java
  • sdks/java/src/main/java/org/byteveda/taskito/resources/ResourceDefinition.java
  • sdks/java/src/main/java/org/byteveda/taskito/resources/ResourceRuntime.java
  • sdks/java/src/main/java/org/byteveda/taskito/spi/QueueBackend.java
  • sdks/java/src/main/java/org/byteveda/taskito/worker/Worker.java
  • sdks/java/src/main/java/org/byteveda/taskito/worker/WorkerLifecycle.java
  • sdks/java/src/test/java/org/byteveda/taskito/core/InterceptionTest.java
  • sdks/java/src/test/java/org/byteveda/taskito/core/PredicateTest.java
  • sdks/java/src/test/java/org/byteveda/taskito/core/RequeueTest.java
  • sdks/java/src/test/java/org/byteveda/taskito/resources/ResourceReloadTest.java
  • sdks/java/src/test/java/org/byteveda/taskito/worker/ShutdownTest.java
  • sdks/java/test-support/src/main/java/org/byteveda/taskito/test/InMemoryQueueBackend.java

Comment thread sdks/java/src/main/java/org/byteveda/taskito/DefaultTaskito.java
Addresses review: reload now runs under the runtime monitor teardown takes, shutdown drains rather than sweeping once, and the in-memory backend fences outcomes on status like the core does.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
sdks/java/test-support/src/main/java/org/byteveda/taskito/test/InMemoryQueueBackend.java (1)

162-163: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Serialize cancellation with requeue.

requestCancel can observe running, then requeueJob clears cancelRequested, after which requestCancel writes it back to true. The fresh attempt is then cancelled by a request intended for the stale one. Synchronize requestCancel on this backend monitor as well.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@sdks/java/test-support/src/main/java/org/byteveda/taskito/test/InMemoryQueueBackend.java`
around lines 162 - 163, Synchronize requestCancel on the InMemoryQueueBackend
monitor so checking running and updating cancelRequested is atomic with
requeueJob. Preserve requeueJob’s clearing of cancelRequested, ensuring a stale
cancellation cannot mark the fresh attempt for cancellation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@sdks/java/test-support/src/main/java/org/byteveda/taskito/test/InMemoryQueueBackend.java`:
- Around line 1244-1286: Update InMemoryQueueBackend’s settleable, token
bookkeeping, and completeJob/failJob/cancelJob flow to fence outcomes by
execution attempt: store a unique claim generation with each token, then under
the backend monitor validate both the job’s running status and matching
generation while applying the outcome. Ensure requeue or reclaim invalidates the
original token so stale handlers cannot settle a pending or newer attempt, and
add coverage that reclaims a job before the original handler is released.

---

Outside diff comments:
In
`@sdks/java/test-support/src/main/java/org/byteveda/taskito/test/InMemoryQueueBackend.java`:
- Around line 162-163: Synchronize requestCancel on the InMemoryQueueBackend
monitor so checking running and updating cancelRequested is atomic with
requeueJob. Preserve requeueJob’s clearing of cancelRequested, ensuring a stale
cancellation cannot mark the fresh attempt for cancellation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d7dc12a5-67e6-476e-9eb8-54b338e338ef

📥 Commits

Reviewing files that changed from the base of the PR and between 41e03d1 and 6b7185d.

📒 Files selected for processing (4)
  • sdks/java/src/main/java/org/byteveda/taskito/DefaultTaskito.java
  • sdks/java/src/main/java/org/byteveda/taskito/resources/ResourceRuntime.java
  • sdks/java/test-support/src/main/java/org/byteveda/taskito/test/InMemoryQueueBackend.java
  • sdks/java/test-support/src/test/java/org/byteveda/taskito/test/InMemoryQueueBackendTest.java
🚧 Files skipped from review as they are similar to previous changes (2)
  • sdks/java/src/main/java/org/byteveda/taskito/resources/ResourceRuntime.java
  • sdks/java/src/main/java/org/byteveda/taskito/DefaultTaskito.java

The status fence was read outside the monitor requeueJob and claimNext hold, so a concurrent requeue could slip between the check and the transition.
@kartikeya-27
kartikeya-27 merged commit 71593e8 into master Jul 27, 2026
56 of 59 checks passed
@kartikeya-27
kartikeya-27 deleted the feat/java-admin-surface branch July 27, 2026 04:05
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.

Java: requeueJob and the admin surface

2 participants