Skip to content

fix: drop write-only query_runs table and dead active_index_db config - #3694

Merged
Sinity merged 2 commits into
masterfrom
feature/schema-prune/drop-query-runs-active-index-db
Aug 3, 2026
Merged

Sinity merged 2 commits into
masterfrom
feature/schema-prune/drop-query-runs-active-index-db

Conversation

@Sinity

@Sinity Sinity commented Aug 3, 2026

Copy link
Copy Markdown
Owner

Summary

Drops two confirmed-dead schema surfaces named in polylogue-yp5p's write-only-table/unconsumed-config census: the query_runs ops.db table (write-only telemetry with zero readers) and the active_index_db config property (a no-op alias with zero callers). The other five findings in that bead were re-verified against current source and turned out to already be resolved by unrelated prior work -- see Verification below for the disposition of each.

Problem

polylogue-yp5p (2026-07-29 exhaustive rg-based read/write census, .agent/handoffs/polylogue-deep-research-2026-07-09/2026-07-09-codebase-structure-audit.md section 3) flagged three write-only tables and seven unconsumed config properties ahead of the reindex campaign. This PR re-verifies each finding against present source (~5 days of drift since the census) and purges what's still genuinely dead, per the operator's explicit schema-pruning request this session.

Solution

query_runs (ops.db, disposable tier) -- still write-only, deleted:

  • ArchiveCanonicalPlanEvaluator.evaluate() (polylogue/archive/query/production_evaluator.py) wrote one bounded telemetry row per standing-query evaluation (daemon/convergence_stages.py) and per MCP from query:<hash> resolution (mcp/server_cutover.py), but no surface anywhere read the table back -- confirmed by grepping for FROM query_runs/SELECT ... query_runs across the tree.
  • Dropped the table + its two indexes from storage/sqlite/archive_tiers/ops.py. ops.db is the disposable tier (OPS_SCHEMA_VERSION stays at 1, no migration chain, not tracked by devtools lab policy schema-versioning), so this is a plain DDL edit.
  • Removed record_query_run (and its now-unused _json_or_none helper) from ops_write.py, and ArchiveCanonicalPlanEvaluator._record_query_run + its call site from production_evaluator.py. The evaluator's now-dead surface constructor parameter went with it; updated its one caller (mcp/server_cutover.py).
  • Removed it from docs/plans/layering.yaml's writer-module entrypoint inventory (devtools verify layering enforces this list matches the module's actual exports).
  • Deleted tests/unit/storage/test_query_runs.py (tested the writer function directly) and trimmed the query_runs assertions out of tests/unit/archive/query/test_production_evaluator.py and tests/unit/daemon/test_standing_queries_default_evaluator.py -- their real assertions (exactness, member_refs, stage completion) are untouched.
  • Updated doc comments in cli/commands/diagnostics.py, operations/route_observation.py, and core/query_identity.py that described query_runs as a peer/exclusion of the tables they document.

Not touched: ArchiveStore.query_runs() / run_projection_reads.query_runs() (repository methods for querying session runs) and retained_query_runs (a durable, user.db table backing query-run: refs, with real readers) -- both are unrelated same-named things the original grep also had to disambiguate from.

active_index_db (config.py) -- still dead, deleted:
ResolvedArchivePaths.active_index_db was a trivial @property returning self.index_db, with zero attribute-access call sites anywhere in prod or tests. The real resolver production code actually uses is the unrelated _active_index_db_path() function in daemon/cli.py. Deleted the dead property.

Findings that drifted resolved -- left alone, documented here per the task's "if it gained a reader, leave it and note why":

