Skip to content

Simplified setup: AddTyphon(), DatabaseEngine.Open(), component registration #147

Closed
1 of 1 issue completed

Description

@nockawa

🔄 Re-scoped 2026-06-29

Parent: #146 · Granularity: Feature · Area: Execution

✅ Shipped: AddPagedMemoryMappedFile() correct spelling exists (Hosting/public/TyphonBuilderExtensions.cs:166); old AddPagedMemoryMappedFiled typo removed.

✅ Implemented & merged in PR #451 (2026-07-04) — the one-line-setup surface:

  • TyphonOptions fluent class with Register<T>() + RegisterArchetype<TArch>() (AOT-safe: concrete generic instantiations, no reflection / MakeGenericType)
  • services.AddTyphon(Action<TyphonOptions>) extension (wraps the ~7 internal Add* calls)
  • DatabaseEngine.Open(string, Action<TyphonOptions>, ILoggerFactory) static factory — owns + disposes a private ServiceProvider (teardown exception-guarded)
  • Wire component + archetype registration + InitializeArchetypes into engine init (post-build hook: AddTyphon decorates the DatabaseEngine descriptor)
  • TyphonOptions.ConfigureSpatialGrid(SpatialGridConfig) — applied via the same post-build hook, before InitializeArchetypes
  • Tests: DI path, factory path, multi-Register<T>, AOT-safety, power-user regression; individual Add* methods kept

Target:

services.AddTyphon(o => o.DatabaseFile("game.typhon").Register<Position>().RegisterArchetype<Player>());
using var dbe = DatabaseEngine.Open("game.typhon", o => o.Register<Position>().RegisterArchetype<Player>());

Design decisions (Q1–Q4) + the RegisterArchetype finding resolved 2026-07-03 — see design doc §9–§11.

Related Documents

Sub-issues

Sub-issues

1 of 1 Issues completed
Loading 1 sub-issues

