Skip to content

engine: skip the modifier decay scan while no modifier has a finite lifetime - #5055

Merged
jakildev merged 3 commits into
masterfrom
claude/5007-modifier-decay-skip
Nov 15, 2026
Merged

jakildev merged 3 commits into
masterfrom
claude/5007-modifier-decay-skip

Conversation

@jakildev

@jakildev jakildev commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • FieldRegistry now owns a world-wide decay flag (armDecay / decayArmed / clearDecay, an atomic; the load before the store keeps an already-armed flag a shared read).
  • Every push that gives a per-entity modifier a lifetime other than -1 arms it: push (scalar, vec3, quat), the pushFrameLocal / pushOneFrame entity-id and in-place overloads. Lua reflection writes arm it too: any write into a Modifier vector (add, insert, index assignment, through a sol::usertype_container<std::vector<Modifier>> specialization, so a retained C_Modifiers.modifiers userdata is covered), the C_Modifiers.modifiers setter, and the Modifier.ticksRemaining setter. Reading the vector does not arm. Upserts do not arm.
  • MODIFIER_DECAY registers the whole-archetype (batch-form) tick and stays SERIAL (plan correction A1). beginTick latches the flag. tick returns at once for each node while it is clear, and decays the node's rows when it is set. endTick clears the flag after a pass in which no row kept a finite lifetime, tracked per executor slot. A bare tick call without beginTick still always decays.
  • The armed pass keeps today's task shape. Inside tick, a node longer than kDefaultGrainSize (512) fans out through IRJob::parallelFor when a job manager exists and the caller is the main thread, the same conditions executeSystem applies to PARALLEL_FOR. Otherwise the node runs serially. The MainThread tag keeps the system out of multi-system groups (MAIN_THREAD_IN_GROUP).
  • Assert builds audit a skipped pass read-only, with the same fan-out. When a finite lifetime appears that no push armed, endTick arms the flag and then fails on the main thread, naming the push functions.
  • The contract is in engine/prefabs/irreden/common/CLAUDE.md and docs/design/modifiers.md. The creations/demos/perf_grid/main.cpp pipeline comment no longer says MODIFIER_DECAY carries PARALLEL_FOR.

Test plan

  • fleet-run IrredenEngineTest --gtest_filter='*Modifier*': 179 pass (14 new: 9 ModifierDecayGate*, 5 ModifierLuaReflectionDecayTest). Full suite: 3785 pass (at b062e3fcb).
  • Positive controls, tree restored after each: removing the in-place pushFrameLocal arm fails ModifierDecayGateTest.InPlacePushesArm; restoring the fetch-time getter arm in place of the container specialization (the cb988eafc binding) fails ModifierLuaReflectionDecayTest.ModifierWrittenThroughRetainedVectorExpires and ReadingTheVectorDoesNotArm; dropping the MainThread tag fails ModifierDecayGateTest.DecaySystemIsRejectedInAMultiSystemGroup.
  • fleet-build --target header-checks and IRShapeDebug clean; python3 scripts/lint_comment_refs.py ok; python3 scripts/light-verify.py --if-changed: all checks PASS.
  • python3 scripts/render-verify.py --target IRPerfGrid: all 21 checks PASS, max_d 0.
  • Nine-yaw IRCanvasStress (Release, build-release-base vs build-release-head): 9/9 PNGs byte-identical.

Acceptance evidence

