Release or report compute left running after a failed resume or exec #245
Read does not verify the journal's hash chain (sqlitelog/sqlitelog.go:638–648). If a stored SUSPEND is corrupted into RESUME, this guard can accept the unverified LIVE projection and omit the compute-left-running report even after the controller rejects the journal. Verify these records before using them as ownership evidence; verification failure should report unknown ownership and skip release.
A LIVE turn on the same harness can belong to an older compute instance: if Create returns a replacement, the controller refuses it with ErrMemoryStateLost before appending, but this predicate still suppresses release and reporting. Compare nonempty g.inc.ComputeInstance and the journal's recorded instance using controller.LatestComputeInstance(recs, g.turnRanHere) before accepting LIVE as ownership. Keep mismatched instances on the release/report path and add a replacement-instance regression test.
This scan can attribute a fork child's compute to a turn in the parent's copied prefix. If the parent's completed turn used override B, a child on A can Resume with no pending turn and append only RESUME. A subsequent failed override onto B then sees LIVE plus the inherited B name and skips both release and reporting, although B has never run that child. Stop at the latest FORK marker and treat a child with no subsequent turn as running on its own harness.
<!-- ccr-overview-v2 -->
🟡 Changes recommended
The guard relies on unverified or misattributed ownership evidence, allowing replacement instances, inherited fork turns, or corrupted journal records to incorrectly suppress compute release and reporting.
<details open>
<summary><strong>3 open issues</strong></summary>
</details>
<details>
<summary><strong>What changed in this PR</strong></summary>
This PR addresses #242 by adding cleanup or explicit reporting when Exec or Resume fails after allocating compute, using journal state to determine ownership.
Changes:
ErrComputeLeftRunning, preserving the original error classification.| File | Description |
| ---- | ----------- |
| sqlitelog/sqlitelog.go | Uses the shared compute-state projection. |
| sqlitelog/sessions.go | Removes the relocated projection helper. |
| spec.md | Defines cleanup, reporting, and early cursor-check behavior. |
| session/compute_left_running_test.go | Tests public reporting and stale-cursor refusal. |
| session/compute_left_running_error_test.go | Tests preservation of gRPC error codes. |
| placement/registry.go | Extracts a reusable cursor check. |
| placement/placement.go | Integrates compute guards into Exec and Resume. |
| placement/ownership_test.go | Extends runtime fixtures for cleanup tests. |
| placement/compute_guard.go | Implements ownership checks, cleanup, and reporting. |
| placement/compute_guard_test.go | Tests failure paths and cross-harness ownership. |
| internal/computestate/computestate.go | Centralizes event-to-compute-state projection. |
| internal/computestate/computestate_test.go | Tests individual events and journal folding. |
| docs/allocation-ownership.md | Documents cleanup outside the allocation ledger. |
| changelog/unreleased/compute-left-running.md | Records the cleanup and reporting change. |
| changelog/unreleased/compute-left-running-compat.md | Explains error, timing, and cursor compatibility. |
</details>
<sub>Review effort: Balanced</sub>
Fixed, but compared with p.ranHere instead of turnRanHere. That is the attribution the controller's own ErrMemoryStateLost check uses, so the guard calls an instance a replacement exactly when the controller refuses it.
Fixed at the RESUME marker rather than at FORK. A filesystem-tier child can fork inside a turn and re-drive it on B across the marker, and the same misattribution happens without a fork (B turn, Suspend, Resume on A). When the journal can't tell which harness a Resume ran on, the guard now reports and releases nothing if the call runs on either candidate harness and the runtime returned no replacement instance; a replacement, or a call on a third harness, is treated as unowned.
If the final SUSPEND is lost during allocation, the remaining completed-turn prefix still passes chain verification, so both ownership checks see LIVE and suppress cleanup and reporting for compute restored from a COLD journal. Reject a returned head below headBefore as unknown ownership before evaluating either prefix. The captured head makes this truncation detectable.
If the journal becomes unreadable after an approval request is appended, handoffPark fails before suspension, but the already-disarmed guard skips unknown-ownership reporting for compute still running. Disarm only after handoffPark successfully commits the park; keep the guard armed on failure. Same issue in the Resume path at placement/placement.go:1332–1333.
<!-- ccr-overview-v2 -->
🟡 Changes recommended
Critical ownership-handling flaws allow journal truncation and premature guard disarming to suppress cleanup or unknown-ownership reporting for restored or still-running compute.
<details open>
<summary><strong>2 open issues</strong></summary>
</details>
<details>
<summary><strong>3 resolved since last review</strong></summary>
</details>
<sub>Review effort: Balanced</sub>
Two cases where the new guard doesn't report compute it can't account for. Both match the latest Copilot threads and reproduce locally.
1. If reading the journal fails inside handoffPark, after the approval request is written, the actor is still running but Exec returns only the read error, not ComputeLeftRunningError. Could the guard stay armed until the park succeeds?
2. If the journal comes back shorter than headBefore (say the SUSPEND record is missing), the remaining records look LIVE, so the guard treats the compute as owned. Could a head below headBefore count as unknown?
@gambtho Yes to both, folded into "fix(placement): release or report compute left running after a failed resume or exec". The guard now stays armed through handoffPark and is disarmed only once its SUSPEND commits, so an unreadable journal there comes back as ComputeLeftRunningError. A journal that ends before headBefore (or is empty) is reported as unknown ownership and nothing is released. Each has a test row in compute_guard_test.go for both Exec and Resume.
Two unchecked Registry.Resume calls on separate hosts can both select override harness B before either finishes; after the first writes END/RESUME, the second can find no pending turn and append another RESUME while still using B. This branch attributes that second RESUME to the session's own harness A, so a later failed allocation on A is incorrectly treated as owned and neither released nor reported. Preserve uncertain ownership across consecutive RESUME markers, or record the resolved harness explicitly, and cover this interleaving with a two-registry regression test.
With session.WithAuthorization enabled, a failed allocation confirmation or RESUME append maps to INTERNAL, and the deferred authorization.internalError replaces the entire response with "internal error". This discards the new compute-left-running warning, so those callers still receive no indication that compute remains. Preserve a safe warning or structured status detail through the service mapping and sanitization path, without exposing the original cause, and add an authorization-enabled regression test.
<!-- ccr-overview-v2 -->
🟡 Changes recommended
Concurrent RESUME handling can misattribute compute ownership and leave failed allocations unreleased, while authorization-enabled error sanitization hides warnings that compute remains running.
<details open>
<summary><strong>2 open issues</strong></summary>
</details>
<details>
<summary><strong>2 resolved since last review</strong></summary>
</details>
<sub>Review effort: Balanced</sub>
With authorization on, an Exec or Resume INTERNAL failure that left compute running now returns internal error; compute instance "<id>" may still be running, with no cause or request text. Every other INTERNAL error is still sanitized. Fixed in 3a637e9.
Agreed. A RESUME is now treated as possibly run on the session's own harness or on any turn's harness since the latest fork marker. When those span this host and another, the guard reports instead of claiming the compute. Added a two-host test. Fixed in 3a637e9.
After an approval park commits SUSPEND, controller.CloseApproval can append a host-only NOT_EXECUTED or OUTCOME_UNKNOWN TOOL_RESULT without waking compute. A subsequent Exec/Resume that allocates compute but fails during confirmation or dialing treats that receipt as LIVE ownership, skipping both release and ErrComputeLeftRunning. Ignore these receipts when deriving ownership, without changing the shared SES-8 projection, and add a park → CloseApproval → failed-dial regression test.
<!-- ccr-overview-v2 -->
🟡 Changes recommended
Host-only CloseApproval receipts can be mistaken for live ownership after suspension, causing failed Exec/Resume attempts to leave allocated compute running without releasing it or reporting ErrComputeLeftRunning.
<details open>
<summary><strong>2 open issues</strong></summary>
</details>
<details>
<summary><strong>1 resolved since last review</strong></summary>
</details>
<sub>Review effort: Balanced</sub>
Confirmed this one locally: close an approval with NOT_EXECUTED after the park, then fail the next Exec's dial, and the actor stays running with no release or report. Probably just needs the guard to skip host-only receipts, plus a test for that path.
For interleaved executions such as START(x1, A), START(x2, B), FORK, END(x1), RESUME, this scan attributes x1's post-FORK record to B and omits A from the possible owners, allowing release instead of reporting uncertain ownership. The same attribution error in liveOwner at line 335 can treat B's compute as owned after END(x1), suppressing both release and reporting; controller/harness_identity_test.go:56–63 already covers interleaved execution records. Resolve each record through its matching EXECUTION_START by ExecutionID, preserving that mapping across FORK and the fallback for legacy records, and add regression coverage for both lookups.
<!-- ccr-overview-v2 -->
🟡 Changes recommended
Interleaved execution records can be attributed to the wrong owner across FORK, allowing unsafe release or suppressing release and uncertainty reporting, so both ownership lookups need ExecutionID-based matching and regression coverage.
<details open>
<summary><strong>2 open issues</strong></summary>
</details>
<details>
<summary><strong>1 resolved since last review</strong></summary>
</details>
<sub>Review effort: Balanced</sub>
Good catch, fixed. liveOwner and resumeCandidates now resolve each turn record to the EXECUTION_START with its ExecutionID, including an inherited turn's START before a FORK marker, and a record with no ExecutionID (or none with a START) still counts as the session's own harness. With A as the session's own harness your exact sequence over-reported rather than released, but with a third harness it released compute the journal owned, and the new TestLiveOwnerByExecutionID and interleaved TestComputeGuardAcrossPlacers rows cover both.
For a journal ending in START(x1, A), START(x1, B), this branch attributes LIVE compute to B even though executionHarnesses retains A and the controller rejects the duplicate start. If an override Exec on B allocates compute and then fails confirmation or dialing, the guard skips both release and reporting because hash-chain verification does not validate invocation structure. Treat conflicting starts as unknown ownership and add a regression test with the duplicate START at the journal tail.
This warning drops left.ComputeInstance, logging only the reusable incarnation ID. For a runtime that replaces compute under the same ID, operators cannot distinguish which instance the failed call left running—especially when cancellation prevents the client from receiving the error containing its UID. Include the returned compute-instance identity alongside incarnation_id so the host's report identifies the same compute as the error.
<!-- ccr-overview-v2 -->
🟡 Changes recommended
A critical ownership error on duplicate START entries can skip compute release and reporting, and the warning omits the compute-instance identity needed to identify the runtime left running.
<details open>
<summary><strong>3 open issues</strong></summary>
</details>
<details>
<summary><strong>1 resolved since last review</strong></summary>
</details>
<sub>Review effort: Balanced</sub>
Confirmed with a regression test: with a journal ending in two EXECUTION_START records for one execution, naming C and then B, an override Exec on B that failed its confirm or dial kept the compute without releasing or reporting it. Fixed in "fix(placement): release or report compute left running after a failed resume or exec". executionHarnesses now also reports whether the journal attributes every turn to one harness. Conflicting STARTs, a START with no ID or no payload, a START after its execution's other records, an ID-less record the controller would reject, or an ID'd record with no START right after an unfinished legacy turn make ownership unknown anywhere in the journal, so the guard reports the compute instead of keeping or releasing it. turnHarness now resolves a START through the same map as every other record. A repeated START naming the same harness still counts as that harness.
The warning now logs compute_instance (ComputeInstance, empty when the backend does not tell instances apart) next to incarnation_id, so it names the same compute as the error. I also added the field to docs/observability.md. The log still carries no error text.
<!-- ccr-overview-v2 -->
🔵 Needs a closer look
The ownership fold duplicates replay identity rules and controls cleanup across multi-host Resume/Fork interleavings, requiring maintainer validation of ownership and runtime-release invariants.
<details open>
<summary><strong>1 open issue</strong></summary>
</details>
<details>
<summary><strong>2 resolved since last review</strong></summary>
</details>
<sub>Review effort: Balanced</sub>
One more fork race: the child is listed at its first fence, before the prefix finishes copying. A Resume in that window restores on B but writes only RESUME, which the guard reads as A's, so a failed Exec on A leaves compute running unreported. Reproduced at 3ef571a8. Counting B as a possible owner, or not listing the child until the copy finishes, would fix it. Possibly just a follow-up?
Approved these changes.
gambtho
aramase
Refs #242
A Resume or Exec that fails after the runtime returns compute (lazy dial, confirm, recheck, fence) left that compute running with nothing journaled to own it, and the caller got no signal.
LIVEfrom this harness, not a replacement instance) alone.CleanupRuntime.ReleaseSession(30s, ignores caller cancellation). Otherwise, or when another owner may hold it (checkpoint, fence, deletion, moved head) or the journal cannot say who owns it, the error becomesErrComputeLeftRunning. gRPC codes are unchanged.expected_last_seqbefore creating a runtime.internal/computestate(no behavior change).Detection only; re-suspend or a release SPI stays open on #242. It errs toward reporting: a turn a fork superseded is reported even when the fork then succeeds.