Repository navigation
Description
User Story
I use OpenShell's Kubernetes backend in a kind demo to create, run, and delete sandbox workloads. I need deletion to remain reliable while the Agent Sandbox controller is updating sandbox status, so that a successful delete does not leave a compute resource that OpenShell can no longer manage.
Problem Statement
The Kubernetes driver treats a DELETE precondition conflict as proof that the Sandbox resource is already absent.
delete_sandbox_inner lists the Sandbox and copies both its UID and resourceVersion into the DELETE preconditions. A controller update between LIST and DELETE changes the resourceVersion without replacing the resource. Kubernetes can then reject DELETE with HTTP 409 while leaving the original UID present.
The driver handles both 404 and 409 by returning deleted=false. The gateway interprets false as confirmed absence, removes the durable sandbox record, and returns a completed deletion. Subsequent driver snapshots cannot restore that record because the gateway ignores snapshots for unknown IDs.
This differs from an accepted asynchronous deletion: here Kubernetes has rejected the deletion request.
Impact / Why This Matters
A concurrent status or metadata update can cause OpenShell to report a completed deletion while the Sandbox CR remains. Its workload, supervisor, and other dependents may also remain. The user loses the normal OpenShell handle for observing or cleaning up the resource and must inspect Kubernetes directly.
This report does not claim that a workload continues running indefinitely after gateway state is removed.
Acceptance Criteria
- A resourceVersion conflict for a still-present Sandbox UID does not produce a confirmed-absence result or completed gateway deletion.
- A retry can complete deletion without losing the gateway's management record prematurely.
- A genuine 404 retains the existing already-absent behavior.
- UID protection is preserved so retries cannot delete a replacement resource.
- Regression coverage includes LIST at version N, DELETE 409, and a subsequent GET returning the same UID at version N+1.
Reproduction Steps
Deployment reproduction targets an expendable sandbox in an OpenShell Kubernetes deployment. Do not run the annotation writer against a sandbox that must be kept.
- Create a sandbox and locate its Agent Sandbox CR through the sandbox ID label. Record the CR name, namespace, UID, and resourceVersion.
- Continuously update a harmless annotation on that CR while issuing
openshell sandbox deletefor the sandbox. Bound the annotation writer to the duration of this delete attempt. - Inspect the CLI result, the OpenShell sandbox record, and the CR after the writer has stopped. Repeat with a new expendable sandbox if the race is not hit.
- The failing interleaving is: the driver's LIST sees version N; the annotation writer or controller produces version N+1; DELETE carrying the old version is rejected with 409; OpenShell reports completion and removes its record while the same CR UID remains.
Two bounded annotation-writer/CLI-delete attempts on the kind deployment completed normally and did not hit this interleaving. The complete gateway race is therefore not yet reproduced live. The deterministic driver test and the real Kubernetes API control below verify the two components of the failure separately.
Verification
A deterministic test extracted the unmodified delete_sandbox_inner method from the affected source and used a kube Client mock. Discovery and dedicated-topology fixture helpers were supplied around that method.
LIST: 200, UID=same-sandbox-uid, resourceVersion=20
DELETE: 409 Conflict, stale resourceVersion
Driver result: Ok(false)
GET: 200, UID=same-sandbox-uid, resourceVersion=21
The gateway consequence is confirmed by its false-result branch and the existing already_absent_driver_resource_is_removed_synchronously test. The full gateway integration test was not executed during this initial verification.
Real kind API control
A disposable sandbox was created through OpenShell 0.1.8. After reading its CR UID and resourceVersion, one harmless annotation update was made. A DELETE carrying the saved UID and old resourceVersion then returned:
{"deleteStatus":409,"reason":"Conflict","uidUnchanged":true,"deletionTimestamp":null}A subsequent GET returned the original CR UID at a newer resourceVersion. This is a live Kubernetes result, not a mock. It confirms that a version conflict is not evidence that the original resource was replaced or disappeared. The control directly called the Kubernetes API; it does not by itself reproduce the gateway's incorrect completion result.
To repeat this control in a shared-mode deployment, use a new expendable sandbox and the deployment's namespace. In another terminal, run kubectl proxy --port=8001 with the kubeconfig for that deployment. No additional packages are required.
openshell sandbox create --name repro-del-conflict --detach --no-auto-providers --no-tty -- /bin/sleep 600
# Set NS to the namespace of this shared-mode OpenShell deployment.
CR=default--repro-del-conflict
sb_uid=$(kubectl -n "$NS" get sandbox "$CR" -o jsonpath='{.metadata.uid}')
rv_before=$(kubectl -n "$NS" get sandbox "$CR" -o jsonpath='{.metadata.resourceVersion}')
kubectl -n "$NS" annotate sandbox "$CR" openshell.ai/delete-repro=changed-after-snapshot --overwrite
curl --noproxy '*' -sS -i -X DELETE -H 'Content-Type: application/json' \
--data "{\"apiVersion\":\"v1\",\"kind\":\"DeleteOptions\",\"preconditions\":{\"uid\":\"$sb_uid\",\"resourceVersion\":\"$rv_before\"}}" \
"http://127.0.0.1:8001/apis/agents.x-k8s.io/v1beta1/namespaces/$NS/sandboxes/$CR"
kubectl -n "$NS" get sandbox "$CR" -o custom-columns=UID:.metadata.uid,DELETING:.metadata.deletionTimestamp
openshell sandbox delete repro-del-conflictOnly the version strings, generic resource names, and redacted result are included here. Hostnames, internal addresses, client credentials, and private filesystem paths are omitted.
Environment
- Source checked:
2e5589b2180dd432320adda124c4f7bcede119b5. - The same affected branch is present in the
v0.1.8source. - Live API control: OpenShell CLI/gateway 0.1.8; Agent Sandbox controller v1.0.3; kind v0.33.0; Kubernetes v1.37.0; Linux x86_64.
- Workspace mode: shared.
Activity
levyshira commentedon Dec 2, 2026
This appears to be addressed by merged PR #5843