Skip to content

fix(storage): Give the ops tier a retirement route - #5391

Merged
Sinity merged 1 commit into
masterfrom
fix/ops-db-diet
Sep 22, 2026
Merged

Sinity merged 1 commit into
masterfrom
fix/ops-db-diet

Conversation

@Sinity

@Sinity Sinity commented Sep 22, 2026

Copy link
Copy Markdown
Owner

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.ai/code/session_01ToWqpkXotr573DiQex5vcy

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
@coderabbitai

coderabbitai Bot commented Sep 22, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 45 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

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

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: eefc411b-e302-477f-b67d-7a49318598a4

📥 Commits

Reviewing files that changed from the base of the PR and between 0df0f6a and 54aa899.

📒 Files selected for processing (4)
  • devtools/verify_schema_manifest.py
  • polylogue/storage/sqlite/archive_tiers/bootstrap.py
  • polylogue/storage/sqlite/archive_tiers/ops.py
  • tests/unit/storage/test_archive_tiers_ops_write.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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-22T05:25:08.139189Z 54aa899 PR opened
🔒 Security Review ✅ Completed 2026-09-22T05:27:04.715231Z 54aa899 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Sinity
Sinity enabled auto-merge (squash) September 22, 2026 05:17
@Sinity
Sinity merged commit 9f450db into master Sep 22, 2026
3 checks passed
@Sinity
Sinity deleted the fix/ops-db-diet branch September 22, 2026 05:27
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