fix: report journal-derived execution state #228
An ID-less END after a modern INPUT reports COMPLETED even though EXE-16 forbids ID-less execution records after the legacy prefix and Replay/Resume reject this history. A later ID-less INPUT can also leave a completed modern execution reported as COMPLETED when an earlier legacy row already exists. Mark this boundary violation as sticky reporting corruption during append and migration backfill so both cases report RUNNING, while preserving genuine legacy prefixes.
<!-- ccr-overview-v2 -->
🟡 Changes recommended
Execution projection can incorrectly report COMPLETED for invalid ID-less records after the legacy prefix, requiring sticky corruption handling during append and migration backfill so affected histories report RUNNING.
<details open>
<summary><strong>1 open issue</strong></summary>
</details>
<details>
<summary><strong>1 file not reviewed</strong></summary>
<ul>
<li><strong><code>api/genpb/session.pb.go</code></strong>: Generated file</li>
</ul>
</details>
<details>
<summary><strong>What changed in this PR</strong></summary>
This PR replaces the nonempty-journal COMPLETED fallback with journal-derived execution state across Session responses and CLI output. RUNNING represents unfinished or uncertain work, not controller liveness.
Changes:
| File | Description |
| ---- | ----------- |
| sqlitelog/sqlitelog.go | Register schema v7 and project outcomes during append. |
| sqlitelog/sessions.go | Read guarded execution state from the shared projection. |
| sqlitelog/execution_projection.go | Add outcome reduction and migration backfill. |
| sqlitelog/execution_projection_test.go | Cover outcomes, migration, corruption, and rollback. |
| sqlitelog/deletion_v3_migration_test.go | Preserve migration assertions across the new column. |
| sqlitelog/approval_projection.go | Share backfill logic between projection migrations. |
| spec.md | Define execution-state semantics and upgrade requirements. |
| session/service.go | Render the store-projected execution state. |
| session/service_test.go | Check state during execution and recovery. |
| session/run_status_test.go | Assert FAILED after a journaled error. |
| session/delete_error_test.go | Supply explicit execution state in rendering fixtures. |
| session/delete_approval_test.go | Expect RUNNING after approval without completion. |
| integrations/substrate/e2e/session_fixture_test.go | Extract a reusable Sessions API fixture. |
| integrations/substrate/e2e/execution_state_test.go | Add seven execution-state end-to-end cases. |
| integrations/substrate/e2e/delete_fixture_test.go | Reuse the shared API fixture. |
| docs/substrate-conformance.md | Describe execution-state conformance coverage. |
| docs/quickstart.md | Update CLI examples and add manual checks. |
| docs/concepts.md | Explain state derivation, recovery, and migration. |
| docs/api-reference.md | Update generated execution-state documentation. |
| cmd/agentsessionsd/lifecycle_e2e_test.go | Update CLI smoke expectations for execution state. |
| cmd/agentctl/main.go | Display execution state in get/list and lifecycle output. |
| cmd/agentctl/main_test.go | Test execution-state display and persistence. |
| cmd/agentctl/approval.go | Display execution state after approval decisions. |
| cmd/agentctl/approval_test.go | Assert execution state in approval output. |
| CHANGELOG.md | Document v0.4.0 behavior and upgrade precautions. |
| api/state.go | Clarify RUNNING and FAILED comments. |
| api/session.proto | Document execution-state semantics without wire changes. |
| api/genpb/session.pb.go | Reflect updated proto comments. |
| .github/workflows/substrate-e2e.yml | Include execution-state tests in the stateless pass. |
</details>
<sub>Review effort: Balanced</sub>
This claims schema v8, but main already uses v8 for #226's rung (migrateV7ToV8). A v8 journal written by main and opened by this build skips migration, and every SessionInfo/ListSessions then fails with no such column: a.outcome; the reverse direction opens fine but leaves outcome stale. Could you rebase onto main, keep #226's v7->v8 rung, and add this as migrateV8ToV9 with SchemaVersion = 9 (spec §18, CHANGELOG and concepts.md updated to v9), with the migration test extended through both rungs?
nit (non-blocking): this says invalid execution structure reports RUNNING, but a modern START/INPUT/OUTPUT followed by an ID-less END reports COMPLETED (and EXE-16 calls that history invalid). Either narrow the wording to the checks the reducer actually does, or treat an ID-less non-lifecycle record after a modern row as corrupt in projectExecution.
nit (non-blocking): "recovery remains possible" after FAILED holds for modern executions only; for a legacy ID-less prefix ERROR finishes the turn (controller/resume.go:45). spec.md:216 already says "modern"; same qualifier here and in session.proto:23?
Once #224 lands, its SessionStore contract (store.go comment and STORE-2) lists only last_seq, compute_state and pending_approval as append-transaction projections; with this PR ExecState also comes from the store, so whichever lands second should add it there.
Fixed the reducer rather than narrowing the contract in 2b0d853. A missing-ID non-lifecycle record after modern execution now sets sticky reporting corruption, so Get/List report RUNNING and withhold pending approval references. The shared reducer applies this during both append and migration; genuine legacy prefixes and session-scoped lifecycle records remain supported.
Fixed in 2b0d853. ID-less non-lifecycle records after modern execution now mark sticky session-level reporting corruption during append and migration. Later END records or newer executions cannot restore success or pending approvals. Added regressions for both reported histories, approval suppression, reopen, and genuine legacy-prefix compatibility.
Fixed in 2b0d853. Qualified recovery as modern-only in api/state.go and session.proto, including the Session field comment, and regenerated the derived documentation. concepts.md now explicitly explains that ERROR finishes a legacy turn for recovery purposes, so Resume does not rerun it.
Fixed in 2b0d853: merged current main, kept migrateV7ToV8 unchanged, and moved execution outcomes to migrateV8ToV9 with SchemaVersion = 9. Migration coverage now starts at v6, v7 and v8, checks read-only/fault rollback, and preserves verified-approver journal bytes/hashes and allocation/inventory evidence. Updated the spec, concepts and changelog fragments under the new release workflow.
Addressed the SessionStore follow-up now that #224 has landed: session/store.go and STORE-2 explicitly include ExecState / exec_state among the projections committed atomically with journal appends. This and the inline review fixes are in 2b0d853.
LGTM. The schema now moves v8 to v9 on top of #226, and the migration, rollback and docs line up.
One nit outside the diff: docs/interaction-model.md:177 still links to concepts.md "for the compatibility fallback", which this PR removes. Consider changing the link text to "for execution-state derivation".
aramase
ridhoq
Summary
Fixes agent-primitives/sessions#79.
Validation
go test -race -shuffle=on ./..., build, vet, lint, govulncheck, and dependency neutrality checks passed.integrations/substratemodule passed race tests, vet, and lint.