Finding Disposition
otlp_telemetry table Gone entirely -- PR #3665 already removed the whole OTLP receiver path (writer + table). devtools/daemon_workload_probe.py even carries a "v19 removes dead OTLP ops-tier table inventory" comment marking this cleanup. Nothing to delete.
session_commits table Gained a real reader: polylogue-cijx.3 wired get_session_commits into api/archive.py's correlation payload (checkout_commits) and insights/correlation_view.py. No longer write-only.
hook_sidecar_dir config False positive in the original census (or fixed since) -- consumed internally in config.py to build hooks_pending, which feeds the local source-discovery candidate list (("hooks", source_paths.hooks_pending)). Real production consumer.
ingest_parse_workers config Not a dead property -- it's a ConfigInventoryEntry documenting that POLYLOGUE_INGEST_PARSE_WORKERS is read directly by resolve_parse_worker_count() (bypassing the Settings object), which is genuinely wired into the rebuild path (maintenance/rebuild_index.py, maintenance/replay.py, storage/repair.py). The rebuild is NOT silently ignoring it.
log_level config Already gone -- PR #3455 ("delete two inert config keys and the whale off-switch") removed it.
slow_query_notice_seconds config Already gone -- same PR #3455.
effective_path config False positive -- it's a helper @property on ConfigInventoryEntry used internally by polylogue config --format json diagnostics rendering (2 call sites in config.py), not a settings value itself.
layer_paths config Real production consumer: cli/commands/maintenance/_shared.py reads settings.layer_paths.get(layer).

Deliberately out of scope: while verifying otlp_telemetry, found that its current-day incarnation otlp_spans (source.db, durable tier) is now fully dead -- zero writer (the receiver that wrote it is already gone) AND zero reader, worse than merely write-only. docs/schema.md already flags it: "The empty durable table remains pending an explicit migration decision." Dropping a durable-tier table needs the copy-forward-design + explicit-consent gate this repo's schema policy requires, and it wasn't the bead's literal target, so it's left for a follow-up rather than folded into this PR silently.

