Skip to content

controller,substrate: handle transient Substrate unavailability without permanent Task failure - #463

Merged
aprajitaarora13 merged 1 commit into
google:mainfrom
aprajitaarora13:fix/issue-421-transient-substrate-unavailable
Oct 15, 2026
Merged

aprajitaarora13 merged 1 commit into
google:mainfrom
aprajitaarora13:fix/issue-421-transient-substrate-unavailable

Conversation

@aprajitaarora13

Copy link
Copy Markdown
Collaborator

Fixes #421

Problem

When the Substrate control plane (ateapi) is briefly unavailable (for example during a pod rollout or initial connection establishment), EnsureAtespace, EnsureActor, or ResumeActor fails immediately with Unavailable or DeadlineExceeded, and TaskReconciler.Reconcile permanently marks the Task as Phase: Failed. In addition, CreateTask and ResumeTask overwrite Task.Status.Phase to Failed, leaving no way for ax apply or ax resume to recover the task once Substrate is reachable again.

Changes

  • internal/substrate/client.go:
    • Configure default dial options with grpc.WithDefaultCallOptions(grpc.WaitForReady(true)) and grpc.WithConnectParams (BaseDelay: 100ms, MaxDelay: 5s, MinConnectTimeout: 1s) on both NewClientWithOptions and NewClient.
    • Bound individual Substrate RPCs with callContext (DefaultCallTimeout = 10s) when the caller's context does not carry a deadline so WaitForReady(true) waits through brief connection drops without blocking indefinitely.
  • internal/controller/reconciler.go:
    • Classify codes.Unavailable, codes.DeadlineExceeded, and context.DeadlineExceeded as transient via isTransientSubstrateError.
    • When EnsureAtespace, EnsureActor, or ResumeActor fails with a transient Substrate error, keep task.Status.Phase = "Pending" and record condition Ready=False (Reason: SubstrateUnavailable) instead of transitioning to Phase: "Failed".
  • internal/server/server.go:
    • Preserve reconciled.Status (Phase: "Pending" and SubstrateUnavailable condition) on transient Substrate errors in CreateTask and ResumeTask, and return codes.Unavailable to callers.
    • Allow CreateTask to re-run reconciliation when an existing task is still in Phase == "Pending".
  • Unit Tests:
    • internal/substrate/client_test.go: TestClient_WaitForReady_WaitsForLateServer and TestClient_WaitForReady_HonorsCallTimeout.
    • internal/controller/reconciler_test.go: TestTaskReconciler_TransientSubstrateUnavailable.
    • internal/server/server_test.go: TestServer_TransientSubstrateUnavailableRecovery.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@mayawang mayawang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @aprajitaarora13, the problem write-up and the recovery test made this easy to follow, and treating Unavailable as transient is right. #468 sets out how this fits with #457 and #465; easiest to rebase once those two land.

