Repository navigation
refactor(devtools): unify read-only SQLite opens on one canonical helper - #3316
Conversation
Problem: 18 devtools/ call sites hand-rolled sqlite3.connect() for
read-only archive/testmon access, disagreeing with each other on
timeout (default/5.0/30.0/120.0), a manual PRAGMA query_only=ON in two
of them, and immutable=1 in two others -- a real risk (inconsistent
locking/timeout semantics across tools that all claim read-only), not
style noise. A canonical helper (open_readonly_connection in
polylogue/storage/sqlite/connection_profile.py) already existed and
was already used correctly by 6 other devtools files, so most of the
divergence was files that simply never adopted it.
What changed:
- Extended open_readonly_connection() with an immutable: bool = False
parameter (default preserves existing behavior for its 30+ existing
callers). immutable=1 tells SQLite the file will never change and
skips all locking/WAL checks -- verified genuinely load-bearing at
its two call sites (index_v37_fast_forward.py, archive_schema_fast_forward.py),
which each explicitly check for zero WAL/SHM/journal sidecars on a
stopped-daemon clone immediately before opening immutable. Kept both
as immutable=True; did not spread immutable to any site lacking that
precondition proof.
- Migrated all 18 sqlite3.connect(...?mode=ro...) call sites across 14
files (degraded_archive_proof.py, index_v37_fast_forward.py x2,
index_fast_forward.py x3, archive_schema_fast_forward.py,
cost_reconciliation_probe.py, scale_regression_probe.py,
deployment_smoke.py, self_verify.py, render_demo_corpus_datasheet.py,
read_package.py, dev_loop.py x2, schema_generate.py,
failure_context.py, test_economics_report.py) to open_readonly_connection.
- Preserved genuinely justified timeout overrides: index_fast_forward.py's
plan_index (30s) and _quick_check_only/_runtime_version_sanity (120s)
read a potentially-live archive under daemon lock contention; dropped
their now-redundant manual PRAGMA query_only=ON since the helper's
READ_CONNECTION_PRAGMA_STATEMENTS already sets it.
- Unified one non-default variant: read_package.py's explicit
timeout=5.0 was byte-for-byte the canonical READ_DB_TIMEOUT default,
so it collapsed to no override (behavior-identical).
- Behavior change worth flagging: archive_schema_fast_forward.py's
_open_immutable_readonly previously built its URI via
resolved.as_uri() (percent-encoded); the canonical helper uses plain
f"file:{path}" string interpolation, matching all other
open_readonly_connection callers already in this codebase. This
drops percent-encoding for paths with reserved URI characters (space,
#, ?) -- an existing, accepted risk shared by 30+ pre-existing
callers, not a new one introduced by this change.
- row_factory = sqlite3.Row assignments at several call sites (e.g.
cost_reconciliation_probe.py, scale_regression_probe.py) were left
untouched: that is query-ergonomics, not a connection-open semantic,
applied by the caller after open.
- Left untouched: the many other sqlite3.connect() calls in these same
files that open read-write connections (index_v37_fast_forward.py's
clone-transform writer, degraded_archive_proof.py's scenario setup,
etc.) -- out of scope, not read-only opens.
- turso_probe.py's file:...?mode=ro strings use the turso library, not
sqlite3.connect(); ATTACH DATABASE (...'?mode=ro') statements in
pipeline_probe/result.py and daemon_workload_probe.py attach a
sibling tier to an already-open connection, not a new connect() call
-- both out of scope for this bead.
Verification:
- ruff check/format devtools polylogue: all checks passed, all files
already formatted
- mypy polylogue devtools (strict): Success, no issues found in 1250
source files
- devtools render all --check: exit 0, no "out of sync" surfaces
- devtools test on the 14 touched files' test modules plus
test_archive_tiers_self_verify.py, test_index_fast_forward_executor.py,
test_index_fast_forward_lifecycle.py, test_index_v37_fast_forward.py,
test_status.py, test_convergence_stages.py, test_daemon_status.py,
test_mcp_call_log.py, test_ingest_batch_wal_checkpoint.py,
test_blob_gc_generation_gate.py, test_archive_tiers_assertions.py,
test_repair_blobs.py, test_session_insight_parallel_fanout.py,
test_wal_journal_size_limit.py, test_daemon_cli.py: 149+360 passed;
14 pre-existing failures in test_index_v37_fast_forward.py /
test_index_fast_forward_lifecycle.py (schema-drift assertions
unrelated to connection opening) and 1 in test_status.py (async
facade route-catalog coverage) reproduce identically on
origin/master before this change (confirmed via git stash A/B).
Ref polylogue-ykhy
Co-Authored-By: Claude <[email protected]>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Review limit reached
Next review available in: 27 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (15)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Migrates all 18 devtools/ call sites that hand-rolled
sqlite3.connect()forread-only archive/testmon access onto the repo's existing canonical helper,
open_readonly_connection(polylogue/storage/sqlite/connection_profile.py),extended with an
immutable: bool = Falseparameter for the two call sitesthat genuinely need
immutable=1.Problem
At least 18
devtools/files hand-rolled their ownsqlite3.connect()callfor opening the archive read-only, with real, risk-bearing divergence:
timeout varied across default/5.0/30.0/120.0, two sites additionally set
PRAGMA query_only = ONmanually, and two sites setimmutable=1. This isinconsistent locking/timeout/immutability semantics across tools that all
claim to be "read-only" — a real risk, not style noise (polylogue-ykhy).
Investigation found the repo already has the natural shared-utility home:
open_readonly_connectioninpolylogue/storage/sqlite/connection_profile.py,already correctly used by 6 other devtools files (
archive_space_report.py,affordance_usage.py,temporal_archive_aggregates.py,claim_vs_evidence.py,lineage_validation.py,daemon_workload_probe.py). Most of the divergencewas simply files that never adopted it, not a missing abstraction.
Solution
open_readonly_connection()withimmutable: bool = False(default preserves behavior for its 30+ existing callers). The docstring
states the precondition explicitly:
immutable=1is only correct against averified-stable snapshot; callers requesting it own that precondition
check.
mode=rocall sites across 14 files onto the helper:degraded_archive_proof.py,index_v37_fast_forward.py(x2,immutable=True),index_fast_forward.py(x3),archive_schema_fast_forward.py(
immutable=True),cost_reconciliation_probe.py,scale_regression_probe.py,deployment_smoke.py,self_verify.py,render_demo_corpus_datasheet.py,read_package.py,dev_loop.py(x2),schema_generate.py,failure_context.py,test_economics_report.py.immutable=1kept, not spread: verified both existingimmutable=1sites (
index_v37_fast_forward.py,archive_schema_fast_forward.py) eachexplicitly check for zero WAL/SHM/journal sidecars on a stopped-daemon
clone immediately before opening immutable — genuinely load-bearing, not
copy-paste drift. Did not add
immutable=Trueanywhere else.index_fast_forward.py'splan_index(30s) and_quick_check_only/_runtime_version_sanity(120s)read a potentially-live archive under daemon lock contention — plausible,
deliberate. Dropped their now-redundant manual
PRAGMA query_only = ONsince the helper's
READ_CONNECTION_PRAGMA_STATEMENTSalready sets it.read_package.py's explicittimeout=5.0was byte-for-byte the canonicalREAD_DB_TIMEOUTdefault —collapsed to no override (behavior-identical).
Behavior change flagged honestly
archive_schema_fast_forward.py's_open_immutable_readonlypreviously builtits URI via
resolved.as_uri()(percent-encoded). The canonical helper usesplain
f"file:{path}"string interpolation — the same pattern already usedby all 30+ pre-existing
open_readonly_connectioncallers in this codebase.This drops percent-encoding for paths containing reserved URI characters
(space,
#,?). This is an existing, accepted risk already shared by everyother caller of the canonical helper, not a new risk introduced by this PR;
flagging it rather than silently reformatting the connection semantics.
Explicitly not touched
row_factory = sqlite3.Rowassignments (cost_reconciliation_probe.py,scale_regression_probe.py,read_package.py, ...) — query ergonomicsapplied by the caller after open, not a connection-open semantic.
sqlite3.connect()calls in these same files that openread-write connections (
index_v37_fast_forward.py's clone-transformwriter,
degraded_archive_proof.py's scenario setup,scale_regression_probe.py'sseed writer, etc.) — out of scope, not read-only opens.
turso_probe.py'sfile:...?mode=rostrings use thetursolibrary, notsqlite3.connect()— deliberately probing a different backend's URIbehavior.
ATTACH DATABASE (...'?mode=ro')statements inpipeline_probe/result.pyand
daemon_workload_probe.pyattach a sibling tier to an already-openconnection, not a new
connect()call — different mechanism, out of scope.Verification
ruff check devtools polylogue/ruff format --check devtools polylogue: all checks passed, 1250 files already formattedmypy polylogue devtools(strict):Success: no issues found in 1250 source filesdevtools render all --check: exit 0, noout of syncsurfacesdevtools teston all 14 touched files' own test modules plus adjacentcoverage (
test_archive_tiers_self_verify.py,test_index_fast_forward_executor.py,test_index_fast_forward_lifecycle.py,test_index_v37_fast_forward.py,test_status.py,test_convergence_stages.py,test_daemon_status.py,test_mcp_call_log.py,test_ingest_batch_wal_checkpoint.py,test_blob_gc_generation_gate.py,test_archive_tiers_assertions.py,test_repair_blobs.py,test_session_insight_parallel_fanout.py,test_wal_journal_size_limit.py,test_daemon_cli.py): 149 + 360 passed.14 pre-existing failures in
test_index_v37_fast_forward.py/test_index_fast_forward_lifecycle.py(schema-drift assertions unrelatedto connection opening) and 1 in
test_status.py(async facaderoute-catalog coverage) reproduce identically on
origin/masterbeforethis change — confirmed via
git stashA/B comparison.git pushran the pre-pushdevtools verify --quickgate: exit 0.Ref polylogue-ykhy