Skip to content

Enforce StorageMode is fixed per (component, revision); fixes parallel-fixture data-loss - #547

Merged
nockawa merged 3 commits into
mainfrom
fix/530-followup
Jul 20, 2026
Merged

nockawa merged 3 commits into
mainfrom
fix/530-followup

Conversation

@nockawa

@nockawa nockawa commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

Problem

Enabling parallel test fixtures in Typhon.Engine.Tests (removing the bare [NonParallelizable] markers) surfaced one deterministic, silent-wrong-data failure: EntitySpawnTests.ReadAll_InheritedArchetype_IncludesParentComponents read back Health = 0 for an inherited archetype's own component (~1×/run).

Root cause: the cluster-layout fields (IsClusterEligible, ClusterLayout, entity-record size, slot masks) live on the process-shared ArchetypeMetadata, but they are derived from each engine's component StorageMode. A peer fixture that registered the same components as SingleVersion (via the test-only storageModeOverride) made the archetype cluster-eligible and stomped the shared metadata for a concurrent pure-Versioned engine — truncating the entity record so the child's own top slot read back as default (0). Inherited slots below it survived.

Fix — enforce the schema invariant instead of tolerating divergence

StorageMode is part of a component's schema identity: it is fixed per (component name, revision). The only thing that let two engines disagree for the same archetype was storageModeOverride, a test-only knob with no production caller. Rather than make the engine robust to an incoherent input, this PR makes the incoherent input impossible:

  • Removed storageModeOverride from RegisterComponentFromAccessor / RegisterComponentByType — StorageMode now comes solely from the [Component] attribute.
  • Reopen guard: re-declaring a persisted component at the same revision with a different StorageMode now throws (definition.Revision == persisted.Comp.SchemaRevision && declared != persisted). Changing the mode requires a [Component] revision bump.
  • Tests that faked SingleVersion via the override now use declared-SV twin types (SvEcsTestSchema): ChangeFilterTests, ViewDeltaTests, SubscriptionStressTests, OutputPhaseTests. Removed the now-obsolete StorageModeInfrastructureTests.Register_StorageModeOverride_OverridesAttribute.
  • New StorageModeRevisionLockTests verifies the guard via a two-session reopen (same name + revision, different mode ⇒ throws).

With this, an archetype's components resolve to the same StorageMode in every engine, so the shared cluster-layout fields are globally consistent — the stomp is impossible by construction, and the fields legitimately stay on the shared ArchetypeMetadata.

Testing

  • Full Typhon.Engine.Tests suite green: 4029 passed, 0 failed, 38 skipped.
  • New StorageModeRevisionLockTests covers the reopen enforcement.

Follow-ups (not in this PR)

  • Schema migration: support StorageMode change across a revision bump #546 — schema migration should support a StorageMode change across a revision bump (the sanctioned escape hatch is not yet wired end-to-end).
  • The [NonParallelizable] marker strip (the original motivation) is now unblocked but intentionally out of scope here.
  • Documentation (rules/ecs.md SCHEMA-01) lands in the separate typhon-claude repo (its own PR).

🤖 Generated with Claude Code

https://claude.ai/code/session_0166rY7C3gqgTJe1GbE9tA9P

@github-actions

Copy link
Copy Markdown
Contributor

📝 Doc-accuracy review (advisory · scoped · Layer 2)

Reviewed:

  • doc/feature-set/Ecs/storage-modes/README.md
  • doc/feature-set/Ecs/storage-modes/storage-mode-singleversion.md
  • doc/feature-set/Ecs/schema-versioning-migration.md
  • doc/feature-set/Ecs/ (remaining catalog entries — skimmed for gross contradictions)
  • doc/guide/01-first-app.md
  • doc/guide/02-modeling.md
  • doc/guide/using-with-ai-coding-agents.md
  • doc/in-depth-overview/06-ecs.md
  • doc/key-concepts/storage-mode.md
  • doc/key-concepts/component.md
  • doc/key-concepts/ (remaining pages — skimmed)

Findings:

  1. doc/feature-set/Ecs/storage-modes/README.md:23 ↔ src/Typhon.Engine/Ecs/public/DatabaseEngine.cs:2449

    "changing it requires recreating the database"

    The error message added by this PR tells users "increase the [Component] revision to change how the component is stored" — the opposite of "recreate the database." The doc should align with the error message.

    Suggested fix: Change "changing it requires recreating the database" → "changing it for a given (name, revision) requires bumping the [Component] revision; re-using the same revision with a different mode throws InvalidOperationException."

  2. doc/feature-set/Ecs/storage-modes/README.md:55 ↔ test/Typhon.Engine.Tests/Data/StorageModeInfrastructureTests.cs

    StorageModeInfrastructureTests — "[Component(StorageMode = ...)] attribute defaults/overrides, per-mode segment allocation differences"

    The Register_StorageModeOverride_OverridesAttribute test was deleted by this PR; the word "overrides" in the description is now stale (and describes a feature that no longer exists).

    Suggested fix: Remove "overrides" from the test description — e.g. "[Component(StorageMode = ...)] attribute defaults, per-mode segment allocation differences."


Map maintenance:

The following page is not in the scoped list but has significant drift from this PR and should be added to the map:

  • doc/in-depth-overview/04-schema.md — §5 "Registration flow" still documents the removed storageModeOverride parameter in both RegisterComponentFromAccessor<T>() (line 329) and RegisterComponentByType() (line 360) signatures, plus a "Storage mode override" prose section (lines 367–369) that explains the now-deleted behaviour. This page is the most detailed reference for RegisterComponent* and will mislead readers until it's updated.

Advisory & scoped to the pages the change touches — recall for cross-cutting or unmapped drift is covered by the weekly Layer 3 audit.

