Fix c1z corruption from incomplete WAL checkpoint before saveC1z #675
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 384 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.356
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #675"
general
weight: 0.35
loganintech
Summary
Fixes intermittent c1z corruption where
saveC1z()compresses an incomplete SQLite database because the WAL checkpoint before compression silently fails to move all frames into the main db file.Root cause
saveC1z()reads the main.dbfile via rawos.Open()— it does not read the-walfile. If the WAL checkpoint didn't move all frames into the main db, the resulting c1z is missing data. Three compounding issues made this likely:1. Unbounded connection pool blocks checkpoint:
NewC1Filenever calledSetMaxOpenConns, sosql.DBcould hold multiple idle connections. In WAL mode, each idle connection holds a read lock that preventsPRAGMA wal_checkpoint(TRUNCATE)from completing all frames. In theory we only make one connection, but let's make sure.2. Partial checkpoint undetectable: The checkpoint used
ExecContextwhich discards the(busy, log, checkpointed)return values. A partial checkpoint returnednilerror — the code had no way to know frames were left in the WAL.3. Hard failures swallowed: Even outright checkpoint errors (context cancellation, I/O) were logged as warnings and execution continued to
saveC1z.This manifests most on ZFS with large ARC caches because more WAL data accumulates before flush, and longer TXG intervals create bigger WAL files with more frames to checkpoint.
Changes
c1file.go:
SetMaxOpenConns(1)aftersql.Open()— eliminates pool connection interference with WAL checkpointExecContextwithQueryRowContext+Scanto read the(busy, log, checkpointed)result and detect partial checkpointsrawDb/dbon error paths to prevent use-after-close on retryclone_sync.go:
rawDb.Close()instead of deferring fullC1File.Close()out.init()call (already called internally byNewC1File)outFile.Close()checkpointTest plan
SetMaxOpenConns(1)doesn't cause deadlocks in sync workflows (confirmed: no nested/concurrent query patterns exist in codebase)(0, -1, -1), conditionlog >= 0is false, skips the incomplete checkWAL checkpoint failedorWAL checkpoint incompleteerrors in production after deploy<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
Summary by CodeRabbit
Release Notes
Bug Fixes
Improved database cleanup and error handling for WAL checkpoint operations, ensuring proper resource cleanup on failures.
Enhanced error reporting for incomplete database checkpoints.
Chores
* Optimized internal database connection management and resource handling to prevent contention during database operations.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->