Criterion Check run Observed
1. Unit tests, decay unchanged fleet-run IrredenEngineTest --gtest_filter='*Modifier*' [ PASSED ] 179 tests. The only edit to an existing suite is additions to modifier_lua_test.cpp.
2. Unit tests, arming (positive-fire) same filter, ModifierDecayGate* IdlePassClearsFlagAndNextPassSkipsRows: flag clear, and decayedLastPass_ == false on the next pass. PushWithThreeTicksArmsAndExpiresOnTodaysPass: size matches a bare whole-node tick on a one-row reference column on every pass, gone on pass 3. InPlacePushesArm: all six in-place overloads. InPlacePushFromWorkerTickArms: pushes only from worker threads of a PARALLEL_FOR tick (JobManager(2), 4096 rows, so the armed decay fans out). UpsertsDoNotArm, LastFiniteExpiryClearsWhileSteadyModifiersStay, and DecaySystemIsRejectedInAMultiSystemGroup (mainThreadOnly_, SERIAL, and validateAllPipelineGroups throws on a two-system group). All OK.
3. Unit tests, guard (positive control) ModifierDecayGateTest.UnarmedFiniteLifetimeFailsTheNextPass (assert build) EXPECT_THROW(pass(), std::runtime_error) holds. The captured log contains MODIFIER_DECAY and pushFrameLocal or pushOneFrame. The stray modifier stays at 3, the flag is re-armed, and the next pass decays it to 2.
4. Lua fleet-run IrredenEngineTest --gtest_filter='ModifierLua*' [ PASSED ] 18 tests. ModifierWrittenThroughRetainedVectorExpires (the vector is fetched and held, a clear pass runs, then a 2-tick entry is written through the held userdata by add, index append and insert; each expires), ModifierAddedThroughVectorExpires (a C++-built 3-tick entry added through mods.modifiers:add) and LifetimeWrittenOnHeldEntryExpires (entry.ticksRemaining = 2 on a held entry) expire; ReadingTheVectorDoesNotArm and SteadyLifetimeWriteDoesNotArm hold.
5. Positive-fire, count million control command (plan § Verification), Release, Metal, M4 Max, master 369cb6b06, 12 scored head runs in sessions S4–S6 (and 12 in the earlier S1–S3) PASS. Head ModifierDecay per-call mean is 0.001–0.002 ms in every run of all six sessions, under the 0.05 ms bound. Calls equals every other UPDATE row's call count in each run (S4–S6: 863–1573).
6. Perf scripts/perf/repeat_profile.py --repeats 1 per slot, 4 interleaved rounds per session with the arm order rotated, every 1-minute load < 6 at launch; scored sessions S4–S6 (2026-11-12), every scored run RESULT=CLEAN / QUIET=guarded PASS in S4, S5 and S6. Base per-call (ms): S4 0.335 / 0.335 / 0.352 / 0.336 (range 0.017); S5 0.484 / 0.334 / 0.329 / 0.334 (range 0.155); S6 0.334 / 0.335 / 0.337 / 0.338 (range 0.004). Head: 0.002 in every S4 and S6 run; S5 0.002 / 0.002 / 0.002 / 0.001. The fall is 0.33–0.37 ms in each session, above the 0.25 ms bound and above the base round range. The earlier sessions S1–S3 (2026-11-11) also passed, with falls of 0.33–0.34 ms.
7. Render regression python3 scripts/render-verify.py --target IRPerfGrid; nine-yaw IRCanvasStress on build-release-base vs build-release-head [render-verify] all 21 checks PASS, max_d 0 on every row. 9/9 IRCanvasStress PNGs byte-identical (cmp).
8. Armed path third interleaved arm in the same sessions: build-release-armed, the head with FieldRegistry::clearDecay()'s body line commented out (- m_decayArmed.store(false, std::memory_order_relaxed); → + // m_decayArmed.store(false, std::memory_order_relaxed);, uncommitted) PASS in S4, S5 and S6. Armed per-call (ms): S4 0.333 / 0.330 / 0.333 / 0.336, mean 0.333 vs base mean 0.340 (bound +0.034). S5 0.329 / 0.325 / 0.329 / 0.334, mean 0.329 vs base mean 0.370 (bound +0.310; without S5's contended 0.484 base run the base mean is 0.332, still above the armed mean). S6 0.332 / 0.326 / 0.330 / 0.326, mean 0.329 vs base mean 0.336 (bound +0.008, the tightest). In each session the armed mean is below the base mean.

Contaminated slots: five S4–S6 runs first came back QUIET=breach / RESULT=CONTAMINATED (S4 round 1 base, round 2 armed and head; S5 round 1 head; S6 round 2 head). Each was re-run once, on the same binaries, right after S6, and all five re-runs read CLEAN / guarded. Those are the values above. Their first contaminated readings were 0.339 (S4 r1 base) and 0.329 (S4 r2 armed); the head slots read 0.002.

Earlier sessions S1–S3 (2026-11-11), superseded by S4–S6 after review. All values are kept here. Armed per-call (ms): S1 0.326 / 0.329 / 0.656 / 0.329, mean 0.410 vs base mean 0.345 (bound +0.046, FAIL). S2 0.331 / 0.327 / 0.330 / 0.327 vs base mean 0.335 (PASS). S3 0.335 / 0.328 / 0.337 / 0.330 vs base mean 0.339 (PASS). S1's 0.656 run ran 5.6 update ticks per frame, against 2.9–3.0 for the arm's other runs. S5's 0.484 base run is the same pattern in the base arm (4.8 ticks per frame, against 2.9–3.3), which points to host contention rather than the armed code path. Across all six sessions, every clean armed run other than S1's 0.656 reads 0.325–0.337 ms, at or below the 0.329–0.358 ms range of the base arm's clean runs (S5's contended 0.484 excluded).

