v0.7.0 — B1 schema-level provenance check for validation_attempts (deferred from !2900)
What
Implement Cause B1 from !2900 (pr-reviewer quality). The skill-text fixes (Causes A/C/D/E) shipped in !188 (merged) / v0.6.0 — but the structural enforcement that makes the protocol unforgeable was deferred because it needs a v2→v3 schema migration.
Why this matters
Without B1, the pr-reviewer protocol is enforced only by reviewer discipline. The !2900 incident showed that rubber-stamp/fabricated rows pass the current validation_attempts.feedback CHECK constraint (which only validates the literal MCP-availability prefix). The schema accepts:
agent='pr-reviewer'+verdict='pass'+ valid prefix → row stored- Whether the reviewer actually did review work → unchecked
We saw 3 rows fabricated this way in the !2900 remediation (rows 7-8-9, deleted) before strict re-spawn caught them. The skill text now says "don't do that" — but nothing prevents it at the DB layer.
The fix — B1 (lightweight, recommended)
Add constraints to validation_attempts:
subagent_session_idNOT NULL.- CHECK that
subagent_session_idis not empty AND not a placeholder (e.g., reject'retroactive-*','bro-fallback-*','<stub>', etc.). - Optionally: cross-reference check that
subagent_session_idmatches a row in a newagent_spawnsledger table (proper provenance tracking — heavier; might escalate to v0.7.0).
Minimum viable: NOT NULL + reject placeholder patterns via CHECK.
Schema migration plan (v2→v3)
- Add migration
migrateV2toV3indb.tsparallel to existingmigrateV1toV2. - Backfill: for existing rows with NULL
subagent_session_id, populate with a deterministic anchor'pre-v3-migration-task<task_id>-attempt<n>'so the NOT NULL constraint can apply. - Add NOT NULL + CHECK constraint to schema.sql.
- Bump
TARGET_SCHEMA_VERSIONto 3. - Regression tests: migration test asserts rows pre-migration are backfilled correctly; post-migration writes with NULL or placeholder session_id rejected.
Files
mcp/trajectory-server/src/db.ts— addmigrateV2toV3; bumpTARGET_SCHEMA_VERSION = 3mcp/trajectory-server/src/schema.sql— add NOT NULL + CHECKmcp/trajectory-server/src/test/schema-upgrade.test.ts— migration regression testmcp/trajectory-server/src/test/validation.test.ts— assert NULL/placeholder INSERT rejected
Acceptance
- All existing tests pass (no regression).
- v1→v2→v3 migration chain tested end-to-end.
- New INSERT with NULL
subagent_session_idrejected at the DB layer. - New INSERT with placeholder pattern (matching the regex) rejected.
Cross-references
!2900(closed) — pr-reviewer quality; original analysis.!2899(closed) — workflow violation that surfaced !2900's findings.- Memory
feedback_mcp_recovery— documents the honor-system fallback that B1 reinforces structurally. - v0.6.0 release notes acknowledge B1 as deferred.