Skip to content

feat(devtools): gate parser/classifier decision-boundary drift - #3532

Merged
Sinity merged 2 commits into
masterfrom
feature/devtools/classifier-fingerprint-gate
Aug 2, 2026
Merged

Sinity merged 2 commits into
masterfrom
feature/devtools/classifier-fingerprint-gate

Conversation

@Sinity

@Sinity Sinity commented Aug 2, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds devtools lab policy classifier-fingerprints, a new static verification gate that detects when a parser/classifier's acceptance decision changes for identical input bytes without a declared reparse. This closes the gap named in polylogue-gucv: the existing schema-versioning lint is keyed entirely to a version integer and cannot see this class of change.

Problem

devtools lab policy schema-versioning (devtools/verify_schema_upgrade_lane.py) enforces the durable-vs-derived schema evolution policy boundary, but every one of its four checks reads from INDEX_SCHEMA_VERSION or lifecycle.py's version-keyed declarations. It has zero visibility into polylogue/sources/** or polylogue/archive/artifact_taxonomy/**, where the actual "is this raw payload a session?" decision is made.

PR #3428 (ab8a92c1a, "require positive conversation evidence before session classification") is the confirmed case: it tightened looks_like_record_entry and looks_like_code so that a payload the classifier used to admit is now refused, for identical bytes. INDEX_SCHEMA_VERSION stayed unchanged, lifecycle.py gained no new declaration, and devtools lab policy schema-versioning ran green — correctly per its own contract, uselessly for this defect. Already-indexed rows under the old classification went silently stale with no signal a reparse was ever needed. CLAUDE.md's own claim ("a bump without a declaration is a policy violation") only holds for the version-bump case; a same-version classifier change bypasses it entirely.

Related, not duplicated: polylogue-9rw0 owns the fast-forward/equivalence-proof mechanism (its own notes already concede "parser-content drift is NOT covered"); polylogue-zqph owns the data-side repair of the ~5,257 existing phantom rows. This PR is the missing gate only.

Solution

