Skip to content

fix(agent): scope runtime agent dir by workspace_id (orphaned dirs on workspace delete)#205

Merged
Fullstop000 merged 2 commits into
mainfrom
fix/agent-workspace-dir
May 23, 2026
Merged

fix(agent): scope runtime agent dir by workspace_id (orphaned dirs on workspace delete)#205
Fullstop000 merged 2 commits into
mainfrom
fix/agent-workspace-dir

Conversation

@Fullstop000
Copy link
Copy Markdown
Owner

Bug (found by dogfooding)

Agent runtime working directories are created at the wrong path, so deleting a workspace orphans them on disk and the agent-workspace file API points at the wrong directory.

  • start_agent (manager.rs) built the dir from the runtime Agent.workspace_id, but that field is empty — the bridge.target frame doesn't carry workspace_id and target_to_agent (reconcile.rs) fills String::new(). So the inline data_dir.join(workspace_id).join("{name}-{id}") collapsed to agents/{name}-{id} (no workspace segment).
  • Every platform-side path uses the real DB workspace_id via AgentWorkspace::path_for = agents/{workspace_id}/{name}-{id}: workspace delete (agents.rs:565), the agent-workspace file API (agent_workspace.rs:88,112).
  • Result: create writes one path, delete/file-API expect another → orphaned runtime dirs accumulate on workspace delete, and the file API can't see the agent's real files.

Pre-existing since the workspace-isolation work (#202); unit tests + review missed it because nothing exercised the live bridge-start path and checked the on-disk location. Surfaced while dogfooding the autonomous task loop.

Fix

start_agent now resolves workspace_id from the store (agent_workspace_id) and builds the dir via AgentWorkspace::path_for — the same single source of truth the delete and file-API paths use. Creation and the platform-side paths now agree on agents/{workspace_id}/{name}-{id}.

Localized: manager.rs:233 was the only runtime reader of Agent.workspace_id, so no bridge.target protocol change is needed.

Test

agent_workspace_dir_is_scoped_by_store_workspace_id — asserts the computed dir equals AgentWorkspace::path_for(db_workspace_id, name, id) and includes the workspace_id segment. clippy -D warnings clean; 550 lib tests pass.

🤖 Generated with Claude Code

Fullstop000 and others added 2 commits May 23, 2026 11:17
The runtime `Agent` arrives over the bridge with an empty `workspace_id`
(the `bridge.target` frame omits it; `target_to_agent` fills
`String::new()`), so `start_agent`'s inline path join produced
`agents/{name}-{id}` — dropping the `{workspace_id}` segment. But
workspace delete (`agents.rs`) and the agent-workspace file API
(`agent_workspace.rs`) build `agents/{workspace_id}/{name}-{id}` via
`AgentWorkspace` using the DB `workspace_id`. The mismatch orphaned agent
runtime directories on workspace delete and pointed the file API at the
wrong directory.

Resolve `workspace_id` from the store in `start_agent` and build the path
via `AgentWorkspace::path_for`, so creation matches the delete/file-API
paths. Found by dogfooding the autonomous task loop.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@Fullstop000 Fullstop000 merged commit 1da6962 into main May 23, 2026
3 checks passed
@Fullstop000 Fullstop000 deleted the fix/agent-workspace-dir branch May 23, 2026 03:22
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.

1 participant