Skip to content

refactor(devtools): unify read-only SQLite opens on one canonical helper - #3316

Merged
Sinity merged 1 commit into
masterfrom
feature/refactor/devtools-sqlite-open-helper
Jul 27, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/refactor/devtools-sqlite-open-helper

Conversation

@Sinity

@Sinity Sinity commented Jul 27, 2026

Copy link
Copy Markdown
Owner

Summary

Migrates all 18 devtools/ call sites that hand-rolled sqlite3.connect() for
read-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 = False parameter for the two call sites
that genuinely need immutable=1.

Problem

At least 18 devtools/ files hand-rolled their own sqlite3.connect() call
for 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 = ON manually, and two sites set immutable=1. This is
inconsistent 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_connection in polylogue/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 divergence
was simply files that never adopted it, not a missing abstraction.

Solution

  • Extended open_readonly_connection() with immutable: bool = False
    (default preserves behavior for its 30+ existing callers). The docstring
    states the precondition explicitly: immutable=1 is only correct against a
    verified-stable snapshot; callers requesting it own that precondition
    check.
  • Migrated all 18 mode=ro call 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=1 kept, not spread: verified both existing immutable=1
    sites (index_v37_fast_forward.py, archive_schema_fast_forward.py) each
    explicitly 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=True anywhere else.
  • Timeout overrides kept where justified: 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 — plausible,
    deliberate. Dropped their now-redundant manual PRAGMA query_only = ON
    since the helper's READ_CONNECTION_PRAGMA_STATEMENTS already sets it.
  • One variant unified as accidental: read_package.py's explicit
    timeout=5.0 was byte-for-byte the canonical READ_DB_TIMEOUT default —
    collapsed to no override (behavior-identical).

Behavior change flagged honestly

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 — the same pattern already used
by all 30+ pre-existing open_readonly_connection callers in this codebase.
This drops percent-encoding for paths containing reserved URI characters
(space, #, ?). This is an existing, accepted risk already shared by every
other 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.Row assignments (cost_reconciliation_probe.py,
    scale_regression_probe.py, read_package.py, ...) — query ergonomics
    applied by the caller after open, not a connection-open semantic.
  • 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, scale_regression_probe.py's
    seed writer, etc.) — out of scope, not read-only opens.
  • turso_probe.py's file:...?mode=ro strings use the turso library, not
    sqlite3.connect() — deliberately probing a different backend's URI
    behavior.
  • 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 — different mechanism, out of scope.

Verification

  • ruff check devtools polylogue / ruff format --check devtools polylogue: all checks passed, 1250 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 all 14 touched files' own test modules plus adjacent
    coverage (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 comparison.
  • git push ran the pre-push devtools verify --quick gate: exit 0.

Ref polylogue-ykhy

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]>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Sinity, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 27 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 7e088d17-3499-40ca-8fba-073ae79f852f

📥 Commits

Reviewing files that changed from the base of the PR and between 0394316 and 72d88d1.

📒 Files selected for processing (15)
  • devtools/archive_schema_fast_forward.py
  • devtools/cost_reconciliation_probe.py
  • devtools/degraded_archive_proof.py
  • devtools/deployment_smoke.py
  • devtools/dev_loop.py
  • devtools/failure_context.py
  • devtools/index_fast_forward.py
  • devtools/index_v37_fast_forward.py
  • devtools/read_package.py
  • devtools/render_demo_corpus_datasheet.py
  • devtools/scale_regression_probe.py
  • devtools/schema_generate.py
  • devtools/self_verify.py
  • devtools/test_economics_report.py
  • polylogue/storage/sqlite/connection_profile.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/refactor/devtools-sqlite-open-helper

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Sinity
Sinity merged commit 1170f7f into master Jul 27, 2026
3 checks passed
@Sinity
Sinity deleted the feature/refactor/devtools-sqlite-open-helper branch July 27, 2026 10:07
Sinity added a commit that referenced this pull request Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant