Skip to content

fix(#11212): the async executor counts as idle once waitCompletion() returns - #11217

Merged
lvca merged 1 commit into
mainfrom
fix/11212-async-idle-after-wait-completion
Nov 3, 2026
Merged

lvca merged 1 commit into
mainfrom
fix/11212-async-idle-after-wait-completion

Conversation

@lvca

@lvca lvca commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Fixes #11212.

Problem

Since #11191 waitCompletion() returns when the last marker counts its latch down. AsyncThread.executeTask called message.completed() (the countdown) before executingTask.set(nested), so isProcessing() asked right after the return could answer true with nothing left to run (5-48% of calls in the reporter's measurements). Dispatched commands had the same gap: commandCompleted() removed the sequence the barrier waits on before decrementing the count isProcessing() reads.

Fix

  • executeTask: completedTaskCount++ and the flag reset now happen before completed(), for every task. Every completed() override only signals a waiter (latch countdown, park signal), so whoever it releases - the waitCompletion() marker, scanType(), a browse iterator - finds the worker idle.
  • commandCompleted(): count first, then the set, the mirror of submitCommand()'s order.
  • Javadoc of waitCompletion() / isProcessing() states the restored post-condition, and that isProcessing() stays a point-in-time answer (it is not a durability predicate, and a task being taken off a queue at that instant can be missed while others submit).

This keeps the old post-condition rather than only documenting its loss, as the reporter offered: it is free (a reordering, no new state) and callers such as the Python bindings relied on it.

Tests

Issue11212IdleAfterWaitCompletionTest:

  • aTaskCompletionIsSignalledOnlyOnceTheWorkerCountsAsIdle: deterministic, asks isProcessing() from inside completed() (failed before the fix).
  • idleRightAfterWaitCompletionOfDispatchedCommands: 100 async DDL commands (failed before the fix).
  • the reporter's loop with 1 and 3 workers, and the same check after scanType().

Ran 270 tests (all com.arcadedb.database.async tests plus every *Async*, *GraphBatch*, Issue5665* and *WaitCompletion* engine test): all green.

Summary by CodeRabbit

  • Bug Fixes
    • Improved async task completion signaling so processing state and completion counts are updated before completion notifications. This makes executor status more reliable immediately after completion waits, when no new work is submitted.
    • Improved tracking of commands in flight as they complete.
  • Documentation
    • Clarified that processing status is a point-in-time indicator and does not confirm whether a worker batch has committed.

…returns

A worker counted the waitCompletion() marker's latch down before it dropped its
executing-task flag, so isProcessing() asked right after the return answered
true in up to half of the calls with nothing left to run (since #11191). The
worker now drops the flag before completed() releases any waiter, and a
dispatched command's in-flight count goes down before its sequence leaves the
set the barrier waits on.
@lvca lvca added this to the 26.11.1 milestone Nov 3, 2026
@lvca lvca self-assigned this Nov 3, 2026
@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

The async executor now updates task and command completion state before signaling completion. Its documentation clarifies the behavior and limits of isProcessing(). New regression tests check the reported state after completion-related waits and operations.

Changes: Async completion and idle state

Layer / File(s) Summary
Completion state and API contract
engine/src/main/java/com/arcadedb/database/async/DatabaseAsyncExecutor.java, engine/src/main/java/com/arcadedb/database/async/DatabaseAsyncExecutorImpl.java
The executor updates task state and the in-flight command count before completion signaling. The documentation describes when isProcessing() returns false and notes that its result is point-in-time and does not establish batch commit.
Idle-state regression tests
engine/src/test/java/com/arcadedb/database/async/Issue11212IdleAfterWaitCompletionTest.java
New tests check the reported processing state after task callbacks, waitCompletion(), dispatched commands, and scanType() calls. They also check callback and record counts, command errors, and timeouts.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: robfrank

Merge Risk: Minimal · up to 44419

Completion waits report idle under the stated conditions. No merge-blocking risk was identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the main change: the async executor reports idle after waitCompletion() returns. It is concise and specific.
Description check Passed The description explains the problem, motivation, implementation, related issue, and test coverage. It does not use the template headings and omits the checklist and Additional Notes section, but it p…
Linked Issues check Passed Issue #11212 requires completion ordering that makes the executor idle before a waiter observes completion, for worker tasks and dispatched commands, plus clear API documentation and regression tests.…
Out of Scope Changes check Passed The reviewed changes are limited to the async completion ordering, related waitCompletion() and isProcessing() documentation, and regression tests for issue #11212. The test coverage directly vali…
Full details: Description check

Explanation

The description explains the problem, motivation, implementation, related issue, and test coverage. It does not use the template headings and omits the checklist and Additional Notes section, but it provides the critical information needed for review.

Full details: Linked Issues check

Explanation

Issue #11212 requires completion ordering that makes the executor idle before a waiter observes completion, for worker tasks and dispatched commands, plus clear API documentation and regression tests. In DatabaseAsyncExecutorImpl, executeTask() now increments completedTaskCount and clears executingTask before message.completed(). commandCompleted() now decrements commandsInFlight before removing the sequence. The added Issue11212IdleAfterWaitCompletionTest covers the deterministic worker ordering, one and three workers, dispatched commands, and scanType(). The PR summary reports the required waitCompletion() and isProcessing() documentation updates. No unmet coding requirement is shown.

Full details: Out of Scope Changes check

Explanation

The reviewed changes are limited to the async completion ordering, related waitCompletion() and isProcessing() documentation, and regression tests for issue #11212. The test coverage directly validates the changed worker, command, and scan completion paths. No unrelated change is shown in the supplied whole-PR summary or focused diffs.

Full details: Docstring Coverage

Explanation

Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 5 functions across 3 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8f74bd49-31d7-4180-9095-9b446bdde9a8
Commits

Reviewing files that changed from the base of the PR and between 62e2e4f and 4441919.

Files selected for processing: 3
  • engine/src/main/java/com/arcadedb/database/async/DatabaseAsyncExecutor.java
  • engine/src/main/java/com/arcadedb/database/async/DatabaseAsyncExecutorImpl.java
  • engine/src/test/java/com/arcadedb/database/async/Issue11212IdleAfterWaitCompletionTest.java

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

@claude

claude Bot commented Nov 3, 2026

Copy link
Copy Markdown

Review: LGTM.

  • Fix: Moving completedTaskCount++ and executingTask.set(nested) ahead of message.completed() closes the window the issue describes. It also drops the try/finally. That is safe, because the state is now updated before completed() can throw. In commandCompleted(), decrementing the count before removing the sequence mirrors submitCommand(), as the PR says.
  • Javadoc: The caveats on isProcessing() (point-in-time answer, not a durability signal) are accurate.
  • Tests: The deterministic test, which asks isProcessing() from inside completed(), is a good regression guard. The loop tests cover the racy paths. Counting busy and asserting zero follows the CLAUDE.md guidance on not asserting wall-clock time.
  • Nit: ROUNDS * 50 and the 100 CREATE DOCUMENT TYPE commands are cheap enough. If these ever flake under load, tag them @Tag("slow").

I did not run the tests. No performance or security concerns.

@mergify

mergify Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@codacy-production

codacy-production Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity

Metric Results
Complexity 0

View in Codacy

🟢 Coverage 100.00% diff coverage

Metric Results
Coverage variation Report missing for b34a11b1
Diff coverage ✅ 100.00% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (b34a11b) Report Missing Report Missing Report Missing
Head commit (4441919) 292661 242490 82.86%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#11217) 4 4 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

1 Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@tae898

tae898 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Verified with the repro from #11212 (WaitCompletionThenIdle.java, unchanged), on the full lib set built from this PR's head 444191929d and from its merge base b34a11bc75 (engine build lines checked in each run), 2 cores, Temurin JDK 21 and 25, 2000 rounds of 50 createRecord calls per arm, parallel level 1 and 3:

JDK engine build parallel isProcessing() true right after waitCompletion() 1 ms later
21.0.12.1 base b34a11bc75 1 157 of 2000 1 of 2000
21.0.12.1 base b34a11bc75 3 617 of 2000 1 of 2000
21.0.12.1 head 444191929d 1 0 of 2000 0 of 2000
21.0.12.1 head 444191929d 3 0 of 2000 0 of 2000
25.0.5 base b34a11bc75 1 118 of 2000 0 of 2000
25.0.5 base b34a11bc75 3 544 of 2000 0 of 2000
25.0.5 head 444191929d 1 0 of 2000 0 of 2000
25.0.5 head 444191929d 3 0 of 2000 0 of 2000

Head: isProcessing() true right after waitCompletion() in 0 of 8000 rounds; base: 1436 of 8000. The post-condition the Python bindings relied on is back on both JDKs. Once this is merged I can drop the wait-for-idle workaround in the bindings' tests, and I can rerun this on any later head if that helps.

@codecov

codecov Bot commented Nov 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.37%. Comparing base (7399c0d) to head (4441919).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main   #11217      +/-   ##
============================================
- Coverage     79.39%   79.37%   -0.02%     
- Complexity     4960     4973      +13     
============================================
  Files          2325     2325              
  Lines        259803   259834      +31     
  Branches      56925    56937      +12     
============================================
- Hits         206261   206236      -25     
- Misses        32548    32588      +40     
- Partials      20994    21010      +16     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lvca
lvca merged commit 614090f into main Nov 3, 2026
39 of 42 checks passed
@lvca
lvca deleted the fix/11212-async-idle-after-wait-completion branch November 3, 2026 16:10
robfrank pushed a commit that referenced this pull request Nov 5, 2026
…returns (#11217)

A worker counted the waitCompletion() marker's latch down before it dropped its
executing-task flag, so isProcessing() asked right after the return answered
true in up to half of the calls with nothing left to run (since #11191). The
worker now drops the flag before completed() releases any waiter, and a
dispatched command's in-flight count goes down before its sequence leaves the
set the barrier waits on.

(cherry picked from commit 614090f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

waitCompletion() can return while isProcessing() still answers true for an instant (since #11191)

2 participants