fix: preserve Kubernetes runtimes after recoverable agent failures (#3824)
This commit is contained in:
@@ -0,0 +1,176 @@
|
||||
---
|
||||
created: 2026-09-19
|
||||
status: blocked
|
||||
requirements:
|
||||
- REQ-EXECUTORS-K8S-FAILURE-RECOVERY-001
|
||||
system_design:
|
||||
- ../../specs/executors/system-design/kubernetes-failure-recovery.md
|
||||
legacy_specs:
|
||||
- ../../specs/kubernetes-executor/spec.md
|
||||
---
|
||||
|
||||
# Implementation Plan: Kubernetes Recoverable Failure Cleanup
|
||||
|
||||
## Overview
|
||||
|
||||
Preserve the runtime needed by Resume after a recoverable Kubernetes agent
|
||||
failure. One sequential work order covers the cross-boundary regression and fix.
|
||||
Implementation was authorized by the user after the design handoff.
|
||||
|
||||
## Evidence and root cause
|
||||
|
||||
Read-only backend diagnostic bundle `84da3c3c3d03360d63cbfda4f5e1e579`
|
||||
reported ready with no warnings or lost log entries. Running version:
|
||||
`v0.94.0-247-ge3ed7bfd5`; inspected checkout: `794773dd6`.
|
||||
Affected task: `73dca427-4819-4ac5-9b44-4ac65a53a486`, session:
|
||||
`c4a5774f-a68e-4f16-91f3-286901e75f8b`.
|
||||
|
||||
Retained `backend-logs.log` timestamps on 2026-09-19, UTC+01:00:
|
||||
|
||||
1. 13:10:41: backend shutdown stops initial Kubernetes execution `30c4651b...`
|
||||
without force. At 13:19:27, execution `3767871c...` resumes successfully.
|
||||
2. 14:30:03: agent reports `Internal error`; orchestrator handles it as
|
||||
recoverable, then stops execution with `reason=agent completed, force=true`.
|
||||
3. 14:30:04: stop finishes successfully. At 14:31:11 idle reclaim preserves
|
||||
the runtime row for resume.
|
||||
4. 14:35:58: relaunch fails resolving `env_secret_id_AGENTCTL_AUTH_TOKEN`,
|
||||
referencing the original `kandev-runtime:30c4651b-7325-4e22-b2e4-eb8d1363ebd6:agentctl-auth`.
|
||||
|
||||
Source trace: `handleRecoverableFailureLockedState` ->
|
||||
`cleanupAgentExecution` -> forced `StopExecution` ->
|
||||
`StopAgentWithReason` -> `KubernetesExecutor.StopInstance` -> exact resource
|
||||
deletion and `deleteKubernetesRuntimeSecrets`. The old resource-instance ID is
|
||||
expected across resume; its reuse alone is not the defect. Destructive cleanup
|
||||
while promising recovery is the defect.
|
||||
|
||||
The bundle proves the cleanup request and subsequent missing secret. It does
|
||||
not establish the PVC storage mode, current cluster state, or recoverability of
|
||||
files. The original provider `Internal error` remains unexplained by these logs.
|
||||
No live runtime or database was modified during diagnosis.
|
||||
|
||||
## Scope
|
||||
|
||||
### In scope
|
||||
|
||||
Recoverable established-session failure teardown, exact-execution concurrency,
|
||||
credential/resource retention, and real error-to-Resume verification.
|
||||
|
||||
### Out of scope
|
||||
|
||||
Repairing this historical session's data, masking missing secrets, changing
|
||||
provider routing, fresh launch rollback, or changing other runtimes. UI cleanup
|
||||
is sibling task `e8757499-cfd8-4715-8b04-81fb7c1f3749`, created without a parent.
|
||||
|
||||
## Technical approach
|
||||
|
||||
Implement the [design](../../specs/executors/system-design/kubernetes-failure-recovery.md)
|
||||
using a specific recoverable-failure stop reason and lifecycle-owned Kubernetes
|
||||
retention. Keep generic forced cleanup and explicit archive/delete behavior.
|
||||
No schema or public API changes. Reuse existing teardown claims rather than
|
||||
introducing a second cleanup coordinator.
|
||||
|
||||
## Tests
|
||||
|
||||
New `event_handlers_kubernetes_recovery_test.go` in orchestrator:
|
||||
`TestKubernetesRecoverableFailurePreservesResume`, covering criteria .1-.2;
|
||||
`TestKubernetesRecoverableFailureCleanupBeforeWorkflowResume`, covering .3,
|
||||
including publisher return and immediate workflow-triggered resume. Duplicate
|
||||
cleanup with persisted inventory is covered at the lifecycle boundary.
|
||||
|
||||
New `manager_kubernetes_recoverable_failure_test.go` in lifecycle:
|
||||
`TestKubernetesRecoverableFailurePreservesRuntimeAndSecrets`, covering .1-.2;
|
||||
destructive-stop and non-Kubernetes controls for .4; existing auth resolution
|
||||
tests for .5. Use fresh and resumed established executions in the matrix.
|
||||
|
||||
## E2E tests
|
||||
|
||||
Add `apps/web/e2e/tests/kubernetes/kubernetes-failure-recovery.spec.ts` in
|
||||
`containers` with `preserves Kubernetes workspace after recoverable agent error`.
|
||||
Use the existing mock error scenario, a sentinel file, existing Resume control,
|
||||
exact Pod/PVC identities, restart, and archive assertions. Covers .1-.4.
|
||||
No component markup or mobile composition changes are planned.
|
||||
|
||||
## Work orders
|
||||
|
||||
- [ ] [Task 01: Preserve Kubernetes recoverable runtimes](task-01-preserve-recoverable-runtime.md)
|
||||
|
||||
## Verification results
|
||||
|
||||
Initial orchestrator and lifecycle regression failures reproduced destructive
|
||||
cleanup. A blocked-stop regression reproduced workflow Resume preceding cleanup;
|
||||
a publisher-return assertion reproduced synchronous cleanup blocking publication.
|
||||
The retained-inventory duplicate regression reproduced fallback into destructive
|
||||
persisted cleanup. Those focused tests now pass. The existing dynamic successor
|
||||
failure test exposed a session-guard deadlock; its caller now defers cleanup.
|
||||
Final race-enabled tests passed for both packages, including a rerun after the
|
||||
last production change. Kind verification is blocked by local fixture setup:
|
||||
|
||||
- Initial managed build was rejected as stale after a production edit. Rebuilt
|
||||
the required Linux artifacts and reused the completed Vite/plugin builds.
|
||||
- First refreshed run failed before the test body: `kind load docker-image`
|
||||
exceeded the fixture's 180-second timeout.
|
||||
- One retry with `E2E_DEBUG=1` reused image layers but failed creating the Kind
|
||||
node: no log line matched `Reached target .*Multi-User System.*|detected cgroup v1`.
|
||||
- Both attempts discovered one test. Neither executed the recovery assertions.
|
||||
Fixture cleanup removed their owned clusters and image tags. Do not count
|
||||
either run as evidence for Pod/PVC retention or backend-restart recovery.
|
||||
|
||||
Focused Go race checks, targeted Go lint (0 issues), ESLint, Prettier,
|
||||
architecture lint, and documentation
|
||||
validation passed. The remaining gate is a successful Kind scenario on a
|
||||
working local/CI container runner. The user explicitly requested a ready PR
|
||||
with this known integration-verification blocker disclosed.
|
||||
Read-only lifecycle trace: confirmed the destructive failure-cleanup path.
|
||||
`python3 scripts/list-docs.py validate`: passed (291 decisions, 1040 specifications).
|
||||
`python3 scripts/lint-spec-files.test.py`: passed (36 tests).
|
||||
`python3 scripts/lint-spec-files.py --all`: passed.
|
||||
`git diff --check`: passed.
|
||||
|
||||
## Risks
|
||||
|
||||
- Already-deleted credentials and managed workspace data cannot be restored by
|
||||
this patch. Current affected-session recovery requires separate evidence.
|
||||
- Late cleanup can race immediate Resume; preserving secrets alone is insufficient.
|
||||
- A global change to force cleanup can leak runtimes or weaken explicit cleanup.
|
||||
- Kind validation requires Docker and disposable resources; never use the
|
||||
affected live cluster for reproduction.
|
||||
|
||||
|
||||
## PR review remediation
|
||||
|
||||
- Cleanup failures now block workflow recovery and release their exact claim for
|
||||
retry. Completed teardown claims allow deferred workflow redelivery without
|
||||
repeating a stop; in-flight duplicates cannot bypass cleanup.
|
||||
- Recovery workers share service shutdown ownership with dynamic successors.
|
||||
Cancellation suppresses workflow Resume, and shutdown drains tracked workers.
|
||||
- Authentication and managed-NPM startup failures use bootstrap cleanup, keeping
|
||||
fresh-launch rollback destructive and resumed-bootstrap retention intact.
|
||||
- Async workflow route, cancellation, reconciliation, and panic tests now await
|
||||
worker completion. SQLite-backed recovery tests use bounded real-time signals.
|
||||
- Full affected-package race suites passed:
|
||||
`go test -race ./internal/orchestrator ./internal/agent/runtime/lifecycle ./internal/orchestrator/executor -count=1 -timeout=15m`.
|
||||
This includes every backend CI assertion that failed on the opening head.
|
||||
- Container CI reached the new test and exposed an invalid failure injection:
|
||||
`/e2e:error` emits text but does not fail ACP. The test now uses the existing
|
||||
`/transport-lost` prompt error in separate fresh-session cases with and without
|
||||
backend restart. A retries-disabled local run used rebuilt backend, Linux
|
||||
helpers, and plugin artifacts, but again hit the Kind image-load timeout before
|
||||
entering either assertion path. The run was interrupted during fixture cleanup;
|
||||
CI's Kubernetes runner remains the integration gate. Docker also reported that
|
||||
it could not immediately kill the owned Kind node; it subsequently exited and
|
||||
was removed explicitly. The owned image was already removed by fixture cleanup.
|
||||
No recovery assertion is counted as passing from this local attempt.
|
||||
|
||||
Architecture lint rejected direct lifecycle imports in new callers; stop reasons
|
||||
and missing-execution checks now use the public runtime facade. After that
|
||||
adjustment, race tests for Kubernetes recovery, dynamic failure, all agent-error
|
||||
workflow routes, runtime missing-execution handling, and stop paths passed across
|
||||
orchestrator, runtime, and lifecycle. Architecture lint passed.
|
||||
|
||||
A subsequent review exposed the same already-absent outcome in transient retry
|
||||
teardown. The R5 workflow-route regression failed for a missing execution, then
|
||||
passed after the transient path adopted the runtime facade's `IsNotFound` check.
|
||||
Success, already-absent, and real stop-error controls now run together. The race
|
||||
command `go test -race ./internal/orchestrator -run 'TestDispatchKanbanAgentErrorTrigger|TestKubernetesRecoverableFailure|Test.*TransientRetry' -count=1 -timeout=180s`
|
||||
passed. Cleanup ownership and synchronization helpers also received explanatory
|
||||
comments in response to the standalone documentation-coverage suggestion.
|
||||
+174
@@ -0,0 +1,174 @@
|
||||
---
|
||||
id: "01-preserve-recoverable-runtime"
|
||||
title: "Preserve Kubernetes recoverable runtimes"
|
||||
status: blocked
|
||||
wave: 1
|
||||
depends_on: []
|
||||
plan: "plan.md"
|
||||
requirements:
|
||||
- REQ-EXECUTORS-K8S-FAILURE-RECOVERY-001
|
||||
acceptance_criteria:
|
||||
- AC-EXECUTORS-K8S-FAILURE-RECOVERY-001.1
|
||||
- AC-EXECUTORS-K8S-FAILURE-RECOVERY-001.2
|
||||
- AC-EXECUTORS-K8S-FAILURE-RECOVERY-001.3
|
||||
- AC-EXECUTORS-K8S-FAILURE-RECOVERY-001.4
|
||||
- AC-EXECUTORS-K8S-FAILURE-RECOVERY-001.5
|
||||
system_design:
|
||||
- ../../specs/executors/system-design/kubernetes-failure-recovery.md
|
||||
---
|
||||
|
||||
# Task 01: Preserve Kubernetes Recoverable Runtimes
|
||||
|
||||
## Summary
|
||||
|
||||
Separate recoverable agent-failure teardown from destructive runtime cleanup.
|
||||
Keep existing Kubernetes resources and secret values available to Resume while
|
||||
stopping the failed agent and releasing its local execution slot.
|
||||
|
||||
## In scope
|
||||
|
||||
- Add the orchestrator regression first; prove the existing handler reaches
|
||||
destructive Kubernetes cleanup. Cover fresh and resumed established sessions.
|
||||
- Route recoverable failure through a distinct stop reason, preserving existing
|
||||
exact-execution claims, stream retirement, and non-Kubernetes behavior.
|
||||
- Apply Kubernetes retention at the lifecycle boundary and prove secret values,
|
||||
references, inventory, and remote resources survive.
|
||||
- Block cleanup in a deterministic test while a replacement is requested;
|
||||
cover duplicate events and synchronous workflow restart without deadlock or
|
||||
predecessor teardown affecting the replacement.
|
||||
- Add the Kind scenario named in the plan and verify archive cleanup afterward.
|
||||
|
||||
## Out of scope
|
||||
|
||||
Live data mutation, recovery-token regeneration, UI redesign, new schema, broad
|
||||
cleanup refactoring, and unexplained provider failures.
|
||||
|
||||
## Acceptance
|
||||
|
||||
1. The regression fails before the correction because recoverable failure
|
||||
requests destructive Kubernetes teardown, and passes after it.
|
||||
2. Recovery retains the same workspace and credentials across retry/restart;
|
||||
late or duplicate failures cannot damage the replacement execution.
|
||||
3. Explicit destructive cleanup, missing-secret fail-closed behavior, and
|
||||
existing non-Kubernetes teardown remain covered and passing.
|
||||
|
||||
## Verification
|
||||
|
||||
From the repository root; install workspace dependencies before the first pnpm
|
||||
command if this worktree has not been installed. Docker is required for Kind.
|
||||
|
||||
```bash
|
||||
(cd apps && pnpm install --frozen-lockfile)
|
||||
(cd apps/backend && go test -race ./internal/orchestrator -run 'Test(KubernetesRecoverableFailure|HandleRecoverableFailure|HandleAgentFailed|HandleAgentStartFailed|RunDetachedDynamicSuccessorLaunch|ClaimForcedExecutionCleanup|RegisterExecutionStopOwner|HandleAgentStopped)' -count=1)
|
||||
(cd apps/backend && go test -race ./internal/agent/runtime/lifecycle -run 'Test.*(Kubernetes.*(Failure|Stop|Cleanup|Resume)|ResolveLaunchAuthToken|PersistedKubernetesInventory)' -count=1)
|
||||
(cd apps/web && KANDEV_E2E_CONTAINERS=1 pnpm e2e:run --host --project containers tests/kubernetes/kubernetes-failure-recovery.spec.ts)
|
||||
python3 scripts/list-docs.py validate
|
||||
python3 scripts/lint-spec-files.py --all
|
||||
git diff --check
|
||||
```
|
||||
|
||||
## Files likely touched
|
||||
|
||||
- `apps/backend/internal/orchestrator/event_handlers_agent.go`
|
||||
- `apps/backend/internal/orchestrator/dynamic_launch.go`
|
||||
- `apps/backend/internal/orchestrator/event_handlers_kubernetes_recovery_test.go` (new)
|
||||
- `apps/backend/internal/orchestrator/execution_teardown_ownership_test.go`
|
||||
- `apps/backend/internal/agent/runtime/lifecycle/manager_interaction.go`
|
||||
- `apps/backend/internal/agent/runtime/lifecycle/manager_kubernetes_restart_cleanup.go`
|
||||
- `apps/backend/internal/agent/runtime/lifecycle/recovery_stop.go` (recoverable stop reason)
|
||||
- `apps/backend/internal/orchestrator/execution_failure_cleanup.go`
|
||||
- `apps/backend/internal/agent/runtime/lifecycle/manager_kubernetes_recoverable_failure_test.go` (new)
|
||||
- `apps/backend/internal/agent/runtime/lifecycle/manager_kubernetes_resume_bootstrap_cleanup_test.go`
|
||||
- `apps/web/e2e/tests/kubernetes/kubernetes-failure-recovery.spec.ts`
|
||||
|
||||
## Dependencies
|
||||
|
||||
None. Execute after the explicit implementation request.
|
||||
|
||||
## Risks
|
||||
|
||||
The failure handler dispatches workflow callbacks that can immediately resume.
|
||||
Respect existing cancellation/teardown ordering; do not hold a session guard
|
||||
across a callback that needs the same guard. Do not change the shared helper's
|
||||
default behavior for terminal or orphan callers.
|
||||
|
||||
## Parallelism
|
||||
|
||||
`sequential`
|
||||
|
||||
## Inputs
|
||||
|
||||
- [Requirements](../../specs/executors/requirements/kubernetes-failure-recovery.md)
|
||||
- [System design](../../specs/executors/system-design/kubernetes-failure-recovery.md)
|
||||
- [Evidence and source trace](plan.md#evidence-and-root-cause)
|
||||
- Existing `newAgentErrorTestService`, teardown-claim tests, failed-resume
|
||||
bootstrap retention tests, and Kubernetes Kind fixtures.
|
||||
|
||||
## Results
|
||||
|
||||
Implementation complete; integration verification blocked. The destructive-stop, cleanup ordering, publisher
|
||||
return, and persisted-inventory duplicate regressions were observed failing and
|
||||
then passing. Final checks include the existing dynamic successor failure tests,
|
||||
which exposed and drove correction of another guarded cleanup caller.
|
||||
Focused non-race regressions plus dynamic failure tests passed after the final
|
||||
production edit. Race-enabled orchestrator/lifecycle checks passed, including
|
||||
recoverable failures, event handling, teardown claims, Kubernetes cleanup and
|
||||
resume controls, persisted cleanup, and auth resolution. A final race-enabled
|
||||
rerun of `TestKubernetesRecoverableFailure|TestRunDetachedDynamicSuccessorLaunch`
|
||||
passed for both packages.
|
||||
|
||||
Kind verification was attempted twice against refreshed artifacts. The first
|
||||
failed during image loading (180-second fixture timeout); a debug retry failed
|
||||
while creating the Kind node (missing expected systemd boot log). Neither
|
||||
entered the test body. Owned clusters and image tags were cleaned up. Rerun the
|
||||
same managed `containers` command on a working Kind runner before completing
|
||||
this work order. The user explicitly authorized committing and opening a ready
|
||||
PR with the unresolved integration verification disclosed.
|
||||
|
||||
The shared Go build cache lost entries during the first race attempt. Successful
|
||||
runs used `GOCACHE=/tmp/kandev-recovery-go-cache`; the failures were build errors,
|
||||
not test assertions.
|
||||
|
||||
Targeted Go lint passed with 0 issues. The E2E file passed ESLint and Prettier.
|
||||
Architecture and documentation validators passed. Final Docker inspection
|
||||
confirmed no owned test containers or runtime image tags remained.
|
||||
|
||||
|
||||
## PR review remediation
|
||||
|
||||
- Cleanup failures now block workflow recovery and release their exact claim for
|
||||
retry. Completed teardown claims allow deferred workflow redelivery without
|
||||
repeating a stop; in-flight duplicates cannot bypass cleanup.
|
||||
- Recovery workers share service shutdown ownership with dynamic successors.
|
||||
Cancellation suppresses workflow Resume, and shutdown drains tracked workers.
|
||||
- Authentication and managed-NPM startup failures use bootstrap cleanup, keeping
|
||||
fresh-launch rollback destructive and resumed-bootstrap retention intact.
|
||||
- Async workflow route, cancellation, reconciliation, and panic tests now await
|
||||
worker completion. SQLite-backed recovery tests use bounded real-time signals.
|
||||
- Full affected-package race suites passed:
|
||||
`go test -race ./internal/orchestrator ./internal/agent/runtime/lifecycle ./internal/orchestrator/executor -count=1 -timeout=15m`.
|
||||
This includes every backend CI assertion that failed on the opening head.
|
||||
- Container CI reached the new test and exposed an invalid failure injection:
|
||||
`/e2e:error` emits text but does not fail ACP. The test now uses the existing
|
||||
`/transport-lost` prompt error in separate fresh-session cases with and without
|
||||
backend restart. A retries-disabled local run used rebuilt backend, Linux
|
||||
helpers, and plugin artifacts, but again hit the Kind image-load timeout before
|
||||
entering either assertion path. The run was interrupted during fixture cleanup;
|
||||
CI's Kubernetes runner remains the integration gate. Docker also reported that
|
||||
it could not immediately kill the owned Kind node; it subsequently exited and
|
||||
was removed explicitly. The owned image was already removed by fixture cleanup.
|
||||
No recovery assertion is counted as passing from this local attempt.
|
||||
|
||||
Architecture lint rejected direct lifecycle imports in new callers; stop reasons
|
||||
and missing-execution checks now use the public runtime facade. After that
|
||||
adjustment, race tests for Kubernetes recovery, dynamic failure, all agent-error
|
||||
workflow routes, runtime missing-execution handling, and stop paths passed across
|
||||
orchestrator, runtime, and lifecycle. Architecture lint passed.
|
||||
|
||||
A subsequent review exposed the same already-absent outcome in transient retry
|
||||
teardown. The R5 workflow-route regression failed for a missing execution, then
|
||||
passed after the transient path adopted the runtime facade's `IsNotFound` check.
|
||||
Success, already-absent, and real stop-error controls now run together. The race
|
||||
command `go test -race ./internal/orchestrator -run 'TestDispatchKanbanAgentErrorTrigger|TestKubernetesRecoverableFailure|Test.*TransientRetry' -count=1 -timeout=180s`
|
||||
passed. Cleanup ownership and synchronization helpers also received explanatory
|
||||
comments in response to the standalone documentation-coverage suggestion.
|
||||
@@ -354,6 +354,12 @@ Current connection configuration and recorded workload configuration serve diffe
|
||||
|
||||
Ordinary Stop and backend shutdown close local clients and forwards but preserve the Pod and workspace. Agent or main-container restart keeps the Pod volumes; Kandev performs a new nonce handshake and local port-forward. If a Pod disappears, managed or existing PVC storage can support a replacement Pod after identity checks; `emptyDir` cannot.
|
||||
|
||||
A recoverable agent error also preserves the established Pod, workspace, and
|
||||
recovery credentials. Use **Resume** to continue that session. If its retained
|
||||
credentials or storage are missing, recovery fails rather than silently creating
|
||||
an empty replacement workspace. A software update cannot restore resources that
|
||||
were already deleted.
|
||||
|
||||
Archive/delete terminal cleanup and explicit force cleanup are destructive. Before deletion, Kandev verifies the recorded namespace, name, UID, and complete standard plus `kandev.ai/*` ownership-label set. It then deletes the exact Pod with UID/resource-version preconditions and deletes a PVC only when inventory proves Kandev created that managed claim. Existing claims are never deleted. A missing object is idempotent; an inventory read error, same-name replacement, UID mismatch, missing label, changed label, extra `kandev.ai/*` label, or mismatched create nonce fails closed without deleting the ambiguous object.
|
||||
|
||||
Kandev blocks deleting an executor, or changing an executor into or out of Kubernetes, while runtime inventory still refers to it. Finish normal session cleanup first. Profile deletion does not rewrite or destroy a retained workload because recovery owns the recorded profile ID and snapshot.
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
---
|
||||
status: draft
|
||||
system: executors
|
||||
created: 2026-09-19
|
||||
owners:
|
||||
- kandev
|
||||
---
|
||||
|
||||
# Kubernetes Failure Recovery
|
||||
|
||||
## Overview
|
||||
|
||||
A failed agent turn must not destroy the Kubernetes workspace that the user is
|
||||
offered to resume. This document defines the recoverable agent-failure case
|
||||
alongside the [Kubernetes foundation](../../kubernetes-executor/spec.md).
|
||||
The executor system owns resource retention; task state remains task-owned.
|
||||
|
||||
## Requirements
|
||||
|
||||
### REQ-EXECUTORS-K8S-FAILURE-RECOVERY-001: Retained recovery resources
|
||||
|
||||
**Intent:** Keep an established Kubernetes session usable after an agent error.
|
||||
|
||||
#### Acceptance criteria
|
||||
|
||||
- **AC-EXECUTORS-K8S-FAILURE-RECOVERY-001.1:** When an established Kubernetes
|
||||
session encounters a recoverable agent failure, stopping its failed execution
|
||||
shall preserve its Pod, workspace, and credentials needed for recovery.
|
||||
- **AC-EXECUTORS-K8S-FAILURE-RECOVERY-001.2:** After that failure, Resume shall
|
||||
reconnect to the retained session and preserve workspace changes, including
|
||||
after a backend restart. Cleanup shall not leave recovery referencing
|
||||
credentials that cleanup itself removed.
|
||||
- **AC-EXECUTORS-K8S-FAILURE-RECOVERY-001.3:** A delayed or repeated failure for
|
||||
an earlier execution shall not stop a newer execution or delete its resources.
|
||||
- **AC-EXECUTORS-K8S-FAILURE-RECOVERY-001.4:** Explicit archive, delete, and
|
||||
destructive cleanup shall retain their existing ownership verification and
|
||||
cleanup behavior. Existing operator-owned claims shall remain untouched.
|
||||
- **AC-EXECUTORS-K8S-FAILURE-RECOVERY-001.5:** Missing or inaccessible retained
|
||||
credentials shall remain an actionable recovery failure; the system shall not
|
||||
silently substitute credentials, adopt another workload, or recreate an empty
|
||||
workspace as if recovery succeeded.
|
||||
|
||||
## Exclusions
|
||||
|
||||
Restoring already-deleted data, changing provider error classification, changing
|
||||
other executors' teardown behavior, and redesigning error presentation are outside
|
||||
this contract. Fresh launch rollback remains governed by the foundation.
|
||||
@@ -0,0 +1,85 @@
|
||||
---
|
||||
status: draft
|
||||
system: executors
|
||||
requirements:
|
||||
- REQ-EXECUTORS-K8S-FAILURE-RECOVERY-001
|
||||
---
|
||||
|
||||
# Kubernetes Failure Recovery Design
|
||||
|
||||
## Boundary
|
||||
|
||||
Implements [retained failure recovery](../requirements/kubernetes-failure-recovery.md)
|
||||
within the existing [resource ownership decision](../../../decisions/2026-08-24-kubernetes-executor-resource-ownership.md).
|
||||
No new storage, credential rotation, public endpoint, or resource ownership rule
|
||||
is needed. The foundation's inventory and identity checks remain authoritative.
|
||||
|
||||
## Failure teardown
|
||||
|
||||
`handleRecoverableFailureLockedState` currently schedules
|
||||
`cleanupAgentExecution`, which calls `StopExecution` with reason `agent completed`
|
||||
and `force=true`. Kubernetes interprets force as destructive Pod/PVC teardown;
|
||||
`StopAgentWithReason` subsequently deletes authentication and bootstrap secrets.
|
||||
The recoverable task state and retained inventory then disagree with reality.
|
||||
|
||||
Use a distinct semantic reason for recoverable agent-failure teardown. Keep the
|
||||
existing exact-execution ownership claim and activity retirement. Do not globally
|
||||
change the shared cleanup helper's force setting: it also serves terminal,
|
||||
orphan, and stale-resume callers.
|
||||
|
||||
At the lifecycle boundary, use the recorded execution runtime to make this
|
||||
specific reason non-destructive for Kubernetes, whether the established
|
||||
execution originated from a fresh launch or a resumed session. Stop the failed
|
||||
agent through agentctl with a bounded cleanup context, close local connections,
|
||||
and release the in-memory execution slot. Preserve authoritative runtime
|
||||
inventory and both secret references and values. Other runtimes retain their
|
||||
existing force behavior. Explicit destructive reasons retain priority.
|
||||
|
||||
The existing failed-resume-bootstrap retention path in
|
||||
`manager_kubernetes_resume_bootstrap_cleanup_test.go` provides the nearest
|
||||
pattern. Startup authentication and managed-NPM failures carry the bootstrap
|
||||
stop reason, so resumed startup retains resources while fresh-launch rollback
|
||||
remains destructive.
|
||||
|
||||
## Concurrency and failure handling
|
||||
|
||||
Retain the exact `(session, execution)` teardown claim and stale-event guards.
|
||||
Failure cleanup and a subsequent resume must be ordered so predecessor cleanup
|
||||
cannot tear down the newly attached execution or its shared retained Pod. Cover
|
||||
this ordering with a blocked-stop test, including synchronous `on_agent_error`
|
||||
restart. Run cleanup and its subsequent workflow callback together after releasing
|
||||
the session guard, on a service-owned worker: lifecycle failure publication can
|
||||
hold the prompt lock until its subscribers return. Do not add a session-wide
|
||||
lock across callbacks that reacquire it. A repeated recoverable stop for an
|
||||
execution no longer tracked in memory must not enter destructive persisted
|
||||
Kubernetes cleanup.
|
||||
|
||||
Keep secret lookup failures fail-closed in `resolveLaunchAuthToken`.
|
||||
Regenerating a secret would not restore a deleted PVC or authenticate to an
|
||||
already-running agentctl. Do not silently migrate broken historical sessions.
|
||||
Cleanup errors release only the exact failed teardown claim so a later attempt
|
||||
can retry; they suppress workflow dispatch. A successful teardown records
|
||||
completion on its claim, allowing workflow redelivery without repeating cleanup.
|
||||
An in-flight duplicate cannot dispatch ahead of the owning cleanup. An already
|
||||
absent execution is a successful cleanup outcome.
|
||||
|
||||
Recovery workers share the dynamic-successor cancellation context and wait group.
|
||||
Shutdown rejects new workers, cancels active work, and drains within the existing
|
||||
shutdown bound. Workflow recovery checks cancellation after cleanup and receives
|
||||
the worker context, so a stop finishing during shutdown cannot start Resume.
|
||||
|
||||
## Validation
|
||||
|
||||
Map criteria .1-.3 to orchestrator failure-handler, teardown ownership, and
|
||||
lifecycle tests. Verify .4 with existing exact Kubernetes cleanup tests plus
|
||||
explicit destructive-stop controls. Verify .5 with secret-store missing/error
|
||||
tests. A Kind scenario must write a workspace sentinel, inject an agent error,
|
||||
resume, and prove unchanged Pod/PVC identity and sentinel contents. Repeat after
|
||||
a backend restart; archive at the end to prove cleanup remains available.
|
||||
|
||||
No rendered interface changes are required. The existing Resume control is the
|
||||
user-visible entry point. The separate error-UI task owns presentation changes.
|
||||
|
||||
## Implementation plan
|
||||
|
||||
[Kubernetes recoverable failure cleanup](../../../plans/kubernetes-recoverable-failure-cleanup/plan.md)
|
||||
Reference in New Issue
Block a user