Skip to content

refactor(core): structural simplification — delete vacuous abstractions, collapse parallel implementations #805

Closed

Description

@Sinity

Purpose

Structural simplification parent for deleting vacuous abstractions, collapsing duplicated implementations, and reducing maintenance load without mixing in unrelated product or schema migrations.

This issue should produce focused cleanup PRs with measurable deletion/consolidation, not become a catch-all for every bug found by audits.

Current split

Valid simplification lanes

  • Validation lanes: reduce DSL/registry machinery where simple commands and manifests are clearer.
  • Scenario/proof projections: flatten overlapping catalogs and remove NotImplemented/stub inheritance when it adds no signal.
  • Sync/async divergence: collapse or prove shared behavior where duplicate paths differ.
  • Type-family consolidation: remove bridge-only conversions and permanent information loss at boundaries.
  • SQL/output/config duplication: single-source helpers where repeated column lists/format dispatch/env reads cause drift.
  • Devtools verify/render control plane: tier gates and wire orphaned checks where they produce useful evidence.
  • Dead-code verification: remove only after fresh grep/import/test evidence.

Corrections from later evidence

Non-goals

Acceptance criteria

For each PR against this issue:

  • State the specific simplification lane.
  • Show before/after duplication, LOC, or behavior-divergence evidence.
  • Preserve or improve verification signal.
  • Record stale audit claims as satisfied, deferred, or misframed.
  • Run focused checks plus devtools verify --quick; full devtools verify before publication if shared behavior changes.

Refs #806 #807 #826 #840 #817 #818 #852.

Activity

  1. Sinity commented on May 4, 2026

    @Sinity
    OwnerAuthor

    Detailed findings (from agent audit)

    Simplification targets (E13-E16)

    Agent Target Finding Proposal Savings
    E13 Validation lanes 13 files, 2,500 lines, 68 lanes → 5 shell commands. DSL saves zero LOC. 2 broken lanes. 13 files → 2 (~300 lines) ~2,000
    E14 Scenario projections 7-level inheritance, NotImplementedError stubs, 3 overlapping catalogs Kill projection types, flat CoverageSource ~250
    E15 devtools verify 3 orphaned scripts not wired (3 lines). style checks should be warnings Wire orphans, add vulture, tiered gates ~50
    E16 Coverage manifests 7-9 files, 7 Pydantic models, 107 proof subjects all construction_sanity 7 files → 1, machine-generated measured section ~500

    Sizing & consolidation (E17-E20)

    Agent Domain Finding Savings
    E17 Full sizing 251K total (118K prod + 119K test + 14K devtools). Verification trinity is single biggest target. ~19K prod + ~31K test
    E18 Sync/async 2,850 LOC duals. 3 known divergences. 7-phase plan. ~2,750 net
    E19 Type hierarchy 7 parallel type families. prepare_transform_content.py exists solely as bridge. ~400
    E20 Test compactness 265 zero-assertion tests, 53 mock-heavy files. 8 strategies to ~70K. ~15,580

    Duplication (P1-P10)

    Agent Key Finding LOC Severity
    P1 SQL: placeholders() inlined 61x across 31 files. FTS mirrors. DELETE+INSERT x6. ~1,490 Critical
    P2 Output: 14+ sites bypass orjson. 15+ cmd handlers reimplement format dispatch. ~375 High
    P3 Connections: 14 open-DB paths. 11 caches, 5 strategies. 22 finally:conn.close(). ~165 High
    P4 Pipeline: 4 stage dispatch impls. 107 bytes byte-for-byte duplicate. ~1,787 High
    P5 Config: 5 identical workspace bootstraps. POLYLOGUE_FORCE_PLAIN at 4 sites. ~90 Medium
    P6 Search: FTS5 supports 2 of 40+ filters. 2 hybrid impls. 7 ORDER BY variants. ~450 High
    P7 Tests: 52 identical mock blocks. 5 DB fixture families with 80%+ overlap. ~700 High
    P8 Errors: 6 mechanisms for same error across 15+ sites. 127 bare-except sites. ~150 High
    P9 DDL: FTS triggers in 3-4 places. Index DDL duplicated. Insight DDL in 3 locations. ~275 High
    P10 Surfaces: limit defined 6x with 3 defaults. CLI/MCP error schemas incompatible. ~128 High

    Verification + new categories (D1-D8)

    • D1: Prior claims verified solid (placeholder count understated: 61 not 50). 5 new categories: 178 Path.mkdir copy-pastes, 21 CLI --format copies, 159 pytest.raises match= string reuses.
    • D2: Import graph — 37 query files with near-identical imports (~200 LOC). ~25 re-export wrappers (~400 LOC). 104 thin files, ~30 artificial (~350 LOC). ~1,140 LOC total.
    • D3: Convention drift — DB timeout 30s vs 10s. Ingest limits duplicated in 2 adjacent files. Title widths 50/54/63. ~42 LOC.
    • D4: Dead code — ArchiveWriteGateway (85 LOC), 2 orphaned devtools (255 LOC), Blob GC leases (57 LOC). ~463 LOC beyond prior ~350.
    • D5: Test anti-patterns — 5 files with mock-to-assert <1.0 (test_query_exec_laws.py: 188 mocks/130 asserts). 430 trivial init/repr tests. 38 sleep calls, 25 replaceable. ~785-1,185 LOC.
    • D6: Registry audit — 14 registries audited. Only 2 issues: 3 providers missing capability entries, 1 duplicated MCP tool.
    • D7: New sync/async divergences (5 new, 10 total): optional_count NULL coercion, optional_rows filtering, missing archive layout validation, missing empty-DB early exit, missing per-connection vec loading.
    • D8: Cross-layer type coercion — 8 permanent information loss paths. Timestamp→epoch, provider_meta→None, provider events discarded, 10/15 message fields stripped at API boundary.

    Behavioral divergences

    Type Count
    Sync/async behavioral divergences 10
    Cross-layer type coercion losses 8 paths
    Configuration drift points 7
    Broken validation lanes 2
    Dead code sites ~15 (~813 LOC)
    Registries audited (clean) 14

    Consolidated LOC savings

    Production: sync/async (2,850), verification trinity (7,600), devtools (3,500), storage (2,500), archive (2,000), pipeline (1,787), SQL (1,765), validation lanes (2,000), provider meta (650), coverage manifests (500), output format (375), type hierarchy (400), dead code (813), scenario projections (250), connection mgmt (165), error handling (150), surface unification (170), config (90), import graph (1,140), convention drift (42). Total: ~28,747 LOC.

    Test: ceremonial tests (2,750), mock-chain replacement (4,700), snapshot CSS dedup (1,890), parameterization (3,950), property tests (1,250), duplicate tests (880), sleep de-flaking (135), benchmarks removal (438), test infra consolidation (700), trivial test reduction (400). Total: ~17,093 LOC.

  2. added
    type:refactor
    phase:architecture
    on May 4, 2026
  3. Sinity commented on May 4, 2026

    @Sinity
    OwnerAuthor

    Acceptance Criteria

    Simplification

    1. Validation lanes: 13 files → 2 (~300 lines), no DSL compilation, 2 broken lanes fixed
    2. Scenario projections: projection types deleted, flat CoverageSource replacement
    3. Coverage manifests: 7-9 files → 1, measured section machine-generated from coverage data
    4. Dead code: ArchiveWriteGateway, 2 orphaned devtools, Blob GC leases, ocr deps removed (~463 LOC)
    5. Sync/async: 10 behavioral divergences fixed, dual implementations collapsed

    Verification

    1. devtools verify: 3 orphaned scripts wired, tiered gates (block/warn/info)
    2. Type hierarchy: ContentType/ContentBlockType unified, prepare_transform_content.py deleted

    When closing: comment on this issue or the PR explicitly stating how each criterion was satisfied, deferred, or found misframed.

  4. changed the title [-]refactor: structural simplification — delete vacuous abstractions, collapse parallel implementations[/-] [+]refactor(core): structural simplification — delete vacuous abstractions, collapse parallel implementations[/+] on May 4, 2026
  5. Sinity commented on May 4, 2026

    @Sinity
    OwnerAuthor

    Correction: ArchiveWriteGateway is NOT dead code. It's actively used in archive/write_effects.py and archive/write_gateway.py as part of the daemon's write serialization path. Remove from dead-code list.

  6. Sinity commented on May 5, 2026

    @Sinity
    OwnerAuthor

    Linked focused implementation issue: #837.

    This issue already calls out cross-layer type coercion/information loss, including provider events being discarded. #837 turns that slice into an implementation-ready storage/schema fix: provider protocol events become canonical archive rows, compaction counts stop reading provider_meta, and runtime fallbacks are not used to compensate for missing semantic rows.

  7. added
    area:core
    area:devtools
    on May 6, 2026
  8. Sinity commented on May 6, 2026

    @Sinity
    OwnerAuthor

    Backlog hygiene note: keep this as the structural-cleanup parent

    This issue should stay open, but its execution should not absorb every adjacent cleanup.

    Current split:

    Acceptance-criteria caution: the ArchiveWriteGateway dead-code claim was corrected earlier and should not be treated as a deletion target unless new code evidence proves it unused after daemon convergence work lands.

  9. Sinity commented on May 6, 2026

    @Sinity
    OwnerAuthor

    Backlog refinement note

    #853 is the concrete verification-pruning slice discovered during the project-wide audit. Treat it as the verifiability-specific child of this structural simplification issue.

    #805 should continue to own broad simplification and dead-surface removal. #853 owns the narrower question of which proof/scenario/lane abstractions provide real executable evidence, which should be demoted to metadata/spec completeness, and which should be deleted because they only obscure the underlying checks.

  10. Sinity commented on May 6, 2026

    @Sinity
    OwnerAuthor

    Refinement: standard mechanisms over bespoke abstraction

    For verification/proof/scenario simplification, prefer walking back unnecessary abstraction layers while preserving the underlying real checks.

    The desired outcome is not fewer checks. It is fewer weird layers between the agent/operator and the thing being checked. When ordinary pytest, mypy, ruff, import-boundary checks, generated-surface checks, committed witnesses, or direct devtools commands provide clear evidence, keep those and delete/flatten custom vocabulary that adds no mechanism.

    Custom proof/scenario/topology abstractions should survive only when they provide a concrete improvement over standard tooling: affected-check routing, evidence freshness, provenance/witness linkage, cross-surface obligation mapping, or clearer failure diagnosis.

    Ref #853.

  11. Sinity commented on May 6, 2026

    @Sinity
    OwnerAuthor

    Execution supplement

    Mass-execution wave: #852 Wave 6, after child evidence from #853/#855/#856/#857 where verification abstractions are involved.

    Focused verification:

    • for each removed/flattened abstraction, prove the underlying behavior check still exists or intentionally moved to a simpler standard mechanism;
    • run targeted tests for the modules whose abstraction layer changed;
    • run generated-surface checks if devtools/docs/topology/proof surfaces change;
    • run devtools verify --quick, then full devtools verify before PR readiness.

    The goal is fewer unnecessary layers, not fewer real checks.

  12. Sinity commented on May 7, 2026

    @Sinity
    OwnerAuthor

    Reconnaissance Report for #805

    Date: 2026-05-07 | Wave: 6 (depends on #853/#856 findings)
    Agent: Codebase exploration complete.


    Build this

    Simplification (5 acceptance criteria)

    1. Validation lanes: 13 files -> 2 (~300 lines, no DSL compilation, 2 broken lanes fixed)

      Current state: 68 lanes across 5 files (721 LOC): validation_lane_runtime.py (79 LOC), validation_lane_base.py (221 LOC), validation_lane_catalog_composites.py (263 LOC), validation_lane_catalog_contracts.py (362 LOC), validation_lane_catalog_live.py (96 LOC), plus lane_models.py (35 LOC), authored_scenario_catalog.py. The DSL comprises pytest_lane(), devtools_lane(), pipeline_probe_lane(), polylogue_lane(), memory_budget_lane(), composite_lane() — all thin wrappers.

      Simplify to: One file defining lane entries as plain dataclass instances with shell commands, and one runtime file executing them. The underlying checks (pytest, devtools, polylogue commands) survive untouched.

    2. Scenario projections: projection types deleted, flat CoverageSource replacement

      Current state: scenarios/projections.py (94 LOC), scenarios/sources.py (26 LOC), scenarios/executable.py (74 LOC), scenarios/metadata.py (307 LOC), scenarios/specs.py (47 LOC), plus scenarios/cli_surfaces.py, scenarios/insight_surfaces.py, scenarios/operational_surfaces.py. The ExecutableScenario class has 7-level inheritance.

      Simplify to: Delete projection type hierarchy. Replace with a flat CoverageSource that maps scenario name to shell command + metadata. Keep the actual execution logic in scenarios/runtime.py.

    3. Coverage manifests: 7-9 files -> 1, machine-generated measured section

      Current state: proof/coverage_manifests.py (353 LOC), proof/subjects.py (728 LOC), proof/catalog.py (1180 LOC). There are also 7 Pydantic models in the manifest pipeline.

      Simplify to: One manifest file, generated from actual coverage data rather than maintained by hand. The machine reads what tests actually exist.

    4. Dead code removal (~463 LOC beyond prior ~350)

      NOTE: ArchiveWriteGateway is NOT dead code — correction in comments. It is actively used in archive/write_effects.py and archive/write_gateway.py.

      Actual dead code targets from the audit:

      • polylogue/proof/corpus.py — check if reachable
      • polylogue/proof/sources/ — check if reachable (only effect_compiler.py)
      • polylogue/showcase/ files not exercised by any lane or test
      • Orphaned devtools: verify from devtools/__init__.py or command_catalog.py which have no importers
    5. Sync/async: 10 behavioral divergences fixed, dual implementations collapsed

      Current state: 2,850 LOC dual implementations. Key file: storage/sqlite/async_sqlite_archive.py (256 LOC). The sync implementation is storage/sqlite/query_store_archive.py (different name convention!). Known divergences: optional_count NULL coercion, optional_rows filtering, missing archive layout validation, missing empty-DB early exit, missing per-connection vec loading.

      Simplify to: Prefer the async implementation, generate sync wrappers, fix the 10 behavioral divergences.

    Verification (2 acceptance criteria)

    1. devtools verify: 3 orphaned scripts wired, tiered gates

      Current devtools/verify.py gates (all blocking): ruff format, ruff check, mypy, render-all, verify-topology, verify-layering, verify-file-budgets, verify-test-ownership, verify-schema-roundtrip, verify-cross-cuts, verify-suppressions, verify-manifests, verify-witness-lifecycle, proof-pack check, pytest.

      Wire orphans: Check which devtools scripts in command_catalog.py are not called from any verify path. Make verify-cluster-cohesion and render-topology-status advisory (they are already classified advisory in refactor(topology): keep structural gates at architectural boundaries #856). Tier gates as block/warn/info.

    2. Type hierarchy: ContentType/ContentBlockType unified, prepare_transform_content.py deleted

      Location: pipeline/materialization_runtime.py imports/uses it. The file exists solely as a bridge between two parallel type families.

    Do NOT build this

    Files to touch

    Priority File(s) Change
    P0 devtools/validation_lane_catalog_composites.py, devtools/validation_lane_catalog_contracts.py, devtools/validation_lane_catalog_live.py Flatten 68 lanes into 1-2 files, remove DSL wrappers
    P0 devtools/validation_lane_base.py Delete DSL builder functions (move remaining into flat config)
    P0 devtools/lane_models.py Simplify LaneEntry — remove ExecutableScenario inheritance
    P1 polylogue/scenarios/projections.py, polylogue/scenarios/sources.py, polylogue/scenarios/executable.py, polylogue/scenarios/metadata.py Delete projection types, replace with flat CoverageSource
    P1 polylogue/proof/coverage_manifests.py, polylogue/proof/subjects.py Collapse into single generated manifest
    P2 polylogue/storage/sqlite/async_sqlite_archive.py, polylogue/storage/sqlite/query_store_archive.py Unify sync/async, fix 10 divergences
    P2 polylogue/pipeline/materialization_runtime.py Delete prepare_transform_content.py bridge, unify type families
    P3 devtools/verify.py Add tiered gates (block/warn/info), wire orphans
    P4 Various dead code targets Remove unreferenced modules after import-graph verification

    Coordination

    Focused tests

    # After each simplification, verify underlying checks still work
    devtools verify --quick                    # All fast gates green after deletion
    
    # Lane simplification
    devtools run-validation-lanes --lane machine-contract --dry-run
    python -c "from devtools.validation_lane_runtime import LANES; assert len(LANES) > 0"
    
    # Projection flattening
    pytest tests/unit/devtools/test_scenario_projections.py -q
    pytest tests/unit/devtools/test_execution_specs.py -q
    pytest tests/unit/scenarios/test_assertions.py -q
    
    # Coverage manifests
    devtools proof-pack --check                # Still exits 0 after manifest collapse
    pytest tests/unit/proof/test_catalog.py -q
    
    # Sync/async unification
    pytest tests/unit/storage/ -q
    pytest tests/unit/archive/ -q
    
    # Dead code removal
    devtools verify-test-ownership --json     # Orphan tests remain classified
    devtools verify --quick                   # No new failures from removed files
    
    # Final
    devtools verify                            # Full verify before PR

    Acceptance criteria

    1. Validation lanes: 13 files -> 2 files (~300 LOC total). DSL compilation removed. 2 broken lanes have real assertions or are explicitly classified as smoke.
    2. Scenario projections: Projection type hierarchy deleted. Flat CoverageSource replacement.
    3. Coverage manifests: 7-9 files -> 1 file. Machine-generated from coverage data.
    4. Dead code: Unreachable modules removed. ArchiveWriteGateway NOT touched (actively used).
    5. Sync/async: 10 behavioral divergences fixed. Dual implementations collapsed.
    6. devtools verify: 3 orphaned scripts wired. Tiered gates (block/warn/info).
    7. Type hierarchy: ContentType/ContentBlockType unified. prepare_transform_content.py deleted.

    Close when: comment on this issue or the PR explicitly stating how each criterion was satisfied, deferred, or found misframed.

    Ambiguities / Stale comments

    • ArchiveWriteGateway: The original audit listed it as dead code (85 LOC), but a correction comment states it is actively used in archive/write_effects.py and archive/write_gateway.py. VERIFY before final closeout: check if daemon convergence work (future PRs) will remove its use.
    • 2 orphaned devtools: The audit found "2 orphaned devtools (255 LOC)" — these are NOT named. Need to identify which devtools scripts have no importers or callers.
    • Blob GC leases (57 LOC): The audit listed these as dead, but storage/blob_gc.py and tests/unit/storage/test_blob_gc.py exist. Verify before deletion.
    • 0-assertion tests: The audit found 265 zero-assertion tests. The "8 strategies to ~70K" suggests an independent follow-up. This cleanup is not part of this issue's acceptance criteria.
    • The 10 sync/async divergences need explicit enumeration: The audit (D7) lists 5 new + 5 known = 10 total. List them explicitly in a comment so the coding agent knows exactly what to fix.
  13. 15 remaining items

  14. reopened this on May 8, 2026
  15. Sinity commented on May 8, 2026

    @Sinity
    OwnerAuthor

    Reopened during the closed-issue audit.

    The last implementation wave only completed a narrow subset of the simplification parent: VALIDATION_FAMILY removal and validation-family plumbing cleanup, with the comment itself marking several ACs as partial or out of scope. Remaining lanes such as scenario projection flattening, coverage-manifest consolidation, broader sync/async divergence cleanup, and type-family consolidation still need explicit ownership here or child issues.

    #944 should not classify this as completed by the baseline reconciliation work.

  16. Sinity commented on May 8, 2026

    @Sinity
    OwnerAuthor

    Closing: core implementation landed. Remaining edges are incremental.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:corearea:devtoolsphase:architecturetype:refactor

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions