← Back to Pull requests

feat: add machine-readable session error reasons #258

Merged
gambtho merged 21 files (1037 lines) on Nov 12, 2026 22:39 UTC
View on GitHub
gambtho gambtho commented on Nov 10, 2026 01:47 UTC
Author

Adds machine-readable reasons to known session failures, so clients can choose a recovery path without parsing messages.

Existing lifecycle codes stay the same. Compute-start cancellations no longer default to INTERNAL, and direct Go callers retain the original cause.

This adds the runtime error categories; Substrate classification will follow separately. Unknown backend failures still return INTERNAL without a reason.

Refs #250.

Diff: 1037 lines (+955 / -82) across 21 files Reviewer: aramase Review duration: 4131m
All Vouch review confidence checks passed
Residual risk 0.07 = Change Risk (0.72) × (1 − Review Confidence (0.90)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.72 · 1037 lines diff across 21 files
0.72
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.89 · 5 substantive comment(s)
0.89
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.400
Mass File Touch mass_file_touch
0.080
Real PR Conversation Timeline
32 items
Copilot Copilot commented on code on Nov 10, 2026 01:53 UTC
Code Review
placement/cleanup.go:1
@@ -44,3 +46,15 @@ func (p *Placer) allocate(ctx context.Context, log eventlog.Store, operation str
 	}
 	return in, nil
 }
