Repository navigation
feat(remote-worker): per-session workspace directory on the container tier (#408) - #461
Conversation
…on the container tier On the container tier every session's turns ran in the one shared /workspace, so user 2's agent saw user 1's `git clone`, and two sessions cloning the same repo collided on the same path (rossoctl#408). A worker-only change would not fix that: every path the sandbox tools send is absolute under the harness's podCwd (`cd '/workspace' && ...`), so the directory the child starts in does not matter. Both sides change, gated by a new Hello capability: - remote-worker: WorkspaceRunner wraps BashRunner. A non-empty workspace_key runs in <SH_WORKSPACE_ROOT>/<key>, created on first use; the key is validated to one path segment with vmpool's rule. An empty key is passed through unchanged. The worker advertises `workspace-subdir`. - Cleanup is idle-only (SH_WORKSPACE_IDLE, default 30m, matching the microVM worker). A directory is renamed to a tombstone name under the lock, then deleted off it, so a session returning mid-delete gets a fresh directory. A key with a running Exec is never swept (rossoctl#338). - harness: a leased record that advertises `workspace-subdir` gets podCwd = <KAGENTI_SANDBOX_CWD>/<session id>. Pods, older workers and the microVM tier keep podCwd unchanged. This is not a security boundary: the same container and Unix user, so `cd ..` still reaches other sessions. It fixes the collision and the "B sees A's clone" problem; isolation remains MI1 S5 owner binding. Fixes rossoctl#408 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
CodeQL js/polynomial-redos flagged /\/+$/ in sessionPodCwd. Move the linear-scan stripTrailingSlashes out of run-leaf.ts into its own module and use it in both places, so there is one implementation to keep. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Summary
This PR gives each session its own workspace directory on the container tier, gated by the workspace-subdir Hello capability. The worker and the harness agree on the key: take sends workspaceKey: sessionId and sessionPodCwd uses the same id. The lock ordering in Run/Sweep means a running Exec is never swept. The CodeQL js/polynomial-redos alert from the first commit is fixed in 830a60a. stripTrailingSlashes is now one shared linear-scan helper used by both run-leaf.ts and sessionPodCwd, and CodeQL is green. The inline comments are suggestions, not blockers: key validity, config drift between the two env vars, and reclaim behaviour.
Docs not in the diff that still say the container worker ignores workspace_key (now stale; the "no isolation between users" claim itself still holds): deploy/k8s/README.md:314, deploy/vm/README.md:691, docs/demos/vm-multi-user-demo.md:689.
The test plan's live cluster check (two sessions cloning the same repo on one container worker) is still unchecked.
Author: pdettori (MEMBER — maintainer)
Areas reviewed: TypeScript (harness), Go (remote-worker), Docs, Security
Agent/IDE config (.claude/.vscode): none
Commits: 2 commits, all signed-off: yes
CI status: passing (all 14 checks, including CodeQL)
| sessionId: string, | ||
| ): string { | ||
| if (!rec?.capabilities.includes(WORKSPACE_SUBDIR_CAPABILITY)) return podCwd; | ||
| return `${stripTrailingSlashes(podCwd)}/${sessionId}`; |
There was a problem hiding this comment.
suggestion: With the capability on, the container tier now refuses any key that fails ^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$, where before it ran them. Two producers can miss that rule:
leafSessionId→toSessionIdsanitises characters but has no length cap, so a longtenant/run_id/item_id(over 128 chars) now fails every Exec on a capable container worker.acquireTurnSandboxfalls back tosessionId ?? holderId, which yieldsanon:<uuid>(the:is refused).executeTurnalways passesgetSessionId()now, so this looks unreachable today, but the function is still exported.
Consider capping or hashing in toSessionId, plus a test that the ids the harness generates satisfy the worker's rule.
| Idle: wexec.DefaultWorkspaceIdle, | ||
| Inner: wexec.BashRunner{}, | ||
| } | ||
| if v := get("SH_WORKSPACE_ROOT"); v != "" { |
There was a problem hiding this comment.
suggestion: If KAGENTI_SANDBOX_CWD and SH_WORKSPACE_ROOT disagree, the only symptom is cd: …: No such file or directory on every tool call. The name also means something different on microvm-worker, where SH_WORKSPACE_ROOT is a host directory (/srv/workspaces) that by design is not the harness cwd. On a P6 host running both workers, copying the microVM value breaks the container tier. Consider advertising the root in Hello (e.g. a label) so the harness can use it, or at least log a mismatch.
|
|
||
| // DefaultWorkspaceIdle mirrors vmpool.DefaultWorkspaceIdle: an idle key's directory is | ||
| // the only thing a sweep deletes, and it is deleted only after this long with no Exec. | ||
| const DefaultWorkspaceIdle = 30 * time.Minute |
There was a problem hiding this comment.
suggestion: This adds deletion where the container tier had none. Until now, files lived until the container restarted. A session that waits more than 30m on a person (e.g. require_approval) now comes back to an empty workspace, and the harness gets no workspaceReset-style signal it could surface. Consider a longer default on this tier, or call out the new behaviour in the deploy READMEs (deploy/k8s, deploy/vm).
| // workspaceTombstonePrefix names a directory detached from its key and queued for | ||
| // removal. validWorkspaceKey requires an alphanumeric first character, so no key can | ||
| // resolve to one — the same trick, for the same reason, as vmpool's detachWorkspace. | ||
| const workspaceTombstonePrefix = ".reclaiming-" |
There was a problem hiding this comment.
suggestion: Two kinds of leftover are never reclaimed:
- If the worker dies mid-
RemoveAll, orRemoveAllfails (logged and dropped), the.reclaiming-*tombstone stays under Root, where empty-key sessions see it. Keys cannot start with., so a startup pass (or each Sweep) that removesRoot/.reclaiming-*is safe. - Keys are tracked in memory only. On ocp-single the workspace is an emptyDir, which survives a container restart, so the directories of sessions that never return after a worker restart are orphaned. Worth a line in DESIGN.md even if adoption stays out of scope.
`mocactl follow-up SESSIONID "prompt"` is #381's last unbuilt command: a second turn on a finished subagent's session, which keeps the first turn's context, so `get` the result, read it, and ask for the next thing without paying for the first turn again. The result is copied out before the turn is dispatched. The sync path keeps one result record per session and overwrites it unconditionally, so the copy has to precede the dispatch or it races it; `cmdGet`'s write block is now a shared `writeResultFiles` and both commands produce the same three files. An async row is copied nothing: each of its turns keeps its own artifacts for seven days (#840). A record that aged out of its 24 hours is not a refusal, but a result that could not be *read* is, so a transport fault never costs the result it promised to preserve. The dispatch mirrors the row's backend, as a gate decision does: a row with a `turnId` submits another turn, a row without one forks the same detached worker `spawn` uses. The turn is always a prompt, including on a `solve` row -- the session holds the repository workspace already (#461) -- and it inherits the subagent's bundle and workload. The ledger row is replaced by a fresh `record` line rather than updated: `foldLines` keeps the later one, and an update line cannot carry an envelope. That is what makes a gate on the follow-up answerable, since `approve` re-sends the row's envelope and it has to hold the follow-up's text, not the first turn's. Tag and label carry over -- one subagent, one turn on. Refused while the subagent is `running` (wait with `get --wait`) or parked at a gate: a follow-up prompt is not an answer to a gate, and dispatching one would leave it pending for good. Tests: 14 new (12 on the command, 2 on the CLI surface). 189 green across the 7 suites this touches; `make typecheck` and `make check-links` clean. Refs #381 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: cwiklik <[email protected]>
Summary
Fixes #408. On the container tier, every session's turns ran in the one shared
/workspace, so one user's agent saw another'sgit clone, and two sessions cloning the same repo collided on the same path.The issue's worker-only proposal would not have fixed this. Every path the sandbox tools send is absolute under the harness's
podCwd(cd '/workspace' && …,cat '/workspace/x'; seeselect-sandbox.tsandk8s-sandbox/src/operations.ts). So changing the directoryBashRunnerstarts in changes nothing. The harness has to movepodCwdtoo, and it does so only for workers that say they support it:WorkspaceRunnerwrapsBashRunner.workspace_keyruns in<SH_WORKSPACE_ROOT>/<key>, created on first use.invalid-workspace-key: …on refusal.workspace-subdir.SH_WORKSPACE_IDLE, default30m, the same knob and default as the microVM worker).workspace-subdirgetspodCwd = <KAGENTI_SANDBOX_CWD>/<session id>. Pods, older workers and the microVM tier keeppodCwdunchanged; on the microVM tier the guest already mounts the session's workspace at/workspace.Not a security boundary. Every session runs in the same container as the same Unix user, so
cd ..still reaches the others. Isolation remains MI1 S5 owner binding.Deployment note:
KAGENTI_SANDBOX_CWD(harness) must equalSH_WORKSPACE_ROOT(worker). Both default to/workspace.Test plan
go test -race ./...inremote-worker. New tests check that:Dirunset and creates nothing;a/b,..,.hidden, a leading-and a 129-character key are all refused before anything runs;cmd.Dirdisabled, the separate-directory and sweep tests fail.pnpm --filter @moca/harness test: 583 passed. New cases check thatpodCwdmoves only when the record has the capability.make typecheck,make lint,go vet ./...git clonethe same repo.🤖 Generated with Claude Code