fix(server): migrate persistence from KV to native DO SQLite#51
Open
kavinsood wants to merge 1 commit into
Open
fix(server): migrate persistence from KV to native DO SQLite#51kavinsood wants to merge 1 commit into
kavinsood wants to merge 1 commit into
Conversation
Phase A: Fix compaction death spiral - Split rewriteCheckpoint into 3 phases: chunk writes (non-txn), pointer swap (atomic small txn), cleanup (non-txn best-effort) - Add circuit breaker for consecutive compaction failures (max 3) - Make compaction errors visible (console.error + trace) - Add emergency /__yaos/compact admin endpoint Phase B: Native DO SQLite storage - New SqlDocStore using ctx.storage.sql with two tables: snapshot_chunks (chunked BLOB) and journal (append-only deltas) - Automatic KV-to-SQL migration on first load after deploy - Migration marker (_migration_meta table) for state disambiguation - ownedBuffer() helper enforces safe ArrayBuffer semantics for BLOBs - appendUpdate returns null for >1.5MB deltas (explicit size guard, not exception-driven), coordinator routes to checkpoint cleanly Hardening: - KV fallback if SQL load fails (read-only degraded mode, no SV echoes, no persistence attempts — fail-closed, not data-loss waiting room) - Admin routes (compact, cleanup-kv) gated behind YAOS_ENABLE_ADMIN_ROUTES - Observability: storageMode, migrationStatus, migrationMeta, coldLoadDurationMs, oversizedDeltaCount in /__yaos/debug response Tests: 145 new assertions across 5 test files - sql-doc-store.ts: CRUD, compaction, chunking, size guard (28) - sql-migration-edge-cases.ts: idempotence, equivalence, ArrayBuffer (56) - sql-oversized-delta-e2e.ts: coordinator fallback path (25) - admin-route-gating.ts: security surface validation (17) - chunked-doc-store.ts: existing 19 still pass Full CI: npm ci + build + test:ci + test:regressions + server typecheck = green
8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Migrates YAOS server persistence from the legacy Durable Object KV-style checkpoint/journal store to native DO SQLite.
This fixes the compaction death-spiral class of bugs by replacing multi-key journal/checkpoint orchestration with SQL-backed snapshot chunks and append-only journal rows.
Major changes
SqlDocStore(native DO SQLite, two tables:snapshot_chunks+journal)_migration_metamarker to distinguish room statesappendUpdatereturns null for >1.5MB, coordinator routes to checkpoint)ownedBuffer()BLOB safety helper (prevents ArrayBuffer misuse)YAOS_ENABLE_ADMIN_ROUTESenv var/__yaos/debugresponseengineering/sql-storage-migration.md)Validation
npm ci+npm ci --prefix servernpm run build— cleannpm --prefix server run typecheck— cleannpm run test:ci— passnpm run test:regressions→ 72 suites, 0 failuresRollback
Legacy KV data is preserved after migration. Reverting to the previous server version resumes from KV state with no data loss.