…sion); drop storageModeOverride from 04-schema + storage-modes docs; map 04-schema.md [no-ut]

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0166rY7C3gqgTJe1GbE9tA9P
@github-actions

Copy link
Copy Markdown
Contributor

📝 Doc-accuracy review (advisory · scoped · Layer 2)

Reviewed:

  • doc/in-depth-overview/04-schema.md — directly edited in this PR; updated correctly
  • doc/feature-set/Ecs/storage-modes/README.md — directly edited in this PR; updated correctly
  • doc/key-concepts/storage-mode.md
  • doc/key-concepts/component.md
  • doc/guide/01-first-app.md
  • doc/guide/02-modeling.md
  • doc/guide/using-with-ai-coding-agents.md
  • doc/in-depth-overview/06-ecs.md (excerpt)
  • Skimmed doc/feature-set/Ecs/storage-modes/storage-mode-*.md — no references to storageModeOverride or "immutable" found

Findings:

  • doc/key-concepts/storage-mode.md:11 ↔ src/Typhon.Engine/Ecs/public/DatabaseEngine.cs (reopen check added in this PR)

    "Set on the [Component] attribute and immutable after registration."

    The phrase "immutable after registration" is now inaccurate. This PR establishes that StorageMode is fixed for a given (name, revision) — it can be changed by bumping the [Component] revision. The sibling pages (storage-modes/README.md ¶ Guarantees, 04-schema.md §5) were both updated to "fixed for a given (name, revision)", but this key-concept page was not.

    Suggested fix: Replace the sentence opening with:

    "Fixed for a given (component name, revision) — to change the mode, bump the [Component] revision; re-using the same revision with a different mode throws InvalidOperationException on reopen."


Advisory & scoped to the pages the change touches — recall for cross-cutting or unmapped drift is covered by the weekly Layer 3 audit.

…gistration (key-concepts/storage-mode.md) [no-ut]

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0166rY7C3gqgTJe1GbE9tA9P
@github-actions

Copy link
Copy Markdown
Contributor

📝 Doc-accuracy review (advisory · scoped · Layer 2)

Reviewed:

Deep scrutiny (hand-written narrative):

  • doc/in-depth-overview/04-schema.md (edited in PR)
  • doc/key-concepts/storage-mode.md (edited in PR)
  • doc/in-depth-overview/06-ecs.md
  • doc/key-concepts/component.md
  • doc/key-concepts/database-engine.md
  • doc/key-concepts/archetype.md
  • doc/key-concepts/cluster-storage.md
  • doc/key-concepts/entity.md
  • doc/key-concepts/bulk-load.md
  • doc/key-concepts/component-collection.md
  • doc/key-concepts/entity-link.md
  • doc/key-concepts/view.md
  • doc/guide/01-first-app.md
  • doc/guide/02-modeling.md
  • doc/guide/using-with-ai-coding-agents.md

Skim for gross contradictions (feature-set catalog):

  • doc/feature-set/Ecs/storage-modes/README.md (edited in PR)
  • doc/feature-set/Ecs/storage-modes/storage-mode-singleversion.md
  • doc/feature-set/Ecs/storage-modes/storage-mode-versioned.md
  • doc/feature-set/Ecs/storage-modes/storage-mode-transient.md
  • doc/feature-set/Ecs/storage-modes/storage-mode-committed.md
  • doc/feature-set/Ecs/README.md
  • doc/feature-set/Ecs/schema-versioning-migration.md
  • doc/feature-set/Ecs/component-collections.md
  • doc/feature-set/Ecs/entity-archetype-model.md
  • doc/feature-set/Ecs/entity-clusters.md
  • doc/feature-set/Ecs/entity-lifecycle-crud/README.md
  • doc/feature-set/Ecs/entity-lifecycle-crud/batch-soa-spawn.md
  • doc/feature-set/Ecs/entity-lifecycle-crud/enable-disable-components.md
  • doc/feature-set/Ecs/entity-lifecycle-crud/generated-multi-component-accessors.md
  • doc/feature-set/Ecs/entity-relationships.md
  • doc/feature-set/Ecs/query-system.md
  • doc/feature-set/Ecs/reactive-views.md

No contradictions found in the reviewed pages.

The three pages edited by this PR (storage-modes/README.md, 04-schema.md, key-concepts/storage-mode.md) are all correctly updated to reflect the removal of storageModeOverride and the new (name, revision) mode-lock semantics. All other in-scope pages either do not mention StorageMode mutability or describe it in terms consistent with the new code. No other page retains the old "immutable after registration / requires recreating the database" language.

Advisory & scoped to the pages the change touches — recall for cross-cutting or unmapped drift is covered by the weekly Layer 3 audit.

@nockawa
nockawa merged commit 6cfb30f into main Jul 20, 2026
9 checks passed
@nockawa
nockawa deleted the fix/530-followup branch July 20, 2026 12:19
nockawa added a commit that referenced this pull request Jul 20, 2026
…eqlock stall (PR #550)

Fix page-cache seqlock stall: memory slots were reused without resetting the ModificationCounter, so the checkpoint spin-waited its 100ms skip timeout on a phantom writer (~650ms per engine close). Reset on reuse + guard CopyPageWithSeqlock against a stale odd counter on an unlatched page. Adds a regression test.

Parallelize the suite: strip [NonParallelizable] from fixtures whose only reason was the archetype-registry race (fixed upstream by #547). Isolate the 7 Durability fixtures' DBs into per-fixture temp dirs to remove parallel file-lock contention. Raise the default test page-cache 2→8 MiB. Keep NonParallelizable on the timing-sensitive Runtime fixtures.
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