+
+// Only the caller's context during start is an admission interruption. Confirmation
+// uses an independent deadline, and checkpoint supersession remains ABORTED.
+func allocationStartError(ctx context.Context, err error) error {
+	if err != nil && errors.Is(context.Cause(ctx), errSuperseded) {
+		return fmt.Errorf("%w (compute start ended with: %v)", errSuperseded, err)
+	}
+	if err != nil && ctx.Err() != nil {
+		return fmt.Errorf("%w: %w: %w", ErrAdmissionInterrupted, ctx.Err(), err)

If the caller cancels but the runtime error wraps an independent context.DeadlineExceeded, this retains both context errors and admissionInterruptedCode returns DEADLINE_EXCEEDED instead of CANCELED. Carry the caller's context outcome in a distinct marker and select the public code from it, while retaining the backend cause for Go callers. Same issue in session/errors.go:107–108 for Suspend/Fork.

Copilot Copilot commented on code on Nov 10, 2026 01:53 UTC
Code Review
session/service.go:1
@@ -1030,7 +1030,7 @@ func (s *Service) Fork(ctx context.Context, req *v1.ForkRequest) (response *v1.F
 	// The fan-out is all-or-nothing: Placer.Fork rolls back everything it provisioned on failure,
 	// so children_created stays 0 rather than reporting compute that no longer exists.
 	if err := placer.Fork(ctx, parent, req.GetSession(), children, atSeq); err != nil {
-		return nil, forkError(req.GetSession(), err)
+		return nil, forkError(req.GetSession(), runtimeContextError(ctx, err))

If a later child fails with ErrComputeUnavailable while the caller is live, but the caller expires while Fork rolls back earlier children, this late context check replaces UNAVAILABLE/COMPUTE_UNAVAILABLE with DEADLINE_EXCEEDED and no reason. Classify caller interruption at the failing runtime operation before rollback, rather than after the whole fan-out returns, so cleanup cannot change the primary failure's status.

Copilot Copilot commented on code on Nov 10, 2026 01:53 UTC
Code Review
session/service.go:1
@@ -1361,11 +1357,13 @@ func serviceErrorKind(err error) string {
 	if err == nil {
 		return ""
 	}
-	if errors.Is(err, context.Canceled) {
-		return "canceled"
-	}
-	if errors.Is(err, context.DeadlineExceeded) {
-		return "deadline_exceeded"
+	if status.Code(err) == codes.Unknown {
+		if errors.Is(err, context.Canceled) {
+			return "canceled"
+		}
+		if errors.Is(err, context.DeadlineExceeded) {

The new cause-preserving statuses let observability/grpc.go's context-first grpcCode checks override the selected RPC status. A live caller's Describe timeout returns UNAVAILABLE/HARNESS_UNAVAILABLE but is logged as grpc_code=DeadlineExceeded and error_kind=deadline_exceeded, misclassifying a harness outage as a caller timeout. Make that helper prefer the selected gRPC status too, using context classification only for errors without a status.

copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Nov 10, 2026 01:53 UTC
Reviewer

<!-- ccr-overview-v2 -->

🟡 Changes recommended

Context-error handling can select incorrect RPC codes, let rollback timeouts overwrite primary failures, and cause observability to misclassify backend outages as caller timeouts.

<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 caller cancellation when backend cause is a deadline · 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> Classify caller interruption before rollback changes the primary error · 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> Prefer selected gRPC status over context when classifying errors · New

  • </details>

    <details>
    <summary><strong>1 file not reviewed</strong></summary>

    <ul>
    <li><strong><code>api/genpb/session_grpc.pb.go</code></strong>: Generated file</li>
    </ul>
    </details>

    <details>
    <summary><strong>What changed in this PR</strong></summary>

    Adds machine-readable session error reasons so clients can choose recovery actions without parsing messages. This establishes backend-neutral error categories for #250; Substrate classification remains separate.

    Changes:

  • Attach host-owned ErrorInfo details to recognized failures while preserving causes for direct Go callers.

  • Classify compute-start failures and caller interruption, with tests for error mapping and streamed details.

  • Document reasons, precedence, compatibility, and diagnostic-safety requirements.
  • | File | Description |
    | ---- | ----------- |
    | spec.md | Defines error reasons, precedence, and recovery contracts. |
    | session/​service.go | Applies shared status mapping to lifecycle operations. |
    | session/​errors.go | Centralizes reason details and cause-preserving statuses. |
    | session/​error_start_test.go | Tests compute-start failures and unchanged journal heads. |
    | session/​error_reasons_test.go | Tests mappings, causes, sanitization, and cleanup precedence. |
    | session/​delete.go | Reuses the shared status helper. |
    | session/​authorization.go | Preserves sanitization despite newly exposed cause chains. |
    | placement/​cleanup.go | Marks caller interruption during allocation. |
    | placement/​cleanup_context_test.go | Tests allocation and confirmation context boundaries. |
    | docs/​api-reference.md | Documents recognized reasons in the API reference. |
    | client/​client_test.go | Checks error details survive Exec’s first frame. |
    | changelog/​unreleased/​error-reasons.md | Announces structured reasons and retained Go causes. |
    | changelog/​unreleased/​error-reasons-compat.md | Records status and diagnostic-visibility changes. |
    | api/​session.proto | Adds service comments describing error details. |
    | api/​runtime.go | Adds backend-neutral compute failure sentinels. |
    | api/​genpb/​session_grpc.pb.go | Reflects service documentation in generated comments. |
    </details>

    <sub>Review effort: Balanced</sub>

    gambtho gambtho commented on code on Nov 10, 2026 01:56 UTC
    Code Review
    placement/cleanup.go:1
    @@ -44,3 +46,15 @@ func (p *Placer) allocate(ctx context.Context, log eventlog.Store, operation str
     	}
     	return in, nil
     }
    +
    +// Only the caller's context during start is an admission interruption. Confirmation
    +// uses an independent deadline, and checkpoint supersession remains ABORTED.
    +func allocationStartError(ctx context.Context, err error) error {
    +	if err != nil && errors.Is(context.Cause(ctx), errSuperseded) {
    +		return fmt.Errorf("%w (compute start ended with: %v)", errSuperseded, err)
    +	}
    +	if err != nil && ctx.Err() != nil {
    +		return fmt.Errorf("%w: %w: %w", ErrAdmissionInterrupted, ctx.Err(), err)

    I reproduced this on bd00da0: the call fails with DEADLINE_EXCEEDED, retains both causes, and appends no turn. I'm keeping the CANCELED versus DEADLINE_EXCEEDED distinction as a follow-up; it doesn't turn the failed operation into a successful one.

    gambtho gambtho commented on code on Nov 10, 2026 01:56 UTC
    Code Review
    session/service.go:1
    @@ -1030,7 +1030,7 @@ func (s *Service) Fork(ctx context.Context, req *v1.ForkRequest) (response *v1.F
     	// The fan-out is all-or-nothing: Placer.Fork rolls back everything it provisioned on failure,
     	// so children_created stays 0 rather than reporting compute that no longer exists.
     	if err := placer.Fork(ctx, parent, req.GetSession(), children, atSeq); err != nil {
    -		return nil, forkError(req.GetSession(), err)
    +		return nil, forkError(req.GetSession(), runtimeContextError(ctx, err))

    I verified the late classification change on bd00da0. The detached rollback still runs and the original failure remains in the Go cause chain, but its RPC code and reason can change when the caller ends during cleanup. I'm keeping that classification correction as a follow-up rather than changing the rollback boundary in this PR.

    gambtho gambtho commented on code on Nov 10, 2026 01:56 UTC
    Code Review
    session/service.go:1
    @@ -1361,11 +1357,13 @@ func serviceErrorKind(err error) string {
     	if err == nil {
     		return ""
     	}
    -	if errors.Is(err, context.Canceled) {
    -		return "canceled"
    -	}
    -	if errors.Is(err, context.DeadlineExceeded) {
    -		return "deadline_exceeded"
    +	if status.Code(err) == codes.Unknown {
    +		if errors.Is(err, context.Canceled) {
    +			return "canceled"
    +		}
    +		if errors.Is(err, context.DeadlineExceeded) {

    I reproduced the logging mismatch on bd00da0: the selected RPC status is UNAVAILABLE, while the logging helper reports DeadlineExceeded. The response code and ErrorInfo remain unchanged, so I'm leaving the logging-only correction to a follow-up.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Nov 10, 2026 01:57 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    🔵 Needs a closer look

    Error handling can misclassify caller cancellations, replace primary Fork failures after rollback, and produce request diagnostics that disagree with the actual RPC status.

    No open issues 🎉

    <details>
    <summary><strong>1 previously missed issue</strong></summary>

    In code that hasn't changed since last review

    <details>
    <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> Classify Suspend/Fork failures using caller context</summary>

    session/​errors.go:108

    A canceled Suspend/Fork caller can be reported as DEADLINE_EXCEEDED when the backend error wraps an independent context.DeadlineExceeded: this wrapper retains both sentinels, and admissionInterruptedCode selects the backend's deadline before the caller's cancellation. Capture the caller context error as explicit classification data and make the mapper use it without discarding the original backend cause.
    </details>
    </details>

    <details>
    <summary><strong>3 resolved since last review</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> Prefer selected gRPC status over context when classifying errors

  • <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> Classify caller interruption before rollback changes the primary error

  • <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 caller cancellation when backend cause is a deadline

  • </details>

    <details>
    <summary><strong>1 file not reviewed</strong></summary>

    <ul>
    <li><strong><code>api/genpb/session_grpc.pb.go</code></strong>: Generated file</li>
    </ul>
    </details>

    <sub>Review effort: Balanced</sub>

    gambtho gambtho commented on code on Nov 10, 2026 02:12 UTC
    Code Review
    placement/cleanup.go:1
    @@ -44,3 +46,15 @@ func (p *Placer) allocate(ctx context.Context, log eventlog.Store, operation str
     	}
     	return in, nil
     }
    +
    +// Only the caller's context during start is an admission interruption. Confirmation
    +// uses an independent deadline, and checkpoint supersession remains ABORTED.
    +func allocationStartError(ctx context.Context, err error) error {
    +	if err != nil && errors.Is(context.Cause(ctx), errSuperseded) {
    +		return fmt.Errorf("%w (compute start ended with: %v)", errSuperseded, err)
    +	}
    +	if err != nil && ctx.Err() != nil {
    +		return fmt.Errorf("%w: %w: %w", ErrAdmissionInterrupted, ctx.Err(), err)

    Fixed in 94b88ba. The caller's outcome now chooses the context code independently of a backend timeout, while both Go causes remain available. The regression covers Exec and the Suspend/Fork mapping.

    gambtho gambtho commented on code on Nov 10, 2026 02:12 UTC
    Code Review
    session/service.go:1
    @@ -1030,7 +1030,7 @@ func (s *Service) Fork(ctx context.Context, req *v1.ForkRequest) (response *v1.F
     	// The fan-out is all-or-nothing: Placer.Fork rolls back everything it provisioned on failure,
     	// so children_created stays 0 rather than reporting compute that no longer exists.
     	if err := placer.Fork(ctx, parent, req.GetSession(), children, atSeq); err != nil {
    -		return nil, forkError(req.GetSession(), err)
    +		return nil, forkError(req.GetSession(), runtimeContextError(ctx, err))

    Fixed in 94b88ba. Fork now classifies the failure before rollback, so cancellation during cleanup cannot replace its code or reason. The regression cancels during an earlier child's rollback after the next child fails.

    gambtho gambtho commented on code on Nov 10, 2026 02:12 UTC
    Code Review
    session/service.go:1
    @@ -1361,11 +1357,13 @@ func serviceErrorKind(err error) string {
     	if err == nil {
     		return ""
     	}
    -	if errors.Is(err, context.Canceled) {
    -		return "canceled"
    -	}
    -	if errors.Is(err, context.DeadlineExceeded) {
    -		return "deadline_exceeded"
    +	if status.Code(err) == codes.Unknown {
    +		if errors.Is(err, context.Canceled) {
    +			return "canceled"
    +		}
    +		if errors.Is(err, context.DeadlineExceeded) {

    Fixed in 94b88ba. Request diagnostics now prefer the selected RPC status and classify context errors only when no status exists. The regression covers wrapped statuses and bare context errors.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Nov 10, 2026 02:18 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    🔵 Needs a closer look

    Cancellation and deadline responses can bypass INTERNAL-only sanitization and expose raw backend diagnostics, potentially leaking credential-bearing URLs to clients.

    No open issues 🎉

    <details>
    <summary><strong>1 previously missed issue</strong></summary>

    In code that hasn't changed since last review

    <details>
    <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> Prevent leaking backend diagnostics in canceled and deadline responses</summary>

    placement/​cleanup.go:58

    This exposes raw backend diagnostics in CANCELED/DEADLINE_EXCEEDED responses, bypassing authorization's INTERNAL-only sanitization without the runtime opting into safe diagnostics. For example, an Exec deadline_unix can expire during Create while the RPC remains live, allowing a backend error containing a credential-bearing URL to reach the client. Omit Cause from this message while retaining it through Unwrap for direct Go callers.
    </details>
    </details>

    <details>
    <summary><strong>1 file not reviewed</strong></summary>

    <ul>
    <li><strong><code>api/genpb/session_grpc.pb.go</code></strong>: Generated file</li>
    </ul>
    </details>

    <sub>Review effort: Balanced</sub>

    gambtho gambtho commented on code on Nov 10, 2026 02:25 UTC
    Code Review
    placement/cleanup.go:1
    @@ -44,3 +46,15 @@ func (p *Placer) allocate(ctx context.Context, log eventlog.Store, operation str
     	}
     	return in, nil
     }
    +
    +// Only the caller's context during start is an admission interruption. Confirmation
    +// uses an independent deadline, and checkpoint supersession remains ABORTED.
    +func allocationStartError(ctx context.Context, err error) error {
    +	if err != nil && errors.Is(context.Cause(ctx), errSuperseded) {
    +		return fmt.Errorf("%w (compute start ended with: %v)", errSuperseded, err)
    +	}
    +	if err != nil && ctx.Err() != nil {
    +		return fmt.Errorf("%w: %w: %w", ErrAdmissionInterrupted, ctx.Err(), err)

    Fixed in 32d881e. The caller's outcome chooses the status, and backend diagnostics stay out of context-response messages while Go callers retain the cause.

    gambtho gambtho commented on code on Nov 10, 2026 02:25 UTC
    Code Review
    session/service.go:1
    @@ -1030,7 +1030,7 @@ func (s *Service) Fork(ctx context.Context, req *v1.ForkRequest) (response *v1.F
     	// The fan-out is all-or-nothing: Placer.Fork rolls back everything it provisioned on failure,
     	// so children_created stays 0 rather than reporting compute that no longer exists.
     	if err := placer.Fork(ctx, parent, req.GetSession(), children, atSeq); err != nil {
    -		return nil, forkError(req.GetSession(), err)
    +		return nil, forkError(req.GetSession(), runtimeContextError(ctx, err))

    Fixed at 32d881e. The two-child regression verifies that cancellation during rollback cannot replace the original code or reason.

    gambtho gambtho commented on code on Nov 10, 2026 02:25 UTC
    Code Review
    session/service.go:1
    @@ -1361,11 +1357,13 @@ func serviceErrorKind(err error) string {
     	if err == nil {
     		return ""
     	}
    -	if errors.Is(err, context.Canceled) {
    -		return "canceled"
    -	}
    -	if errors.Is(err, context.DeadlineExceeded) {
    -		return "deadline_exceeded"
    +	if status.Code(err) == codes.Unknown {
    +		if errors.Is(err, context.Canceled) {
    +			return "canceled"
    +		}
    +		if errors.Is(err, context.DeadlineExceeded) {

    Fixed at 32d881e. Request logs now honor the selected response status, including wrapped statuses, rather than a nested timeout.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Nov 10, 2026 02:30 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    🔵 Needs a closer look

    Human assessment is needed because cancellation can erase journal recovery classifications, while resource-exhaustion failures remain misclassified as internal faults in diagnostics.

    No open issues 🎉

    <details>
    <summary><strong>1 file not reviewed</strong></summary>

    <ul>
    <li><strong><code>api/genpb/session_grpc.pb.go</code></strong>: Generated file</li>
    </ul>
    </details>

    <sub>Review effort: Balanced</sub>

    gambtho gambtho commented on code on Nov 10, 2026 02:42 UTC
    Code Review
    placement/cleanup.go:1
    @@ -44,3 +46,15 @@ func (p *Placer) allocate(ctx context.Context, log eventlog.Store, operation str
     	}
     	return in, nil
     }
    +
    +// Only the caller's context during start is an admission interruption. Confirmation
    +// uses an independent deadline, and checkpoint supersession remains ABORTED.
    +func allocationStartError(ctx context.Context, err error) error {
    +	if err != nil && errors.Is(context.Cause(ctx), errSuperseded) {
    +		return fmt.Errorf("%w (compute start ended with: %v)", errSuperseded, err)
    +	}
    +	if err != nil && ctx.Err() != nil {
    +		return fmt.Errorf("%w: %w: %w", ErrAdmissionInterrupted, ctx.Err(), err)

    Fixed in cd66a75. The caller's outcome controls cancellation/deadline classification, backend diagnostics stay out of the response, and both Go causes survive.

    gambtho gambtho commented on code on Nov 10, 2026 02:42 UTC
    Code Review
    session/service.go:1
    @@ -1030,7 +1030,7 @@ func (s *Service) Fork(ctx context.Context, req *v1.ForkRequest) (response *v1.F
     	// The fan-out is all-or-nothing: Placer.Fork rolls back everything it provisioned on failure,
     	// so children_created stays 0 rather than reporting compute that no longer exists.
     	if err := placer.Fork(ctx, parent, req.GetSession(), children, atSeq); err != nil {
    -		return nil, forkError(req.GetSession(), err)
    +		return nil, forkError(req.GetSession(), runtimeContextError(ctx, err))

    Fixed in cd66a75. Fork classifies a failing runtime child before rollback; cancellation during cleanup cannot replace that result, and journal conflicts keep their recovery reasons.

    gambtho gambtho commented on code on Nov 10, 2026 02:42 UTC
    Code Review
    session/service.go:1
    @@ -1361,11 +1357,13 @@ func serviceErrorKind(err error) string {
     	if err == nil {
     		return ""
     	}
    -	if errors.Is(err, context.Canceled) {
    -		return "canceled"
    -	}
    -	if errors.Is(err, context.DeadlineExceeded) {
    -		return "deadline_exceeded"
    +	if status.Code(err) == codes.Unknown {
    +		if errors.Is(err, context.Canceled) {
    +			return "canceled"
    +		}
    +		if errors.Is(err, context.DeadlineExceeded) {

    Fixed in cd66a75. Logs prefer the selected RPC status, use context classification only without a status, and label capacity failures as resource_exhausted rather than internal.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Nov 10, 2026 02:44 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    🔵 Needs a closer look

    Human assessment is needed because caller-interruption handling can mask established lifecycle recovery reasons across Exec, Resume, Fork, and Suspend.

    No open issues 🎉

    <details>
    <summary><strong>1 file not reviewed</strong></summary>

    <ul>
    <li><strong><code>api/genpb/session_grpc.pb.go</code></strong>: Generated file</li>
    </ul>
    </details>

    <sub>Review effort: Balanced</sub>

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Nov 10, 2026 02:56 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    🔵 Needs a closer look

    Human assessment is needed to evaluate a subtle allocation/cancellation interaction that can cause sessions to report an internal error instead of cancellation or deadline expiry.

    No open issues 🎉

    <details>
    <summary><strong>1 file not reviewed</strong></summary>

    <ul>
    <li><strong><code>api/genpb/session_grpc.pb.go</code></strong>: Generated file</li>
    </ul>
    </details>

    <sub>Review effort: Balanced</sub>

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Nov 10, 2026 03:20 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    🟢 Approval recommended

    No active review issues remain for the machine-readable error-reason changes.

    No open issues 🎉

    <details>
    <summary><strong>1 file not reviewed</strong></summary>

    <ul>
    <li><strong><code>api/genpb/session_grpc.pb.go</code></strong>: Generated file</li>
    </ul>
    </details>

    <sub>Review effort: Balanced</sub>

    gambtho gambtho commented on code on Nov 10, 2026 03:24 UTC
    Code Review
    placement/cleanup.go:1
    @@ -44,3 +46,15 @@ func (p *Placer) allocate(ctx context.Context, log eventlog.Store, operation str
     	}
     	return in, nil
     }
    +
    +// Only the caller's context during start is an admission interruption. Confirmation
    +// uses an independent deadline, and checkpoint supersession remains ABORTED.
    +func allocationStartError(ctx context.Context, err error) error {
    +	if err != nil && errors.Is(context.Cause(ctx), errSuperseded) {
    +		return fmt.Errorf("%w (compute start ended with: %v)", errSuperseded, err)
    +	}
    +	if err != nil && ctx.Err() != nil {
    +		return fmt.Errorf("%w: %w: %w", ErrAdmissionInterrupted, ctx.Err(), err)

    Fixed in 4b419a1. Context codes now use the recorded caller outcome, not a nested backend timeout; both Go causes remain available and established lifecycle reasons keep priority.

    gambtho gambtho commented on code on Nov 10, 2026 03:24 UTC
    Code Review
    session/service.go:1
    @@ -1030,7 +1030,7 @@ func (s *Service) Fork(ctx context.Context, req *v1.ForkRequest) (response *v1.F
     	// The fan-out is all-or-nothing: Placer.Fork rolls back everything it provisioned on failure,
     	// so children_created stays 0 rather than reporting compute that no longer exists.
     	if err := placer.Fork(ctx, parent, req.GetSession(), children, atSeq); err != nil {
    -		return nil, forkError(req.GetSession(), err)
    +		return nil, forkError(req.GetSession(), runtimeContextError(ctx, err))

    Fixed in 4b419a1. Runtime failures are classified before rollback, so cancellation during cleanup cannot replace the primary code or reason. Journal refusals keep their own recovery reasons.

    gambtho gambtho commented on code on Nov 10, 2026 03:24 UTC
    Code Review
    session/service.go:1
    @@ -1361,11 +1357,13 @@ func serviceErrorKind(err error) string {
     	if err == nil {
     		return ""
     	}
    -	if errors.Is(err, context.Canceled) {
    -		return "canceled"
    -	}
    -	if errors.Is(err, context.DeadlineExceeded) {
    -		return "deadline_exceeded"
    +	if status.Code(err) == codes.Unknown {
    +		if errors.Is(err, context.Canceled) {
    +			return "canceled"
    +		}
    +		if errors.Is(err, context.DeadlineExceeded) {

    Fixed in 4b419a1. Logs use the selected RPC status, falling back to context only when no status exists. Capacity failures also have their own error kind.

    aramase aramase commented on Nov 10, 2026 15:56 UTC
    Reviewer

    Looks good to me. Two non-blocking nits inline.

    aramase aramase commented on code on Nov 10, 2026 15:56 UTC
    Code Review
    session/service.go:1
    @@ -1134,7 +1134,7 @@ func (s *Service) Suspend(ctx context.Context, req *v1.SuspendRequest) (session
     		if refused != nil && err == refused {
     			return nil, refused
     		}
    -		return nil, suspendError(uid, err)
    +		return nil, suspendError(uid, runtimeContextError(ctx, err))

    nit: once the caller's context is done, this treats every Suspend failure as a caller interruption. That includes a SUSPEND journal append that failed on its own after a successful Snapshot, which was INTERNAL on main and now logs and counts as Canceled. Could the classification be limited to the Snapshot error, like allocationStartError does, or to errors.Is(err, ctx.Err())?

    aramase aramase commented on code on Nov 10, 2026 15:56 UTC
    Code Review
    session/errors.go:1
    @@ -0,0 +1,110 @@
    +package session
    +
    +import (
    +	"context"
    +	"errors"
    +
    +	"github.com/agent-primitives/sessions/api"
    +	"github.com/agent-primitives/sessions/eventlog"
    +	"github.com/agent-primitives/sessions/placement"
    +	"google.golang.org/genproto/googleapis/rpc/errdetails"
    +	"google.golang.org/grpc/codes"
    +	"google.golang.org/grpc/status"
    +)
    +
    +// statusCause chooses the boundary code without accepting a backend transport status,
    +// while retaining the original cause for direct Go callers. Causes do not cross RPCs.
    +type statusCause struct {
    +	cause  error
    +	status *status.Status
    +}
    +
    +func (e *statusCause) Error() string              { return e.status.Err().Error() }
    +func (e *statusCause) Unwrap() error              { return e.cause }
    +func (e *statusCause) GRPCStatus() *status.Status { return e.status }
    +
    +func withStatusCause(code codes.Code, err error) error {

    nit: withStatusCause now attaches ErrorInfo for every caller, so Approve/CloseApproval (SESSION_DELETED), RegisterHarness (HARNESS_UNAVAILABLE) and authorized mutations (SESSION_BUSY) return reasons, while session.proto, spec.md and api-reference.md say only Exec, Resume, Suspend, Fork and DeleteSession do. Should withStatusCause stay reasonless, with statusError used only in the operation mappers, or should the docs list these RPCs (and the busy case in approval.go use statusError too)?

    gambtho gambtho commented on code on Nov 11, 2026 13:55 UTC
    Code Review
    session/service.go:1
    @@ -1134,7 +1134,7 @@ func (s *Service) Suspend(ctx context.Context, req *v1.SuspendRequest) (session
     		if refused != nil && err == refused {
     			return nil, refused
     		}
    -		return nil, suspendError(uid, err)
    +		return nil, suspendError(uid, runtimeContextError(ctx, err))

    I’ll track “Preserve Suspend journal failures after caller cancellation” as a separate follow-up issue. The call at 4b419a1 still fails and keeps its Go cause; cancellation changes the reported code and diagnostics.

    gambtho gambtho commented on code on Nov 11, 2026 13:55 UTC
    Code Review
    session/errors.go:1
    @@ -0,0 +1,110 @@
    +package session
    +
    +import (
    +	"context"
    +	"errors"
    +
    +	"github.com/agent-primitives/sessions/api"
    +	"github.com/agent-primitives/sessions/eventlog"
    +	"github.com/agent-primitives/sessions/placement"
    +	"google.golang.org/genproto/googleapis/rpc/errdetails"
    +	"google.golang.org/grpc/codes"
    +	"google.golang.org/grpc/status"
    +)
    +
    +// statusCause chooses the boundary code without accepting a backend transport status,
    +// while retaining the original cause for direct Go callers. Causes do not cross RPCs.
    +type statusCause struct {
    +	cause  error
    +	status *status.Status
    +}
    +
    +func (e *statusCause) Error() string              { return e.status.Err().Error() }
    +func (e *statusCause) Unwrap() error              { return e.cause }
    +func (e *statusCause) GRPCStatus() *status.Status { return e.status }
    +
    +func withStatusCause(code codes.Code, err error) error {

    I’ll track “Clarify ErrorInfo method and path coverage” as a separate follow-up issue, to settle the method list and approval-path consistency together. At 4b419a1, the extra host-owned details leave the refusal codes unchanged; I’ll keep that coverage decision separate from the Substrate classifier.

    aramase aramase approved these changes on Nov 12, 2026 22:38 UTC
    Approved Reviewer

    Approved these changes.

    Reviewers
    Assignees
    gambtho gambtho
    Labels
    risk: low confidence: 90.4% 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: 71.5% (HIGH) · Higher = larger blast radius
    71.5%
    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.4% · Lower = rushed or shallow review
    90.4%
    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: 6.8% · Safe to merge
    6.8%