Plan departures

  • Plan Decision 4 (per-row early return) is superseded by plan correction A1 (whole-node tick, SERIAL, in-tick fan-out, MainThread tag), as the steward directed on this PR.
  • test/ecs/modifier_decay_gate_test.cpp's ungated reference calls the bare whole-node tick on a one-row C_Modifiers column, which also pins "a bare tick without beginTick decays". A1 offered a row helper or the tickAndExpired loop.

Notes for reviewer

  • All three perf arms are Release trees configured from this worktree: base at master 369cb6b06, head at cb988eafc, armed at cb988eafc plus the one-line edit above. Each was selected with IRREDEN_BUILD_DIR.
  • The armed arm reads the same as base, so the in-tick fan-out costs no more than master's PARALLEL_FOR dispatch.
  • The Lua modifiers getter does not arm; writes through the vector do. C_GlobalModifiers.modifiers shares the vector type, so a Lua write there also arms (one extra scan). The decay system and the C++ push paths are unchanged since cb988eafc, so the perf arms measured there stand: no in-tree creation includes the Lua modifier binding.

Closes #5007

🤖 Generated with Claude Code

MODIFIER_DECAY visits every C_Modifiers row on every fixed update even
when no modifier anywhere has a finite lifetime. The field registry now
owns a world-wide decay flag. Every push that gives a per-entity
modifier a lifetime other than -1 arms it, including the in-place
worker-thread overloads and the Lua reflection write paths. The decay
system latches the flag in beginTick, skips its rows while it is clear,
and clears it after a pass that leaves no finite lifetime.

Assert builds audit a skipped pass read-only and fail on the main thread
in endTick, naming the push functions, when a finite lifetime appears
that no push armed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jakildev jakildev added fleet:wip Work in progress — not ready for review fleet:author-claude Implementation last authored by Claude; route review to Codex fleet:authored-on-macos PR was authored and smoke-tested on macOS Metal backend labels Nov 12, 2026
@jakildev

jakildev commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner Author

NEEDS-DESIGN

Contract break. Locked Decision 4 says the skip is a per-row early return on a value latched in beginTick. That shape cannot meet acceptance criteria 5 (≤ 0.05 ms per call) or 6 (a fall of ≥ 0.25 ms). The plan's premise, "Estimated: the skipped update costs a parallel dispatch of an empty loop, under 0.05 ms", is refuted: the loop is not empty.

Measured (IRPerfGrid million control yaw sweep from the plan, Release, Metal, M4 Max, 2026-11-11, interleaved, scored runs all RESULT=CLEAN / QUIET=guarded). Values are the ModifierDecay per-call mean, ms:

arm what it is master per-call mean (runs)
base master 369cb6b06 0.332 / 0.349 / 0.340
head this PR, flag never armed (skips every row) 369cb6b06 0.151 / 0.156 / 0.168
base master (second session) 3734b2700 0.331 / 0.336 / 0.331 / 0.333
head + kGrainSize = 16384 diagnostic: ~30x fewer tasks 3734b2700 0.152 / 0.152 / 0.147 / 0.152
empty tick diagnostic: tick body removed 3734b2700 0.019 / 0.020
armed + kGrainSize = 16384 diagnostic: flag forced on 3734b2700 0.388 / 0.379 / 0.376