devtools/verify_classifier_fingerprints.py:

  1. Discovers every module-level function under the two classification directories whose name matches looks_like* or classify_artifact* (36 functions currently — the exact naming convention this codebase already uses for payload-shape/acceptance decisions).
  2. Fingerprints each one as a SHA-256 hash of its AST with the leading docstring stripped, so reformatting, comment edits, and docstring rewrites never trip the gate, but a change to the function's actual logic always does.
  3. Compares against a committed manifest (docs/plans/classifier-fingerprints.json). A fingerprint mismatch is undeclared drift and fails the gate unless the manifest entry names one of:
    • semantic_reparse_version — an INDEX_SCHEMA_VERSION bump whose lifecycle.py declaration actually carries SEMANTIC_REPARSE for that version (cross-checked against INDEX_DELTA_DECLARATIONS, not just asserted).
    • acknowledged_safe — an explicit reason (≥20 chars) plus a bead/issue ref (polylogue-xxxx or #N), for cases judged safe without a reparse (e.g. only tightening a shape that never validly matched).
  4. A brand-new classifier function with no manifest entry, or a manifest entry whose function no longer exists, both fail — the manifest must track exactly the live set.

A --ack <qualname> --reason ... --ref ... [--semantic-reparse N] maintenance mode upserts a manifest entry at the function's current fingerprint after validating the covered_by shape.

Wired into devtools verify's default (non---commit) path immediately next to lab policy schema-versioning — static, archive-independent, sub-second (0.61s measured).

The initial manifest bootstraps all 36 discovered functions as acknowledged_safe. The two functions PR #3428 actually changed (looks_like_record_entry, looks_like_code) are acknowledged with a reason naming that PR and a ref to polylogue-zqph, which owns the existing-row repair — this PR does not touch live data or trigger a reindex.

Both devtools/verify_schema_upgrade_lane.py's module docstring and docs/internals.md's Schema Versioning Model section now state the scope gap explicitly, per the bead's AC: a green lab policy schema-versioning run is no longer readable as "no reparse needed" without checking the classifier-fingerprint gate too.

Verification

  • devtools test tests/unit/devtools/test_verify_classifier_fingerprints.py — 10 passed, including a historical regression test that reconstructs the pre-PR-fix(sources): require positive conversation evidence before session classification #3428 manifest state (git show ab8a92c1a~1:polylogue/sources/parsers/claude/code_detection.py, fingerprinted the same way) and asserts the new gate flags looks_like_code as undeclared drift — proving this gate would have caught PR fix(sources): require positive conversation evidence before session classification #3428 before it landed.
  • mypy on the new module and test file: Success: no issues found in 2 source files.
  • ruff format --check / ruff check on all changed files: clean.
  • devtools render all --check: no out of sync lines.
  • devtools verify closure-matrix: closure-matrix: clean (33 domains).
  • devtools verify --quick: full local static gate, exit_code: 0, including the new lab policy classifier-fingerprints step (0.61s). Re-ran automatically and passed again via the pre-push hook.

Not run: the heavy devtools test tests/unit full suite (per-PR CI convention skips it; this change touches only devtools/ + one new test file, no polylogue/ runtime module, so the topology projection did not need regeneration).

Ref polylogue-gucv

Summary by CodeRabbit

  • New Features

    • Added a classifier-fingerprint policy check to the verification lab.
    • Detects missing, orphaned, invalid, or changed classifier fingerprints.
    • Supports JSON reporting and recording acknowledged fingerprints.
  • Documentation

    • Documented classifier-fingerprint verification, acknowledgment requirements, and schema-check limitations.
    • Added the new command to the developer tools catalog.
  • Tests

    • Added comprehensive coverage for fingerprint discovery, drift detection, manifest validation, and stability.

Problem: `devtools lab policy schema-versioning` is keyed entirely to
INDEX_SCHEMA_VERSION, so it has no visibility into whether a parser or
classifier under polylogue/sources/ or polylogue/archive/artifact_taxonomy/
changed what it accepts for identical input bytes. PR #3428 tightened
looks_like_record_entry and looks_like_code (removing bare "type" as
sufficient session evidence) without any version bump, and the
schema-versioning lint ran green on it -- correctly per its own narrow
contract, uselessly for this defect. Already-indexed rows stayed silently
stale with no signal a reparse was ever needed (polylogue-gucv, -9ykn,
-zqph).

Solution: new devtools/verify_classifier_fingerprints.py
(`devtools lab policy classifier-fingerprints`) discovers every
looks_like*/classify_artifact* function under the two classification
directories, fingerprints each one's AST (docstring stripped, so
reformatting/comment/docstring edits never trip it), and compares against a
committed manifest (docs/plans/classifier-fingerprints.json). A function
whose fingerprint drifts from the manifest without a matching declaration
fails the gate. Drift resolves one of two ways, recorded in the manifest:
a `semantic_reparse_version` entry naming an INDEX_SCHEMA_VERSION bump whose
lifecycle.py declaration actually carries SEMANTIC_REPARSE, or an
`acknowledged_safe` entry with an explicit reason + bead/issue ref. New or
removed classifier functions also fail (missing/orphaned manifest entries).
Wired into `devtools verify --quick`/default path next to
`lab policy schema-versioning` (static, archive-independent, sub-second).

The initial manifest bootstraps all 36 discovered functions as
acknowledged_safe; the two PR #3428 changed (looks_like_record_entry,
looks_like_code) are acknowledged referencing polylogue-zqph, which owns
the existing-row repair. verify_schema_upgrade_lane.py's docstring and
docs/internals.md now state the scope gap explicitly, so a green
schema-versioning run is not read as "no reparse needed".

Verification: devtools test tests/unit/devtools/test_verify_classifier_fingerprints.py
(10 passed, including a historical regression test that reconstructs the
pre-PR-#3428 manifest state via `git show ab8a92c~1:...` and asserts the
new gate flags looks_like_code as undeclared drift); mypy --strict on the
new module; ruff format/check; devtools render all --check; devtools verify
closure-matrix; devtools verify --quick (full local static gate, exit 0,
includes the new "lab policy classifier-fingerprints" step at 0.61s).

Ref polylogue-gucv

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

coderabbitai Bot commented Aug 2, 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: 38 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: 4793d33f-bab2-459c-83be-57717b2a0e69

