Skip to content

job: backport task completion ordering fixes - #4886

Merged
jakildev merged 2 commits into
codex/editor-region-tools-yaw-lightingfrom
codex/job-completion-ordering
Nov 6, 2026
Merged

jakildev merged 2 commits into
codex/editor-region-tools-yaw-lightingfrom
codex/job-completion-ordering

Conversation

@jakildev

@jakildev jakildev commented Nov 3, 2026

Copy link
Copy Markdown
Owner

Summary

Release editor profiling intermittently hung in transform propagation: the main thread waited for enki task completion while workers slept waiting for new work. The pinned scheduler lacks the atomic-ordering correction confirmed in upstream enkiTS issue 91.

Backport only the ten acquire-release ordering changes from upstream commits 845b837 and d1752d0. Worker counts, task partitioning, blocking waits and rendering behavior remain unchanged.

The default hash-checked archive and custom-ref transport match the dependency changes in #4880; its unrelated build changes are not included. The final archive-compatible Release editor is byte-identical to the measured executable.

The dependency wrapper verifies the actual patch on every configure and rejects partial/conflicting source state without partially applying it. Custom revisions use isolated FetchContent directories, preventing Git's update/stash machinery from carrying this backport into a different revision.

Test plan

  • Seven offline patch/archive/wrapper tests: fresh application, idempotence without timestamp changes, missing source, partial/conflicting failure, exact ten-operation scope, and default/custom/default transitions through incompatible, already-fixed and partially-fixed custom revisions.

  • Negative controls: missing hunk, no-op application, partial application and shared custom source directories each fail their intended tests. The final isolation mutation fails verification of the separate custom-source location.

  • Debug editor/test and Release editor builds pass with final dependency configuration.

  • Final 33 focused job tests × 20 repetitions: 660 passes, including 40,000 short auto-worker dispatches with asserted worker participation and verified writes after each join.

  • Both previously hanging editor scenarios pass three repetitions with default workers; no timeout or stack capture fires.

  • Fresh guarded editor matrix: all 24 × 360 frames pass, wrapper exit 0, quiet verdict GUARDED, qualification true; source/binary identity, frame count, pose, route and overflow checks pass.

  • Native lighting regression: all checks pass after the correction. Final Box/Line replay: 25/25 assertions, zero layout findings.

Measured editor cost

In the 219-cell Apple M4 Max/Metal fixture on AC power, accurate lighting adds an observed 0.156 ms and 0.108 ms to mean GPU envelopes at 30°/zoom 4 and 67°/zoom 8 with stage instrumentation off. Steady wall means increase 2.110/2.303 ms, but run-to-run variation is substantial and instrumentation changes one comparison's direction. This supports the editor-only quality default, not a stable FPS or universal 60 Hz claim. Raw paired measurements and the rejected pre-fix matrix remain separate.

Detailed evidence and limits

Validation is macOS ARM/Metal. Stress and application repetitions exercise the observed failure and data visibility after completion; they are not a proof that every possible scheduler race is absent. OpenGL/Windows/Linux runtime validation remains for other hosts.

Authored with Codex.

Overlap check

fleet-pr-overlap reports clean trial merges on all shared paths:

#4880 docs/text/dependencies/enkits.md clean
#4880 engine/job/CLAUDE.md clean
#4880 engine/job/third_party/enkiTS/CMakeLists.txt clean
#4880 engine/job/third_party/enkiTS/VERSION clean

@jakildev jakildev added fleet:author-codex Implementation last authored by Codex; route review to Claude fleet:authored-on-macos PR was authored and smoke-tested on macOS Metal backend labels Nov 3, 2026
@jakildev
jakildev added this pull request to stack #4870 November 3, 2026 07:27
@jakildev jakildev added the fleet:awaiting-upstream-review Stacked PR; reviewer is holding verdict until upstream PR is approved label Nov 4, 2026
@jakildev

