Repository navigation
feat(combat): deterministic Q32.32 damage resolver - #212
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
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. Comment |
a084db2 to
f7f70ab
Compare
d36b486 to
6811ff0
Compare
Move the PR #212 fixed-point type into astraweave-math, keep its arithmetic and tests, and hash the contract bytes as the required fixed64 replay case on the three-OS determinism workflow. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
4b7a5a7 to
e3f3f09
Compare
* feat(math): add canonical Q32.32 Fixed64 Move the PR #212 fixed-point type into astraweave-math, keep its arithmetic and tests, and hash the contract bytes as the required fixed64 replay case on the three-OS determinism workflow. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com> * chore: lock astraweave-math serde dependency Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com> * fix(sdk): link Windows sockets and profile libs in the C harness The Windows harness failed LNK2019 on WSAStartup, GetUserProfileDirectoryW, and NtReadFile because cl was not given ws2_32, userenv, or ntdll. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com> * fix: drop conflict markers from the math lock edge Keep both astraweave-gameplay and astraweave-math on astraweave-core's dev-dependencies after the rebase onto main. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
Design only. Locks an integer hyperbola, modifier floors, SimRng hit streams, and golden stage hashes for a future astraweave-combat crate. No engine code. Gate is Needs-human at r3. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
The approved design is now a crate: resolve_hit, resolve_heal, expected damage, effective health, RON tables with ceilings, an ECS tick, and save meta for sub-unit HP, poise, and the unused thread-strain hook. Fixed64 and SimRng are local seams until those types are on main. The default schools are physical, weave, and mundane hazards. AI estimates refuse hidden stats. The canonical hit hash is unchanged. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
Property tests use proptest seed 0xC0BA7E57. A three-OS workflow compares the seeded battle digest. The timer walk reuses a scratch buffer. The benchmark shard map includes astraweave-combat, which was why every shard failed validation. Legacy damage paths stay. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
PR #211 added astraweave_core::SimRng and no Fixed64. Combat re-exports the RNG, keeps the Q32.32 type, and leaves both golden hashes unchanged. combat_resolve is a required case of determinism-replay.yml. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
The verified commit is 9f75e24. Fixed64 remains local; combat_resolve is a required determinism-replay case. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
astraweave-combat's bench made the aggregate count 49. The workflow still required 48, so the merge was incomplete before the pre-existing shard timeouts. Section 23 records CI failures that PR #217's ledger does not cover. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
PR #245 owns the Q32.32 type. Combat keeps whole_raw because it returns CombatError. The stage hash and the battle digest are unchanged. fixed64 and combat_resolve are both required replay cases. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
The verified commit is be41362. Combat re-exports astraweave-math's type. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
The harness prints 0.4.0. PowerShell indexed that string with [0] and compared the character 0, so the job failed after the socket libs linked. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
The cl harness already links ws2_32, userenv, and ntdll. The CMake example did not, so it failed LNK2019 after the version gate passed. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
A landed hit on CCover enqueues an Impact on DestructionWorld. Weave schools are data in astraweave-weaving, sorted by school id. The Aravath slice deals sword 25, a weave rating of 15, and breaks the cover bond. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
The verified commit is df4b07b. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
This tree is the feat/destruction crate so combat can enqueue impacts. Delete it from this branch once PR #243 is the single copy. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
Fixed64 is the math type. The destruction crate stays until PR #243. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
b897afa to
5bc0030
Compare
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
Note
Copilot was unable to run its full agentic suite in this review.
Copilot review overview
3 open findings
defender_keepscurrently relies on a sentinel0keep-factor to terminate iteration and includes… · Newdefender_keepscurrently relies on a sentinel0keep-factor to terminate iteration and includes… · New The graph solver repeatedly uses linear searches (iter().position) to mapnode.id -> index… · New
What changed in this PR
Introduces a deterministic Q32.32 combat damage resolver and a deterministic destruction subsystem, adds a weave “Aravath slice” integration path, and wires new determinism/benchmark CI coverage plus architecture documentation.
Changes:
- Added
astraweave-combatcrate (fixed-point resolver, sim RNG seam, tables/mods, save meta, ECS system, tests/benches). - Added
astraweave-destructioncrate (command log, support graph/fracture, terrain edits + voxel DAG, query jobs, debris, tests/bench). - Integrated weaving-side Aravath slice caller + element school application, updated docs and CI workflows for determinism/benchmark expectations.
| File | Description |
|---|---|
| docs/architecture/combat.md | Adds architecture trace documentation for the new combat damage system. |
| CLAUDE.md | Registers the new combat architecture trace in the docs index. |
| astraweave-weaving/src/lib.rs | Exposes new weaving modules and re-exports Aravath slice + element school API. |
| astraweave-weaving/src/damage.rs | Adds element school “data merge” helper into combat offense/defense components. |
| astraweave-weaving/src/aravath.rs | Adds an end-to-end slice wiring combat + destruction together with a regression test. |
| astraweave-weaving/examples/aravath_slice.rs | Adds a runnable example invoking the Aravath slice. |
| astraweave-weaving/Cargo.toml | Adds deps needed for Aravath slice and registers the example. |
| astraweave-ecs/src/archetype.rs | Adds append_entities_with_component helper used by combat scratch walking. |
| astraweave-destruction/Cargo.toml | Introduces the new destruction crate in the workspace. |
| astraweave-destruction/src/budget.rs | Adds fixed budgets for deterministic destruction simulation. |
| astraweave-destruction/src/command.rs | Adds deterministic destruction command log schema + serialization and validation. |
| astraweave-destruction/src/rng.rs | Adds deterministic per-command RNG derived from core sim seed system. |
| astraweave-destruction/src/graph.rs | Adds deterministic support graph solve + island assignment. |
| astraweave-destruction/src/octree.rs | Adds voxel DAG implementation and image-query helper for jobs. |
| astraweave-destruction/src/terrain.rs | Adds integer terrain edits and DAG rebuild hooks. |
| astraweave-destruction/src/jobs.rs | Adds deterministic multithreaded query pool over a published DAG image. |
| astraweave-destruction/src/fracture.rs | Adds deterministic fracture helpers + a baked gate asset hash lock test. |
| astraweave-destruction/src/debris.rs | Adds fixed debris pool and deterministic stepping over terrain. |
| astraweave-destruction/tests/tick_alloc.rs | Adds no-allocation-after-warm destruction tick test. |
| astraweave-destruction/tests/source_scan.rs | Adds simulation-source scan for banned float/map/clock usage. |
| astraweave-destruction/tests/frame_budget.rs | Adds frame budget timing test for collapse tick. |
| astraweave-destruction/benches/destruction.rs | Adds benchmark suite for destruction subsystems. |
| astraweave-core/src/sim.rs | Adds new system IDs for combat and destruction RNG streams. |
| astraweave-combat/Cargo.toml | Introduces the new combat crate and its dependencies/benches/tests. |
| astraweave-combat/src/lib.rs | Defines public API + errors and re-exports for combat crate modules. |
| astraweave-combat/src/fixed.rs | Re-exports Fixed64 and provides range-check conversion helper. |
| astraweave-combat/src/sim_rng.rs | Adds hit RNG construction using core SimRng and system ID folding. |
| astraweave-combat/src/tables.rs | Adds combat table parsing/validation/mod-apply + semantic hashing. |
| astraweave-combat/src/resolve.rs | Adds deterministic hit/heal resolution and AI estimate helpers. |
| astraweave-combat/src/save.rs | Adds save meta encoding/decoding for vitals and table-hash gating. |
| astraweave-combat/src/ecs.rs | Adds ECS components and the simulation-stage combat resolve system. |
| astraweave-combat/src/logic_tests.rs | Adds logic/regression tests (golden hash, lore safety, save meta, ordering, etc.). |
| astraweave-combat/src/property_tests.rs | Adds proptest-driven properties with fixed seed. |
| astraweave-combat/tests/no_alloc.rs | Adds global-allocator allocation guard tests for resolver and timer-walk. |
| astraweave-combat/tests/replay_hash.rs | Adds replay hash generation for determinism compare workflow. |
| astraweave-combat/benches/resolve_hit.rs | Adds criterion benchmarks for resolve_hit + allocation assertions. |
| Cargo.toml | Adds new crates to workspace members and dependency list. |
| .github/workflows/determinism-replay.yml | Adds combat replay hash generation and merge step; adds required case. |
| .github/workflows/sdk-ci.yml | Fixes Windows version parsing and adds required link libs + error checks. |
| .github/workflows/benchmark.yml | Updates benchmark accounting counts for added crates. |
| .github/workflows/benchmark_alert.yml | Updates benchmark alert accounting counts for added crates. |
| .github/scripts/benchmark-runner.sh | Adds new crates into benchmark shard grouping. |
🧠 Review effort: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| fn defender_keeps( | ||
| tables: &CombatTables, | ||
| def: &DefenderView<'_>, | ||
| ) -> Result<[u32; MAX_MODIFIERS], CombatError> { | ||
| let mut buf = [Modifier { | ||
| id: 0, | ||
| kind: ModifierKind::DefenderReduceBp, | ||
| bp_or_flat: 0, | ||
| }; MAX_MODIFIERS]; | ||
| let mut n = 0usize; |
| // Trailing 10_000 entries are not iterated: caller uses a separate count. | ||
| // Pack the count into keeps by returning only the prefix via a second value. | ||
| let _ = tables; | ||
| let _ = count; | ||
| // Rewrite: return pair. This function's signature is the array only so the | ||
| // loop in the caller would also multiply identity factors. Store count in | ||
| // a sentinel by using 0 as "stop" — 0 is not a legal keep (min keep is 1000). | ||
| if count < MAX_MODIFIERS { | ||
| keeps[count] = 0; | ||
| } | ||
| Ok(keeps) | ||
| } |
| } else { | ||
| continue; | ||
| }; | ||
| let Some(other_index) = self.nodes.iter().position(|node| node.id == other) |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5bc00302ce
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if due_len < MAX_DUE { | ||
| due[due_len] = self.pending[index]; | ||
| due_len += 1; | ||
| } | ||
| self.pending.swap_remove(index); |
There was a problem hiding this comment.
Retain commands beyond the fixed due batch
When more than 16 commands target the current tick—possible from the combat bridge alone because it can emit up to 32 cover impacts—this loop removes every due command from pending but copies only the first 16 into due. The overflow is therefore silently discarded rather than applied, logged, or deferred, permanently losing destruction events; leave excess commands pending for a later tick or reject them at enqueue time.
Useful? React with 👍 / 👎.
| area, | ||
| }) | ||
| } | ||
| _ => return Err(CommandError::ZeroExtent), |
There was a problem hiding this comment.
Decode every command kind written to the save log
push_command serializes Detach, Anchor, and Weave as tags 4, 5, and 8, but read_command has no corresponding match arms and reaches this error branch. Consequently, DestructionWorld::restore fails for any valid persisted world that has applied one of those public command kinds, including the newly added weave integration.
Useful? React with 👍 / 👎.
| CommandKind::Explosion(explosion) if explosion.radius.raw() <= 0 => { | ||
| Err(CommandError::ZeroExtent) | ||
| } | ||
| CommandKind::Weave(weave) if weave.radius == 0 => Err(CommandError::ZeroExtent), |
There was a problem hiding this comment.
Bound the work performed by weave commands
A Weave command validates any nonzero u16 radius, so an untrusted or mod-authored command with a large radius is accepted and later drives the cubic loops in Terrain::apply_density_delta; at radius 65,535 that is effectively a simulation hang even though brush commands are capped by MAX_BRUSH_CELLS. Apply an equivalent cell/work ceiling to weave radii during validation.
Useful? React with 👍 / 👎.
| if m.kind != ModifierKind::AttackerBonusBp || m.id >= USER_MOD_ID_LIMIT { | ||
| return Err(CombatError::ModifierCeiling); | ||
| } |
There was a problem hiding this comment.
Filter out modifiers that belong to the opposite role
Because each combatant has one shared CModifiers component, an entity can legitimately carry both offensive and defensive effects. If that entity attacks while it has a DefenderReduceBp or FlatAbsorb entry, attacker_factors returns ModifierCeiling instead of ignoring the unrelated entry; the ECS system then silently drops that hit because it only special-cases DoubleWrite. Filter by modifier kind before validating attacker-specific entries, as the flat-absorb path already does.
Useful? React with 👍 / 👎.
| let (cmd, next) = read_command(&bytes[cursor..], index as u32)?; | ||
| cursor += next; | ||
| world.enqueue_preserving_seq(cmd)?; |
There was a problem hiding this comment.
Restore the next command sequence number
After loading a save containing commands, next_seq remains at its constructor value of 1 because replayed commands are inserted without advancing it. The next call to enqueue therefore reuses an old sequence number, making its logged bytes and state hash differ from the uninterrupted world and potentially changing same-tick ordering when pending commands exist; restore next_seq to one past the maximum persisted sequence.
Useful? React with 👍 / 👎.
| RollMode::Expected { .. } => { | ||
| let expect = 10_000 + i128::from(chance) * (i128::from(mult) - 10_000) / 10_000; | ||
| run.raw = mul_div(run.raw, expect, 10_000, &mut run.saturated)?; |
There was a problem hiding this comment.
Apply guaranteed critical hits in expected damage
For an ability with always_crit = true, the rolled path always applies the critical multiplier, but this expected-value branch only weights the multiplier by the attacker's ordinary crit chance. With zero precision, for example, expected_hit reports entirely non-critical damage even though every real hit is critical, which can mislead AI target and ability selection; use the full multiplier when the ability is guaranteed to crit.
Useful? React with 👍 / 👎.
* docs: destruction archaeology and design for review Map the existing physics, terrain, mesh, and damage code, and propose a new astraweave-destruction crate with thin physics and terrain hooks. Phase 2 waits on review of this design. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com> * feat(math): add canonical Q32.32 Fixed64 Move the PR #212 fixed-point type into astraweave-math, keep its arithmetic and tests, and hash the contract bytes as the required fixed64 replay case on the three-OS determinism workflow. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com> * chore: lock astraweave-math serde dependency Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com> * feat(destruction): deterministic command log, collapse, and replay Add astraweave-destruction on Fixed64: ordered commands, an 8-iteration load push, seeded fracture, integer terrain deltas, and a 256-slot debris pool. The 300-tick Aravath demolition is a required three-OS replay case. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com> * docs: record the destruction trace against 9ad8001 Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com> * feat(destruction): sparse voxel DAG, query jobs, and log persistence Fold the core directives into the sim: edited chunks rebuild a shared voxel DAG, occupancy queries merge in fixed order on two workers, and spawn, weave, and brush commands restore a structure from the log. Navigation receives integer geometry notices. GPU stays off the sim. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com> * fix(sdk): link Windows sockets and profile libs in the C harness The Windows harness failed LNK2019 on WSAStartup, GetUserProfileDirectoryW, and NtReadFile because cl was not given ws2_32, userenv, or ntdll. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com> * feat(destruction): prefracture hash, zero-alloc ticks, 11 ms collapse Lock the bake digest, cut a dynamic node once with a seeded plane, and prove warmed ticks allocate nothing. The scripted collapse tick stays inside 11 ms. The old physics DestructionManager is deferred as issue #255. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com> * fix(destruction): publish real bounds for a structural collapse A collapse GeometryNotice used the placeholder box (0,0,0)-(1,1,1). The notice now unions floor(pos-half) and ceil(pos+half) for pieces that became dynamic in that solve. A bridge-span test covers the drop. The destruction replay digest changes on purpose; fixed64 does not. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com> * docs: record the destruction trace against 7a57104 Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com> * fix(fmt): order imports in the Aravath destruction example The gate rustfmt check rejects the debris import sitting below the grouped destruction import. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>

Description
Implements the approved combat damage design. The PR stays a draft. Base is PR #245 (
cursor/fixed64-math-8aec). #245 merges tomainfirst, then this PR.astraweave-destructionon this branch is a temporary copy of PR #243. Drop that copy when #243 lands. The greybox wiring that callsrun_aravath_sliceis the stacked draft PR #275, based on #205.astraweave-combatis a Q32.32 resolver:Fixed64isastraweave_math::Fixed64. Combat re-exports it and keepswhole_raw.071dc70e116987782a8a8b137a6cce648d390a82967726775308946f1e69da71.combat_resolveSHA-256, unchanged:975aae72e3c83a2335be05142eea2bf2ae4413d621fc5009ed6019f89e2a6e52.fixed64,perception_world, andplanner_purestay required replay cases besidecombat_resolve.CCoverrecords a fixed-capacity impulse and enqueues anImpactonDestructionWorld.astraweave-weaving.run_aravath_slicedeals sword 25, a weave rating of 15, and breaks the cover bond.Gate Decision Card: Pass, reviewer both, 2026-10-14.
Type of change
Security Considerations
astraweave-destructionis the temporary path copy of PR feat(destruction): replay, prefracture, and collapse bounds #243. No new third-party crates.Checklist