Skip to content

fix(harness): expose session workspace in prompt - #3020

Merged
jujn merged 8 commits into
agentscope-ai:mainfrom
ningmao-hlyz:fix/2941-session-workspace-context
Sep 17, 2026
Merged

jujn merged 8 commits into
agentscope-ai:mainfrom
ningmao-hlyz:fix/2941-session-workspace-context

Conversation

@ningmao-hlyz

@ningmao-hlyz ningmao-hlyz commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • derive the effective per-call workspace path from the existing namespace factory for local overlay filesystems
  • advertise that path consistently in both the AgentStateStore context and Workspace prompt sections
  • keep the base workspace for path-policy roots and leave sandbox, remote-filesystem, and shell behavior unchanged

Problem

With session isolation enabled, relative file-tool paths resolve under the session namespace (for example, /workspace/session-1), while the prompt currently advertises the base workspace (/workspace). Models can therefore run skill scripts against the wrong path, write artifacts outside the session namespace, and then fail to find those artifacts through file tools.

This change only corrects the path shown to the model. It reuses WorkspaceManager.resolveRuntimeDataPath so the advertised path follows the same namespace factory already used by runtime data.

Testing

  • mvn -pl agentscope-harness spotless:check
  • mvn -pl agentscope-harness -Dtest="WorkspaceContextMiddlewarePathBoundsTest,WorkspaceContextMiddlewareMemoryPromptTest,WorkspaceContextMiddlewareSandboxPromptTest,LocalFilesystemModeTest,LocalFilesystemWithShellTest" test (38 tests passed)

Fixes #2941

@CLAassistant

CLAassistant commented Sep 7, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@codecov

codecov Bot commented Sep 7, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.17949% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...rness/agent/workspace/WorkspacePathNormalizer.java 76.19% 2 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

@oss-maintainer

Copy link
Copy Markdown
Collaborator

⚠️ Merge conflict detected

This PR currently conflicts with the main branch and cannot be merged. Please rebase (or merge main) and resolve the conflicts:

git fetch origin
git checkout fix/2941-session-workspace-context
git rebase origin/main
# resolve conflicts, then:
git push --force-with-lease

This is a one-time reminder. Feel free to @mention me for a re-review after the conflicts are resolved.


Automated notification by github-manager-bot

@ningmao-hlyz

Copy link
Copy Markdown
Contributor Author

⚠️ 检测到合并冲突

该比例原则目前与该分支存在冲突,无法合并。请重新基底(或合并)并解决冲突:main``main

git fetch origin
git checkout fix/2941-session-workspace-context
git rebase origin/main
# resolve conflicts, then:
git push --force-with-lease

这是一次性提醒。冲突解决后,欢迎随时@mention我重新审核。

由 github-manager-bot 自动通知

@oss-maintainer

@oss-maintainer oss-maintainer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Re-review after the merge conflict was resolved (thanks for the quick rebase, and for the @mention). Conflicts are gone (mergeable: MERGEABLE), CLA is signed, and all checks pass on the current head — including build (windows-latest), which matters for a path-normalisation change.

The fix is the right shape: rather than patching the prompt string in isolation, it derives the advertised root from the same NamespaceFactory the filesystem already applies at operation time, and threads the operation's RuntimeContext through norm(...) so absolute and relative paths converge on one file. Reusing resolveRuntimeDataPath keeps a single source of truth, and the end-to-end sessionIsolation_absoluteAndRelativeWorkspacePathsResolveToSameFile test is the right way to pin that contract — asserting the negative (session-1/session-1/... must not exist) is especially good.

Verdict: no blocking issues; left as COMMENT so the three questions below can be answered or explicitly deferred. Two are about how safely this new dual-mode normaliser resists future misuse, one is a scope question about an adjacent prompt section that appears to have the same bug class as #2941.