📥 Commits

Reviewing files that changed from the base of the PR and between 715deb8 and e9a536e.

📒 Files selected for processing (2)
  • devtools/verify_classifier_fingerprints.py
  • tests/unit/devtools/test_verify_classifier_fingerprints.py
📝 Walkthrough

Walkthrough

Changes

Classifier fingerprint policy

Layer / File(s) Summary
Classifier discovery and fingerprint contracts
devtools/verify_classifier_fingerprints.py
Defines classifier discovery, AST-based SHA-256 fingerprints, and manifest coverage data structures.
Manifest validation and drift reporting
devtools/verify_classifier_fingerprints.py, docs/plans/classifier-fingerprints.json, tests/unit/devtools/test_verify_classifier_fingerprints.py
Validates manifest entries and reports missing, orphaned, drifted, or invalid classifier declarations. Tests cover discovery, normalization, drift, metadata, and historical changes.
Acknowledgment and command-line execution
devtools/verify_classifier_fingerprints.py
Adds acknowledgment options and human-readable or JSON policy results.
Verification integration and policy documentation
devtools/command_catalog.py, devtools/verify.py, devtools/verify_schema_upgrade_lane.py, docs/devtools.md, docs/internals.md
Registers the policy command, adds it to baseline verification, and documents its relationship to schema-version checks and semantic reparse declarations.

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

Sequence Diagram(s)

sequenceDiagram
  participant Developer
  participant Verify
  participant FingerprintVerifier
  participant ClassifierSources
  participant FingerprintManifest

  Developer->>Verify: Run repository verification
  Verify->>FingerprintVerifier: Execute classifier-fingerprint policy
  FingerprintVerifier->>ClassifierSources: Discover classifier functions
  ClassifierSources-->>FingerprintVerifier: Return current fingerprints
  FingerprintVerifier->>FingerprintManifest: Load manifest entries
  FingerprintManifest-->>FingerprintVerifier: Return fingerprints and coverage
  FingerprintVerifier-->>Verify: Return drift report and exit status
  Verify-->>Developer: Report verification result
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.00% 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 title clearly and concisely describes the new gate for parser and classifier decision-boundary drift.
Description check ✅ Passed The description covers the problem, solution, verification, affected modules, policy behavior, and known scope, with sufficient implementation detail.
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 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/devtools/classifier-fingerprint-gate

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.

@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: 4

🤖 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 `@devtools/command_catalog.py`:
- Around line 1257-1275: Add "lab policy classifier-fingerprints" to the
VERIFICATION_LAB_COMMAND_NAMES tuple so the CommandSpec registered by
verification_lab_command_specs() appears in the CLI inventory, generated
documentation, surface test, and JSON command listing.

In `@devtools/verify_classifier_fingerprints.py`:
- Around line 358-433: The test suite lacks coverage for the manifest-writing
path in _cmd_ack. Add a unit test in
tests/unit/devtools/test_verify_classifier_fingerprints.py that uses a temporary
manifest path, invokes _cmd_ack or main with --ack for a discovered classifier,
and verifies the saved ManifestEntry fingerprint, covered_by kind, reason, ref,
and semantic-reparse version as applicable.
- Around line 120-139: Update _fingerprint_function to preserve the source
function’s decorator_list when constructing replacement, so decorator additions,
removals, and changes are included in ast.dump and alter the fingerprint.
- Around line 148-152: Update the exception handling in
collect_classifier_functions around path.read_text and ast.parse to also catch
UnicodeDecodeError, skipping files with non-UTF-8 content while preserving the
existing SyntaxError skip behavior.
🪄 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 Plus

Run ID: a0b5dae3-0375-4f7c-bef3-56abec85e7d9

📥 Commits

Reviewing files that changed from the base of the PR and between 1059339 and 715deb8.

📒 Files selected for processing (8)
  • devtools/command_catalog.py
  • devtools/verify.py
  • devtools/verify_classifier_fingerprints.py
  • devtools/verify_schema_upgrade_lane.py
  • docs/devtools.md
  • docs/internals.md
  • docs/plans/classifier-fingerprints.json
  • tests/unit/devtools/test_verify_classifier_fingerprints.py

