fix(substrate): classify compute-start failures #267
When a failed CreateTag is followed by a missing parent or changed snapshot, Backend.Fork formats the tag error with %v at runtime/substrate/substrate.go:1286, so direct Go callers lose the original peer cause despite the new classification wrapper. Wrap that error with %w alongside the lifecycle refusal, preserving memory-loss/superseded precedence and the sanitized message.
RESOURCE_EXHAUSTED alone does not establish that compute capacity is exhausted: gRPC also returns it when a GetActor response exceeds the receive-message limit. Mapping that failure to ErrComputeResourceExhausted contradicts the sentinel's "no eligible compute capacity" contract and directs callers toward the wrong recovery. Require structured evidence of capacity exhaustion before assigning this reason, or use a capacity-neutral classification for ambiguous resource limits.
If the caller's deadline expires during the detached cleanup read after a failed resume, placement.Fork samples the expired context and replaces the compute failure with DEADLINE_EXCEEDED without its reason. Capture the caller's state when resume fails and preserve that outcome through cleanup and placement, so cleanup does not change the primary failure's classification.
<!-- ccr-overview-v2 -->
🟡 Changes recommended
Ambiguous resource limits are classified as compute exhaustion, while fork and resume failure paths can lose the original cause or failure classification.
<details open>
<summary><strong>3 open issues</strong></summary>
</details>
<details>
<summary><strong>What changed in this PR</strong></summary>
This PR connects Substrate control-plane failures to Sessions’ backend-neutral compute error codes and reasons, addressing part of #250 while keeping peer diagnostics out of classified responses.
Changes:
| File | Description |
| ---- | ----------- |
| runtime/substrate/substrate.go | Omits secondary peer diagnostics from fork cleanup errors. |
| integrations/substrate/go.mod | Makes the RPC details dependency direct. |
| integrations/substrate/errors.go | Adds sanitized compute-error classification wrappers. |
| integrations/substrate/errors_test.go | Tests adapter mappings and retained causes. |
| integrations/substrate/error_paths_test.go | Tests service error paths, precedence, privacy, and streaming. |
| integrations/substrate/adapter.go | Applies classification at control-plane boundaries. |
| docs/substrate-conformance.md | Documents mappings, scope, and verification limits. |
| changelog/unreleased/substrate-compute-errors.md | Records the error-contract change. |
</details>
<sub>Review effort: Balanced</sub>
I verified that this %v branch predates this PR and loses the tag cause only after MEMORY_STATE_LOST or SNAPSHOT_SUPERSEDED has taken precedence. The lifecycle refusal still blocks the fork. I’m deferring this cause-retention edge case to a separate change rather than expanding the runtime edits here.
I reproduced this with an explicitly lowered receive limit; the same response succeeds with the default limit. The call still fails with safe diagnostics and its original cause, but the reason can be too specific. I’m deferring the capacity-versus-transport distinction to a separate change rather than parsing peer text or broadening this contract here.
I reproduced this with a live caller at resume failure and a deadline expiring during detached cleanup: the public result becomes DEADLINE_EXCEEDED, while the original Go cause survives. Cleanup still removes the clone and tag, and lifecycle refusals retain precedence. I’m deferring the pre-existing timing issue to a separate change.
nit: a small wording point. When a fork's tag fails and the parent turns out to be gone or superseded, runtime/substrate/substrate.go:1286 formats the tag error with %v. With the new wrapper that prints only the sentinel text, so the original cause isn't kept on that path. Could this say "classified responses keep the original cause for direct Go callers" (and the same in changelog/unreleased/substrate-compute-errors.md:7)? Or 1286 could switch to %w in the follow-up you mentioned.
Thanks, this looks good to me. Classified compute failures now get the right public code without leaking peer text, and the precedence against busy, memory-loss and snapshot refusals holds. I left one optional wording note inline, and a non-blocking suggestion on the existing RESOURCE_EXHAUSTED thread.
Thanks for checking the default limit. One small change could close most of this without parsing anything. At substrate v1.0.0, ate-api only returns RESOURCE_EXHAUSTED from the resume scheduler (workflow_resume.go:434, no worker room). GetActor, CreateActor, CreateTag and CreateActorFromTag never return it, so on those calls the code can only come from a local or intermediary limit. Would you consider mapping RESOURCE_EXHAUSTED to capacity only on ResumeActor, leaving the other calls unclassified, and having the conformance table say so? The comment on computeError calls these codes unambiguous, and on the read and tag calls this one isn't. Non-blocking: fine to leave for the follow-up if you'd rather keep this PR as it is.
Approved these changes.
aramase
gambtho
Substrate compute-start failures now distinguish unavailable compute from exhausted capacity with Sessions codes and ErrorInfo reasons, rather than returning INTERNAL.
Peer diagnostics stay out of classified responses; direct Go callers retain the original cause. Busy and lost-memory checks keep their precedence. Ambiguous configuration failures remain INTERNAL without a reason.
Root and Substrate module race/shuffle tests passed, including cold Exec, attach, Resume, both Fork kinds and stream trailers. Live Substrate fault tests weren't run.
Refs #250.