Repository source: docs/concepts/read_model_rebuild.md
Derived read-model rebuild
Purpose: Reconstruct queryable site state from canonical records and their accepted history. Scenario: An operator runs rebuild or build-static; canonical content, attribution, reactions and activity evidence are derived into SQLite. Candidate-based CLI paths validate before promotion; some write-maintenance paths rebuild directly. A completed derivation is distinct from static release activation.
Availability (2026-11-09, rebuild availability): every full rebuild a write, a queued task or a page request starts builds a candidate beside the live file and renames it into place, so readers keep the old file until the new one is complete. A write that triggers a rebuild holds the write lock throughout. The queued rebuild builds without the lock and swaps under it; a candidate that missed commits during its build (ReadModelCandidateBehindHead) is rebuilt, and after two misses the last build runs under the lock. Page requests read with a 2-second wait and show the busy page when the file is locked. With a task worker available they never rebuild: a stale or behind-HEAD model keeps serving while a rebuild is queued, and an old schema shows the update page. Without a worker, a request still rebuilds, by swapping. A connection opened before a swap keeps reading the old file; RouteServices::pdo() reopens when the file changed.
Sources: builder (source unavailable), candidate validation (source unavailable), promotion (source unavailable), CLI (source unavailable), request handling (source unavailable) (ensureReadModel()), write-time rebuild (source unavailable) (rebuildReadModel()), queued rebuild (source unavailable), tests (source unavailable), queued-rebuild tests (source unavailable).
Known limitation: Several passes retain corpus-sized collections; the QDB audit documents evidence, not a delivered memory-capacity guarantee.
Commit indexing uses streamed raw tree changes for file counts, preserving Git's existing rename/merge defaults without computing line statistics. Activity evidence refresh uses a temporary file-backed manifest lookup shared across bounded batches, fetching only each action's source/signature/key paths. A failed manifest load rolls back its scratch transaction; missing history keeps existing fallback evidence. Scratch storage is removed after each refresh, including failures, and never becomes part of a read-model export or a later refresh. Full commit-detail views retain their existing manifest contract. See history evidence indexing for scratch lifetime, trust parity and measured workload limits.
Recent reader: Schema 42 adds posts_recent_idx for visible, non-retracted posts ordered by created_at/post_id. Startup compatibility rebuilds older derived models before the live Recent query; static deployments also require republishing. Bounded projections cap each page at 50 entries. Schema, compatibility tests (source unavailable).
Local capacity boundary: The normal-entry study reproduces a 128 MiB parsing failure at 40000 synthetic 2 KiB-body records, while retaining the prior live candidate-based model. A smaller fixture rebuild/publication succeeds. This is local PHP 8.1 evidence; PHP 8.3 host recovery and other corpus shapes remain unverified.
— Codex · 2026-11-01 UTC