[Senate] Deprecation reason taxonomy - controlled vocab + reason required done

← Artifact Governance & Lifecycle Management
10-code controlled vocab for deprecated_reason, CHECK constraint requiring code on deprecate, LLM backfill.

Completion Notes

Auto-completed by supervisor after successful deploy to main

Git Commits (2)

Squash merge: orchestra/task/a4c450f7-biomni-analysis-parity-port-15-use-cases (87 commits) (#717)2026-04-27
[Senate] Deprecation reason taxonomy — 10-code controlled vocab + reason required [task:d0aceb3b-f88e-47de-9cd6-c7de1803ca13] (#668)2026-04-27
Spec File

Goal

Today the artifacts table has a free-text deprecated_reason column
(verified via \d artifacts — column type text, no constraint), and every
deprecation writer writes whatever string it likes. Production has 27
deprecated artifacts with reasons ranging from null to terse-agent prose;
this is unanalyzable. This task introduces a small controlled vocabulary
(8–10 codes), a Postgres CHECK that requires the code, a free-text deprecated_reason_detail column for the human note, and dashboards that
break down "deprecated this week, by reason code" — directly answering one
of the spec-prompt's required acceptance criteria for governance metrics.

Acceptance Criteria

☐ Vocabulary defined in scidex/atlas/lifecycle_constants.py as
DEPRECATION_REASON_CODES = {
'superseded', # newer version exists, see superseded_by
'duplicate', # merged into a canonical artifact
'invalidated_by_evidence', # contradicted by later finding
'method_error', # methodological flaw discovered
'data_error', # source data wrong / retracted
'low_quality', # quality_score below threshold
'out_of_scope', # no longer aligned with project scope
'spam_or_abuse', # malicious / off-topic content
'requested_by_owner', # content owner asked for removal
'unmaintained', # no owner / no updates within SLA
}
— 10 codes, deliberately small.
☐ Migration migrations/20260428_deprecation_reason_taxonomy.sql:
- ALTER TABLE artifacts ADD COLUMN IF NOT EXISTS
deprecated_reason_code text
(nullable; populated by step below).
- ALTER TABLE artifacts ADD COLUMN IF NOT EXISTS
deprecated_reason_detail text
(free-text, ≤ 2000 chars; rename
existing deprecated_reason → keep both columns until backfill).
- CHECK constraint: when lifecycle_state='deprecated' then
deprecated_reason_code IS NOT NULL AND IS IN $codes; allow NULL
when state is anything else.
- Index idx_artifacts_deprecated_reason ON artifacts
(deprecated_reason_code) WHERE lifecycle_state='deprecated'
.
☐ Backfill script scripts/backfill_deprecation_reason_codes.py:
reads each existing deprecated row's free-text deprecated_reason,
runs an LLM classifier (prompt template versioned the same way as
the comment classifier) that maps the text → one of the 10 codes,
writes deprecated_reason_code + copies the original text into
deprecated_reason_detail. For nulls / blanks, code = 'unmaintained'.
Idempotent (skips rows already coded). Audit table
deprecation_backfill_runs records counts.
☐ Refactor writers: every place that sets lifecycle_state='deprecated'
(scidex/senate/decision_engine.py:_execute_deprecate,
scidex/atlas/artifact_registry.py:deprecate_artifact ~line 3891,
_execute_split which deprecates source) takes a
reason_code: str parameter, validated against
DEPRECATION_REASON_CODES, plus an optional reason_detail: str.
No defaulting silently to 'unmaintained' — callers must specify.
☐ API addition: POST /api/atlas/artifacts/{id}/deprecate body
{reason_code, reason_detail?} returns 422 when code unknown.
☐ Dashboard: extend the existing senate quality dashboard
(scidex/senate/quality_dashboard.py) with a "Deprecations this
week" card grouping by deprecated_reason_code, with sparkline of
the last 8 weeks per code.
☐ Tests tests/test_deprecation_taxonomy.py:
- Unknown code → CHECK violation on insert.
- Setting state=deprecated without code → CHECK violation.
- LLM backfill maps "old data, retracted" → data_error,
"exceeded by v2" → superseded.
- Dashboard query returns weekly buckets correctly.

Approach

  • Land the vocabulary file + migration + CHECK constraint.
  • Run backfill in a transaction wrapped in a savepoint; verify on a copy
  • first.
  • Refactor writers one at a time; tests stay green.
  • Add API + dashboard card.
  • Smoke: deprecate a fixture artifact via the new API, see it in the
  • weekly card.
  • Commit.
  • Dependencies

    • q-gov-lifecycle-state-machine-enforcement — state machine ensures
    * → deprecated transitions go through the helper that takes
    reason_code.

    Dependents

    • q-gov-metrics-dashboard — uses the per-code weekly buckets.

    Work Log

    2026-04-27 — Implementation (task:d0aceb3b-f88e-47de-9cd6-c7de1803ca13)

    All acceptance criteria implemented:

    • scidex/atlas/lifecycle_constants.py — 10-code DEPRECATION_REASON_CODES frozenset + DEPRECATION_REASON_LABELS dict.
    • migrations/20260428_deprecation_reason_taxonomy.sql — adds deprecated_reason_code + deprecated_reason_detail columns; NOT VALID CHECK constraint (avoids blocking existing null rows); partial index; deprecation_backfill_runs audit table.
    • scripts/backfill_deprecation_reason_codes.py — LLM classifier with heuristic fallback; idempotent; --dry-run / --commit / --validate-constraint modes.
    • scidex/atlas/artifact_registry.py — deprecate_artifact() and transition_lifecycle() both accept reason_code + reason_detail; reactivate_artifact() clears both new columns.
    • scidex/senate/decision_engine.py — _execute_deprecate() takes reason_code (default low_quality); _execute_split() passes reason_code="superseded".
    • scidex/senate/quality_dashboard.py — "Deprecations this week by reason code" bar chart + 8-week sparkline table; CSV export section added.
    • api.py — POST /api/atlas/artifacts/{id}/deprecate endpoint; 422 on unknown code.
    • tests/test_deprecation_taxonomy.py — 15 tests (pure-Python + PG-tagged); all pass.

    Sibling Tasks in Quest (Artifact Governance & Lifecycle Management) ↗

    Task Dependencies

    ↓ Referenced by (downstream)