Skip to content

fix(storage): resolve managed archive index identity - #3055

Merged
Sinity merged 3 commits into
masterfrom
feature/fix/archive-reliability-overhaul
Jul 18, 2026
Merged

Sinity merged 3 commits into
masterfrom
feature/fix/archive-reliability-overhaul

Conversation

@Sinity

@Sinity Sinity commented Jul 17, 2026 •

Copy link
Copy Markdown
Owner

Summary

Make the configured archive root and its atomically selected index generation one explicit location contract.

Problem

A split-tier archive may keep durable tiers under its configured root while an active-index pointer selects a generation elsewhere. Direct root/index.db consumers bypassed that pointer, allowed reset to create a shadow index, and made diagnostics infer missing durable siblings from the generation directory.

Solution

Adds ArchiveLocation, routes active-index configuration, reset, rebuild planning, and path diagnostics through it, and refuses destructive reset operations against a managed active generation. Legacy no-pointer layouts retain their prior behavior.

Verification

  • devtools test tests/unit/storage/test_archive_identity.py tests/unit/storage/test_index_generation.py tests/unit/core/test_paths.py tests/unit/cli/test_reset.py tests/unit/cli/test_archive_maintenance_cli.py — 124 passed.
  • ruff check … and strict mypy on changed production modules — clean.
  • devtools verify --seed-testmon --skip-slow — all static/generated gates passed; seeded full pytest had 41 broad failures outside this path change (including existing fast-forward fixture and mocked ArchiveStore signature failures).

Summary by CodeRabbit

  • New Features

    • Added support for managed archive generations with active index locations selected through a pointer.
    • Enhanced paths output with active index and shadow index details.
    • Added validation for inconsistent archive layouts.
  • Bug Fixes

    • Maintenance and reset operations now target the active index correctly.
    • Reset operations prevent accidental deletion of managed active indexes and provide recovery guidance.
  • Tests

    • Added coverage for managed index resolution and reset safety behavior.

Problem: a configured archive root can share durable tiers with an\natomically promoted index elsewhere. Direct root/index.db access bypassed that\npointer, let reset create a shadow index, and caused diagnostics to derive\nmissing durable siblings from an index-generation directory.\n\nWhat changed: add ArchiveLocation as the configured-versus-active tier\nauthority; make active-index resolution follow the pointer; route reset,\nrebuild planning, and path diagnostics through it; and refuse destructive\nresets of managed active generations.\n\nCompatibility: legacy archives without an active-index pointer retain their\nexisting root/index.db layout.

Co-Authored-By: Codex <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

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

Next review available in: 28 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

Run ID: ac25a328-6182-4bc1-9e00-69a0b939bc65

📥 Commits

Reviewing files that changed from the base of the PR and between bbcb1f7 and f7e11ea.

📒 Files selected for processing (14)
  • polylogue/cli/commands/debt.py
  • polylogue/cli/commands/maintenance/_rebuild_index.py
  • polylogue/daemon/cli.py
  • polylogue/daemon/convergence_stages.py
  • polylogue/maintenance/replay.py
  • polylogue/paths/_roots.py
  • polylogue/storage/index_generation.py
  • tests/unit/cli/test_archive_maintenance_cli.py
  • tests/unit/cli/test_debt_command.py
  • tests/unit/core/test_paths.py
  • tests/unit/daemon/test_convergence_stages.py
  • tests/unit/daemon/test_daemon_cli.py
  • tests/unit/storage/test_incremental_rebuild_equivalence.py
  • tests/unit/storage/test_index_generation.py
📝 Walkthrough

Walkthrough

The change adds ArchiveLocation for configured and active tier resolution, validates .index-active-pointer targets, routes path, rebuild, and reset commands through the active index path, and prevents reset operations from deleting managed active generations.

Changes

Active generation resolution

Layer / File(s) Summary
Location and identity resolution
polylogue/paths/_roots.py, polylogue/storage/archive_identity.py, polylogue/config.py, tests/unit/core/test_paths.py, tests/unit/storage/test_archive_identity.py
ArchiveLocation resolves configured and active tiers, pointer-based index paths are validated, identity conflicts use active generations, and tests cover pointer resolution and shadow indexes.
Command integration
polylogue/cli/commands/maintenance/_rebuild_index.py, polylogue/cli/commands/paths.py
Rebuild planning and execution use the active index path, while paths reports resolved tier paths, the active pointer, and shadow configuration.
Managed-generation reset protection
polylogue/cli/commands/reset.py, tests/unit/cli/test_reset.py
Index and database resets reject deletion of a pointer-selected active index.db; integration tests verify failure and file preservation.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Operator
  participant PathsCommand
  participant ArchiveLocation
  participant ActiveIndex
  Operator->>PathsCommand: request archive paths
  PathsCommand->>ArchiveLocation: resolve archive root
  ArchiveLocation-->>PathsCommand: active tiers and pointer metadata
  PathsCommand->>ActiveIndex: identify active index path
  ActiveIndex-->>PathsCommand: resolved path
  PathsCommand-->>Operator: render path information
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.79% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed Concise and specific; it clearly matches the main storage/index-identity fix.
Description check ✅ Passed It includes the required Summary, Problem, Solution, and Verification sections, with only optional sections omitted.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/archive-reliability-overhaul

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 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bbcb1f7753

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread polylogue/paths/_roots.py
Comment on lines +132 to +136
if pointer.exists():
target = Path(pointer.read_text(encoding="utf-8").strip())
if not target.is_absolute() or target.name != "index.db":
raise RuntimeError(f"invalid active index pointer: {target}")
return target

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep durable tiers rooted at the configured archive

