fix(agent): scope runtime agent dir by workspace_id (orphaned dirs on workspace delete)#205
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 runtimeAgent.workspace_id, but that field is empty — thebridge.targetframe doesn't carryworkspace_idandtarget_to_agent(reconcile.rs) fillsString::new(). So the inlinedata_dir.join(workspace_id).join("{name}-{id}")collapsed toagents/{name}-{id}(no workspace segment).workspace_idviaAgentWorkspace::path_for=agents/{workspace_id}/{name}-{id}: workspace delete (agents.rs:565), the agent-workspace file API (agent_workspace.rs:88,112).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_agentnow resolvesworkspace_idfrom the store (agent_workspace_id) and builds the dir viaAgentWorkspace::path_for— the same single source of truth the delete and file-API paths use. Creation and the platform-side paths now agree onagents/{workspace_id}/{name}-{id}.Localized:
manager.rs:233was the only runtime reader ofAgent.workspace_id, so nobridge.targetprotocol change is needed.Test
agent_workspace_dir_is_scoped_by_store_workspace_id— asserts the computed dir equalsAgentWorkspace::path_for(db_workspace_id, name, id)and includes theworkspace_idsegment. clippy-D warningsclean; 550 lib tests pass.🤖 Generated with Claude Code