Comment on lines +1257 to +1275
CommandSpec(
"lab policy classifier-fingerprints",
"verification lab",
"Verify parser/classifier decision-boundary changes are declared as reparse-requiring or acknowledged.",
"devtools.verify_classifier_fingerprints",
use_when=(
"Catch the gap `lab policy schema-versioning` cannot see (polylogue-gucv): a parser/classifier "
"under polylogue/sources/ or polylogue/archive/artifact_taxonomy/ (looks_like*/classify_artifact* "
"functions) changes what it accepts for identical input bytes without any INDEX_SCHEMA_VERSION "
"bump at all, so already-indexed rows go silently stale with no signal a reparse was needed "
"(PR #3428 shipped exactly this, green, against the version-keyed gate)."
),
examples=(
"devtools lab policy classifier-fingerprints",
"devtools lab policy classifier-fingerprints --json",
"devtools lab policy classifier-fingerprints --ack polylogue/sources/parsers/foo.py:looks_like_x "
"--reason 'only tightens a shape that never validly matched' --ref polylogue-abcd",
),
),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n -C 4 -P '\bVERIFICATION_LAB_COMMAND_NAMES\b' devtools
rg -n -C 4 -F 'lab policy classifier-fingerprints' devtools docs

Repository: Sinity/polylogue

Length of output: 8567


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== command_catalog header/tuple =="
sed -n '1,70p' devtools/command_catalog.py
echo
echo "== command_catalog registry functions =="
sed -n '1820,1870p' devtools/command_catalog.py
echo
echo "== command_catalog consumers in repo =="
rg -n -C 4 -P 'VERIFICATION_LAB_COMMAND_NAMES|verification_lab_command_specs\(' .

Repository: Sinity/polylogue

Length of output: 9969


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== render_devtools_reference.py =="
sed -n '50,110p' devtools/render_devtools_reference.py
echo
echo "== click_dispatch.py =="
sed -n '25,80p' devtools/click_dispatch.py
echo
echo "== devtools/unit tests command_catalog =="
sed -n '1,90p' tests/unit/devtools/test_command_catalog.py
echo
echo "== devtools/unit tests devtools_main =="
sed -n '1,40p' tests/unit/devtools/test_devtools_main.py

Repository: Sinity/polylogue

Length of output: 8888


Add lab policy classifier-fingerprints to VERIFICATION_LAB_COMMAND_NAMES.

verification_lab_command_specs() builds the CLI inventory, generated docs/devtools.md surface, test_verification_lab_surface_is_explicit_and_implemented(), and devtools --list-commands --json from this tuple, so the new CommandSpec is missing from several authoritative output paths.

🤖 Prompt for 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.

In `@devtools/command_catalog.py` around lines 1257 - 1275, Add "lab policy
classifier-fingerprints" to the VERIFICATION_LAB_COMMAND_NAMES tuple so the
CommandSpec registered by verification_lab_command_specs() appears in the CLI
inventory, generated documentation, surface test, and JSON command listing.

Comment on lines +358 to +433
def _cmd_ack(qualname: str, *, reason: str, ref: str, semantic_reparse_version: int | None) -> int:
current = collect_classifier_functions()
if qualname not in current:
print(f"error: {qualname!r} is not a currently discovered classification function", file=sys.stderr)
return 2
manifest = load_manifest()
covered_by = CoveredBy(
kind="semantic_reparse_version" if semantic_reparse_version is not None else "acknowledged_safe",
reason=reason,
ref=ref,
version=semantic_reparse_version,
)
problem = _validate_covered_by(covered_by)
if problem is not None:
print(f"error: {problem}", file=sys.stderr)
return 2
manifest[qualname] = ManifestEntry(fingerprint=current[qualname].fingerprint, covered_by=covered_by)
save_manifest(manifest)
print(f"recorded {qualname} ({covered_by.kind})")
return 0