Activity

  1. added theissue type on Jun 29, 2026
  2. updated Priority and Estimate on Jul 1, 2026
  3. moved this to Todo in Typhonon Jul 1, 2026
  4. moved this from Todo to In Progress in Typhonon Jul 3, 2026
  5. nockawa commented on Jul 3, 2026

    @nockawa
    CollaboratorAuthor

    Implementation plan (accepted — autonomous build)

    Scope: the #147 core surface (TyphonOptions + AddTyphon + Open). Options.Validate() (#148) and the .typhon bundle format (#450) are out of scope; DatabaseFile adopts .typhon as canonical now, mapping to today's .bin behavior (design §Q2). Decisions Q1–Q4 per design doc §9.

    Acceptance criteria

    1. TyphonOptions fluent class — AOT-safe Register<T>() where T:unmanaged (static closed-generic delegate to RegisterComponentFromAccessor<T>, no MakeGenericType/MakeGenericMethod); DatabaseFile(path); forwarders to the real sub-option types (no duplicate fields).
    2. services.AddTyphon(Action<TyphonOptions>) — composes the 7 internal Add* calls.
    3. DatabaseEngine.Open(string, Action<TyphonOptions>, ILoggerFactory) — owns + disposes a private ServiceProvider; using var dbe = Open(...) is leak-free.
    4. Component registration wired into engine init — AddTyphon decorates the DatabaseEngine descriptor; fires once at first resolve; power-user AddDatabaseEngine path untouched.
    5. Tests — DI, factory, multi-Register<T>, AOT-safety, power-user regression; individual Add* retained.

    Order of implementation

    TyphonOptions → AddTyphon + descriptor decoration → Open() + owned-provider disposal → tests → full-suite + code-review gate.

    Key implementation notes

    • AOT: Register<T> uses static dbe => dbe.RegisterComponentFromAccessor<T>() — one closed generic per T, zero captured state.
    • Post-build hook (§4a): decorate the DatabaseEngine ServiceDescriptor inside AddTyphon (capture inner factory → build → ApplyComponentRegistrations → return). Register-once (the method is not idempotent beyond its type HashSet).
    • Owned-provider disposal: engine's Dispose disposes _ownedProvider last, after IsDisposed = true — the provider's re-entrant dispose of the singleton engine short-circuits at the guard. MMF double-dispose is already idempotent (same as host-DI path today).

    Design: claude/design/Hosting/simplified-setup.md

  6. nockawa commented on Jul 3, 2026

    @nockawa
    CollaboratorAuthor

    ✅ Implemented — AC evidence (2026-07-03)

    Files: Hosting/public/TyphonOptions.cs (new), Hosting/public/DatabaseEngine.Open.cs (new), Hosting/public/TyphonBuilderExtensions.cs (AddTyphon + descriptor decoration), Ecs/public/DatabaseEngine.cs (owned-provider disposal in Dispose), test/…/Hosting/TyphonSetupTests.cs (new).

    AC Evidence
    1. TyphonOptions + AOT-safe Register<T> / RegisterArchetype<TArch> Static closed-generic delegates (RegisterComponentFromAccessor<T>, Archetype<TArch>.Touch()); no MakeGeneric*. Verified by review.
    2. AddTyphon composes the 7 Add* AddTyphon_DiPath_ResolvesWorkingEngine_WithRegisteredComponent — resolves a working engine, CompA round-trips.
    3. Open() owns + disposes its provider Open_FactoryPath_OwnsAndDisposesItsPrivateProvider — asserts the owned ServiceProvider throws ObjectDisposedException after Dispose (not just the .bin handle).
    4. Registration + InitializeArchetypes wired into engine init Descriptor decoration runs component reg → archetype touch → InitializeArchetypes, once at first resolve. Proven by the DI/multi-register tests spawning with no manual init.
    5. Tests incl. power-user regression PowerUser_ManualAddStarChain_StillBuildsEngine — manual Add* chain unaffected. AddTyphon_MultipleRegister_AllComponentsUsable.

    New fixture: 4/4 green (~200 ms). Full suite: 3977 passed, 34 skipped-by-design; the only failures are 4 pre-existing parallel-flaky lock-timeout tests (*WhenLockTimeout_DoesNotLeak*, UpdateField_EntryInRingBuffer_*) that pass in isolation — no code-path overlap with this change.

    Design decision surfaced + approved during impl: RegisterArchetype<TArch>() — registering components alone doesn't make user archetypes spawnable (InitializeArchetypes only wires archetypes in the registry). See design doc §10.

    Code review: independent pass — no Critical/High. Fixed: a false-positive AC3 test (asserted the .bin handle, which the engine releases regardless) → now asserts the owned provider is disposed; guarded the init-failure cleanup so it can't mask the original exception. Documented one deferred LOW: owned-provider disposal isn't exception-guarded against a throw during engine teardown (pre-existing Dispose structure; §11).

    Ready for review + commit. Not committed (per convention).

  7. nockawa commented on Jul 4, 2026

    @nockawa
    CollaboratorAuthor

    Dispose-hardening follow-ups 2026-07-04 (same branch, pending review + commit)

    Two robustness items from the §11 as-built review:

    6a — owned-provider disposal is now exception-guarded. DatabaseEngine.Dispose previously disposed _ownedProvider as its last statement, so a throw from an earlier teardown step (e.g. PersistEngineState on a full disk during the final checkpoint) skipped it and leaked the private container (watchdog + timer threads, allocator native memory) on the Open() path. Fixed: teardown is extracted to DisposeCore and runs inside a try; _ownedProvider is released in a finally (after IsDisposed = true, preserving the re-entrancy short-circuit; the provider disposal is itself guarded so it can't mask the original teardown exception, which still propagates). New test TyphonSetupTests.Open_TeardownThrows_StillDisposesOwnedProvider forces the throw via an internal ThrowInDisposeCoreForTest seam and asserts the provider is disposed anyway.

    5 — PagedMMF.Dispose is now null-safe against half-construction. An early ctor throw (e.g. options.Validate before Logger/_backpressureStrategy are assigned) still registers the node in the resource tree, so Dispose can run on a partially-built instance. Null-guarded Logger?. and _backpressureStrategy?. (the latter was already needed for the #450 legacy-artifact rejection path). Defense-in-depth — the #148 DI validator now preempts the reachable invalid-options path, but "Dispose never NREs on a half-constructed object" is a clean invariant to hold unconditionally.

    6b (AOT smoke test) — dropped, not deferred. On closer look it can't be isolated to the registration path: a minimal app still pulls in the whole engine, which isn't AOT-clean overall (e.g. Activator.CreateInstance in the MMF factory), so the test would fail for unrelated reasons. It only makes sense as the capstone of a broader "make Typhon AOT/trim-ready" effort. The Register<T>/RegisterArchetype<T> code stays structurally AOT-safe by construction (closed generics, no MakeGeneric*), verified by inspection.

    Full suite 3992 passed, 0 real failures (only the known lock-timeout parallel-flakes). Design doc §11 updated.

  8. moved this from In Progress to Done in Typhonon Jul 4, 2026
  9. added a commit that references this issue on Jul 4, 2026
  10. self-assigned this
    on Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Fields

Priority

P0-Critical

Estimate

S

Area

Execution

Start date

None yet

Target date

None yet

Product

Engine

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions