Phase 78: Derivation Layer, Eligibility & Anti-Drift Test Harness#224
Merged
Conversation
…+ anti-drift harness)
…Q2 + align validation
- every stage x {not_started,in_flight,done,failed} via resolve_status
- DERIV-02 precedence (inflight wins over done/failed), DERIV-03 partial-row NULL
- DERIV-05 fingerprint one-success-wins, D-03 metadata failure-only -> FAILED
- subprocess banned-import guard (T-78-01 agent DB-free boundary)
…adder - Stage (7 members) / Status (4 members) StrEnums, DB-free (D-04 agent boundary) - resolve_status(stage, scalars): in_flight > done > failed > not_started (DERIV-02) - analyze done gated on completed_at IS NOT NULL (DERIV-03); metadata done needs row present AND failed_at NULL (D-03); fingerprint 1:N one-success-wins (DERIV-05) - imports stdlib only; Mapping type-only under TYPE_CHECKING (T-78-01 boundary)
- DAG topology (enrich -> (); downstream conjuncts) - ELIG-01 discovered file eligible for all 3 enrich in any order - ELIG-02 downstream conjuncts + approved-vs-pending apply gate - ELIG-03 terminal-failed-analyze regression (over-enqueue guard) - ELIG-04 non-vacuous failed-fingerprint-stays-eligible (derived via resolve_status)
- metadata/fingerprint eligible iff status not in (DONE, IN_FLIGHT) (ELIG-01/04) - analyze eligible iff NOT_STARTED -- FAILED is terminal (ELIG-03 over-enqueue guard) - apply gated on has_approved_proposal, not bare done(review) (ELIG-02) - tracklist/propose/review gate on upstream DAG conjuncts all DONE - pure over status_map, DB-free; 100% module coverage
- SUMMARY for enums/stage.py (Stage/Status, ELIGIBILITY_DAG, resolve_status, eligible) - DERIV-01/02/03/05 + ELIG-01/02/03/04, 44 DB-free tests, 100% module coverage
…egrade (RED) - Parametrized (stage × status) matrix asserting sql_status == py_status == expected - DERIV-05 [success,failed]→done, ELIG-04 failed-only→not-done, D-03 metadata failure-only→failed - INFLIGHT-01 ledger in_flight cell + INFLIGHT-02 saq_jobs SAVEPOINT-degrade test - stage_status import deferred to runtime so --co collects in the RED state
…ht + saq_detail SAVEPOINT (GREEN)
- done_clause/failed_clause/inflight_clause per stage + stage_status_case CASE ladder (in_flight≻done≻failed≻not_started)
- fingerprint done = .in_(('success','completed')) any engine (DERIV-05); analyze done = completed_at IS NOT NULL; metadata done requires failed_at IS NULL (D-03)
- inflight authoritative from scheduling_ledger key; saq_detail static SQL in begin_nested() SAVEPOINT, degrade-safe (D-01/D-02)
- D-01 decision record in module docstring; DERIV-04 equivalence matrix now GREEN (25 passed), 100% module coverage
…ock plan Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BUw3t717VsNST6rHFcZUfK
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase 78: Derivation Layer, Eligibility & Anti-Drift Test Harness
Goal: Ship the single-source-of-truth predicate module —
enums/stage.py(DB-free, agent-safe) +services/stage_status.py— so every caller derives per-file, per-stage{not_started | in_flight | done | failed}and eligibility from the output tables +saq_jobs, with the SQL and Python definitions locked together against drift.Status: Verified ✓ (12/12 must-haves) · Threat-secure (
threats_open: 0) · Nyquist-compliant · UAT 4/4Purely additive — no existing reader or writer cuts over this phase (cutover is Phase 79+). This lands the authoritative per-stage semantics and eligibility rules in one place, proven by fast unit tests and a real-Postgres SQL⇔Python equivalence lock, so later reader/writer cutovers can be verified against a fixed contract.
Changes
Plan 78-01: Derivation Layer (DB-free half)
src/phaze/enums/stage.py— stdlib-only, agent-safeStage/StatusStrEnums,ELIGIBILITY_DAGtopology, the pure-Pythonresolve_status()precedence ladder (in_flight ≻ done ≻ failed ≻ not_started, encoding DERIV-02/03/05 + D-03 metadata-failure-only-is-FAILED), and the pureeligible()predicate (ELIG-01 enrich independence, ELIG-02 apply-gated-on-approved-proposal, ELIG-03 terminal-failed-analyze guarding the 44.5K over-enqueue class, ELIG-04 failed-fingerprint-stays-eligible). A subprocess banned-import test enforces the agent import boundary (nophaze.models/phaze.database/sqlalchemy).Key files:
src/phaze/enums/stage.py,tests/shared/test_stage_resolver.py,tests/shared/test_stage_eligibility_dag.pyPlan 78-02: SQL Derivation Layer + Anti-Drift Equivalence Lock
src/phaze/services/stage_status.py— SQLAlchemyColumnElement[bool]done/failed/in_flightbuilders +stage_status_caseCASE ladder, within_flightderived authoritatively fromscheduling_ledger(D-01) andsaq_jobsread only as abegin_nested()SAVEPOINT-isolated corroborating detail that degrades safe. The D-01 written decision record lives in the module docstring. Locked to the Wave-1 Python resolver by the DERIV-04 parametrized SQL⇔Python equivalence matrix (real Postgres).Key files:
src/phaze/services/stage_status.py,tests/integration/test_stage_status_equivalence.pyRequirements Addressed
completed_at IS NOT NULL= done, fingerprint 1:N aggregation (one success wins)scheduling_ledger-derived in-flight, SAVEPOINT-degrade onsaq_jobs, written D-01 decision recordVerification
tests/shared/test_stage_resolver.py(27) +test_stage_eligibility_dag.py(17) greentests/integration/test_stage_status_equivalence.py(25) green vs real Postgresenums/stage.pyat 100% coverage78-SECURITY.md,threats_open: 0)78-VALIDATION.md)78-UAT.md)Key Decisions
in_flight's authoritative source isscheduling_ledger(a ledger row = in_flight);saq_jobsis corroborating-only. A ledger row survives a broker truncate, so a crashed-mid-run / callback-lost file readsin_flight, never falselynot_started.done(metadata)requiresfailed_at IS NULL; a failure-only row derives FAILED, not DONE.enums/stage.pyand the SQLAlchemyservices/stage_status.pytwin, locked by the DERIV-04 equivalence test.Code review notes (advisory, 0 blockers)
done(review)==done(propose); downstreameligible()not gating onIN_FLIGHT), backstopped by deterministic-key dedup; resolve at reader cutover._DONE_FPfingerprint allowlist duplicated across the two halves (drift nit the equivalence test would catch at runtime); worth consolidating before cutover.Also included: trailing Phase-77 audit docs (
77-SECURITY/UAT/VALIDATION.md) produced after PR #223 (Phase 77 squash-merge) with no earlier vehicle. No Phase-77 code change — those are docs-only.🤖 Generated with Claude Code
https://claude.ai/code/session_01BUw3t717VsNST6rHFcZUfK