Repository navigation
postgres - #844
Merged
Merged
postgres#844
Conversation
|
@dev-marvel Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Closes #734
Closes #735
Closes #737
Closes #739
1. ISP-064: Storage Contention & VACUUM Death Spiral Eliminated
telemetry_YYYYMM): Insrc/services/storageEngine.js, telemetry writes are directed into monthly partition tables unified under a singleVIEW telemetry. Retention expiration executes metadata-onlyDROP TABLEoperations in <5ms, returning space without page-rewriting or freelist fragmentation (<15% freelist bloat after 30 days).VACUUMis strictly banned in-browser. Space reclamation is performed viarunIncrementalVacuumBudget()executingPRAGMA incremental_vacuum(50)slices during idle windows. The loop aborts within 100ms whenever dispatch backlog exists (syncManager.getDispatchBacklog() > 0) or frame rates drop below 30 fps.BEGIN IMMEDIATEwithbusy_timeout = 5000ms. Upon persistent lock contention (SqliteBusyError), inserts fall back to the IndexedDB durable outbox insrc/lib/secureStorage.ts. Zero dispatches are lost.BEGIN DEFERRED. Under contention,src/workers/telemetryWorker.jsrelaxes cadence from 5s to 30s, coalescing records and tracking dropped fixes viadropped_telemetry.src/styles/animations.css(mdpulse,mdfloat) are gated underprefers-reduced-motionand the.performance-throttledgovernor.2. ISP-065: Postgres Replication Lag, Phantom Reads & Indexer Exactly-Once
server/db/connection.ts,getHistoryConn(lagBudgetMs = 10000)checkspg_stat_replication.replay_lag(1s cache). If lag ≤ 10s, queries route to the replica. If lag > 10s, queries fall back to the primary-reserve pool (capped at 5 connections inserver/db/poolManager.ts). When the reserve is exhausted, the server returns HTTP 209 Stale withRetry-After: 5.server/routes/history.tsemitsX-Replica-Lag-MsandX-As-Of-LSNon every request. ReplacedOFFSETwith keyset cursor pagination(server_seq, id) > ($cursor_seq, $cursor_id)returning an opaqueX-Next-Cursortoken, eliminating phantom skips across moving replica snapshots.server/indexer/exporter.tswraps projection andindexer_checkpointin a single transaction protected bypg_advisory_xact_lock(hashtext('exporter'))and deduplicated on(doc_id, client_id, clock).server/indexer/parser.tsvalidates monotonic per-client clock sequences, logging gaps toindexer_gap_logand triggering backfill requests rather than silently dropping batches.server/db/maintenance.tspauses maintenance passes when lag > 30s.server/db/migrator.tsrefuses non-urgent DDL when lag > 15s. Telemetry bulk writes shed to Redis buffer when lag > 30s.3. ISP-066: Full-State Hydration OOM & Dehydration Protocol
server/routes/dispatch.tsexposesGET /api/dispatch?slice=open-today(<1MB payload). New devices render active dispatches immediately while 30-day historical data backfills in the background.server/routes/sync.tspublishes CDN-cached base snapshots (Cache-Control: public, max-age=300) and serves paged deltas (GET /api/sync/deltas?since_vector=&limit=500).src/services/crdtSync.jshydratePaged()checkpoints state vectors after each 500-op page insrc/lib/secureStorage.ts, guaranteeing resumption upon disconnection (<15% rework) and keeping peak heap <250MB on 2GB devices.src/workers/routingWorker.jsgates route calculation during background backfill, returning{ status: 'history-partial', badge: 'history-partial', eta: null }to prevent misleading ETAs.server/indexer/auditStreamer.jsverifies snapshot IDs, high-water sequences, and SHA-256 hashes before marking hydration complete.4. ISP-067: Crash-Atomic Triple-Write & Resurrection
(device_id, seq)are recorded across SQLite, the IDB journal store, and CRDT snapshot headers.crashRecovery.ts):torn_frames_droppedcounter surfaced).seq > sqliteHighwater.snapshot.journal_highwater > sqliteHighwaterwithout IDB journal coverage.PRAGMA wal_checkpoint(TRUNCATE).src/lib/syncManager.tsupload lane blocks untilcrashRecovery.tsemitsRECOVERY_COMPLETE, preventing device-server forks.server/routes/sync.tsenforcesUNIQUE(device_id, seq)ondispatch_logviamigrations/20260511000000_dispatch_device_seq_unique.sql, returning HTTP 200{ deduped: true }on duplicate replay.5. Frontend UI & Telemetry Integration
src/App.tsx:⚠️ Stale ~XswhenreplicaLagMs > 10,000.🔄 Syncing history X%during background hydration.🛡️ Recovering...with.hp-offline-indicatorwhile boot reconcile executes.Verification & Test Evidence
All 5 dedicated spike test suites and regression suites pass cleanly (89/89 tests passing):
npx vitest run test/storage-contention-vacuum.test.js \ test/indexer-exactly-once.test.js \ test/history-no-phantom.test.js \ test/crdt-dehydration-paged.test.js \ test/triple-write-crash.test.jstest/storage-contention-vacuum.test.jstest/indexer-exactly-once.test.jstest/history-no-phantom.test.jstest/crdt-dehydration-paged.test.jstest/triple-write-crash.test.js(device_id, seq)deduplicationBenchmark CLI verification:
Documentation Updated
incremental_vacuum(50)budget table, and dirty-boot resurrection procedure.