def main(argv: list[str] | None = None) -> int:
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument("--json", action="store_true", help="emit machine-readable JSON")
parser.add_argument(
"--ack",
metavar="QUALNAME",
help="record an acknowledged_safe (or, with --semantic-reparse, semantic_reparse_version) "
"manifest entry for a classification function at its current fingerprint",
)
parser.add_argument("--reason", help="justification text for --ack (required with --ack)")
parser.add_argument("--ref", help="bead id (polylogue-xxxx) or issue number (#N) for --ack (required with --ack)")
parser.add_argument(
"--semantic-reparse",
dest="semantic_reparse_version",
type=int,
metavar="VERSION",
help="with --ack: record semantic_reparse_version covered_by instead of acknowledged_safe",
)
args = parser.parse_args(argv)

if args.ack:
if not args.reason or not args.ref:
parser.error("--ack requires --reason and --ref")
return _cmd_ack(
args.ack,
reason=args.reason,
ref=args.ref,
semantic_reparse_version=args.semantic_reparse_version,
)

report = compute_drift_report()

if args.json:
print(
json.dumps(
{
"missing": list(report.missing),
"orphaned": list(report.orphaned),
"drifted": list(report.drifted),
"invalid_covered_by": [
{"qualname": qualname, "problem": problem} for qualname, problem in report.invalid_covered_by
],
"ok": report.ok,
},
indent=2,
)
)
else:
print(_format_report(report))

return 0 if report.ok else 1

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

No test coverage for _cmd_ack or the human-readable _format_report path.

tests/unit/devtools/test_verify_classifier_fingerprints.py exercises main(["--json"]), load_manifest, compute_drift_report, _fingerprint_function, and _validate_covered_by, but never calls _cmd_ack (the only write path that mutates the committed manifest file) or checks _format_report's plain-text output. Since _cmd_ack is the mechanism operators use to resolve drift, a regression here (e.g., an incorrect covered_by construction, or save_manifest writing a malformed entry) would go undetected by the current suite.

Add a test that calls _cmd_ack (or main with --ack) against a temporary manifest path and asserts the resulting entry.

🧰 Tools
🪛 ast-grep (0.45.0)

[info] 416-427: use jsonify instead of json.dumps for JSON output
Context: json.dumps(
{
"missing": list(report.missing),
"orphaned": list(report.orphaned),
"drifted": list(report.drifted),
"invalid_covered_by": [
{"qualname": qualname, "problem": problem} for qualname, problem in report.invalid_covered_by
],
"ok": report.ok,
},
indent=2,
)
Note: [CWE-116] Improper Encoding or Escaping of Output.

(use-jsonify)

🤖 Prompt for 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.

In `@devtools/verify_classifier_fingerprints.py` around lines 358 - 433, The test
suite lacks coverage for the manifest-writing path in _cmd_ack. Add a unit test
in tests/unit/devtools/test_verify_classifier_fingerprints.py that uses a
temporary manifest path, invokes _cmd_ack or main with --ack for a discovered
classifier, and verifies the saved ManifestEntry fingerprint, covered_by kind,
reason, ref, and semantic-reparse version as applicable.

…code errors

CodeRabbit findings on PR #3532: decorator changes on a classifier
function were silently excluded from its fingerprint (decorator_list=[]
in the AST replacement), and collect_classifier_functions only guarded
against SyntaxError, not UnicodeDecodeError, for non-UTF-8 source files.

Regenerated the baseline manifest against the fixed hash -- zero entries
changed, since none of the currently-tracked classifier functions carry
decorators. Added regression tests for both cases.

Co-Authored-By: Claude <[email protected]>
@Sinity
Sinity merged commit 1a2ea50 into master Aug 2, 2026
3 checks passed
@Sinity
Sinity deleted the feature/devtools/classifier-fingerprint-gate branch August 2, 2026 10:37
Sinity added a commit that referenced this pull request Aug 2, 2026
…fier tightening

