Skip to content

refactor(reworks): deterministic ReworkCenter? do not merge#454

Draft
stephenkirk wants to merge 4 commits into
devfrom
steph/competitive-agent-refactor
Draft

refactor(reworks): deterministic ReworkCenter? do not merge#454
stephenkirk wants to merge 4 commits into
devfrom
steph/competitive-agent-refactor

Conversation

@stephenkirk
Copy link
Copy Markdown
Member

@stephenkirk stephenkirk commented Jun 4, 2026

A probably-overcomplex prototype of ReworkCenter that, in theory, doesn't desync: trades the old in-place center mutation for a frozen baseline + ledger + pure projection, so reworks stop depending on what order you clicked through the menu. Verified entirely against stubbed game globals, so trust it about as far as you'd trust any three-tier engine.

Allan please add details

… + ledger + pure projection)

Replace the in-place center-mutation model (mp_<layer>_<prop> smearing, the
"NULL" sentinel, prefix-scan restore, incremental rarity re-sort) with a
three-tier engine: a frozen deep-copied vanilla baseline, a normalized
override ledger, and G.P_* recomputed as a pure projection of
(table_id, key, active-layer-chain).

- ApplyReworks is the sole writer of G.P_*, run at run start (symmetric on
  both clients); idempotent under repeated/varied call history
- PreviewReworks computes into an isolated _PREVIEW_VIEW; menu + replay sites
  no longer mutate live center state (kills the asymmetric-preview desync),
  guarded by a _PREVIEW_ACTIVE phase check
- rebuild_rarity_pools rebuilds buckets wholesale with a stable (.order, key)
  sort so two clients land byte-identical regardless of call history
- LoadReworks kept as a thin shim -> ApplyReworks (~70 release.lua sites unchanged)
- migrate m_glass (numbers unchanged); add j_sixth_sense rarity rework under a
  now-defined release layer to exercise the rarity path
- add tests/test_rework_determinism.lua (30 checks: purity, preview isolation,
  rarity determinism, frozen-baseline immutability, SP modifier-drop)

Produced via a competitive multi-agent workflow. Verified: 9/9 luac, 30/30
determinism test, ruleset shape snapshot unchanged (10 pass / 4 known-stale fail).

Known caveats (pre-merge review): rarity-bucket membership assumes integer
rarities; preview_center proxy is __index-only; no live two-client engine
proof yet. Full migration of release.lua's ~58 joker reworks is follow-up.
…omments; recursive shape harness

- idol_rare: replace the j_mp_idol_rare reimpl with MP.ReworkCenter("j_idol",
  experimental: rarity 3 / cost 8); drop j_idol from banned_silent, list it in
  reworked_jokers for the info panel (vanilla keys skip the auto-mp_include graft,
  so it isn't pool-gated), remove the dead j_mp_idol_rare loc (en-us, ru)
- fix preview_center crash: Card:set_ability finds center_key by identity scan of
  G.P_CENTERS, which the preview proxy fails; set it from the key at the call site
- trim the LLM-verbose comments across the rework engine and definition files
  (cut old-model history + repeated determinism restatements; keep contracts)
- tests: lua_files_in now recurses (find) so rulesets/experimental/*.lua load;
  regenerate ruleset shape snapshot (15 rulesets, incl. WIP release ruleset)
@stephenkirk stephenkirk changed the title refactor(reworks): deterministic ReworkCenter (frozen baseline + ledger + projection) refactor(reworks): deterministic ReworkCenter? do not merge Jun 4, 2026
@stephenkirk stephenkirk marked this pull request as draft June 4, 2026 17:21
Game:start_run applies reworks but nothing reverted them on the way out, so
leaving a run left G.P_CENTERS holding the last run's reworked numbers — the
vanilla collection screen would show them until the next run started. Wrap
Game:main_menu (covers pause-quit / game-over / disconnect) to call
ApplyReworks(nil): empty layer chain rebuilds every owned prop and the rarity
pools from the frozen baseline. Idempotent, local cosmetic fix, not a desync.
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.

1 participant