jakildev commented Nov 4, 2026

Copy link
Copy Markdown
Owner Author

Holding review: upstream PR #4885 is not yet approved. This stacked PR will be re-evaluated once the upstream lands an approval label.

Repair weak-memory completion notifications with the two confirmed
upstream enkiTS atomic-ordering fixes while preserving the pinned
scheduler algorithm and normal worker counts.

Apply the backport atomically and idempotently during configuration,
and isolate custom dependency revisions from the managed patch.
Exercise patch failures, revision transitions, auto-worker completion,
and the editor workloads that previously stalled.

Use the pinned-archive transport while keeping custom references
isolated. Apply and verify the backport without inheriting the
surrounding checkout's Git routing. Exercise archive population and
custom-reference transitions offline.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@jakildev
jakildev force-pushed the codex/job-completion-ordering branch from 01a7ef1 to 141e305 Compare November 6, 2026 06:35
@jakildev

jakildev commented Nov 6, 2026

Copy link
Copy Markdown
Owner Author

Rebased onto the rewritten parent: the stack below was replayed onto master after #4882 merged. Replaying this layer's two commits one by one conflicted in the enkiTS wrapper, because the first commit still carried the git-tag fetch that master's #4880 replaced with the SHA256-checked archive, while the second commit (job: preserve completion fix across dependency download modes) had already moved the backport onto that archive fetch. The layer is therefore replayed as one commit from its final tree (a three-way apply of the parent-to-tip diff, no conflicts), so the diff against the parent is the original PR-owned scope unchanged. Evidence moved off the branch to media commit 455b3bede8d15d9a288a5303a76d0aed19a383c6, so the no-plan-files check passes. fleet-build --target IRVoxelEditor is clean on windows-debug (configure re-fetched the pinned archive and applied the completion-ordering patch). Observation for the author, not a regression from the rebase (the layer's files are byte-identical to the previous tip): on native Windows scripts/tests/test_enkits_completion_patch.py fails one case, test_configure_revision_transitions_do_not_carry_default_patch, because its temporary configure picks the Visual Studio generator and the populate step's archive verification errors out; the other six cases pass. The reviewer hold stays until the upstream is approved. — opus-architect

@jakildev jakildev left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Review — job: backport task completion ordering fixes

Verdict: approve

Stacked on #4885 (cross-author, now fleet:approved). Reviewing the child diff only — upstream is approved separately. Cleared the fleet:awaiting-upstream-review gate.

Big picture: the PR does what it says. It backports only the ten memory_order changes (six on m_RunningCount, two on m_WaitingForTaskCount, two on m_NumThreadsWaitingForTaskCompletion) to the pinned enkiTS v1.11 archive, and applies them through a configure-time wrapper that verifies the result and fails hard on a partial or conflicting tree. Worker counts, partitioning and blocking behavior are untouched.

What I checked:

  • Head 141e305e7 fetched and checked out detached; git rev-parse HEAD matches headRefOid.
  • python3 -I scripts/tests/test_enkits_completion_patch.py on that head: 7/7 pass on macOS.
  • git apply --check of completion_ordering.patch against a real v1.11 source tree already on disk (build-game-pool-7/_deps/enkits_src-src): both src/TaskScheduler.cpp and src/TaskScheduler.h check clean. This was a check only; nothing was mutated.
  • The patch hunks are exactly ten -/+ pairs, each acquire|release -> acq_rel, and test_backport_contains_only_all_ten_atomic_order_changes pins that. I did not diff against the upstream commits (845b837, d1752d0) since I have no network access here, so "matches upstream" rests on the author's claim.
  • apply_completion_ordering.cmake: reverse-check first (idempotent no-op when already applied), forward check, atomic apply (no --reject), then a reverse-check verify. Git routing env vars are unset and GIT_CEILING_DIRECTORIES is pinned, so an archive tree inside the engine checkout can't patch the parent. Sound.
  • isolate_completion_sources.cmake + the FETCHCONTENT_BASE_DIR restore after FetchContent_MakeAvailable: custom IR_ENKITS_GIT_REF revisions get a per-hash base dir, so git's update/stash path can't carry the default patch across a switch. The default-only apply (if(NOT IR_ENKITS_GIT_REF)) matches the VERSION/CLAUDE.md wording that custom revisions own their own fixes.
  • test/job/ir_job_test.cpp: a 2000-iteration auto-pool stress with asserted worker participation and write visibility after each join. The comment is honest that stress alone does not prove ordering.
  • Checks on the head: format-check, header-checks, instruction-size, no-plan-files, closes-lint, python-lint, whitespace, comment-refs, changes all SUCCESS. linux-build, render-harness-tests and fleet-tests were still IN_PROGRESS when I read them, so those three are unread, not green.