The classifier-fingerprint gate (PR #3532, merged after this branch was cut)
correctly caught that PR #3537's looks_like_ai tightening moved a parser
decision boundary without a declared reparse delta. Bump
INDEX_SCHEMA_VERSION to 54, declare the SEMANTIC_REPARSE delta, and
acknowledge the manifest entry accordingly.

Co-Authored-By: Claude <[email protected]>
Sinity added a commit that referenced this pull request Aug 2, 2026
#3542)

## Summary
Adds one-call, depth-annotated delegation ancestry (root-to-node) and
subtree (node-to-descendants) queries over `delegation_facts`, exposed
through the existing `get`/`read` MCP surface via new
`delegation:ancestry:<id>`/`delegation:subtree:<id>` ObjectRef prefixes.

## Problem
Delegation in this archive is a tree (subagents dispatch their own
subagents), and `delegation_facts` already models arbitrary depth
implicitly (each row is one parent→child edge). What's missing is a
query surface returning a whole ancestry chain or subtree in one call,
depth-annotated, without N+1 queries or client-side reassembly.

## Solution
- **Design decision (argued from evidence, not assumed)**:
`work_evidence_nodes/edges` (index v46+) supports arbitrary-depth
traversal by construction but is measured "structurally hollow"
(constant authority/confidence, 100% NULL time/actor, zero rows sourced
from Claude Code delegation — only Workflow orchestration runs populate
it). A pure on-demand adapter already exists
(`polylogue/insights/delegation_work_evidence.py`, polylogue-1vpm.6.1)
projecting `delegation_facts` into that vocabulary, with no production
caller — establishing that `delegation_facts` is the richer typed source
of truth and the generic graph is a consumer-side adapter, not a
persistence target. Built natively over `delegation_facts` (via the
`delegations` view) rather than growing a second persisted graph.
- `ArchiveStore.get_delegation_ancestry(session_id)` /
`get_delegation_subtree(session_id)`
(`storage/sqlite/archive_tiers/archive.py`) — `WITH RECURSIVE` CTEs over
`delegations`, depth-annotated, no N+1.
- Cycle/orphan handling reuses the existing `mapping_state !=
'quarantined'` exclusion (no second vocabulary invented); a defensive
visited-path guard is kept and proven necessary by a constructed
two-node-cycle test (from genuinely `resolved`, non-quarantined edges
the topology quarantine pass never inspects).
- New `delegation:ancestry:`/`delegation:subtree:` ObjectRef prefixes
(`core/refs.py`) route through the existing `get`/`read` MCP tools via
`resolve_ref` (`api/archive.py`) — no new MCP tool/dispatcher entry
needed.
-
`docs/plans/classifier-fingerprints.json`/`lifecycle.py`/`archive_tiers/index.py`:
also declares INDEX_SCHEMA_VERSION v54 (SEMANTIC_REPARSE) for PR #3537's
`looks_like_ai` tightening, which the classifier-fingerprint gate (PR
#3532, merged after this branch was cut) correctly flagged as undeclared
drift blocking push.

## Non-goals
Rewriting `delegation_facts`' identity-matching mechanism (owned by
polylogue-1vpm.7, already fixed). Building the HTML/report rendering
(this surface's shape is designed to feed the html-report skill's
delegation-tree pattern directly, without restitching, but the renderer
itself is out of scope). Live corpus depth/fan-out re-measurement
(deferred pending the coordinator's separately-managed reindex).

## Verification
`devtools test tests/unit/storage/test_delegations_view.py
tests/unit/api/test_facade_contracts.py tests/unit/core/test_refs.py
tests/unit/insights/test_delegation_work_evidence.py` — 390 passed, 1
pre-existing failure
(`test_archive_tiers_api_raw_artifacts_read_source_tier`, stale
hardcoded timestamp) confirmed identical on unmodified master. `devtools
verify --quick` exit 0 (ruff format/check, mypy --strict,
render-all-check, classifier-fingerprints, schema-versioning).

Ref polylogue-qsb4

Co-Authored-By: Claude <[email protected]>

Co-authored-by: Claude <[email protected]>
Sinity added a commit that referenced this pull request Aug 2, 2026
Documents the corrected finding (origin_specs.py artifact_rules were
uncovered by PR #3532's function-only fingerprinting) and this PR's fix,
directly on the bead this branch's code change addresses.

Co-Authored-By: Claude <[email protected]>
Sinity added a commit that referenced this pull request Aug 2, 2026
…tifact rules

Problem: devtools lab policy classifier-fingerprints (PR #3532) fingerprints
looks_like*/classify_artifact* function bodies, but polylogue-qs4b's original
concrete case -- PR #3088 changing parse_as_session for four Claude Workflow
artifact kinds -- edited a declarative data table, origin_specs.py's
OriginSpec.artifact_rules, not a function. Reproduced live: mutating an
OriginArtifactRule's parse_policy with no INDEX_SCHEMA_VERSION bump passed
both devtools lab policy schema-versioning and the pre-existing
classifier-fingerprints gate.

Solution: fingerprint every OriginArtifactRule reachable from ORIGIN_SPECS
(hash of path_pattern/parse_policy/parser_path/coverage_role/path_suffixes;
fidelity_note excluded as prose, mirroring docstring exclusion for function
fingerprints), tracked in the same manifest and covered_by contract as the
existing function fingerprints. Bootstrapped the 7 live Claude Code artifact
rules as acknowledged_safe baseline entries.

Verification:
- Reproduced the #3088 failure shape live: mutated agent_transcript's
  parse_policy (session -> fact) with no version bump -> classifier-
  fingerprints failed (exit 1, named the rule as undeclared drift) while
  schema-versioning stayed green -- confirmed the gap, then confirmed the
  fix closes it, then reverted the mutation.
- devtools test tests/unit/devtools/test_verify_classifier_fingerprints.py:
  16 passed (12 pre-existing + 4 new, including a historical regression test
  replaying the #3088 parse_policy mutation and a fingerprint-stability test
  proving fidelity_note edits alone don't fire).
- devtools verify --quick: exit_code 0 (ruff format/check, mypy, render all,
  layering, closure-matrix, both lab policy gates, schema promotion audit).

Ref polylogue-qs4b

Co-Authored-By: Claude <[email protected]>
Sinity added a commit that referenced this pull request Aug 2, 2026
Documents the corrected finding (origin_specs.py artifact_rules were
uncovered by PR #3532's function-only fingerprinting) and this PR's fix,
directly on the bead this branch's code change addresses.

Co-Authored-By: Claude <[email protected]>
Sinity added a commit that referenced this pull request Aug 2, 2026
…tifact rules

Problem: devtools lab policy classifier-fingerprints (PR #3532) fingerprints
looks_like*/classify_artifact* function bodies, but polylogue-qs4b's original
concrete case -- PR #3088 changing parse_as_session for four Claude Workflow
artifact kinds -- edited a declarative data table, origin_specs.py's
OriginSpec.artifact_rules, not a function. Reproduced live: mutating an
OriginArtifactRule's parse_policy with no INDEX_SCHEMA_VERSION bump passed
both devtools lab policy schema-versioning and the pre-existing
classifier-fingerprints gate.

Solution: fingerprint every OriginArtifactRule reachable from ORIGIN_SPECS
(hash of path_pattern/parse_policy/parser_path/coverage_role/path_suffixes;
fidelity_note excluded as prose, mirroring docstring exclusion for function
fingerprints), tracked in the same manifest and covered_by contract as the
existing function fingerprints. Bootstrapped the 7 live Claude Code artifact
rules as acknowledged_safe baseline entries.

Verification:
- Reproduced the #3088 failure shape live: mutated agent_transcript's
  parse_policy (session -> fact) with no version bump -> classifier-
  fingerprints failed (exit 1, named the rule as undeclared drift) while
  schema-versioning stayed green -- confirmed the gap, then confirmed the
  fix closes it, then reverted the mutation.
- devtools test tests/unit/devtools/test_verify_classifier_fingerprints.py:
  16 passed (12 pre-existing + 4 new, including a historical regression test
  replaying the #3088 parse_policy mutation and a fingerprint-stability test
  proving fidelity_note edits alone don't fire).
- devtools verify --quick: exit_code 0 (ruff format/check, mypy, render all,
  layering, closure-matrix, both lab policy gates, schema promotion audit).

Ref polylogue-qs4b

Co-Authored-By: Claude <[email protected]>
Sinity added a commit that referenced this pull request Aug 2, 2026
Documents the corrected finding (origin_specs.py artifact_rules were
uncovered by PR #3532's function-only fingerprinting) and this PR's fix,
directly on the bead this branch's code change addresses.

Co-Authored-By: Claude <[email protected]>
Sinity added a commit that referenced this pull request Aug 2, 2026
…tifact rules (#3563)

## Summary

Extends `devtools lab policy classifier-fingerprints` (PR #3532) to also fingerprint `origin_specs.py`'s `OriginSpec.artifact_rules` declarative table, closing the specific gap named in polylogue-qs4b that the function-only gate did not cover.

## Problem

polylogue-qs4b's investigation asked whether the schema-versioning lint (`devtools/verify_schema_upgrade_lane.py`) could be made to catch an undeclared classification-semantic change, citing PR #3088 as the concrete case: it changed `parse_as_session` for four Claude Workflow artifact kinds by editing `origin_specs.py`'s `artifact_rules` table (a `parse_policy` field per `OriginArtifactRule`), with no `INDEX_SCHEMA_VERSION` bump at all.

By the time this session started, the sibling bead polylogue-gucv (a narrower but related finding about the same lint's blindness to `looks_like*`/`classify_artifact*` function drift, concrete case PR #3428) had already merged a fix: PR #3532 added `devtools lab policy classifier-fingerprints`, an AST-fingerprint gate over classification functions.

Reproduced live in this session: mutating an `OriginArtifactRule.parse_policy` (`session` -> `fact`) with no version bump passed **both** `devtools lab policy schema-versioning` and the pre-PR-#3532 `classifier-fingerprints` gate, because `OriginArtifactRule` entries are data, not `looks_like*`/`classify_artifact*` function bodies, so they were never in scope for the existing AST scan.

## Solution

`devtools/verify_classifier_fingerprints.py`:

- `collect_origin_artifact_rules()`: walks `ORIGIN_SPECS`, fingerprinting each `OriginArtifactRule` as a SHA-256 hash of its classification-relevant fields (`path_pattern`, `parse_policy`, `parser_path`, `coverage_role`, `path_suffixes` as canonical JSON). `fidelity_note` is excluded as prose documentation, mirroring how a function's leading docstring is stripped before hashing.
- `collect_all_classification_surfaces()`: merges function fingerprints and artifact-rule fingerprints into one dict, now the default `current` for `compute_drift_report` and the lookup used by `--ack`.
- Bootstrapped the 7 live Claude Code artifact rules into `docs/plans/classifier-fingerprints.json` as `acknowledged_safe` baseline entries (same mechanism PR #3532 used for the initial 36 functions).
- Updated the module docstring, `_format_report` wording ("classification functions" -> "classification surfaces" where it now covers both kinds), and `docs/internals.md`'s Schema regimes section to describe both fingerprinted surfaces and name PR #3088 as the case this half of the gate exists for.

## Verification

- Reproduced the exact failure mode before the fix: mutated `agent_transcript`'s `parse_policy` from `session` to `fact` (the same class of edit as PR #3088) with no `INDEX_SCHEMA_VERSION` bump. Confirmed `devtools lab policy schema-versioning` stayed green and the pre-fix `classifier-fingerprints` gate also stayed green (didn't see the rule at all). Reverted, applied the fix, repeated the mutation: `devtools lab policy classifier-fingerprints` now fails with `exit 1`, naming `polylogue/sources/origin_specs.py:artifact_rule:claude-code-session:agent_transcript` as undeclared drift, while `schema-versioning` alone still stays green (expected -- it is not this lint's job). Reverted the mutation again; both gates green on the clean tree.
- `devtools test tests/unit/devtools/test_verify_classifier_fingerprints.py`: 16 passed (12 pre-existing + 4 new -- artifact-rule discovery, fingerprint-changes-on-`parse_policy`-drift, fingerprint-stable-on-`fidelity_note`-edit, and a historical regression test replaying the #3088 mutation shape and asserting the gate flags it as drift).
- `devtools verify --quick`: `exit_code: 0` (ruff format/check, mypy --strict, `render all --check`, topology, layering, closure-matrix, both `lab policy` gates, schema promotion audit).

Not run: the heavy `devtools test tests/unit` full suite (per-PR CI convention skips it; this change touches only `devtools/` + `docs/` + one test file, no `polylogue/` runtime module).

Ref polylogue-qs4b
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