Path: redb-tsak/changelog/worker-devlog-2026-03.md Snapshot: redb-tsak, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-tsak Page: https://redbase.app/src/dev-2026-12-06/redb-tsak/changelog/worker-devlog-2026-03.md ---- # redb.Tsak.Worker — Changelog ## 2026-03-15 (2): Collectible ALC Fix, Redb Store Schema Init ### ModuleAssemblyLoadContext.cs (redb.Tsak.Core) #### Fix: Collectible ALC incompatible with Reflection.Emit Modules loaded in a collectible `AssemblyLoadContext` crash at runtime when using `XmlSerializer`, compiled `Regex`, `System.Text.Json` source generators, or any other `Reflection.Emit`-based tool. The .NET runtime forbids non-collectible dynamic assemblies (generated by Emit) from referencing types in a collectible ALC. Changed `isCollectible` default from `true` to `false`. Added a configuration option `Tsak:HotReload:Collectible` (default `false`) so users who are certain their modules are Emit-free can opt in to full memory reclamation. Added `TryUnload()` — safe wrapper that calls `Unload()` only when collectible, no-op otherwise. All call sites in `HotReloadService` now use `TryUnload()`. ### HotReloadService.cs (redb.Tsak.Core) - All 6 `new ModuleAssemblyLoadContext(...)` calls now pass `_collectible` from options. - All 8 `.Unload()` calls replaced with `.TryUnload()`. - Leaked ALC counter (`_leakedAlcCount`) tracks non-collectible orphaned ALCs. - **Startup log** (Collectible=false): INFO — old module versions will not be unloaded. - **Per hot-swap log** (Collectible=false): WARNING — N orphaned ALC(s) in memory, not reclaimable until process restart. ### HotReloadOptions.cs (redb.Tsak.Core) New property: `Collectible` (bool, default `false`). ### TsakHostedService.cs (redb.Tsak.Worker) #### Fix: Redb storage schemes not registered before first use `InitializeAsync(ensureCreated: true)` only syncs schemes annotated with `[RedbSchemeAttribute]`. `TsakStateProps` and `TsakModuleProps` are plain classes — their schemes were never created, causing `InvalidOperationException` on first query. Added explicit `EnsureSchemeFromTypeAsync()` and `EnsureSchemeFromTypeAsync()` calls immediately after `InitializeAsync`. ### Configuration ```json "HotReload": { "Collectible": false } ``` | Collectible | Behavior | |---|---| | `false` (default) | Safe: compatible with XmlSerializer/Emit. Old ALCs stay in memory. | | `true` | Full unload: old module versions freed. Crashes if module uses Emit. | --- ## 2026-03-15: Storage & DI Fixes, Persistent Stores ### ServiceCollectionExtensions.cs #### Fix: Redb registration decoupled from Storage:Type Previously, `ConfigureRedb` checked `Storage:Type == InMemory` and returned early, which meant redb was never registered when the storage was in-memory — even if `Tsak:Redb:Provider` was explicitly configured. Routes and other components that depend on `IRedbService` failed silently. Now `ConfigureRedb` checks `Tsak:Redb:Provider` directly. Redb registers whenever a provider is set, regardless of the storage type. #### Fix: UsePostgres namespace conflict (Pro vs open-source) The file imported `redb.Postgres.Extensions` and `redb.MSSql.Extensions`, which exposed the open-source `UsePostgres`/`UseMSSql` extension methods. These conflicted with the Pro variants and threw at runtime when `isPro = true`. Switched to `redb.Postgres.Pro.Extensions` and `redb.MSSql.Pro.Extensions`. The Pro method internally falls back to open-source registration when `isPro = false`, so both license modes work correctly. #### Cleanup: Removed redundant ConfigureRedb call in ConfigureCluster A workaround call to `ConfigureRedb` inside `ConfigureCluster` is no longer needed since the primary `ConfigureRedb` in `AddTsak` now fires correctly. #### New: Redb-backed storage type `ConfigureStorage` now supports `Storage:Type = "Redb"` in addition to `"InMemory"`. When set, it registers `RedbTsakModuleStore` and `RedbTsakStateStore` — persistent implementations backed by the redb ORM. ### TsakHostedService.cs #### Fix: Safe IRedbService resolution Previously used `GetRequiredService()` gated by a `Storage:Type` check. If the config was inconsistent, this threw an unrecoverable exception at startup. Changed to `GetService()` with a null check. The hosted service now starts safely regardless of whether redb is registered in DI. ### RedbTsakStateStore.cs (redb.Tsak.Core — new file) Persistent `ITsakStateStore` implementation using redb ORM. - Schema: `RedbObject` - Key lookup: `ValueString` = state key (fast `WhereRedb` filter on `_objects` table) - Value: `Props.Value` (typed) + `Note` (mirror for admin visibility) - Scope management: `IServiceScopeFactory` → scoped `IRedbService` per operation ### RedbTsakModuleStore.cs (redb.Tsak.Core — new file) Persistent `ITsakModuleStore` implementation using redb ORM. - Schema: `RedbObject` - Key lookup: `ValueString` = module name - Status: `ValueLong` = `(long)TsakModuleStatus` (base-field for filtering) - Props: ModuleName, Version, Description, Dependencies, Status, AssemblyPath - Scope management: `IServiceScopeFactory` → scoped `IRedbService` per operation ### SqlDsl.cs (redb.Route.Sql) - `Param(string, IExpression)`: added `ArgumentNullException.ThrowIfNull(expression)` - `Param(string, object?)`: added comment documenting the `null → "" → DBNull.Value` chain ### RedbRouteExtensions.cs (redb.Route.Core) Added named redb instance support for routes: - `RegisterRedbService(context, name, instance)` — stores in context registry with `redb:` prefix - `GetRedbService(context, name)` — resolves by name, falls back to default `IRedbService` - Original `GetRedbService(context)` unchanged (backward compatible) --- ## Configuration Reference | `Tsak:Storage:Type` | `Tsak:Redb:Provider` | Module/State Store | Redb ORM Available | |----------------------|----------------------|-------------------------|--------------------| | `InMemory` | *(empty)* | In-memory | No | | `InMemory` | `postgres` / `mssql` | In-memory | Yes (for routes) | | `Redb` | `postgres` | **Persistent (redb)** | Yes | | `Redb` | `mssql` | **Persistent (redb)** | Yes | ### Enabling persistent storage ```json { "Tsak": { "Storage": { "Type": "Redb" }, "Redb": { "Provider": "postgres" } }, "ConnectionStrings": { "Postgres": "Host=localhost;Port=5432;Database=redb;Username=postgres;Password=..." } } ``` Schemas (`TsakStateProps`, `TsakModuleProps`) are created automatically on first access (standard redb ORM behavior). No manual migration required. ### Migration notes (InMemory → Redb) - **Module metadata**: re-discovered at startup via the standard module discovery pipeline. - **State entries**: start empty. Any transient state accumulated in-memory is not carried over. If specific state must survive the switch, export it beforehand via the state store API.