Comment thread internal/server/server.go Outdated
_, err = s.store.GetTask(ctx, atespace, taskName)
if err == nil {
existing, err := s.store.GetTask(ctx, atespace, taskName)
if err == nil && existing.GetStatus().GetPhase() != "Pending" {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This accepts a re-apply of a Pending task with any spec, which reopens the immutability from #398. Could it only accept an unchanged spec?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — updated CreateTask to require proto.Equal(existing.GetSpec(), task.GetSpec()) (and preserve CreationTimestamp) when re-applying a Pending task, returning codes.FailedPrecondition if the spec differs. Added a test case in TestServer_TransientSubstrateUnavailableRecovery to verify.

Comment thread internal/server/server.go Outdated
return task, nil
}

func isTransientError(err error) bool {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and isTransientSubstrateError in the reconciler are the same check. One helper in internal/substrate would keep them from drifting.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — consolidated both helpers into substrate.IsTransientError in internal/substrate/client.go with unit tests in internal/substrate/client_test.go.

@rakyll

rakyll commented Oct 14, 2026

Copy link
Copy Markdown
Member

What's the recovery from these transient errors looks like? I don't see any retries in this PR. If there is no easy way to recover, it's better to fail the task creation and asking the client to retry it.

@mayawang

Copy link
Copy Markdown
Collaborator

Update: #465 is closed (AX won't run its own queue, see #367), so please ignore my earlier note about using its loop. Your original approach of keeping the task Pending and returning Unavailable is the right shape. Remaining asks are in the updated #468: rebase after #457, reuse its retry helper, and keep re-apply limited to an unchanged spec.

@aprajitaarora13
aprajitaarora13 force-pushed the fix/issue-421-transient-substrate-unavailable branch from 0c7d7d5 to 3eb65c2 Compare October 14, 2026 20:31
@aprajitaarora13

Copy link
Copy Markdown
Collaborator Author

@rakyll @mayawang Thanks for the reviews! Rebased onto main after #457 and updated per #468:

  1. In-flight retries in internal/substrate: Added codes.Unavailable to fix(substrate): adapt to Substrate v0.4 API and harden actor RPCs #457's retryOnCodes helper across the Substrate client RPCs in internal/substrate/client.go so brief ateapi rollouts recover automatically with jittered exponential backoff within the same RPC call.
  2. Client-driven recovery if retries are exhausted:
    • Consolidated substrate.IsTransientError in internal/substrate/client.go.
    • When Unavailable or DeadlineExceeded persists past the client retry window, the task stays in Phase: Pending (Ready=False, Reason: SubstrateUnavailable) and the server returns codes.Unavailable to the caller.
    • Re-applying CreateTask with an unchanged spec (proto.Equal) or calling ResumeTask re-runs reconciliation so the client can cleanly retry ax apply / ax resume without hitting FailedPrecondition (already exists and is immutable).

@aprajitaarora13
aprajitaarora13 force-pushed the fix/issue-421-transient-substrate-unavailable branch from 3eb65c2 to 8653e7e Compare October 14, 2026 21:02

@mayawang mayawang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @aprajitaarora13, this lines up with #468 exactly, and dropping the dial-level changes made it simpler too. Tests pass on main with #457 and #464 in. Approving, go ahead and merge.

One follow-up, non-blocking: a single Substrate call can now retry Unavailable for up to ~20s, and the task lock is a fixed 30s with no renewal. If Substrate flaps mid-request, a reconcile could outlast the lock. A per-request deadline under the lock TTL would cover it. Could you open an issue for that?

Comment thread internal/server/server.go Resolved
@mayawang

Copy link
Copy Markdown
Collaborator

+1 to @rich7420's suggestion. Once the spec check passes, saving the stored task keeps a re-apply from overwriting status with client-supplied values. Could you take it, with a test? I'll re-approve after.

…ut permanent Task failure

When the Substrate control plane is briefly unavailable (e.g. during ateapi rollout or cold connection establishment), the controller previously marked the Task as Phase: Failed permanently without retrying or distinguishing transient transport errors from permanent actor errors.

- Add codes.Unavailable to retryOnCodes across Substrate client RPCs in internal/substrate/client.go and export substrate.IsTransientError.

- Classify gRPC Unavailable and DeadlineExceeded errors in the TaskReconciler as transient: keep Task.Status.Phase in Pending with condition Ready=False (Reason: SubstrateUnavailable) rather than permanently setting Phase: Failed.

- Preserve Pending status and SubstrateUnavailable condition in CreateTask and ResumeTask when direct reconciliation hits a transient Substrate error, return codes.Unavailable to callers, and allow CreateTask to retry reconciliation on an existing Pending task only when the spec is unchanged.

Fixes google#421
@aprajitaarora13
aprajitaarora13 force-pushed the fix/issue-421-transient-substrate-unavailable branch from 1edb34d to d34865d Compare October 15, 2026 15:18
@aprajitaarora13

Copy link
Copy Markdown
Collaborator Author

@mayawang @rich7420 Updated CreateTask to reuse task = existing on Pending retries and added test cases in TestServer_TransientSubstrateUnavailableRecovery covering retries with omitted status and client-supplied conditions. Also opened #473 to track bounding the task reconciliation deadline under the 30s task lock TTL. PTAL!

@mayawang mayawang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approving with the stored-task fix, tests pass on main. Thanks @rich7420 for the catch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Controller marks Tasks Failed permanently when Substrate is briefly unavailable

4 participants