Findings

  • [Warning] WorkspacePathNormalizer.java:100 — the 1-arg normalize(String) overload now silently resolves the namespace from an empty context, which reproduces the double-nesting bug for any caller that does not pass a RuntimeContext.
  • [Warning] WorkspacePathNormalizer.java:123 — namespace segments are treated as trusted path components; worth pinning the contract with id sanitisation (#2952) via a hostile-id test.
  • [Info] WorkspaceContextMiddleware.java:219 — buildKnowledgeBlock still receives the base workspace, so Knowledge files: stays relative to the un-namespaced root: same bug class as #2941, or intentional?
  • [Info] WorkspaceContextMiddleware.java:243 — two adjacent Path params distinguished only by name; a small holder type would prevent future mix-ups.
  • [Info] WorkspacePathNormalizer.java:118 — multi-segment namespaces and the empty-namespace overlay case are untested.

Suggestions

  • For the overload: prefer making the safe path the only path — either @Deprecated the 1-arg method with a note, or have it throw (or at least log.warn) when namespaceFactory != null. A compile-time/deprecation warning is much cheaper than a misplaced artifact at runtime.
  • For the knowledge block: if base-scoped is deliberate, a one-line comment saying so is enough; otherwise it likely wants effectiveWorkspace too.
  • Consider a test asserting the rendered prompt is unchanged when isolation is disabled, so the refactor of buildWorkspaceParagraph is provably behaviour-preserving for the common single-tenant configuration.

Automated review by github-manager-bot

@oss-maintainer oss-maintainer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Re-review after 443c3502 (the only author commit since my last review — the other new commits are upstream resync merges). Thanks for the follow-up: conflict resolution, @Deprecated on the unscoped overload, and the mention ping.

What I verified this round:

  • Scope of the new commit: git diff 1f5b9b7f..443c3502 touches only WorkspacePathNormalizer javadoc + @Deprecated. No behaviour change, so the previously reviewed logic (single source of truth via resolveRuntimeDataPath, RuntimeContext threaded through norm(...)) still stands.
  • Migration is complete in main: FilesystemTool.norm and ArtifactDeliveryTool.norm are the only production call sites and both pass the RuntimeContext, so the deprecated overload has no in-repo users. That is what makes the finding below a hardening note rather than a defect.
  • Gate correctness: the namespaced strip is only wired in for the OverlayFilesystem + LocalFilesystemWithShell branch (HarnessAgent.java:2692), and the new prompt test asserts both the positive (session-1 advertised) and the negative (Additional roots does not absorb the workspace) — good.
  • CI / CLA / conflicts: check, check windows build, check codeql, check license/cla green on head 443c3502; mergeable: MERGEABLE, mergeStateStatus: BLOCKED (blocked on review/merge settings, not on conflicts).

Verdict: no new blocking issues; nothing here changes my previous assessment. Not approving because the five threads from my previous review are still open and unresolved — I have not restated them; the three notes below are the new ones only, all non-blocking. If you consider the open questions addressed or deferred, resolve the threads (or reply "deferred: …") and @mention me for an approval pass.


Automated review by github-manager-bot

@ningmao-hlyz

Copy link
Copy Markdown
Contributor Author

@oss-maintainer

@oss-maintainer oss-maintainer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Re-review on head 11d3a165 in response to the @mention. The only new commits since my last review (443c3502) are upstream main resync merges — no further changes to the PR's own code, and the merge resolved the previous conflict cleanly.

Verified this round:

  • All 8 review threads from previous rounds are resolved.
  • The namespaced-strip path in WorkspacePathNormalizer.normalize(path, rc) is still correct after the resync: namespaced prefix checked before the unscoped prefix, RuntimeContext threaded through FilesystemTool/ArtifactDeliveryTool, and the deprecated single-arg overload delegates with an empty context only.
  • WorkspaceContextMiddleware advertises the effective (session-scoped) workspace consistently in both the session-context section and the workspace paragraph; knowledgeBlock intentionally keeps the unscoped root.
  • Prompt-bound test (localOverlay_sessionIsolationAdvertisesEffectiveWorkspace) and round-trip test (sessionIsolation_absoluteAndRelativeWorkspacePathsResolveToSameFile) cover both the positive and negative assertions.
  • CI: 6/6 checks passing on 11d3a165; CLA signed; mergeable: MERGEABLE.

LGTM — approving.

Suggestions

  • [non-blocking] If a path carries a different session's namespace segment (e.g. /workspace/session-2/x.txt under a session-1 context), the unscoped fallback yields session-2/x.txt, which the filesystem then resolves under the active namespace. Current callers can't hit this via the prompt, but a defensive note in the javadoc would make the contract explicit.

Automated review by github-manager-bot

@xiaoyuuuuuupeng xiaoyuuuuuupeng left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.本地复测过了

@ningmao-hlyz

Copy link
Copy Markdown
Contributor Author

@jujn 打扰了,可以看看这个pr嘛,目前处于approve状态

@jujn

jujn commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

Assign to @xiaoyuuuuuupeng (Review)

@jujn
jujn merged commit be7211d into agentscope-ai:main Sep 17, 2026
5 checks passed
Nerv4rmore added a commit to Nerv4rmore/agentscope-java that referenced this pull request Sep 24, 2026
Conflict resolutions:
- ReActAgent.maybePatchPendingToolCalls: take upstream's shared
  MessageUtils.lastAssistantMessage(state.contextMutable()); fork's
  patchPendingToolCalls extraction was behaviour-equivalent and its
  findLastAssistantMsg() helper is deleted upstream.
- AgentRunSandbox.shutdown: keep fork side. Upstream agentscope-ai#2302 (keep MCP
  channel open for non-owned sandboxes) is already covered — the fork
  replaced the MCP channel with the HTTP data plane and shutdown() is a
  deliberate no-op, with the isSandboxOwned() guard in destroyInstance().
- WorkspaceContextMiddleware.buildWorkspaceParagraph: combine both —
  upstream agentscope-ai#3020 effectiveWorkspace plus fork's RuntimeContext for the
  sandbox working directory.
- Semantic fix: fork-only ToolRetryLater call site updated to the
  two-arg notifyPostActingHook(entry, false) introduced by agentscope-ai#2891.
- AgentRunSandboxShutdownTest (added by agentscope-ai#2302) rewritten against the
  HTTP data plane / destroyInstance semantics.
- Revision follows upstream at 2.0.4-SNAPSHOT.
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.

[Feature]: 无沙箱环境运行时,运行skill脚本技能的产物读取不到

5 participants