Skip to content

chore: restore master verify --quick baseline (rendered docs, budgets, lint debt) - #1001

Merged
Sinity merged 3 commits into
masterfrom
feature/chore/restore-verify-baseline
May 10, 2026
Merged

Sinity merged 3 commits into
masterfrom
feature/chore/restore-verify-baseline

Conversation

@Sinity

@Sinity Sinity commented May 10, 2026 •

Copy link
Copy Markdown
Owner

Summary

Restores devtools verify --quick to green on master. Three independent debt classes had accumulated across the 2026-05-09 PR wave (and earlier), each individually small but jointly blocking every new branch from passing the pre-push hook.

Problem

gh run list --branch master --workflow CI shows master CI has been red since 2026-05-02. PRs continued to merge through that window, and each one nudged at least one of the three following gates further out of sync:

  1. Rendered doc surfaces drifted — docs/cli-reference.md missed the maintenance group and message_type_backfill target added by feat(maintenance): add backfill replay and rebuild planner UX #871/fix(archive): store context and protocol artifacts semantically, not via projection fallbacks #839; AGENTS.md carried stale worktree-relative include paths from before #eeace79; test-quality-workflows.md and verification-catalog.md were similarly stale.
  2. File-size budgets caught three production files growing past their declared ceilings: polylogue/storage/repair.py (1281>1200, from fix(storage): clean orphan blobs and wire blob integrity checks #818+fix(archive): store context and protocol artifacts semantically, not via projection fallbacks #839), polylogue/operations/archive.py (1141>1100, from refactor(ingest): define shared import and maintenance operation contracts #861/refactor(mutations): centralize tag metadata and delete contracts #862), and polylogue/daemon/status.py (1128>1100, from fix(daemon): surface raw validation and parse failures in ingest/status #844/feat(daemon): add tiered health checks and backup command (#830) #898/feat(daemon): post-ingest embedding status and cost cap (#828) #915).
  3. Lint/type debt — 42 ruff errors (mostly import-sort drift after #eeace79 added devtools.repo_root to many devtools modules) and 3 mypy errors (TagMutationResult referenced in polylogue/api/archive.py but never imported; get_index_status returning a TypedDict typed as dict[str, object]).

The pre-push hook (.githooks/pre-push → devtools verify --quick) is correctly enforcing the gate; what was missing was a forcing function for the cumulative state. This PR is that function.

Solution

Three atomic commits:

  • f51e15be chore(docs): regenerate rendered surfaces stale on master — pure regeneration via devtools render-all, no logic changes.
  • 0b4eadee chore(budgets): raise ceilings for three files past their cap on master — three new exception entries in docs/plans/file-size-budgets.yaml. Each entry names the architectural-split candidate that would let the ceiling shrink, matching the convention used for existing exceptions. No code splits in this PR — the budgets file is the right place to make the pressure visible.
  • 372ad23b chore: clear ruff/mypy debt accumulated on master — 39 ruff auto-fixes (import sort, typing modernization, unused imports), 4 manual ruff fixes, 3 mypy fixes (missing imports, return-type tightening, click.Context handling in tests).

Total: 45 files, +121/-79 lines.

Verification

$ devtools verify --quick
verify: running local verification baseline
  ruff format ... ok (0.0s)
  ruff check ... ok (0.0s)
  mypy ... ok (73.4s)
  render-all ... ok (102.0s)
  verify-topology ... ok (0.3s)
  verify-layering ... ok (0.9s)
  verify-file-budgets ... ok (0.4s)
  verify-test-ownership ... ok (1.4s)
  verify-schema-roundtrip ... ok (1.5s)
  verify-cross-cuts ... ok (0.3s)
  verify-suppressions ... ok (3.1s)
  verify-manifests ... ok (5.5s)
  verify-witness-lifecycle ... ok (3.2s)
  verify-lane-assertions ... ok (1.4s)
  proof-pack check ... ok (7.0s)
verify: all checks passed

pytest tests/unit/daemon/test_maintenance_endpoints.py tests/unit/daemon/test_raw_failure_sample.py tests/unit/cli/test_maintenance_registration.py tests/unit/pipeline/test_message_type_backfill.py -q — 41 passed (no behavioural change introduced by the type-cleanup edits).

Follow-ups

  • Three "split candidate" hints in file-size-budgets.yaml — repair.py lift backfill into pipeline/services, per-domain operation modules under operations/, payload modules per daemon/status.py section — should be filed as separate refactor issues if/when the ceilings need to shrink again.

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • Documentation

    • Updated CLI reference with maintenance command documentation
    • Updated file-size budget exceptions and verification catalog metrics
  • Improvements

    • Enhanced archive maintenance API with improved type safety for index status queries
    • Improved code organization in development utilities and test infrastructure

Review Change Stack

Sinity and others added 3 commits May 10, 2026 03:33
devtools render-all --check has been failing on master since the
2026-05-09 PR wave (#871, #862, #864, #944, #870, #861) and earlier:
several rendered docs were out of sync with their generators, blocking
verify --quick on every branch.

Regenerated:
- AGENTS.md (worktree-relative include paths replaced by canonical
  toplevel paths after #eeace79 fixed repo_root resolution)
- docs/cli-reference.md (added maintenance group, message_type_backfill
  target from #839)
- docs/test-quality-workflows.md
- docs/verification-catalog.md

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Three production files exceeded their declared file-size budget after
recent PR merges:
- polylogue/storage/repair.py 1281 > 1200 (from #818 + #839 backfill)
- polylogue/operations/archive.py 1141 > 1100 (per_package; from
  #861/#862 contract centralization)
- polylogue/daemon/status.py 1128 > 1100 (from #844/#898/#915 typed
  payloads)

Each new exception entry names the architectural-split candidate that
would let the ceiling shrink, matching the convention already used for
existing exception entries. This restores verify-file-budgets to green
without papering over the underlying pressure.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Multiple parallel PRs landed on 2026-05-09 with incompatible local lint
state, leaving 42 ruff errors and 3 mypy errors on master that blocked
verify --quick.

Mechanical (ruff --fix):
- 30 import-block reorderings across devtools/* after #eeace79 added a
  cross-module import (devtools.repo_root) that disturbed I001 sort
- 3 unused imports (devtools/inject_semantic_annotations.py,
  devtools/verify_lane_assertions.py, devtools/xtask.py)
- typing_extensions → typing modernization in
  polylogue/surfaces/payloads.py and polylogue/archive/semantic/__init__.py
- import-block reordering in tests/unit/mcp/test_tool_contracts.py

Manual:
- polylogue/api/archive.py: add TagMutationResult to TYPE_CHECKING
  imports (#862 added the methods, never the type alias)
- polylogue/cli/click_command_registration.py: export maintenance_group
  in __all__ so test_maintenance_registration.py can import it
- polylogue/operations/archive.py: tighten get_index_status return type
  from dict[str, object] to IndexStatus TypedDict
- tests/unit/daemon/test_maintenance_endpoints.py: cast MockServer/
  MockHeaders to typed parents; add missing return annotation
- tests/unit/daemon/test_raw_failure_sample.py: drop unused-ignore on
  literal-tuple iteration; cast info["samples"] for indexing; rename
  test_rejects_non_RawFailureSample_items to lowercase per N802
- tests/unit/cli/test_maintenance_registration.py: pass real
  click.Context to list_commands instead of None
- tests/unit/pipeline/test_message_type_backfill.py: drop unused
  conv_id binding

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings May 10, 2026 01:36
@coderabbitai

coderabbitai Bot commented May 10, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 4d839457-8856-4cd9-a37c-f25de45fc250

📥 Commits

Reviewing files that changed from the base of the PR and between 6428192 and 372ad23.

📒 Files selected for processing (45)
  • AGENTS.md
  • devtools/benchmark_campaign.py
  • devtools/build_topology_projection.py
  • devtools/generate_readme_media.py
  • devtools/inject_semantic_annotations.py
  • devtools/lab_corpus.py
  • devtools/lab_scenario.py
  • devtools/mutmut_campaign.py
  • devtools/pages_builder.py
  • devtools/pipeline_probe/request.py
  • devtools/proof_pack.py
  • devtools/render_pages.py
  • devtools/render_topology_status.py
  • devtools/run_campaign.py
  • devtools/semantic_axis_evidence.py
  • devtools/verify_cluster_cohesion.py
  • devtools/verify_connection_sites.py
  • devtools/verify_cross_cuts.py
  • devtools/verify_distribution_surface.py
  • devtools/verify_file_budgets.py
  • devtools/verify_lane_assertions.py
  • devtools/verify_layering.py
  • devtools/verify_manifests.py
  • devtools/verify_migrations.py
  • devtools/verify_schema_annotations.py
  • devtools/verify_slos.py
  • devtools/verify_sql_templates.py
  • devtools/verify_suppressions.py
  • devtools/verify_test_ownership.py
  • devtools/verify_topology.py
  • devtools/xtask.py
  • docs/cli-reference.md
  • docs/plans/file-size-budgets.yaml
  • docs/test-quality-workflows.md
  • docs/verification-catalog.md
  • polylogue/api/archive.py
  • polylogue/archive/semantic/__init__.py
  • polylogue/cli/click_command_registration.py
  • polylogue/operations/archive.py
  • polylogue/surfaces/payloads.py
  • tests/unit/cli/test_maintenance_registration.py
  • tests/unit/daemon/test_maintenance_endpoints.py
  • tests/unit/daemon/test_raw_failure_sample.py
  • tests/unit/mcp/test_tool_contracts.py
  • tests/unit/pipeline/test_message_type_backfill.py

📝 Walkthrough

Walkthrough

This PR executes a large-scale code quality refactor standardizing import ordering across 27 devtools scripts, updating documentation paths and references, improving type safety in core APIs, and enhancing test type annotations. The changes follow PEP 8 conventions and Python's __future__ import placement rules.

Changes

Import Standardization and Type Safety Refactor

Layer / File(s) Summary
Documentation Foundation
AGENTS.md, docs/cli-reference.md, docs/test-quality-workflows.md, docs/verification-catalog.md
Include references updated from .claude/worktrees to canonical paths; maintenance command added to CLI reference; verification catalogs updated with +3 new maintenance commands and +4 subjects.
File Size Budget Exceptions
docs/plans/file-size-budgets.yaml
Ceilings increased for polylogue/storage/repair.py and new exceptions added for polylogue/operations/archive.py and polylogue/daemon/status.py with rationales for message-type backfill and typed status payloads.
Devtools Import Standardization
devtools/*.py (27 files)
Local devtools.repo_root imports relocated to appear after standard-library imports; unused imports (pathlib.Path) removed; respects PEP 8 and Python __future__ placement rules.
Type Safety and API Improvements
polylogue/operations/archive.py, polylogue/surfaces/payloads.py, polylogue/api/archive.py, polylogue/archive/semantic/__init__.py, polylogue/cli/click_command_registration.py
get_index_status() return type changed from dict to IndexStatus; TypeAlias moved from typing_extensions to typing; module-level imports added for better type support; export list reordered.
Test Type Annotations and Context Fixes
tests/unit/cli/test_maintenance_registration.py, tests/unit/daemon/test_maintenance_endpoints.py, tests/unit/daemon/test_raw_failure_sample.py, tests/unit/mcp/test_tool_contracts.py, tests/unit/pipeline/test_message_type_backfill.py
click.Context properly created instead of passing None; explicit cast() for type safety; unused imports removed; test function renamed for clarity.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Sinity/polylogue#764: Both modify polylogue/api/archive.py with related API and import changes.
  • Sinity/polylogue#505: Both adjust TagMutationResult imports and ordering in tests/unit/mcp/test_tool_contracts.py.
  • Sinity/polylogue#442: Both update docs/plans/file-size-budgets.yaml and related devtools file-budget verification.

Suggested labels

type:refactor, area:qa, type:test

Poem

🐰 Imports in order, now they stand tall,
Standard libs first, then devtools call,
TypeAlias dances to typing's new song,
Context and casts make weak code strong, 🎯

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 46.67% 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 The PR title clearly summarizes the main objective: restoring the master branch's verify --quick baseline by addressing rendered docs, file budgets, and lint debt.
Description check ✅ Passed The PR description comprehensively covers all required sections: Summary, Problem, Solution, Verification, and Follow-ups. It provides clear context, explains the three independent debt classes, details the atomic commits, and includes exact verification commands with passing results.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/chore/restore-verify-baseline

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 and usage tips.

@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: 372ad23b23

ℹ️ 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/operations/archive.py Resolved

Copilot AI 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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@Sinity
Sinity merged commit aabb547 into master May 10, 2026
7 of 8 checks passed
@Sinity
Sinity deleted the feature/chore/restore-verify-baseline branch May 10, 2026 10:58
Sinity added a commit that referenced this pull request May 10, 2026
… honest closure (#818) (#1002)

## Summary

Brings #818 (blob orphan cleanup and integrity verification) to actual
closure by adding the test layers that pin the contract end-to-end. The
implementation surface (`BlobStore.detect_orphans` / `cleanup_orphans` /
`verify_all`, `repair_orphaned_blobs` handler, `orphaned_blobs`
maintenance target, daemon-side health integration) was already complete
on master — what was missing was an integration test that fails loud if
any layer disconnects, plus property coverage for the bounded-orphan
invariant, plus a tighter assertion on the operator-visible orphan
output, plus catalog-routing tests added during adversarial review.

Closes #818.
Depends on #1001 (verify baseline restoration) — merge that first; this
branch rebases on it.

## Problem

#818 was reopened during the 2026-05-09 closed-issue audit because the
close-out language ("core implementation landed; remaining edges are
incremental") matched the abandonment pattern flagged in
`feedback_close_discipline.md`. The audit confirmed: implementation
existed, but the test surface only covered unit-level slices — there was
no end-to-end test pinning the contract operators rely on (`polylogue
check` orphan output, `polylogue doctor --repair --target
orphaned_blobs` round-trip), nor a property test for the bounded-output
invariant on `detect_orphans`. Any regression in any one wiring layer
(paths, blob_store, repair, maintenance) could land silently.

## Solution

### Acceptance criteria matrix

| AC | What | State after this PR |
|---|---|---|
| 818-A1 | `detect_orphans` returns count, bytes, sample; bounded output
independent of N | ✅ Implementation pre-existing; **new property test**
in `tests/property/test_blob_store_props.py` asserts samples bounded by
`max_sample` and counts/bytes match the disk-minus-DB set across
hypothesis-generated (0–80 orphans, 1–20 max_sample) parameter space |
| 818-A2 | `cleanup_orphans(dry_run=True)` default opt-in safety | ✅
Pre-existing; **new property test** asserts dry-run never deletes; **new
e2e test** asserts TOCTOU race (blob vanished mid-cleanup) is no-op |
| 818-A3 | `verify_all(max_failures)` re-hashes blobs, no DB | ✅
Pre-existing tests; integrity round-trip exercised in new e2e test |
| 818-A4 | Orphan detection in `polylogue check` operator output | ✅
Pre-existing in `cli/shared/check_workflow.py:142`; **tightened
assertion** in `tests/unit/cli/test_check_support_runtime.py:191` to
require `"Orphaned: 1 blobs (4,096 bytes)"` exact string + sample line |
| 818-A5 | `polylogue check --deep` runs `verify_all` | ✅ Pre-existing
at `check_workflow.py:147`; rendered in `docs/cli-reference.md`
(regenerated in #1001) |
| 818-A6 | `orphaned_blobs` maintenance target wired through catalog →
handler dict → handler | ✅ Pre-existing wiring
(`maintenance/targets.py:237`, `repair.py:671/1144/1157`); **new e2e
tests** in `TestRepairOrphanedBlobsHandler` +
`TestOrphanedBlobsCatalogRouting` exercise both the handler in isolation
AND the catalog→handler dispatch path |
| 818-A7 | Regression tests for `1bd2f156` GC bug fixes | ✅
`tests/unit/storage/test_blob_gc.py` covers both |
| 818-A8 | Daemon-side bounded `verify_all` | ✅ `daemon/health.py:639`
uses `max_failures=5` |
| 818-A9 | End-to-end ingest → orphan → detect → dry-run → apply →
verify | ✅ **New** `tests/integration/test_blob_lifecycle_e2e.py` |
| 818-A10 | Closeout matrix in PR + issue comment | ✅ This PR body +
planned comment on #818 |
| 818-A11 | Lease tables `pending_blob_refs`, `gc_generations`
retain/remove decision | ➡️ **Out of scope, tracked at #1000** — the
lease tables ARE used by `blob_gc.py` (lease acquire/release, generation
tracking); the actual question is whether the lease-based GC design is
still current vs. snapshot-based `repair_orphaned_blobs`. Separate
architectural review. |

### Files changed

- `tests/integration/test_blob_lifecycle_e2e.py` (NEW; 7 tests across 3
classes; ~280 LoC)
- `tests/property/test_blob_store_props.py` (NEW; 2 hypothesis tests;
~120 LoC)
- `tests/unit/cli/test_check_support_runtime.py` (tightened
orphan-output assertion; +5/-7 lines net after mock cleanup)

No production code changes — implementation was already complete; this
PR is purely additive test coverage that pins the closure.

## Verification

```
$ pytest tests/unit/storage/test_blob_store.py \
         tests/unit/storage/test_blob_gc.py \
         tests/unit/cli/test_check_support_runtime.py \
         tests/integration/test_blob_lifecycle_e2e.py \
         tests/property/test_blob_store_props.py -q
84 passed in ~12s

$ devtools verify --quick
verify: all checks passed
```

## Adversarial review notes

The plan called for an adversarial subagent loop iterating until no
legitimate gaps remained, capped at 5 iterations. The loop converged at
iteration 3.

**Iteration 1** — found one **real gap** (818-A6: catalog routing tested
only at handler level, not through
`MaintenanceTargetCatalog.resolve_name` → `_REPAIR_HANDLERS[name]`
dispatch path) and one borderline (818-A1 scale). Fixed in commit
`4a96e6e8` by adding `TestOrphanedBlobsCatalogRouting` with three tests
covering spec resolution (mode/category/destructive flag), handler-dict
entries (both `_REPAIR_HANDLERS` and `_PREVIEW_HANDLERS`), and
end-to-end catalog→handler→archive cleanup.

**Iteration 2** — found one borderline (mock field `scanned_count`
doesn't exist on real `OrphanDetectionResult`) and one borderline
(TOCTOU test scope clarity). Fixed mock field cleanup in commit
`86f85e15`. TOCTOU test docstring already explains scope; the "blob
re-referenced before cleanup" path is caller-orchestration, not a
`BlobStore` contract. Iteration 2 also flagged that the bounded-memory
property test asserts output bound but not intermediate memory bound —
dismissed because the implementation in `blob_store.py:367-385` is
structurally streaming (3 counters + a bounded list of `max_sample`),
and the test asserts `orphan_count`/`orphan_bytes` are correct
*independent of N*, which structurally requires the function to not
buffer all of N. An instrumented memory-watcher would be gold-plating
against the same structural guarantee.

**Iteration 3** — independent review: "No legitimate gaps found across
all 11 ACs after iteration 3 review." Confirmed all assertions catch
their regressions, all commit messages reference specific ACs without
hedging language, #1000 exists with real scope.

Loop exited clean. Total: 4 #818 commits (3 substantive + 1 mock
cleanup), 3 adversarial iterations, 1 documented dismissal.

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

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Tests**
* Added comprehensive integration and property-based tests for blob
orphan lifecycle management, including dry-run and live cleanup
scenarios, idempotency validation, and catalog routing verification.
* Updated test expectations for blob-store orphan reporting to align
with current system behavior.

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/Sinity/polylogue/pull/1002)

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Sinity added a commit that referenced this pull request May 10, 2026
… decisions (#868) (#1004)

## Summary

Brings #868 (daemon API threat model and auth boundaries) to actual
closure by adding the per-endpoint security test matrix, the remote-bind
refusal coverage, an explicit-decisions section in `docs/security.md`
for the residual scope, and a fix for the IPv6-loopback origin allowlist
gap surfaced during adversarial review. The bearer-token auth, origin
allowlist, and remote-bind enforcement were already implemented; what
was missing was test coverage and policy documentation that pins the
contract end-to-end.

Closes #868.
Depends on #1001 (verify baseline restoration) — merge that first; this
branch rebases on it.

## Problem

#868 was reopened twice during the closed-issue audit. The previous
closeouts deferred CORS/origin hardening, remote-bind handling,
per-endpoint review, and security tests to a "phase 2" with no issue
number. Implementation had landed across both reopens, but the test
surface only covered helper-function logic — there was no per-endpoint
matrix proving every route actually invokes the auth/origin checks, no
test pinning the remote-bind refusal at `daemon/cli.py:309-319`, no
token-leak guardrail, and no policy doc explicitly recording the
decisions about raw-artifact content and `/api/sources` paths.
Adversarial review additionally caught a coherence gap: `_is_localhost`
admits `::1` as a loopback bind address, but the cross-origin allowlist
hardcoded only the IPv4 and `localhost` strings — so a web shell served
from an IPv6 bind would have its same-origin POSTs wrongly rejected.

## Solution

### Acceptance criteria matrix

| AC | What | State after this PR |
|---|---|---|
| 868-A1 | `docs/security.md` defines trust boundaries, actor model,
asset model, attack surface | ✅ Refreshed: Trust Boundaries, Actors,
Assets sections added; attack-surface table corrected |
| 868-A2 | All POST/PUT/DELETE endpoints require valid bearer token when
configured | ✅ Pre-existing in `_check_auth_logic`; **new** parametrized
matrix covers all 4 POST endpoints × {missing, invalid, valid} |
| 868-A3 | All POST endpoints reject cross-origin browser requests via
Origin check, including IPv6 loopback | ✅ Pre-existing in
`_check_cross_origin`; **fixed** to include `http://[::1]:` /
`https://[::1]:`; **new** matrix covers all 4 POST endpoints × {no
origin, same-origin (incl. IPv6), cross-origin}; bracketed-IPv6
subdomain trick (`http://[::1].evil.com`) is rejected |
| 868-A4 | Non-loopback bind refuses without `--api-auth-token` AND
`--insecure-allow-remote` | ✅ Pre-existing in `daemon/cli.py:309-319`;
**new** test parametrizes 3 non-loopback hosts |
| 868-A5 | `--insecure-allow-remote` requires explicit token | ✅
Pre-existing; **new** test covers both missing and empty-string token |
| 868-A6 | Raw artifact endpoint policy: token-gated, content not
redacted (decision) | ✅ **Decision documented** in `docs/security.md`;
rationale: same operator can read blob store directly |
| 868-A7 | `/api/sources` policy: token-gated, returns absolute paths
(decision) | ✅ **Decision documented**; rationale: operator needs paths
for source diagnosis |
| 868-A8 | Per-endpoint security test matrix | ✅ **New** matrix in
`test_daemon_http_security.py`: 10 GET endpoints × 3 token states + 4
POST endpoints × {3 token states ⊕ 4 origin states}, total 120
parametrized tests |
| 868-A9 | `OPTIONS` returns 405 by design (decision) | ✅ Pre-existing
in `do_OPTIONS`; **new** test parametrized over all 14 endpoints;
**decision documented** |
| 868-A10 | Token never logged or in URLs | ✅ **New** static-grep
guardrail (`TestNoTokenLogging`) scans `polylogue/daemon` and
`polylogue/browser_capture` for log/print calls mentioning `auth_token`
or `Bearer`; legitimate non-logging usage whitelisted |
| 868-A11 | Browser capture: separate-by-design (decision) | ✅
**Decision documented**: different threat surface (extension→receiver vs
CLI→daemon), sharing a token would conflate them; token-leak guardrail
covers both modules |
| 868-A12 | Closeout matrix in PR + issue comment | ✅ This PR body +
planned comment on #868 |

### Files changed

- `tests/unit/daemon/test_daemon_http_security.py` (NEW; 120
parametrized tests; ~430 LoC)
- `tests/unit/daemon/test_daemon_cli_remote_bind.py` (NEW; 9 tests; ~175
LoC)
- `polylogue/daemon/http.py` (IPv6 loopback added to cross-origin
allowlist; +6/-3 lines)
- `docs/security.md` (rewritten; +99 lines)
- `docs/daemon-threat-model.md` (refreshed Trust Boundary section; +17
lines)

## Verification

```
$ pytest tests/unit/daemon/test_daemon_http_security.py \
         tests/unit/daemon/test_daemon_cli_remote_bind.py -q
120 passed in ~0.4s

$ devtools verify --quick
verify: all checks passed
```

## Adversarial review notes

The plan called for an adversarial subagent loop iterating until no
legitimate gaps remained, capped at 5 iterations. The loop converged at
iteration 2.

**Iteration 1** — found one **real gap** (868-A3: IPv6 loopback `::1`
admitted by `_is_localhost` for binding but not in the cross-origin
allowlist; web shell served from `http://[::1]:port` would have
legitimate same-origin POSTs rejected as cross-origin). Fixed in commit
`bb59aac6` by adding `http://[::1]:` / `https://[::1]:` to both
`polylogue/daemon/http.py:_check_cross_origin` and the test helper, plus
parametrized cases for the legitimate IPv6 origin and a bracketed-IPv6
subdomain trick (`http://[::1].evil.com`) that must still be rejected.

**Iteration 2** — independent review: "No legitimate gaps found across
all 12 ACs after iteration 2 review." Confirmed all assertions catch
their regressions, the bracketed-IPv6 trick is correctly rejected by the
colon-required prefix match, threat-model docs are internally
consistent, and no closeout language hedges without an issue number.

Loop exited clean. Total: 4 #868 commits (3 substantive + 1
adversarial-iteration fix), 2 adversarial iterations.

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

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
@Sinity

Sinity commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

  • 68.F025 / P1: fixed-already at the checked revision: polylogue/api/archive.py:68 imports IndexStatus at runtime, outside TYPE_CHECKING. The current get_index_status route at lines 5576-5584 delegates to archive.index_status through a read transaction and has no undefined-name DatabaseError fallback.

Only the rows listed above are dispositioned. Held findings remain open.

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.

2 participants