Repository navigation
子代理有两个工作目录:配置应读投影而非 header(实测 0/6 → 6/6)— Subagents carry two working directories: configuration should come from the workingDirectory projection, not header.cwd (measured 0/6 → 6/6) #10824
Trove-design
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
cwd启动的子代理,header 中的cwd复制自父会话,所请求的目录只写入workingDirectory投影。DSH 核心按投影加载指令文件、技能目录和工具,按 header 确定沙箱写入边界,但插件文档没有说明这条规则。dsh-workspace-scope0.5.3 按 header 解析.dsh-scope.json:6 个测试子代理中 0 个读到自己目录的作用域。作用域含rea(207 个 MCP 工具)时每次请求约 256k prompt tokens,空作用域约 12k。WorkingDirectoryService的 E2E:0.5.3 有 9/15 项失败,补丁后 15/15 通过;53 项规格测试通过,16 项定向变异全部被检出。mcp-client是否支持按服务器的工具白名单。Important
A subagent started with
cwdcarries two directories: its header keeps the parent'scwd, and theworkingDirectoryprojection holds the requested one. DSH core reads the projection for configuration and the header for the sandbox boundary, but plugins are not told this rule:dsh-workspace-scope0.5.3 read the header, and 0 of 6 subagents got their folder's scope (6 of 6 after switching to the projection). In this workspace the scope decides between ~256k and ~12k prompt tokens per request.🔍 Problem: one subagent, two working directories
@define9 asked in #703 for subagents that start fully in another directory, and @dotdance traced the root cause there (with #9188, #4873 and #7361): a subagent's session
cwdis copied from the parent. Onmaster@22ddee3(same lines in 0.2.1-rc.2) the subagent tool acceptscwd, but only the projection receives it:parentHeader.cwd(child-agent.ts L144).workingDirectory.set(child, create.cwd)during creation, before the first request (manager.ts L891-L894).The service documents the split: the header "continues to identify the original project", and "existing processes and sandbox grants keep their independent ownership" (README). Core readers follow it consistently:
Szenarien/AudiogetsSzenarien/AudioSzenarien/Audiodsh-workspace-scope0.5.3 by @Ri0n72Y (overview, save, skills, lock)In short: configuration follows the projection, permissions follow the header. The plugin applied the permission rule to configuration.
flowchart TB subgraph start["Subagent start"] tool["subagent tool<br/>cwd: Szenarien/Audio"] end subgraph state["Session state"] direction LR header["header.cwd<br/>workspace root"] proj["workingDirectory<br/>Szenarien/Audio"] end subgraph core["DSH core"] direction LR sandbox["sandbox<br/>write root"] config["AGENTS.md, skills,<br/>bash, fs"] end subgraph plugin["dsh-workspace-scope"] direction LR old["0.5.3<br/>reads header"] fixed["patched<br/>reads projection"] end tool -- "copied from parent" --> header tool -- "set before 1st request" --> proj header --> sandbox proj --> config header --> old proj --> fixed header -. "upper bound" .-> fixed sandbox ~~~ old config ~~~ fixed classDef ok fill:#d3f9d8,stroke:#2b8a3e,color:#0b3d17 classDef bad fill:#ffe3e3,stroke:#c92a2a,color:#5c0a0a classDef fix fill:#d0ebff,stroke:#1971c2,color:#0b2a4a classDef ref fill:#f1f3f5,stroke:#868e96,color:#212529 class config ok class old bad class fixed fix class tool,header,proj,sandbox ref style start fill:transparent,stroke:#868e96 style state fill:transparent,stroke:#868e96 style core fill:transparent,stroke:#868e96 style plugin fill:transparent,stroke:#868e96🟩 reads the projection for configuration · 🟥 reads the header for configuration (0 of 6) · 🟦 the patched plugin (6 of 6) · ⬜ session state and the permission boundary
The effect is silent. In my first run (session
63a0cb3e-…) the AudioAGENTS.mdloaded ("Instructions from: Szenarien/Audio/AGENTS.md"), while the tool set had nomcp__rea__*, consistent with the empty root whitelist. Instructions came from one folder, capabilities from another, and nothing warned.The skill catalog is
cwd-sensitive too: project skills come from the project root of thecwd(skill-filesystem), cached percwd(skill). 0.5.3 hid skills in the header's catalog while tool-skill shows the projection's, so a skill that exists only under the effectivecwdstays visible. I derived this from the code and pinned it with a spec; I did not observe it live.📊 Measured: the scope sets the size of every request
Six subagents (3 in
Szenarien/Audio, 3 inSzenarien/Allgemein) each ran onebashcommand in exactly three model calls; prompt tokens are theassistant/messageusage in the session logs.rea(207 tools)The other two runs of each kind: 767,060 and 767,643; 34,773 and 34,835.
The two scope files differ only in
reaand two skills, and the scenarioAGENTS.mdfiles differ by at most 136 bytes, so the gap of ~244k per request is thereacatalog. Most of it is served from the prompt cache (99.19% hit rate over 45 sessions since 2026-09-09). That lowers the price of each token, not the 22× ratio, and every call still spends 26% of the 1,000,000-token window on schemas this task never calls.Under 0.5.3 the error cuts both ways. With an empty root whitelist, Audio subagents lost
rea(my first run). With a root scope that allowsrea, every Allgemein subagent would carry the 207 schemas: by the figures above, about 767k instead of 35k tokens for the same three commands (projected from the table, not measured).🔧 Fix in the plugin (reference implementation)
The fix belongs in the plugin and is open upstream as Ri0n72Y/dsh-workspace-scope#33, a change to its TypeScript sources with specs. I verified the same rule live with a drop-in build for 0.5.3 (
0.5.4-effcwd.2). All four sites go through one resolver:eff = workingDirectory.get(session); without the service,header.cwd(the 0.5.3 behavior).eff; the nearest.dsh-scope.jsonwins.header.cwd, inclusive, never above.Workspace_Optimized2is not insideWorkspace_Optimized). Ifefflies outside the header subtree, read only<header.cwd>/.dsh-scope.json.configError) and logged once.Note
The walk-up never leaves the session's workspace: it starts at the projection and stops at
header.cwd, the boundary the sandbox uses. The header is canonicalized through thefsservice first, because the projection stores realpaths (working-directory) while the header keeps the spelling it was created with; a symlinked workspace path would otherwise reopen the bug.The per-Agent lock is unchanged: the configuration is read once, at the first request. Only the skill catalog view follows the current
cwd, as tool-skill does on every step. The plugin keeps the 0.5.3injectlist and looksworkingDirectoryup per call, so without the service it still starts and behaves like 0.5.3.The drop-in build also returns
lockedScopefromoverview(path,mode,skills,mcps,headerCwd,effectiveCwd,lockedAt,live): what the running Agent actually locked, independent of what the panel edits. It stays readable after a subagent ends (in memory, last 256 Agents), which is how I checked all six runs. This field is not part of #33.✅ Verification
mainWorkingDirectoryService0.2.1-rc.2dsh-fs-local0.2.1-rc.2 (walk-up, symlinks, save)Nine E2E checks fail on 0.5.3; all pass with the change. Six of the nine are behavior (configuration, MCP mask, skill view, and
save()from the subagent overwriting the root scope file); three check fields that 0.5.3 does not return. The live 0 of 6 comes from my first run (2× Audio, 1× Allgemein, 3×.scopetest; header againstworking-directory/changein the logs), the 6 of 6 from the re-run below.Six subagents, session by session
All six report
headerCwd= workspace root andeffectiveCwd= their folder.lockedScope.pathlockedAt(UTC)fb7a85ac-88c2-44f8-93e6-fb389bc6ca0cSzenarien/Audio/.dsh-scope.json808787c7-8e86-4852-b956-07fdbe81067bSzenarien/Audio/.dsh-scope.json96da5f98-3185-4400-a316-069eb538e44aSzenarien/Audio/.dsh-scope.json223d8700-f65e-47a3-966b-156fb0b3226cSzenarien/Allgemein/.dsh-scope.jsonca103eba-63ae-4018-917e-a8479b4fc945Szenarien/Allgemein/.dsh-scope.json841f73ce-8253-4ce0-821d-c4acf6ca8735Szenarien/Allgemein/.dsh-scope.json🧭 Scope
<header.cwd>/.dsh-scope.json, on purpose: moving the boundary is a core decision (question 2).header.cwd, possibly the root file.reacatalog itself is untouched (question 3).❓ Questions for maintainers
workingDirectory.get(session), boundaries fromheader.cwd" the intended rule for plugins? If so, one sentence in the plugin docs, or a helper on the session, would prevent this class of bug.header.cwd?mcp-clientregisters every tool a server lists (tools.ts); `dsh-mcp-client`: support per-server tool filtering at registration (`allowedTools`) #9385 by @scs001 proposes a per-serverallowedToolsfor exactly this. A scenario that needs 4 of the 207reatools would then carry about 5k tokens of schemas instead of ~244k (estimated from the average schema size). Is that the direction you want?📦 Reproduce
Without any plugin, compare a subagent's header with its projection in the session log:
Output for a subagent started in
Szenarien/Audioon 0.2.1-rc.2:{"type":"session","cwd":".../Workspace_Optimized"} {"type":"working-directory/change","cwd":".../Workspace_Optimized/Szenarien/Audio"}With the patched plugin, the lock of any Agent is visible on its HTTP route:
Core of the resolver (condensed; error handling omitted)
Review of the plugin change is welcome in #33; I can share the drop-in build for a controlled repro.
All reactions