← Back to Pull requests

fix(substrate): classify compute-start failures #267

Merged
gambtho merged 8 files (541 lines) on Nov 14, 2026 18:34 UTC
View on GitHub
gambtho gambtho commented on Nov 13, 2026 14:16 UTC
Author

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.

Diff: 541 lines (+533 / -8) across 8 files Reviewer: aramase Review duration: 1698m
All Vouch review confidence checks passed
Residual risk 0.05 = Change Risk (0.51) × (1 − Review Confidence (0.90)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.51 · 541 lines diff across 8 files
0.51
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.90 · 5 substantive comment(s)
0.90
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
90%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.377
Real PR Conversation Timeline
12 items
Copilot Copilot commented on code on Nov 13, 2026 14:22 UTC
Code Review
integrations/substrate/adapter.go:1
@@ -178,7 +178,7 @@ func (ad *Adapter) TagActor(ctx context.Context, source substrate.ActorRef, tag
 	if status.Code(err) == codes.AlreadyExists {
 		return fmt.Errorf("%w: %s/%s: %w", substrate.ErrTagExists, tag.Atespace, tag.Name, err)
 	}
-	return busy(source, err)
+	return computeError(busy(source, err))

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.

Copilot Copilot commented on code on Nov 13, 2026 14:22 UTC
Code Review
integrations/substrate/errors.go:1
@@ -0,0 +1,35 @@
+package ateadapter
+
+import (
+	"github.com/agent-primitives/sessions/api"
+	"google.golang.org/grpc/codes"
+	"google.golang.org/grpc/status"
+)
+
+// computeFailure keeps peer text/details out of the message the service publishes
+// for a classified error. Direct Go callers can still inspect the original cause.
+// It deliberately does not implement GRPCStatus: Sessions owns the public status.
+type computeFailure struct {
+	kind  error
+	cause error
+}
+
+func (e *computeFailure) Error() string        { return e.kind.Error() }
+func (e *computeFailure) Unwrap() error        { return e.cause }
+func (e *computeFailure) Is(target error) bool { return target == e.kind }
+
+// computeError classifies only unambiguous transport/capacity codes at allocation,
+// attach and clone boundaries. FAILED_PRECONDITION includes lifecycle prerequisites,
+// and INVALID_ARGUMENT can be a request bug; neither proves invalid configuration.
+func computeError(err error) error {
+	var kind error
+	switch status.Code(err) {
+	case codes.Unavailable:
+		kind = api.ErrComputeUnavailable
+	case codes.ResourceExhausted:
+		kind = api.ErrComputeResourceExhausted

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.

Copilot Copilot commented on code on Nov 13, 2026 14:22 UTC
Code Review
runtime/substrate/substrate.go:1
@@ -1494,8 +1494,10 @@ func (b *Backend) discardClone(ctx context.Context, cloner SnapshotCloner, ref A
 		return fmt.Errorf("%w: fork child %s/%s (clone %q) was deleted between its create and resume: %w",
 			ErrActorBusy, ref.Atespace, ref.Name, uid, cause)
 	default:
-		return fmt.Errorf("%w; fork child %s/%s (clone %q) could not be read for cleanup, so it and its tag %q were left in place: %v",
-			cause, ref.Atespace, ref.Name, uid, forkTag(ref.Name), err)
+		// The primary cause can select a non-INTERNAL response. Do not append
+		// untrusted cleanup diagnostics to that otherwise credential-safe message.
+		return fmt.Errorf("%w; fork child %s/%s (clone %q) could not be read for cleanup, so it and its tag %q were left in place",
+			cause, ref.Atespace, ref.Name, uid, forkTag(ref.Name))

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.

copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Nov 13, 2026 14:22 UTC
Reviewer

<!-- 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>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Preserve the CreateTag error in Fork&#39;s wrapped error chain · New

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Avoid classifying ambiguous RESOURCE_EXHAUSTED as capacity exhaustion · New

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Preserve resume failure classification when cleanup expires the context · New

  • </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:

  • Classifies unavailable and resource-exhausted errors across allocation, attach, and clone operations.

  • Adds adapter and service tests for error details, cause preservation, lifecycle precedence, and stream trailers.

  • Documents the mapping and removes peer cleanup diagnostics from fork failure messages.
  • | 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>

    gambtho gambtho commented on code on Nov 13, 2026 14:29 UTC
    Code Review
    integrations/substrate/adapter.go:1
    @@ -178,7 +178,7 @@ func (ad *Adapter) TagActor(ctx context.Context, source substrate.ActorRef, tag
     	if status.Code(err) == codes.AlreadyExists {
     		return fmt.Errorf("%w: %s/%s: %w", substrate.ErrTagExists, tag.Atespace, tag.Name, err)
     	}
    -	return busy(source, err)
    +	return computeError(busy(source, err))

    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.

    gambtho gambtho commented on code on Nov 13, 2026 14:29 UTC
    Code Review
    integrations/substrate/errors.go:1
    @@ -0,0 +1,35 @@
    +package ateadapter
    +
    +import (
    +	"github.com/agent-primitives/sessions/api"
    +	"google.golang.org/grpc/codes"
    +	"google.golang.org/grpc/status"
    +)
    +
    +// computeFailure keeps peer text/details out of the message the service publishes
    +// for a classified error. Direct Go callers can still inspect the original cause.
    +// It deliberately does not implement GRPCStatus: Sessions owns the public status.
    +type computeFailure struct {
    +	kind  error
    +	cause error
    +}
    +
    +func (e *computeFailure) Error() string        { return e.kind.Error() }
    +func (e *computeFailure) Unwrap() error        { return e.cause }
    +func (e *computeFailure) Is(target error) bool { return target == e.kind }
    +
    +// computeError classifies only unambiguous transport/capacity codes at allocation,
    +// attach and clone boundaries. FAILED_PRECONDITION includes lifecycle prerequisites,
    +// and INVALID_ARGUMENT can be a request bug; neither proves invalid configuration.
    +func computeError(err error) error {
    +	var kind error
    +	switch status.Code(err) {
    +	case codes.Unavailable:
    +		kind = api.ErrComputeUnavailable
    +	case codes.ResourceExhausted:
    +		kind = api.ErrComputeResourceExhausted

    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.

    gambtho gambtho commented on code on Nov 13, 2026 14:29 UTC
    Code Review
    runtime/substrate/substrate.go:1
    @@ -1494,8 +1494,10 @@ func (b *Backend) discardClone(ctx context.Context, cloner SnapshotCloner, ref A
     		return fmt.Errorf("%w: fork child %s/%s (clone %q) was deleted between its create and resume: %w",
     			ErrActorBusy, ref.Atespace, ref.Name, uid, cause)
     	default:
    -		return fmt.Errorf("%w; fork child %s/%s (clone %q) could not be read for cleanup, so it and its tag %q were left in place: %v",
    -			cause, ref.Atespace, ref.Name, uid, forkTag(ref.Name), err)
    +		// The primary cause can select a non-INTERNAL response. Do not append
    +		// untrusted cleanup diagnostics to that otherwise credential-safe message.
    +		return fmt.Errorf("%w; fork child %s/%s (clone %q) could not be read for cleanup, so it and its tag %q were left in place",
    +			cause, ref.Atespace, ref.Name, uid, forkTag(ref.Name))

    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.

    aramase aramase commented on code on Nov 13, 2026 19:46 UTC
    Code Review
    docs/substrate-conformance.md:1
    @@ -23,6 +23,28 @@ All of it runs in the `substrate-conformance suite` job (`.github/workflows/subs
     run on the micro-VM sandbox class, so the suite exercises the same isolation class in both and covers
     the micro-VM path end to end.
     
    +## Compute-start errors
    +
    +The adapter classifies structured ate-api codes on `GetActor`, `CreateActor`, `ResumeActor`,
    +`CreateTag` and `CreateActor{source_tag}`. Sessions returns fresh `google.rpc.ErrorInfo` details
    +with domain `agentsessions` and no metadata:
    +
    +| ate-api code | Sessions code | Reason |
    +|---|---|---|
    +| `UNAVAILABLE` | `UNAVAILABLE` | `COMPUTE_UNAVAILABLE` |
    +| `RESOURCE_EXHAUSTED` | `RESOURCE_EXHAUSTED` | `COMPUTE_RESOURCE_EXHAUSTED` |
    +
    +These replace INTERNAL for classified failures in cold Exec, attach, Resume and both Fork kinds.
    +The same `GetActor` mapping applies to shared snapshot, status and cleanup reads, not only starts.
    +Resource exhaustion includes no eligible worker, not just full workers; freeing quota need not fix it.
    +Existing busy, missing-actor and lost-memory checks retain precedence, as does caller interruption.
    +Peer messages and details are not copied into classified responses; direct Go callers retain the cause.

    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.

    aramase aramase commented on Nov 13, 2026 19:46 UTC
    Reviewer

    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.

    aramase aramase commented on code on Nov 13, 2026 19:46 UTC
    Code Review
    integrations/substrate/errors.go:1
    @@ -0,0 +1,35 @@
    +package ateadapter
    +
    +import (
    +	"github.com/agent-primitives/sessions/api"
    +	"google.golang.org/grpc/codes"
    +	"google.golang.org/grpc/status"
    +)
    +
    +// computeFailure keeps peer text/details out of the message the service publishes
    +// for a classified error. Direct Go callers can still inspect the original cause.
    +// It deliberately does not implement GRPCStatus: Sessions owns the public status.
    +type computeFailure struct {
    +	kind  error
    +	cause error
    +}
    +
    +func (e *computeFailure) Error() string        { return e.kind.Error() }
    +func (e *computeFailure) Unwrap() error        { return e.cause }
    +func (e *computeFailure) Is(target error) bool { return target == e.kind }
    +
    +// computeError classifies only unambiguous transport/capacity codes at allocation,
    +// attach and clone boundaries. FAILED_PRECONDITION includes lifecycle prerequisites,
    +// and INVALID_ARGUMENT can be a request bug; neither proves invalid configuration.
    +func computeError(err error) error {
    +	var kind error
    +	switch status.Code(err) {
    +	case codes.Unavailable:
    +		kind = api.ErrComputeUnavailable
    +	case codes.ResourceExhausted:
    +		kind = api.ErrComputeResourceExhausted

    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.

    aramase aramase approved these changes on Nov 14, 2026 18:34 UTC
    Approved Reviewer

    Approved these changes.

    Reviewers
    Assignees
    gambtho gambtho
    Labels
    risk: low confidence: 90.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 50.9% (MEDIUM) · Higher = larger blast radius
    50.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 90.5% · Lower = rushed or shallow review
    90.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 4.9% · Safe to merge
    4.9%