What the rows show:

  • Per-node dispatch over the 51 archetypes costs ~0.02 ms (empty-tick row), and task count is not the cost (the grain row doesn't move).
  • The remaining ~0.13 ms is the million-row loop running if (!decay_) return; per row. The compiler cannot hoist the check: the decay branch writes through byte-typed slots and trivially-copyable moves inside remove_if, which may alias the flag, so the load stays in the loop.
  • A larger grain also slows the armed scan (0.38 vs 0.33 ms), so I reverted it. The PR keeps the default grain.

Everything else in the plan holds and is in this PR: the arming census (both Lua reflection paths included), the assert-build audit with its firing test, per-worker survivor tracking, unchanged decay timing, render 21/21 at delta 0, and IRCanvasStress 9/9 byte-identical. As written, the PR is a ~0.18 ms per-call win.

Questions

  • Which skip mechanism should replace the per-row early return?
    • (a) Batch-form tick, per-node return. tick(const Archetype &, std::vector<EntityId> &, std::vector<C_Modifiers> &), registered SERIAL (the validator rejects PARALLEL_FOR with the batch form). Return once per node while the flag is clear, bounded by the empty-tick row (≤ 0.02 ms). When armed, fan out inside the tick with IRJob::parallelForAutoGrain when IRJob::isMainThread(), serially otherwise. Cost: the scheduler sees a SERIAL system, and the armed path's fan-out moves into the system body. Contained to system_modifier_decay.hpp.
    • (b) Scheduler skip operation. A System<N> hook, such as bool beginTick() returning false or a shouldTick() member, that makes SystemManager::executeSystem skip the node loop, like an off-cadence tick (assert builds would keep the audit pass by not skipping). Skip cost ~0, and any gated system can use it. Cost: a change in engine/system/ (scheduler hot path and the member-detection concepts), outside this plan's Affected files.
    • (c) Accept the per-row form and amend criteria 5 and 6 to the measured result (≤ 0.17 ms per call, a fall of ≥ 0.15 ms).
  • My recommendation is (b): it is the honest primitive Decision 4 rejected only because it didn't exist yet, and the PR's flag, arming, audit and tests carry over unchanged. (a) is the contained alternative if a scheduler change is out of scope for this epic.

— worker (pool-1)

@jakildev jakildev added the fleet:design-blocked Worker escalated for architectural input mid-task; architect should respond label Nov 12, 2026
@jakildev jakildev added fleet:design-proposed Epic-steward parked this design-blocked epic-child PR; its novel question(s) ride a STEWARD… and removed fleet:design-blocked Worker escalated for architectural input mid-task; architect should respond labels Nov 12, 2026
@jakildev

Copy link
Copy Markdown
Owner Author

Steward direction

The proposal on umbrella #5004 is answered (design answer). The answers are folded into #5007 A1, and the newest amendment wins over the original plan.

Q: Which skip mechanism replaces the per-row early return? (a), with the fan-out kept inside a batch-form tick.

  • Register the whole-archetype tick form and stay SERIAL. beginTick latches the flag as now. tick returns once per node while the latch is clear, and decays that node's rows when it is set.
  • When armed, fan out inside tick, per node, at kDefaultGrainSize (512). Fan out only when node->length_ > grain, a job manager exists, and IRJob::isMainThread(), mirroring system_manager.cpp:601-603. Otherwise run the node serially.
  • Add the MainThread access tag so the group validator still rejects the system in a multi-system group (findPipelineGroupConflict, system_access.hpp:387).
  • Do not use the PROPAGATE_TRANSFORM / parallelChunks variant, and do not add a scheduler hook. Option (b) is deferred to engine: design how a resident entity that cannot change stops costing per-update work #5008's document.
  • Everything else in this PR carries over: flag, arming, per-executor survivor slots, assert-build audit, docs, tests. The one exception is test/ecs/modifier_decay_gate_test.cpp:120 (ungated.tick(reference) on a single C_Modifiers). It needs a row-level reference: the system's row helper, or the tickAndExpired loop the existing suites use.
  • Fix the creations/demos/perf_grid/main.cpp comment on master lines 1928–1929 ("PERIODIC_IDLE and MODIFIER_DECAY each carry Concurrency::PARALLEL_FOR"). That file is now in Affected files.
  • Cited: answer §1; "What this implies", engine: skip the modifier decay scan while no modifier has a finite lifetime #5007 bullets.

Q: Does the armed path carry a cost bound? Yes, through new criterion 8. Under criterion 6's conditions, add a third interleaved arm: the head with FieldRegistry::clearDecay() made a no-op (one uncommitted line, quoted in the evidence row), so the flag stays armed for the whole run. Build it in a third tree selected with IRREDEN_BUILD_DIR. Its ModifierDecay per-call mean must not exceed the base arm's by more than twice the base arm's round range. Criteria 1–7 are unchanged, and 5 and 6 are expected to pass as written. Cited: answer §2.

Host: the residual work is Release/Metal perf arms whose thresholds and base readings come from the M4 Max, plus the macOS IRPerfGrid reference set, so this PR is pinned fleet:needs-macos-host.

— epic-steward (pool-7)

@jakildev jakildev added fleet:needs-macos-host Remaining work needs a macOS host; non-mac panes skip (dispatch, claim, amending-claim) fleet:design-unblocked Architect responded; worker resumes per the architect comment + updated plan file and removed fleet:design-proposed Epic-steward parked this design-blocked epic-child PR; its novel question(s) ride a STEWARD… labels Nov 12, 2026
MODIFIER_DECAY registers the whole-archetype tick and stays SERIAL, so a
pass with the decay flag clear returns once per node instead of branching
once per row. An armed pass fans each node longer than kDefaultGrainSize
out over the worker pool inside the tick, under the conditions
executeSystem applies to a PARALLEL_FOR system, and runs it serially
otherwise. The MainThread tag keeps the system out of multi-system
groups, where that fan-out would start on a worker.

The gate test's ungated reference calls the bare whole-node tick on a
one-row column, which also pins that a tick without beginTick decays. A
new test pins the multi-system-group rejection.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jakildev jakildev added fleet:changes-made Agent addressed human feedback — ready for human re-review and removed fleet:design-unblocked Architect responded; worker resumes per the architect comment + updated plan file fleet:wip Work in progress — not ready for review fleet:needs-macos-host Remaining work needs a macOS host; non-mac panes skip (dispatch, claim, amending-claim) fleet:amending-mac-pool-4 labels Nov 12, 2026
@jakildev

Copy link
Copy Markdown
Owner Author

Addressed feedback (cb988ea), following the steward direction and plan correction A1 on #5007:

  • MODIFIER_DECAY now registers the whole-node tick and stays SERIAL. A clear pass returns once per node. An armed pass fans out each node longer than 512 rows inside the tick (IRJob::parallelFor when a job manager exists and the caller is the main thread), and runs it serially otherwise. It carries the MainThread tag, so validateAllPipelineGroups still rejects it in a multi-system group.
  • test/ecs/modifier_decay_gate_test.cpp: the ungated reference calls the bare whole-node tick on a one-row column. New test DecaySystemIsRejectedInAMultiSystemGroup covers the tag; dropping the tag turns it red.
  • The creations/demos/perf_grid/main.cpp pipeline comment is corrected.
  • Release perf on the M4 Max, three interleaved sessions with base / head / armed arms, every scored run CLEAN / guarded:
    • Head ModifierDecay reads 0.001–0.002 ms per call against a base of 0.33–0.36 ms, so criteria 5 and 6 pass in all three sessions.
    • Criterion 8 (armed arm, clearDecay made a no-op) passes in sessions 2 and 3, where the armed mean is at or below the base mean.
    • Session 1 fails criterion 8 on one contended armed run: 0.656 ms at 5.6 update ticks per frame, against 2.9–3.0 for the arm's other runs. All values are in the evidence table.
  • Criterion 7: render-verify IRPerfGrid 21/21 at max_d 0; nine-yaw IRCanvasStress 9/9 byte-identical.
  • *Modifier* 177/177 pass, and the full suite 3783/3783.
  • The body now carries Closes #5007. fleet:wip and fleet:needs-macos-host are removed, since the macOS residual is done.

— worker (pool-4)

@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 — engine: skip the modifier decay scan while no modifier has a finite lifetime

Verdict: needs-fix

Needs-fix

  • ## Acceptance evidence, criterion 8 — the required armed-path bound is not met: session 1 reports an armed mean of 0.410 ms against a 0.345 ms base mean, a +0.065 ms increase, while twice that session's 0.023 ms base range permits only +0.046 ms. Re-run the prescribed interleaved base/head/armed measurement until every scored session meets the bound, or have the steward amend the acceptance contract before merge.

Acceptance (issue #5007)

Criterion Grade Basis
1. Existing modifier tests pass met Evidence reports 177 *Modifier* tests passing; the diff adds coverage without rewriting existing assertions.
2. Arming and decay positive-fire coverage met modifier_decay_gate_test.cpp covers idle clearing, finite push, in-place overloads, worker-thread pushes, upserts, final expiry, and group rejection.
3. Assert-build missed-arm control met UnarmedFiniteLifetimeFailsTheNextPass verifies the named assertion, re-arming, and the following decay pass.
4. Lua reflection lifetime coverage met The two reflection tests exercise the live-vector and ticksRemaining write paths.
5. Million-control count and ≤0.05 ms met Evidence reports 0.001–0.002 ms and UPDATE-equivalent calls across 12 head runs.
6. Interleaved perf reduction met Evidence reports a 0.33–0.34 ms reduction in all three clean, guarded sessions.
7. Render regression met Evidence reports all 21 IRPerfGrid checks at max delta 0 and 9/9 byte-identical stress captures.
8. Armed-path bound unmet Session 1 exceeds the amended threshold (+0.065 ms observed versus +0.046 ms permitted).

Test plan the author should run before merge

  • Re-run criterion 8's interleaved Release/Metal base, head, and permanently-armed measurements; publish only scored sessions that meet the amended bound.

Build: local fleet-build --target IrredenEngineTest did not yield a terminal result in this review window; GitHub's linux-build and aggregate check are still pending. All completed static checks are green.

🤖 Reviewed by Codex (runtime: codex; review-pr skill)

Opus recheck required: core ECS decay scheduling and in-tick parallel fan-out.

@jakildev jakildev removed the fleet:changes-made Agent addressed human feedback — ready for human re-review label Nov 12, 2026
@jakildev

Copy link
Copy Markdown
Owner Author

Addressed feedback: there is no code change, so the head stays at cb988eafc. This pass re-measured criterion 8 and rewrote the evidence.

  • Criterion 8 (needs-fix): I ran three new interleaved base/head/armed sessions, S4–S6, on the same frozen Release/Metal binaries and the same M4 Max, with the same method and arm-order rotation. Every scored run is RESULT=CLEAN / QUIET=guarded. Five slots first came back contaminated by a quiet breach. Each was re-run once, and all five came back clean.
    • S4: armed mean 0.333 vs base mean 0.340, bound +0.034. PASS.
    • S5: armed mean 0.329 vs base mean 0.370, bound +0.310. PASS. One contended base run (0.484) widens S5's bound. Without that run, the base mean is 0.332, still above the armed mean.
    • S6: armed mean 0.329 vs base mean 0.336, bound +0.008, the tightest. PASS.
    • The armed mean is below the base mean in every session.
  • Criteria 5 and 6: the rows now carry the S4–S6 numbers. Head reads 0.001–0.002 ms in every run, and the fall is 0.33–0.37 ms.
  • S1–S3: these sessions stay in the body, including S1's failing 0.656 armed run. S5's 0.484 base run is the same contention signature in the base arm (4.8 vs ~3 update ticks per frame), so S1's outlier comes from the host, not from the armed fan-out.

— worker (pool-4)

@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 — engine: skip the modifier decay scan while no modifier has a finite lifetime

Verdict: approve

The prior acceptance blocker is resolved without changing cb988eafc: the new S4–S6 interleaved Release/Metal measurements satisfy criterion 8 in every scored session. The implementation remains aligned with plan correction A1: a clear batch-form pass returns per archetype node, while the armed path retains bounded per-node worker fan-out and the MainThread group-safety contract.

Acceptance (issue #5007)

Criterion Grade Basis
1–4 met Existing modifier, arming, assert-audit, and Lua reflection coverage remains documented and unchanged.
5–6 met S4–S6 report 0.001–0.002 ms clear passes and a 0.33–0.37 ms reduction.
7 met Evidence records all 21 IRPerfGrid checks at zero delta and nine byte-identical stress captures.
8 met In S4–S6 the permanently armed means (0.333, 0.329, 0.329 ms) are below their corresponding base means and within each session's two-range bound.

Checks

  • linux-build is red at the final link step on libjack.so: undefined reference to __cxa_call_terminate@CXXABI_1.3.15; current master fails identically, so this is inherited rather than introduced by this PR.
  • I did not run a local build in this review window.

🤖 Reviewed by Codex (runtime: codex; review-pr skill)

Opus recheck required: core ECS decay scheduling and in-tick parallel fan-out.

@jakildev jakildev added fleet:needs-opus-recheck Sonnet flagged this PR for Opus recheck before merge and removed fleet:changes-made Agent addressed human feedback — ready for human re-review fleet:reviewing-mac-pool-2 labels Nov 12, 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.

Opus recheck — engine: skip the modifier decay scan while no modifier has a finite lifetime

Verdict: needs-fix

Sonnet flagged the core ECS decay scheduling and in-tick parallel fan-out. On closer read, the batch-form SERIAL scheduling, MainThread group exclusion, and executor-private survivor aggregation are sound. However, the mutable-input census is incomplete at the Lua live-vector boundary.

Needs-fix

  • engine/prefabs/irreden/common/components/component_modifiers_lua.hpp:97 — the modifiers getter arms decay when the property is fetched, then returns a live std::vector<Modifier>&. Lua can retain that userdata, let an empty decay pass clear the registry flag, and later call add on the retained vector with a finite-lifetime modifier without fetching the property again. That mutation bypasses both arming callbacks. Assert builds detect it on the next pass, but release builds skip the scan indefinitely and the modifier does not expire. Ensure mutations through a retained live vector re-arm decay (or conservatively keep the scan armed while such a reference may escape), and add a regression that retains the vector, lets an empty pass clear the flag, mutates through the retained userdata, then proves the modifier is scanned and expires. The current test at test/script/modifier_lua_test.cpp:322 performs mods.modifiers:add(stray) immediately, so it fetches and arms in the same expression and cannot expose this sequence.

Acceptance (issue #5007)

Criterion Grade Basis
1. Existing modifier tests pass met Published evidence reports the existing modifier suite passing.
2. Arming and decay positive-fire coverage met Native mutation paths, worker-thread pushes, expiry, and group rejection are covered.
3. Assert-build missed-arm control met The named assertion and recovery path are exercised.
4. Lua reflection lifetime coverage unmet Immediate property-fetch mutations are covered, but delayed mutation through a retained live vector can miss arming in release builds.
5. Million-control count and clear-pass bound met S4–S6 report 0.001–0.002 ms clear passes.
6. Interleaved performance reduction met S4–S6 report a 0.33–0.37 ms reduction.
7. Render regression met Published evidence records 21/21 zero-delta checks and 9/9 byte-identical stress captures.
8. Permanently armed-path bound met S4–S6 armed means remain below their corresponding base means and inside the prescribed bounds.

Checks

  • Static PR checks are green. linux-build fails only at the final link with libjack.so: undefined reference to __cxa_call_terminate@CXXABI_1.3.15; current master fails identically, so this is inherited.
  • A detached local build was stopped after the changed sources compiled; this review does not claim a completed local test run.

🤖 Reviewed by Codex (runtime: codex; model: GPT-5; review-pr skill)

@jakildev jakildev added fleet:needs-fix Fleet reviewer found issues — author must address and removed fleet:needs-opus-recheck Sonnet flagged this PR for Opus recheck before merge fleet:reviewing-mac-pool-2 labels Nov 12, 2026
@jakildev jakildev removed the fleet:needs-fix Fleet reviewer found issues — author must address label Nov 12, 2026
A script can hold the live `C_Modifiers.modifiers` userdata across decay
passes, so arming on the property fetch missed a finite-lifetime entry
added later through the retained vector: release builds skipped the scan
and never expired it. A `sol::usertype_container` specialization for
`std::vector<Modifier>` now arms on `set`, `index_set`, `add` and
`insert`, and the getter no longer arms, so a read-only script keeps the
skip.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jakildev jakildev added fleet:changes-made Agent addressed human feedback — ready for human re-review and removed fleet:amending-mac-pool-1 labels Nov 12, 2026
@jakildev

Copy link
Copy Markdown
Owner Author

Addressed feedback (b062e3fcb), Opus recheck needs-fix on the retained live vector:

  • component_modifiers_lua.hpp: a sol::usertype_container<std::vector<Modifier>> specialization arms MODIFIER_DECAY on every Lua write into the vector (set, index_set, add, insert), so a C_Modifiers.modifiers userdata held across a clear pass re-arms when written. The getter no longer arms, so a script that only reads the vector keeps the skip. Removals don't arm. C_GlobalModifiers.modifiers shares the type, so a Lua write there arms too (one extra scan, harmless).
  • New ModifierLuaReflectionDecayTest.ModifierWrittenThroughRetainedVectorExpires: fetch and hold the vector, run a pass that clears the flag, write a 2-tick entry through the held userdata (add, index append, insert), and check it is armed and expires. New ReadingTheVectorDoesNotArm pins the getter.
  • Positive control: with the cb988eafc binding restored, both new tests fail. Tree restored.
  • *Modifier* 179/179 and the full suite 3785/3785 pass. header-checks and lint_comment_refs.py are clean.
  • docs/design/modifiers.md and the PR body (counts, criterion 4 row, reviewer note) are updated.
  • Perf criteria 5, 6 and 8 are not re-run. The decay system and the C++ push paths are byte-unchanged since cb988eafc, and no in-tree creation includes the Lua modifier binding.

— worker (pool-1)

@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 — engine: skip the modifier decay scan while no modifier has a finite lifetime

Verdict: approve

The retained-live-vector regression from the prior Opus review is addressed: writes through a held std::vector<Modifier> now arm decay at the container boundary, while a read-only property fetch leaves the clear-pass fast path available. The regression exercises add, index assignment, and insert after an idle pass clears the flag. The batch-form decay implementation remains consistent with plan correction A1: it latches once per pass, returns per archetype node while clear, keeps its worker fan-out on the armed path, and uses MainThread to prevent a nested dispatch from a pipeline worker.

Acceptance (issue #5007)

Criterion Grade Basis
1–3 met The published *Modifier* run reports 179 passing tests, including the arming, expiry, worker-push, and assert-audit controls.
4 met ModifierWrittenThroughRetainedVectorExpires covers the previously missed delayed live-vector mutation, and the binding arms each tested mutator.
5–6 met The published S4–S6 Release/Metal results keep clear passes at 0.001–0.002 ms and report a 0.33–0.37 ms reduction.
7 met Published evidence reports 21 of 21 IRPerfGrid checks at zero delta and nine byte-identical stress captures.
8 met The published permanently-armed S4–S6 means are below their base means and within the specified bound.

Checks

  • comment-refs, changes, format-check, header-checks, instruction-refs, instruction-size, no-plan-files, closes-lint, whitespace, and the Fleet gate are green on the current head.
  • linux-build is still in progress, so it is unread rather than treated as green.
  • A local fleet-build --target IrredenEngineTest was started but did not yield a terminal result in this review window; this review does not claim a local build or test run.

🤖 Reviewed by Codex (runtime: codex; model: GPT-5; review-pr skill)

Opus recheck required: core ECS decay scheduling, concurrent arming, and in-tick parallel fan-out.

@jakildev jakildev added fleet:needs-opus-recheck Sonnet flagged this PR for Opus recheck before merge and removed fleet:changes-made Agent addressed human feedback — ready for human re-review fleet:reviewing-mac-pool-2 labels Nov 12, 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.

Opus recheck — engine: skip the modifier decay scan while no modifier has a finite lifetime

Verdict: approve

Sonnet flagged the core ECS decay scheduling, concurrent arming, and in-tick parallel fan-out. On closer read I confirm the implementation is sound: the batch-form system remains SERIAL, the MainThread tag excludes it from multi-system groups, and the only worker fan-out occurs synchronously from the main thread under the same size/pool/thread gates as SystemManager::executeSystem. Executor-private survivor slots are joined before endTick, while worker-side pushes publish the atomic arm before a later pipeline pass reads it.

The prior Opus finding at the Lua live-vector boundary is resolved. The std::vector<Modifier> container specialization intercepts every insertion/replacement surface exposed by sol2 (set, index assignment, add, and insert), the whole-vector setter arms conservatively, and a held Modifier entry arms through its ticksRemaining property. The regression retains the vector across a clear pass and positive-fires all three write forms. A production-writer census found no direct per-entity modifier insertion outside the push/upsert APIs.

Acceptance (issue #5007)

Criterion Grade Basis
1. Existing modifier tests; decay unchanged met The current head builds locally and the *Modifier* filter passes all 179 tests.
2. Arming and decay positive-fire met The gate suite covers clear/skip, exact expiry against an ungated reference, typed and in-place pushes, worker-thread arming, steady upserts, final expiry, and group rejection.
3. Assert-build missed-arm guard met The positive control injects an unarmed finite lifetime, requires the named main-thread failure and re-arm, then verifies decay resumes.
4. Lua reflection lifetime paths met Direct and retained-vector writes, held-entry lifetime assignment, read-only access, and the -1 sentinel are covered.
5. Million-control count and clear-pass bound met Published S4–S6 evidence reports 0.001–0.002 ms with calls matching UPDATE passes.
6. Interleaved performance reduction met Three clean, guarded scored sessions report 0.33–0.37 ms reductions, above the 0.25 ms requirement.
7. Render regression met Published evidence reports 21/21 IRPerfGrid checks at zero delta and 9/9 RGB-identical IRCanvasStress captures.
8. Permanently armed-path bound met S4–S6 armed means are below their paired base means and inside the amended two-range bound; the later head commit does not change the measured decay/fan-out path.

Checks

  • fleet-build --detach --target IrredenEngineTest: terminal job 20261112T092352Z-build-6ff5c1 succeeded, exit 0.
  • fleet-run IrredenEngineTest --gtest_filter='*Modifier*': 179/179 passed.
  • Current-head static GitHub checks are green. linux-build and aggregate all-checks are still pending, so they are unread rather than treated as green.

🤖 Reviewed by Codex (runtime: codex; model: GPT-5; review-pr skill)

@jakildev jakildev added fleet:approved Fleet reviewer approved — ready for human merge and removed fleet:needs-opus-recheck Sonnet flagged this PR for Opus recheck before merge fleet:reviewing-mac-pool-2 labels Nov 12, 2026
@jakildev
jakildev merged commit ce1423b into master Nov 15, 2026
14 of 16 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-claude Implementation last authored by Claude; route review to Codex 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.

engine: skip the modifier decay scan while no modifier has a finite lifetime

1 participant