Managed OpenShell workload flow
Overview
Kubernetes Compute keeps one OpenShell Sandbox per Agent across revisions. Deployment prepares the Gateway and reconciles the Sandbox workload. OpenShell owns Harness storage. OCE manages the Gateway in its tenant namespace.
Entry Points
apps/controller/src/composition/installation-config.ts:loadInstallationConfigurationselects managed execution from the bundled Sandbox'sintegrationMode: service. All Kubernetes modes retainocc/kubernetesand the configured Compute ID.apps/controller/src/drivers/compute/kubernetes/index.ts:prepareRevisionreceives the authorized Agent revision and prepares the Gateway.apps/controller/src/drivers/sandbox/openshell/managed.ts:reconcileHarnesscreates or updates the Agent's Sandbox through its Backend.
The flow assumes one OCE worker, a dedicated Harness, persistent OpenShell
Sandbox storage and an enabled SandboxUpdates.UpdateSandbox RPC. See
configuration and limits.
Flow
graph TD
A["<b>Prepare Agent Gateway</b><br/>OCE tenant namespace"] --> B["<b>Resolve stable Sandbox</b><br/>OpenShell Workspace API"]
B --> C{"<b>Sandbox exists?</b>"}
C -- "No" --> D["<b>Create Sandbox</b><br/>OpenShell owns storage"]
C -- "Yes, new revision" --> E{"<b>Stopped and updateable?</b>"}
E -- "No" --> F["<b>Refuse replacement</b><br/>No new activation"]
E -- "Yes" --> G["<b>Replace workload</b><br/>Version check and readback"]
G --> H["<b>Start Sandbox</b>"]
D --> I["<b>Image bootstrap</b><br/>Prepare private home"]
H --> I
I --> J["<b>Connect workspace node</b><br/>Outbound link through Envoy"]
J --> K["<b>Verify readiness</b><br/>Activate Agent revision"]
K --> L["<b>Stop or retire</b><br/>Retain Sandbox storage"]
L --> B
K --> M["<b>Delete Agent</b><br/>Delete Sandbox via API"]
classDef operation fill:#EBF3F0,stroke:#7F9D93,color:#2B4038,stroke-width:1px
classDef gate fill:#F7F1E5,stroke:#B3A078,color:#514532,stroke-width:1px
class A,B,D,G,H,I,J,K,L,M operation
class C,E,F gateRetries can adopt the same revision after a lost response. Failed readback prevents start.
Execution Trace
1. Prepare the Workspace and Gateway
apps/controller/src/drivers/sandbox/openshell/managed.ts:ensureNamespace
creates or verifies the logical Workspace through OpenShell.
KubernetesComputeDriver.prepareRevision prepares the Gateway and credentials
in OCE's tenant namespace. apps/controller/src/drivers/compute/kubernetes/harness/runtime.ts:createHarnessRuntime
selects ManagedOpenShellHarnessRuntime for service mode. The Compute constructor
requires a runtime and refuses an execution cluster or ServicePrincipal projection.
KubernetesComputeDriver.admitRevision records the storage owner in
compute.admission. validateHarnessStorage checks it against the Installation
settings for preparation, activation, stop and retirement. Restore the saved
mode if they differ. harnessForRevision also checks the saved Sandbox Driver ID.
KubernetesComputeDriver.harnessLaunch builds the command, environment,
identity and retained-directory requirements. harnessLaunchWithNode adds
workspace node startup settings and identity. Managed sandboxRequirements
carries the logical directories and an empty workspaceMounts list.
ManagedOpenShellSandbox.harnessSpec maps those directories to bootstrap paths
and changes environment values with explicit directory bindings.
OpenShellSandboxDriver.harnessSpecForLayout adds process, network and
Provider settings. sandboxLaunchSpec encodes sizing in the template.resources
protobuf Struct and omits driver_config. canonicalSandboxSpec normalizes resource
Values; immutableWorkload and comparableWorkload retain sizing in replacement
and readback checks. Missing or changed resources fail those checks.
The image bootstrap prepares retained directories for dedicated OpenClaw
in place of prepareNativeWorkspace.
2. Reconcile a stopped workload
ManagedOpenShellSandbox.ensureRuntimeProvider updates credentials before
writing config with a resource-version check. It verifies config, profile and
ownership on readback. A retry can adopt a committed config after a lost
response. A retry for the same revision may renew its setup envelope.
reconcileHarness verifies Namespace and Agent ownership and requires a
confirmed stop for replacement. A difference in immutableWorkload, including
sizing, raises SANDBOX_WORKLOAD_IMMUTABLE before update or start.
Before replacing runtime Provider material or reconciling the owned Sandbox,
requireManagedTemplate refuses the old caller-config layout. The worker treats
SandboxRevisionUnsupportedError as permanent. See
recovery before upgrade.
reconcilePolicy reads the latest policy separately from the creation
specification and checks static policy and non-Git middleware.
For changed attachments, it clears base rules while stopped.
reconcileProviders verifies that intermediate policy, detaches obsolete
Providers, then attaches replacements. Readback after each write verifies
membership, ownership, stopped state and workload identity. OCE then installs
the final policy. A rejected policy leaves the attachments in place so the
next attempt can resume while stopped. With unchanged attachments, OCE updates
policy directly.
ManagedOpenShellSandbox.gitScopeAnnotations fingerprints the repository
Driver and bindings. verifyRetiredGit checks the stopped predecessor's
ownership and the absence of Git middleware and its revision-owned Provider.
Enabling Git creates a fresh Provider and middleware binding. Disabling Git
removes its environment, annotations and enrollment configuration.
verifyGitSandbox checks workload, ownership and live policy. Confirmed
mismatches close the route. See the
repository flow for identity checks.
OpenShellSandboxDriver.gitContinuity checks ownership, readiness and process
identity across two reads. Git verifies Provider receipts, network and supervisor
identities against OpenShell execution reports.
The launch fingerprint excludes OpenShell-internal annotations.
For a deployment-scoped Git grant (protected execution version 9), the Sandbox binds each repository route to one attached Provider. Its profile supplies credentials and contributes zero endpoints. The Worker compares the loaded policy with the authored rules, the sibling Providers and the current supervisor generation. It binds the held launcher to that observation before selecting the finite credential and checks the recipient again before rotation and release. OpenShell authorizes Git locally. Replacing the launcher requires a new revision. Standalone managed credentials retain execution version 8 and use a separate activation path. Each revision can admit only one of these delivery modes.
For an online grant after a restart, observeHeldPreview requires a fresh authenticated denial before
releasePreview acknowledges the launcher. The original worker records release
intent before sending. Uncertain release or worker replacement requires a new
revision. Git lookup checks the same startup acknowledgment after observation.
PostgreSQL checks durable acknowledgment before credential use. Stop withdraws
the binding.
openshell-gateway-client.ts:updateSandbox sends the latest resource version.
The Driver verifies the workload and live policy separately before start because
the specification retains the creation policy.
ManagedOpenShellSandbox.observeHarness reports running when OpenShell
loads the latest policy. The Driver checks the policy fingerprint saved in
the Sandbox annotations before live edits and Git continuity checks. Agent
grants can change independently. Replacement saves the successor's fingerprint.
apps/controller/src/drivers/egress-proxy/openshell.ts:loadedPolicyVersion
checks OpenShell's loaded version against its active version. OCE's egress
plan has a separate generation. wiringStatus verifies the expected policy
and execution evidence before enrollment or revalidation.
apps/controller/src/worker.ts:retireEgressInstallation retires the
predecessor's enrollment after Compute confirms its stop.
recordEgressInstallation records the eligible successor under the Agent
lock. PostgreSQL stores one immutable receipt per revision and permits one
non-retired receipt per sender and Sandbox. Request lookup excludes retired
receipts. Cleanup names the predecessor revision, leaving the successor eligible
for its own enrollment.
Before restarting a native OpenClaw Sandbox whose new revision has not enrolled,
reconcileHarness restores a missing startup exposure through ExposeService.
It reads back the exact port and bearer-passthrough authorization before start.
An incorrect or missing endpoint leaves the Sandbox stopped. After a lost
exposure response, a retry adopts the stored endpoint. Once the new revision
enrolls, the existing withdrawal path deletes the exposure again. Codex retains
its service for the app-server transport.
3. Select storage paths and connect the node
For a saved native Git grant, Kubernetes Compute freezes the inspected image pair and the Agent's Gateway node URL. The Sandbox verifies the node setup against that URL and checks the exact Workspace rule during policy readback. The generated Gateway pairs the node identified by the revision's binding. If an installed binding disappears, becomes invalid, or changes, the Gateway drops its acknowledgment and stops the process that holds the old File Transfer policy. The restart reads the current binding and rebuilds the policy from the admitted configuration. A changed image or route blocks startup.
deploy/runtime/openshell-bootstrap.cjs:prepareManaged creates the private
home at /opt/oce/managed/private/home and links retained workspace, generated images
and Codex sessions from /sandbox/oce. The node state variable points to a real
directory on that volume. OpenClaw checks the node state directory's ancestors
before starting its native worker. See the
storage requirements.
KubernetesComputeDriver.prepareWorkspaceNode supplies the
Envoy node URL.
networkPolicies admits OCE's Envoy Pods in service mode.
deleteUnwrittenAgentPolicies removes obsolete direct workspace-node policies
at activation.
OpenShellSandboxDriver.initializeWorkspace waits for supervisor readiness
and verifies the setup Secret's Namespace, Agent and setup IDs. It passes the
payload over authenticated ExecSandbox stdin, including completed setup
records on retries and later revisions. ManagedOpenShellSandbox.workspaceInitializationPath
selects /sandbox/oce/workspace. See
workspace initialization.
4. Retain or delete
apps/controller/src/drivers/sandbox/openshell/managed.ts:cleanup
preserves a successor workload when retiring an older revision. For the current
revision it calls StopSandbox and confirms stopped state. It does not delete storage.
For a Git revision, OpenShellGitRuntime.withdrawConfirmed first blocks local use
and waits for the route store to record withdrawal. Failure prevents replacement.
After stop, ManagedOpenShellSandbox.retireGit removes Git middleware and clears
base network rules, then detaches the old Git Provider with readback. It deletes
only Providers and profiles marked for that revision, including artifacts left by
an interrupted attempt. Cleanup does not resolve current repository policy.
releaseWithdrawn releases the in-memory route while retaining its tombstone.
Late predecessor cleanup can remove its detached artifacts but cannot stop or
change the successor. The successor restores its complete policy before start.
KubernetesComputeDriver.deleteAgentRuntimeCredentials resolves the tenant's
Kubernetes namespace name and calls ManagedOpenShellHarnessRuntime.deleteAgent.
It deletes the owned Sandbox and runtime Provider through OpenShell before shared
Gateway cleanup. Failure leaves final Agent deletion incomplete. Namespace cleanup removes unused runtime profiles and the Workspace. OCE makes no Harness PVC calls.
Stop and replacement ordering
OCE requires a confirmed stop before replacement. A retry reads the Sandbox and repeats the stop if needed within the worker's convergence limits. Cancellation removes a pending stop before admission. After admission OpenShell finishes the stop despite disconnection, serializing subsequent lifecycle calls. This ordering covers one worker. Provider writes and exposure withdrawal need separate verification.
Debugging and Verification
Run the local checks and deferred cluster checklist. A missing image bootstrap fails launch. An unreachable Envoy endpoint blocks the workspace-node connection. Unsupported or incomplete workload updates leave the Sandbox stopped and the revision inactive. Local protocol and filesystem checks do not establish cluster isolation or durable replacement after failures.