When .index-active-pointer names an index outside the configured root—the split topology this change supports—returning that target globally also changes Config.db_path, while existing consumers still treat db_path.parent as the complete archive root. For example, archive_file_set_root_for_paths returns that parent, initialize_backend_state binds or bootstraps sibling source.db/user.db tiers there, and daemon/lifecycle.py derives ops.db there. If only the index is external and durable tiers remain under the configured root, runtime operations therefore read or create a second set of durable databases beside the index, silently forking archive state. Route only index access through the pointer while preserving the configured root for every other tier, or update these consumers to use ArchiveLocation.

Useful? React with 👍 / 👎.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@polylogue/paths/_roots.py`:
- Around line 78-82: Update the active-index resolution logic around
archive_root() and the .index-active-pointer file so that an existing pointer is
validated and invalid contents raise an error instead of falling back to the
configured or anchor database. Preserve returning the target for valid absolute
paths whose filename is index.db, and align the failure behavior with
active_index_db_path and ArchiveLocation.resolve.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 12ea574a-8f3e-495d-b730-e4fbaa25ad52

📥 Commits

Reviewing files that changed from the base of the PR and between 1e71a63 and bbcb1f7.

📒 Files selected for processing (9)
  • polylogue/cli/commands/maintenance/_rebuild_index.py
  • polylogue/cli/commands/paths.py
  • polylogue/cli/commands/reset.py
  • polylogue/config.py
  • polylogue/paths/_roots.py
  • polylogue/storage/archive_identity.py
  • tests/unit/cli/test_reset.py
  • tests/unit/core/test_paths.py
  • tests/unit/storage/test_archive_identity.py

Comment thread polylogue/paths/_roots.py Resolved
Sinity and others added 2 commits July 18, 2026 00:47
Problem:
A source-to-index rebuild materialized every raw id, discarded its batch
contract, and deleted an inactive candidate after an interrupted run. Large
archives therefore had no safe, resumable path to a replacement index.

What changed:
Persist source-order rebuild transactions alongside their owned inactive
index generations. Each full-source invocation schedules one keyset page,
checkpoints its cursor, and retains the candidate until terminal readiness can
promote it. Source-snapshot drift marks the operation stale rather than
promoting a mixed-evidence index.

Compatibility:
Unfiltered full rebuilds now return a paused operation id until a terminal
resume. Partial explicit selections retain their existing no-promote behavior.

Co-Authored-By: Claude <[email protected]>
Problem: full source-to-index rebuilds materialized every raw identifier before
scheduling work and had no durable byte/deadline envelope. A source mutation
could also leave terminal accounting ambiguous, while external active-index
pointers were still used as durable-tier roots by several consumers.

What changed: persist per-pass scheduling budgets and byte accounting with a
keyset cursor; retain paused, deferred, stale, failed, ready, and promoted
candidate lifecycle evidence. A budget defers remaining work but never
excludes it, including an oversized first raw. Promotion follows an exact
source snapshot and readiness check. Pointer-selected indexes are now kept
separate from configured durable tiers, and malformed pointer resolution
fails uniformly.

Compatibility/migration: existing rebuild transaction records decode with the
new optional fields; resumed operations retain their original budgets.

Co-Authored-By: Codex <[email protected]>
@Sinity
Sinity merged commit 87921d7 into master Jul 18, 2026
2 of 3 checks passed
@Sinity
Sinity deleted the feature/fix/archive-reliability-overhaul branch July 18, 2026 00:22
Sinity added a commit that referenced this pull request Jul 18, 2026
Make source-to-index rebuilds daemon-owned when requested online, while
retaining the offline break-glass command.

## Problem

The rebuild command performed an exclusive generation replay only after
polylogued stopped, despite the daemon already owning the archive writer
boundary.

## Solution

Extract the rebuild protocol into `polylogue.maintenance.rebuild_index` with
typed request and receipt values. Add authenticated
`POST /api/maintenance/rebuild-index`, execute it through the daemon writer
bridge's `run_sync`, and add `rebuild-index --daemon` as the CLI adapter. The
offline adapter keeps the same source-snapshot, readiness, and promotion
protocol, including the resumable bounded-pass transaction fields
(`--operation-id`, `--raw-batch-size`, `--pass-byte-budget-mb`,
`--pass-deadline-seconds`) that master had independently landed inline via
#3055 while this branch was in flight; both are now unified in the shared
module.

## Verification

- `devtools test tests/unit/cli/test_archive_maintenance_cli.py
  tests/unit/daemon/test_maintenance_endpoints.py
  tests/unit/daemon/test_http_write_coordination.py
  tests/unit/daemon/test_write_coordinator.py
  tests/unit/daemon/test_web_auth.py tests/unit/daemon/test_route_contracts.py`
  - 214 passed.
- `devtools render topology-projection && devtools render topology-status`
- `devtools render all --check` - no out-of-sync surfaces.
- `devtools verify --quick` - format, lint, mypy, generated surfaces,
  topology, layering, schema roundtrip, docs gates all passed.

Ref polylogue-ogn1 (follow-up: 8 CodeRabbit findings from the original
review, deferred as tracked debt, not part of this rebase's scope).

Co-Authored-By: Codex <[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