agentscope-java icon indicating copy to clipboard operation
agentscope-java copied to clipboard

[Bug]: WorkspaceTaskRepository orphan sweeper and heartbeat fail under sandbox filesystem

Open chcodex opened this issue 3 months ago • 0 comments

Describe the bug

When a HarnessAgent is configured with a sandbox-backed filesystem (e.g. SandboxBackedFilesystem via the sandbox lifecycle middleware), the background maintenance threads of WorkspaceTaskRepository (ws-task-maint-*) cannot persist or read task records. The sandbox instance is injected into the filesystem only during an agent call (SandboxLifecycleMiddleware.acquireForCall → setSandbox, cleared in releaseForCall), but the heartbeat and orphan sweeper run on a standalone daemon thread with sandbox == null. As a result:

  • The orphan sweeper throws SandboxException.SandboxConfigurationException: No active sandbox — sandbox filesystem used outside of a call context every sweep cycle and only logs a warning, so orphaned tasks are never marked FAILED.
  • The heartbeat silently fails the same way (caught at debug level), so lastUpdatedAt is never refreshed and RUNNING tasks never progress — the whole task-liveness mechanism is broken in sandbox mode.

To Reproduce

  1. Configure HarnessAgent/ReActAgent with a sandbox-backed workspace (sandbox mode + SandboxBackedFilesystem).
  2. Submit an async background subagent task (timeout_seconds=0) via AgentSpawnTool.
  3. Observe logs every ~5 min:
[ws-task-maint-176] WARN i.a.h.a.s.t.WorkspaceTaskRepository: - Orphan sweeper encountered an error: No active sandbox — sandbox filesystem used outside of a call context

Expected behavior

Task records are cross-call orchestration metadata and must not depend on a per-call sandbox instance. The sweeper should detect and mark orphaned tasks as FAILED, and the heartbeat should refresh lastUpdatedAt even when no agent call is in progress.

Root cause (code pointers)

  • io.agentscope.harness.agent.filesystem.sandbox.SandboxBackedFilesystem#requireSandbox (line ~194) throws when sandbox == null.
  • WorkspaceTaskRepository#sweepOrphanedTasks calls WorkspaceManager#listAllTaskRecords → filesystem.glob(...) on the maintenance thread.
  • WorkspaceManager task-record paths (readTaskMap/persistTaskMap/listAllTaskRecords) route through the filesystem layer (readWithOverride/writeUtf8WorkspaceRelative), which requires a live sandbox.
  • SandboxLifecycleMiddleware sets/clears the sandbox only around ReActAgent.beforeAgentExecution/afterAgentExecution.

Environment (please complete the following information):

  • AgentScope-Java Version: latest (2.0.3-SNAPSHOT)
  • Java Version: TBD
  • OS: Linux

Additional context

The ControlPlaneTaskRepository (aistio) is not affected because it persists via the control-plane HTTP API and has no client-side sweeper.

chcodex avatar Aug 17 '26 05:08 chcodex