Skip to content

fix(harness): give an isolated subagent the parent's filesystem policy - #4065

Open
wahllllll wants to merge 1 commit into
agentscope-ai:mainfrom
wahllllll:fix/issue-4023-subagent-spec-copy
Open

wahllllll wants to merge 1 commit into
agentscope-ai:mainfrom
wahllllll:fix/issue-4023-subagent-spec-copy

Conversation

@wahllllll

Copy link
Copy Markdown
Contributor

Background

An ISOLATED declarative subagent is supposed to run under its parent's filesystem policy and only get its own workspace root. It did not.

HarnessAgentBuilderSupport.cloneLocalSpecForSubagent rebuilt the spec from three fields:

LocalFilesystemSpec spec = new LocalFilesystemSpec();
if (parent.getProject() != null) spec.project(parent.getProject());
if (parent.getMode() != null) spec.mode(parent.getMode());
spec.additionalRoots(parent.getAdditionalRoots());

Everything else was dropped. The visible one is isolationScope: the clone carries null, and HarnessAgent.Builder.build() falls back to IsolationScope.USER, so a parent configured with IsolationScope.AGENT got subagent paths prefixed with the user id — a directory layout the parent never configured. The command timeout, the output cap, the environment map, env-inheritance, projectWritable, sharedLocalWorkspace and the concrete spec type were lost the same way.

A second place assumed the same thing: the context workspace in workspaceFor hardcoded

NamespaceFactory ctxNs = rc -> (uid == null || uid.isBlank()) ? List.of() : List.of(uid);

while the main workspace already used fsIsolationScope.toNamespaceFactory(). So even with the clone fixed, the two workspaces of one agent would be laid out under different rules.

Change

  • LocalFilesystemSpec.copy() — copies every policy field and preserves the concrete type through a protected newInstance(), so a subclass that carries its own state can extend the copy instead of silently degrading to the base type. Five read accessors for fields that had none (getExecuteTimeoutSeconds, getMaxOutputBytes, getEnv, isInheritEnv, isSharedLocalWorkspace) so the copy is assertable and the subagent path does not need to guess.
  • cloneLocalSpecForSubagent delegates to copy(). Copying fields by name at the call site is how a field added to the spec ends up dropped for every subagent; one call is one place to keep current.
  • The context workspace namespace comes from the same nsFactory the main workspace uses.

The subagent still gets its own workspace root, so its memory and sessions stay isolated — that difference is what the workspace argument is for.

Tests

SubagentSpecInheritanceTest, two cases:

  • a parent configured with isolationScope(AGENT), a 7 s timeout, a 1234-byte output cap, an env entry, inheritEnv, projectWritable, sharedLocalWorkspace and an extra root keeps all of it after the clone;
  • copy() on a subclass returns the subclass, so an integrating application's spec still overrides.

Red without the fix, with the previous three-field body restored (expected: <AGENT> but was: <null>):

Tests run: 2, Failures: 1, Errors: 0, Skipped: 0
  SubagentSpecInheritanceTest.subagentSpecKeepsParentPolicy:62
  falling back to USER prefixes every subagent path with the user id
  ==> expected: <AGENT> but was: <null>

Green with it, and the whole harness module:

Tests run: 2, Failures: 0, Errors: 0, Skipped: 0   (SubagentSpecInheritanceTest)
Tests run: 1621, Failures: 0, Errors: 0, Skipped: 37
BUILD SUCCESS

No configuration or migration changes; copy() and the accessors are additive.

Closes #4023

The declarative subagent path built its local filesystem spec from three
fields — project, mode and additionalRoots — and dropped everything else,
including the isolation scope. A parent configured with IsolationScope.AGENT
therefore handed the subagent a spec with no scope at all, which falls back to
USER: every subagent path got prefixed with the user id, into a layout the
parent had never configured. The command timeout, the output cap, the
environment, the env-inheritance, project-writable, shared-root and path-mode
flags were lost in the same way, and an overriding spec subclass degraded to
the base type.

Add LocalFilesystemSpec.copy(), which carries every field and preserves the
concrete type through newInstance() so a subclass that carries its own state
can extend it, and delegate the subagent clone to it. Copying fields by name at
the call site is how a field added to the spec ends up silently dropped for
every subagent.

Build the context workspace namespace from the configured isolation scope as
well, instead of assuming a per-user prefix; the main workspace already did.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 重要不紧急

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[harness] cloneLocalSpecForSubagent 丢失 isolationScope 与 spec 子类,声明式 ISOLATED 子 Agent 回落到 USER 作用域

2 participants