Verification

  • devtools test tests/unit/archive/query/test_production_evaluator.py tests/unit/daemon/test_standing_queries_default_evaluator.py tests/unit/storage/test_archive_tiers_ddl.py tests/unit/storage/test_durable_migrations.py tests/unit/mcp/test_reference_query_pipeline.py -- 87 passed
  • devtools test tests/unit/storage/test_index_generation.py tests/unit/daemon/test_daemon_cli.py tests/unit/storage/test_archive_identity.py tests/unit/core/test_config.py tests/unit/core/test_config_inventory.py -- 332 passed
  • devtools test tests/unit/archive/query/test_predicate_payload_roundtrip.py tests/unit/operations/test_route_observation.py -- 28 passed
  • devtools verify --quick -- exit_code: 0 (ruff format/check, mypy --strict, render all, layering, closure-matrix, schema roundtrip, manifests, ci-workflows, doc-commands, docs-coverage, test-infra-currency, pytest-timeout-overrides, degrade-loudly, schema-versioning, classifier-fingerprints, demo-tour-freshness, raw-payload-hash-purity, position-derived-identity, raw-authority-frontier-executability, table-exists-duplication, schema promotion audit)
  • devtools verify layering after removing the record_query_run entrypoint from docs/plans/layering.yaml -- No layering violations found (confirmed the pre-existing "2 baseline entries no longer reproduce" note is unrelated drift, present identically on master before this change via git stash/re-run comparison)
  • Not run: full devtools verify --seed-testmon / testmon-affected suite -- this worktree's testmon cache wasn't pre-seeded (main checkout has testmondata but no seed.json marker, so the linked-worktree auto-bootstrap didn't trigger) and reseeding is a full-suite operation out of scope for this change's size; relied on explicit devtools test selection across every file/test that imports or exercises the touched modules instead.

Ref polylogue-yp5p

Sinity added 2 commits August 4, 2026 00:01
The census behind polylogue-yp5p flagged Settings.ResolvedArchivePaths
.active_index_db as a config property with zero production or test
callers -- it was a trivial alias returning self.index_db, superseded
long ago by the real _active_index_db_path() resolver in daemon/cli.py.
Verified still true against current source: no attribute-access call
site anywhere in the tree.

Ref polylogue-yp5p
The census behind polylogue-yp5p flagged query_runs (ops.db, disposable
tier) as write-only: ArchiveCanonicalPlanEvaluator.evaluate() wrote a
bounded per-execution telemetry row on every standing-query and MCP
`from query:<hash>` evaluation, but no surface anywhere read the table
back. Re-verified against current source before deleting: the writer
(record_query_run) still has exactly the two production call sites the
census found (daemon standing-query stage, MCP reference-pipeline
resolver) and still zero readers, so this is not stale drift like the
otlp_telemetry/session_commits findings in the same bead turned out to
be (see polylogue-yp5p follow-up notes).

ops.db is the disposable tier (OPS_SCHEMA_VERSION stays at 1; no
migration chain, no rebuild plan -- `devtools lab policy
schema-versioning` doesn't even track it), so this is a plain DDL edit,
not a migration.

- Drop the `query_runs` table + its two indexes from
  storage/sqlite/archive_tiers/ops.py.
- Remove `record_query_run` (and its now-unused `_json_or_none` helper)
  from ops_write.py; drop it from docs/plans/layering.yaml's writer
  entrypoint inventory.
- Remove `ArchiveCanonicalPlanEvaluator._record_query_run` and its call
  in production_evaluator.py; the constructor's now-dead `surface`
  parameter goes with it (mcp/server_cutover.py's one caller updated).
- Delete tests/unit/storage/test_query_runs.py (tested the writer
  directly) and the two other tests that asserted a row landed in
  query_runs (test_production_evaluator.py,
  test_standing_queries_default_evaluator.py) -- their real assertions
  (exactness, member_refs, stage completion) are untouched.
- Update doc comments in cli/commands/diagnostics.py,
  operations/route_observation.py, and core/query_identity.py that
  described query_runs as a peer/exclusion of the tables they document.

Ref polylogue-yp5p
@coderabbitai

coderabbitai Bot commented Aug 3, 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: 13 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

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: ff907e34-aef7-4ac7-9228-a16516257d6e

📥 Commits

Reviewing files that changed from the base of the PR and between bf3c89f and 577d3cc.

📒 Files selected for processing (12)
  • docs/plans/layering.yaml
  • polylogue/archive/query/production_evaluator.py
  • polylogue/cli/commands/diagnostics.py
  • polylogue/config.py
  • polylogue/core/query_identity.py
  • polylogue/mcp/server_cutover.py
  • polylogue/operations/route_observation.py
  • polylogue/storage/sqlite/archive_tiers/ops.py
  • polylogue/storage/sqlite/archive_tiers/ops_write.py
  • tests/unit/archive/query/test_production_evaluator.py
  • tests/unit/daemon/test_standing_queries_default_evaluator.py
  • tests/unit/storage/test_query_runs.py

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 a5f5efb into master Aug 3, 2026
3 checks passed
@Sinity
Sinity deleted the feature/schema-prune/drop-query-runs-active-index-db branch August 3, 2026 22:09
Sinity added a commit that referenced this pull request Sep 22, 2026
An ops table removed from `OPS_DDL` survived in every already-bootstrapped
archive forever. `CREATE TABLE IF NOT EXISTS` never drops, the disposable ops
tier has no migration chain, and `OPS_BENIGN_DDL_CONVERGENCE_PLAN` -- the one
same-version convergence hook bootstrap applies to an existing ops.db -- held
only two `CREATE INDEX` statements. Removing a declaration stopped fresh
bootstraps from creating the table and did nothing else.

index.db already has the retirement half (`INDEX_BENIGN_DDL_REGISTRY`, whose
own docstring credits the ops tier with proving the additive pattern) and the
durable source tier has a numbered migration chain plus
`RETIRED_SOURCE_SCHEMA_OBJECTS`. ops had neither.

Four tables show the consequence. Each was deleted from `OPS_DDL` by a named
commit -- slo_samples (#5373), query_runs (#3694, subject "drop write-only
query_runs table"), otlp_spans and otlp_telemetry (#3665) -- and each is still
present, with its indexes, in an ops.db bootstrapped before that commit.

`OPS_BENIGN_DDL_CONVERGENCE_PLAN` becomes a `BenignDDLEntry` tuple, matching
the index registry, so each entry carries the zero-consumer audit that
justifies it. `devtools gate schema-manifest` already validated this plan's
entries for idempotent shape and data-non-transformation; it now names them
`ops:<entry>` instead of `ops[N]`.

Retirement is a declared list, not a structural "drop whatever OPS_DDL omits"
sweep: `polylogue_ops_schema_state` is live bootstrap-internal state that
canonical DDL also does not declare, and a sweep would take it.

Verification
- devtools test tests/unit/storage/test_archive_tiers_ops_write.py -> 23/23
- devtools verify --quick -> exit 0, 25 gates
- devtools render all --check -> exit 0, 0 "out of sync"
- gate schema-manifest / schema-closure / durable-enum-checks -> exit 0 each

Anti-vacuity, executed twice against the production bootstrap route:
- removing the four drop entries: 21 passed / 2 failed
  ("canonical DDL no longer declares these tables";
   "the guard is vacuous while the plan retires nothing")
- adding drop_context_injection_ledger (a still-declared table):
  22 passed / 1 failed on `not dropped & declared`

Schema identity: ops.py and bootstrap.py are closure IN, membership unchanged
(gate schema-closure passed with no --update). INDEX
54804b5d5d00e88753... -> 34e0c29d5ddd1e6bd4...; OPS unchanged at
868662352a182527e6... -- the convergence plan is not part of OPS_DDL, so the
retirement converges on the next open rather than raising SchemaSkew, which is
the benign-DDL regime's point. Must land before a fresh rebuild starts.

Refs polylogue-pnxl6

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01ToWqpkXotr573DiQex5vcy
Sinity added a commit that referenced this pull request Sep 22, 2026
## Summary

`polylogue-pnxl6` asks to shrink `ops.db`. Measurement refutes the plan
**and** uncovers why every previous attempt silently failed: **removing
a table from `OPS_DDL` never removed it from an existing archive.** Four
merged PRs believed they deleted tables. All four tables are still in
the live `ops.db` today.

## The blocker, and the evidence that it has been failing for months

`CREATE TABLE IF NOT EXISTS` does not drop. The disposable ops tier has
no migration chain, and `OPS_BENIGN_DDL_CONVERGENCE_PLAN` held only two
`CREATE INDEX` statements. So a deletion could be merged, pass review,
and never reach an archive.

Still present in the live `ops.db`, with their indexes:

| table | the PR that "removed" it |
|---|---|
| `slo_samples` | #5373 |
| `query_runs` | #3694 — subject literally *"drop write-only query_runs
table"* |
| `otlp_spans`, `otlp_telemetry` | #3665 |

`index.db` already has the retirement half (`INDEX_BENIGN_DDL_REGISTRY`)
and `source.db` has migrations plus `RETIRED_SOURCE_SCHEMA_OBJECTS`. Ops
had neither. This gives ops that route and retires exactly those four
zero-consumer tables.

**Proven to reach real archives, not just cold bootstraps.** An
already-current archive takes bootstrap's cheap convergence-only path;
the retirement fires there too — `cached digest present: True / digest
unchanged: True / slo_samples still present: False`.

## The bead's diet targets ~0% of the file

Read-only `dbstat` against the live `ops.db` (91.7 MB file, 83.35 MiB
content):

| table | size | share |
|---|---|---|
| `daemon_stage_events` + 2 idx | 51.59 MiB | **61.9%** (47,023 rows) |
| `ingest_cursor` + 2 idx | 15.38 MiB | 18.5% |
| `daemon_events` + 4 idx | 11.66 MiB | 14.0% |
| `ingest_attempts` + 4 idx | 4.41 MiB | 5.3% |
| **every other table** | **0.00 MiB** | — |

**Eleven of the thirteen tables the bead wants deleted or moved are
jointly ~0% of `ops.db`**, while the one table that is 62% is the
hardest to remove. The bead also pins 18 tables from `454808b25`;
canonical `OPS_DDL` declares 17 + the identity stamp, and `slo_samples`
has no reference anywhere at head.

Important caveat recorded rather than glossed: **a 0-row table means the
feature is unexercised on this archive, not that it is dead.**
`judgment_scheduler_receipts` has 0 rows and a fully live path
(`daemon/events.py:221` writes →
`operations/judgment_scheduler.read_latest` → `api/archive.py:1933` →
`cli/commands/status.py:1120` reads). A reader census of all 17 confirms
**nothing in the bead's delete list is reader-free**.

## AC3's audit move is refused, on three independent grounds

Moving the MCP call log into audit `machine_requests` does not work:

1. **Shape** — `machine_request_parts.preview_ref` is `TEXT NOT NULL
REFERENCES operation_previews(preview_id)`; a read-only MCP tool call
has no preview and no authorization. `machine_requests` carries no
`finished_at`, duration, success or error column.
2. **Semantics** — `machine_requests` is the mutation
idempotency/authority ledger, not latency evidence. The bead's own
addendum agrees: *"operational latency samples are not that evidence"*.
3. **Durability** — the call log's writer declares itself droppable
telemetry and **sheds records under outbox pressure**
(`McpCallLogRecordRejectedError`, `records_dropped`). A table that sheds
cannot live in a continuity-chained durable tier.

## Anti-vacuity — two mutations executed

- Delete the four `drop_*` entries → `canonical DDL no longer declares
these tables`, plus `the guard is vacuous while the plan retires
nothing`.
- Add `drop_context_injection_ledger` (a table `OPS_DDL` still declares)
→ guard fails. A third variant (`drop_ingest_cursor`) fails harder and
earlier with `no such table: ingest_cursor` from bootstrap, so it never
reaches the guard — recorded in the test docstring.

## Verification

```
devtools test <ops_write, tier_init, schema_manifest>  exit 0, 62/62
devtools verify --quick                                exit 0, 25 gates
devtools render all --check              exit 0, 'out of sync' count 0
gate schema-manifest / schema-closure / durable-enum-checks  all exit 0
```

Closure: both edited production files are **IN**; membership unchanged
(557 = 557), no `--update`. INDEX `54804b5d… → 34e0c29d…`, OPS unchanged
— the convergence plan is not part of `OPS_DDL`, so the retirement
converges on next open rather than raising `SchemaSkew`.

## Filed as residuals, not silently dropped

- **`daemon_stage_events` is the entire diet and has no owner-deletion
rule.** 47,023 rows narrate 2,173 attempts (~21.6 rows/attempt).
Measured **0 orphans, 0 NULL `attempt_id`**, every attempt terminal.
Nothing anywhere DELETEs from it, and it carries no FK to
`ingest_attempts`. `convergence_stages.py:177` already names the defect.
Per the operator's no-retention ruling the fix is an ownership rule, not
a time window — needs a deletion event that does not exist.
- Payload profile for whoever takes it: of 37.7 MB of `payload_json`,
only 14.6 MiB is key *values*; the rest is ~25 fixed key names
re-serialized 47k times. Largest: `current_path` 3.59 MiB, `cgroup_path`
3.40 MiB (near-constant per process).
- **`ops_write.py:21 MCP_CALL_LOG_RETENTION_MS = 90 days` is a
time-based retention window**, which the operator's no-retention ruling
forbids. Removing it without an ownership deletion would make the table
grow forever, so it was left — needs an owner decision.
- A structural "drop whatever `OPS_DDL` omits" sweep would take
`polylogue_ops_schema_state` and two bootstrap-created indexes.
`test_ops_convergence_drops_retired_tables` pins that.

AC1/AC2/AC4 are not attempted; `pnxl6` stays open on them.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01ToWqpkXotr573DiQex5vcy

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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