Skip to content

test(backend): characterize conversation lifecycle - #9532

Merged
Git-on-my-level merged 4 commits into
mainfrom
codex/conversation-lifecycle-contracts-9516
Jul 12, 2026
Merged

Git-on-my-level merged 4 commits into
mainfrom
codex/conversation-lifecycle-contracts-9516

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Jul 12, 2026 •

Copy link
Copy Markdown
Member

Summary

Phase 1 of #9516: add a hermetic characterization suite for the current conversation lifecycle and temporary, bounded telemetry for legacy lifecycle writers.

Refs #9516

Root cause and recurrence evidence

database/conversations.py exposes unconstrained status/discarded writes, while lifecycle drivers independently create, claim, finalize, reprocess, merge, discard, and import conversations. The one existing CAS claim protects one finalization path, but generic writes and several direct upserts bypass it. This is the failure class described in #9516; recent churn spans utils/conversations/, routers/transcribe.py, and routers/conversations.py.

Durable guard

  • Adds conversation_lifecycle to backend/testing/workflow_contracts.json, mapping the current direct-writer inventory to the new contract suite.
  • Characterizes current legal transitions, a generic illegal reversal, double/concurrent claims, sync-vs-live collision, concurrent finalize/reprocess admission, merge during processing, already-completed import persistence, and discard reopening.
  • Adds lazy Prometheus counter conversation_lifecycle_legacy_mutations_total{writer,operation}. Writer labels are bounded to the ten inventoried modules plus other; it lets Phase 2 prove legacy usage reaches zero before deletion without breaking import purity.
  • Repairs the workflow-contract checker so recursive source globs inspect only Python files and preserve repository-relative allowlist matching. This keeps the new workflow guard deterministic even after tests create bytecode.

Scope and rollback

No user-facing behavior, Firestore schema, or lifecycle policy changes. This only observes and locks the current behavior. Roll back by reverting this commit; the collector is lazily registered and has no persisted state.

Verification

  • cd backend && .venv/bin/python -m pytest tests/unit/test_conversation_lifecycle_contract.py tests/unit/test_workflow_contracts.py -q — 31 passed.
  • cd backend && .venv/bin/python scripts/check_workflow_contracts.py — passed.
  • make preflight — passed (12 manifest checks).
  • black --check --line-length 120 --skip-string-normalization backend/database/conversations.py backend/tests/unit/test_conversation_lifecycle_contract.py backend/tests/unit/test_workflow_contracts.py — passed.
  • cd backend && .venv/bin/python scripts/scan_import_time_side_effects.py --files /tmp/omi-9516-import-files.txt — 0 violations.
  • backend/test.sh was run across all 540 unit-test files. It is blocked by the unrelated, unchanged baseline assertion in tests/unit/test_app_client_schema_inventory.py: the test expects app/lib/backend/schema/app.dart:31, while the unchanged origin/main source and inventory report line 32. This PR does not touch either file.
  • No live HTTP/UI path was run because this phase changes neither endpoint behavior nor user-facing state; the real database mutation APIs run through a controllable in-memory Firestore transaction seam in the new contract tests.

Product invariants

None affected (scripts/pr-preflight --suggest).

Review in cubic

CI added 2 commits July 11, 2026 23:31
Refs #9516.

Verification: focused lifecycle and workflow-contract tests pass; the full backend suite is blocked by the unchanged app-client schema inventory line-number assertion, recorded in the PR body.
Filter static workflow scans to Python sources, normalize glob paths to the repository root, and retain the existing app-key tuple exception with its migration reason.
Git-on-my-level and others added 2 commits July 12, 2026 01:05
Concurrent first calls to _record_legacy_lifecycle_mutation could double-register
the Prometheus Counter; use threading.Lock with double-checked initialization.

Co-authored-by: Cursor <[email protected]>

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed — conversation lifecycle characterization tests. Approve-only.

@Git-on-my-level
Git-on-my-level merged commit e243384 into main Jul 12, 2026
24 checks passed
@Git-on-my-level
Git-on-my-level deleted the codex/conversation-lifecycle-contracts-9516 branch July 12, 2026 18:35
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