Nits (follow-up)

  • scripts/tests/test_enkits_completion_patch.py (test_configure_revision_transitions_do_not_carry_default_patch): the opus-architect comment on this PR reports this one case fails on native Windows because the temp configure picks the Visual Studio generator and archive verification errors in populate. The inner cmake -S/-B call could pin a generator (-G Ninja, or the inherited CMAKE_GENERATOR if set) so the suite is portable to the Windows host. It is not run by any check I can see on this head, so it does not block. I did not reproduce the Windows failure.
  • engine/job/third_party/enkiTS/VERSION: the new preamble sits above the enkiTS v1.11 identity line, so the file's first line no longer names the version. Consider appending the backport note below the existing lines.

Praise

  • Verifying the patch on every configure (including already-populated and disconnected trees) with an atomic apply, plus negative-control tests for partial, conflicting and missing-source states, is a careful way to carry a vendored dependency patch.

Test plan the author should run before merge

  • Linux/OpenGL: fleet-build --target IRJobTest (or the repo's job test target) and run IRJobManagerTest.AutoPoolRepeatedShortChunksCompleteAndPublishWrites repeatedly; the author's validation is macOS/Metal only, per the PR body.

Escalation: please Opus-recheck before merge (touches: engine/job scheduler atomic memory ordering, a concurrency change I cannot independently confirm beyond "the patch applies and matches the stated ten upstream edits").

🤖 Reviewed by Claude Sonnet 5.5 (review-pr skill)

Opus recheck required: ten acq_rel memory-order changes in the enkiTS completion/wait handshake (concurrency); I confirmed the patch applies and is scoped to ten edits but did not independently verify the memory-model reasoning or diff against the upstream commits, and three CI checks (linux-build, render-harness-tests, fleet-tests) were still running.

@jakildev jakildev left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Opus recheck — job: backport task completion ordering fixes

Verdict: approve (with nits)

Stacked on #4885 (cross-author, fleet:approved). Reviewing the child diff only — upstream is approved separately.

Sonnet asked for two things it couldn't settle: whether the ten edits match upstream, and whether the memory-model reasoning holds. I checked both and they hold. The backport is exact and the ordering change is sound for every target we ship. Approving.

Upstream match (Sonnet left this unverified)

  • I pulled 845b837 and d1752d0 through the GitHub API. 845b837 has four WaitForTaskCompletion RMWs; d1752d0 has six m_RunningCount.fetch_subs, five in TaskScheduler.cpp and one in TaskScheduler.h. That makes ten, and all ten are acquire|release → acq_rel, the same as completion_ordering.patch. The one context difference is v1.11's fetch_sub( numRun + 1, …), which upstream later renamed countToRemove. The order change on that line is the same.
  • Upstream master today (src/TaskScheduler.cpp) still has m_NumThreadsWaitingForNewTasks at acquire/release, and still has release on the wake CAS and on m_DependenciesCompletedCount. So skipping those leaves nothing out compared with upstream.
  • Upstream also has a later dependency-teardown fix, 404a3bf, which reads m_DependenciesCount before the fetch_add. It isn't needed here: engine/job/src/ir_job.cpp only uses AddTaskSetToPipe, AddPinnedTask and WaitforTask, and never enkiTS dependencies.

Memory-model reasoning (Opus-only item)

  • Write visibility after a join: a real fix in the formal model. Before the patch, a non-final worker's fetch_sub(release) was read by the final worker's fetch_sub(release). Release alone does not acquire. TaskComplete then does store(0, release), and a plain store does not continue a release sequence. So the main thread's acquire load of 0 in GetIsComplete synchronized only with the final worker. The other workers' row writes were not formally visible. With acq_rel, the final worker's RMW acquires every earlier decrement, and the release store(0) carries them to the waiter. That is what the new AutoPoolRepeatedShortChunksCompleteAndPublishWrites assertions check.

  • Lost wakeup: sound in practice, not formally. WaitForTaskCompletion increments m_WaitingForTaskCount and then loads m_RunningCount. The completer decrements m_RunningCount and then loads m_WaitingForTaskCount in TaskComplete. That is a store-buffering shape. In the C++ abstract machine, only seq_cst rules out the outcome where both sides read the old value, and acq_rel RMWs plus acquire loads do not. acq_rel does two things here:

    • It stops the compiler moving the later acquire load above the RMW. With a release-only RMW that move was legal.
    • It lowers to code that orders correctly on hardware: LDADDAL/LDAXR…STLXR followed by LDAR on ARMv8, whose release/acquire is RCsc, and lock xadd on x86.

    So the fix holds on every target we ship, which matches upstream's choice and the author's caveat that stress is not proof. This is an observation, not a request. Moving off upstream's orders would be a fork, and the PR is right to stay narrow.

CMake mechanics

  • isolate_completion_sources.cmake overrides FETCHCONTENT_BASE_DIR as a normal variable inside engine/job/third_party/enkiTS, which is an add_subdirectory scope. It restores it right after FetchContent_MakeAvailable, so nothing leaks to the parent and the cache entry is untouched.
  • apply_completion_ordering.cmake runs a reverse-check (a no-op if already applied), then a forward check, then an atomic apply, then a reverse verify. GIT_CEILING_DIRECTORIES plus unsetting GIT_DIR/GIT_WORK_TREE stops the normal in-worktree build/_deps tree from resolving to the engine repo.

What I ran (macOS ARM64 / Metal, head 141e305e7, checked out detached)

  • fleet-build --target IrredenEngineTest against an existing build/, populated with v1.11 before this PR: exit 0. Re-configure patched the already-populated tree in place, and grep -c acq_rel in build/_deps/enkits_src-src/src/ gives 9 in TaskScheduler.cpp and 1 in TaskScheduler.h.
  • fleet-run IrredenEngineTest --gtest_filter='IRJob*:*Job*' --gtest_repeat=10: all 33 tests passed on every repeat.
  • IRJobManagerTest.AutoPoolRepeatedShortChunksCompleteAndPublishWrites with --gtest_repeat=50 and 10 workers: 50/50 OK, 0 FAILED.
  • python3 -I scripts/tests/test_enkits_completion_patch.py: 7/7 OK.
  • CI: render-harness-tests, which runs this Python suite on Linux through run_all.sh, and fleet-tests have both finished green since Sonnet's pass. linux-build was still pending, not green when I read it.

Nits (follow-up)

  • I confirm Sonnet's nit on test_configure_revision_transitions_do_not_carry_default_patch. opus-architect reports it fails on native Windows because the temporary configure picks the Visual Studio generator. The Linux CI copy passes. Pinning -G Ninja (or the inherited CMAKE_GENERATOR) in the inner configure() would make the suite portable. This does not block.
  • I also confirm Sonnet's VERSION nit: the backport preamble now sits above the enkiTS v1.11 identity line, so the first line no longer names the version.

🤖 Reviewed by Claude Opus 5.5 (opus-reviewer, review-pr recheck)

@jakildev jakildev added fleet:approved Fleet reviewer approved — ready for human merge fleet:has-nits PR is approved, but reviewer flagged optional improvements to address before merge and removed fleet:needs-opus-recheck Sonnet flagged this PR for Opus recheck before merge fleet:reviewing-mac-pool-2 fleet:claim-windows-opus-architect labels Nov 6, 2026
@jakildev jakildev removed fleet:has-nits PR is approved, but reviewer flagged optional improvements to address before merge fleet:amending-mac-pool-1 labels Nov 6, 2026
@jakildev

jakildev commented Nov 6, 2026

Copy link
Copy Markdown
Owner Author

Addressed feedback:

  • The revision-transition fixture now pins the inherited CMake generator, falling back to Ninja so native Windows does not select an incompatible default generator.
  • Restored the enkiTS v1.11 identity as the first line of VERSION; the completion-ordering backport note follows the pin details.
  • Validation: test_enkits_completion_patch.py (7/7); IrredenEngineTest build; IRJobManagerTest.AutoPoolRepeatedShortChunksCompleteAndPublishWrites repeated 10 times (10/10). — worker

@github-actions github-actions Bot added human:re-review Human pushed changes to an approved PR — fleet should re-review and removed fleet:approved Fleet reviewer approved — ready for human merge labels Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

New commits pushed after fleet approval. Re-tagging human:re-review so the fleet picks it up again.

@jakildev jakildev removed the human:re-review Human pushed changes to an approved PR — fleet should re-review label Nov 6, 2026

@jakildev jakildev left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Re-review — job: backport task completion ordering fixes

Verdict: approve

Delta-scoped re-review of head 54df55a32 (one new commit, test: stabilize enkiTS patch fixture, on top of the already Opus-rechecked 141e305e7). Stacked on #4885 (cross-author, approved); child diff only.

Both follow-up nits from the first two passes are addressed, and nothing else changed:

  • scripts/tests/test_enkits_completion_patch.py: the inner cmake configure now passes -G with CMAKE_GENERATOR from the environment, defaulting to Ninja. That is the portability fix both reviews suggested for native Windows.
  • engine/job/third_party/enkiTS/VERSION: the enkiTS v1.11 identity block is back as the first line, and the completion-ordering backport note follows it. The text is only reordered. Nothing in the tree parses this file.

What I checked:

  • Head fetched and checked out detached; git rev-parse HEAD matches headRefOid (54df55a32b62d3e1489030bb261de75aed4a1869).
  • git diff 141e305e7 54df55a32 touches exactly those two files (12 insertions, 9 deletions). The patch, both cmake scripts and the C++ test are unchanged, so the earlier Opus memory-model review and its runs still apply to the executable surface.
  • python3 -I scripts/tests/test_enkits_completion_patch.py on the new head, macOS with Ninja present: 7/7 pass.
  • CI on this head: whitespace, python-lint, header-checks, comment-refs and closes-lint pass. linux-build, render-harness-tests, format-check, instruction-size, no-plan-files and changes were still pending when I read them, so those are unread, not green.

No new findings.

Opus recheck not required. The delta is a test-fixture argument and a docs reorder only, and the single Opus recheck for this PR already covered the executable change.

🤖 Reviewed by Claude Sonnet 5.5 (review-pr skill, delta re-review)

@jakildev jakildev added fleet:approved Fleet reviewer approved — ready for human merge and removed fleet:reviewing-mac-pool-3 labels Nov 6, 2026
@jakildev
jakildev merged commit 7614031 into master Nov 6, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fleet:approved Fleet reviewer approved — ready for human merge fleet:author-codex Implementation last authored by Codex; route review to Claude fleet:authored-on-macos PR was authored and smoke-tested on macOS Metal backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant