Skip to content

[Bug]:现在的记忆是异步写入,会有问题,写入的时候沙箱已经关闭,就会警告memory flush failed: no active sandbox, sandbox filesystem used outside of call context #3110

Closed

Description

@BEN5890

AgentScope-Java is an open-source project. To involve a broader community, we recommend asking your questions in English.

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. You code
  2. How to execute
  3. See error

Expected behavior
A clear and concise description of what you expected to happen.

Error messages
Detailed error messages.

Environment (please complete the following information):

  • AgentScope-Java Version: [e.g. 1.0.12, check your pom.xml dependency version or run mvn dependency:tree | grep agentscope-parent:pom(only mac/linux)]
  • Java Version: [e.g. 17]
  • OS: [e.g. macos, windows]

Additional context
Add any other context about the problem here.

Activity

  1. added
    bug
    on Sep 12, 2026
  2. oss-maintainer commented on Sep 12, 2026

    @oss-maintainer
    Collaborator

    Issue Evaluation

    Category: bug | Status: Confirmed

    Verified against current main (c5db8f7). The report matches the code: the memory flush is scheduled as a fire-and-forget background task, while the sandbox lease is released as soon as the agent event stream terminates — the async write can therefore run after the sandbox is gone and fail with No active sandbox — sandbox filesystem used outside of a call context.

    Root Cause: MemoryFlushMiddleware hooks the flush in doOnComplete and subscribes the actual I/O on Schedulers.boundedElastic() (agentscope-harness/.../middleware/MemoryFlushMiddleware.java:159,203-211). The sandbox is released via Flux.using cleanup in HarnessAgent (HarnessAgent.java:994-1007), and SandboxLifecycleMiddleware.releaseForCall clears the SandboxAcquireResult context binding (SandboxLifecycleMiddleware.java:151-177). The later write through MemoryFlushManager.writeMemoryFiles → WorkspaceManager.appendUtf8WorkspaceRelative → SandboxBackedFilesystem.requireSandbox then throws (SandboxBackedFilesystem.java:239-255).

    Impact: In sandbox-backed deployments, per-call memory extraction/consolidation can be silently lost after the call completes (memory ledgers, session offloads), with Memory flush failed warnings in logs.

    Severity: high

    Possible directions: (1) block on in-flight flush tasks before releasing the sandbox (e.g. drain the flush future inside Flux.using cleanup), or (2) copy the needed memory payload into a sandbox-independent buffer before flush so the persisted write no longer depends on the closed sandbox.

    A maintainer replying /approve here will trigger generation of an automated fix proposal (spec + PR).


    Automated evaluation by github-manager-bot

  3. added
    area/harness
    on Sep 12, 2026
  4. oss-maintainer commented on Sep 12, 2026

    @oss-maintainer
    Collaborator

    Adjacent-PR advisory (no change to the evaluation above)

    Draft PR #3106 (fix(harness): avoid blocking stream completion on transcript persistence, author ningmao-hlyz, opened 2026-09-11) applies option (1) from the evaluation — keep sandbox-backed work in the stream until the async write finishes — but to transcript persistence, and it fixes #3059 rather than this issue. It touches MemoryBackgroundTasks, SessionTranscriptWriter and TranscriptMiddleware; no file overlap with the memory-flush path cited in the evaluation (MemoryFlushMiddleware, MemoryFlushManager, SandboxLifecycleMiddleware, HarnessAgent).

    Consequence: the memory-flush race reported here stays unfixed even if #3106 merges. If #3106 lands first, a fix for this issue should reuse its MemoryBackgroundTasks quiescence pattern instead of adding a second drain mechanism.

    This is supplementary context only — the evaluation and its proposed directions are unchanged.


    Automated evaluation by github-manager-bot

  5. oss-maintainer commented on Sep 12, 2026

    @oss-maintainer
    Collaborator

    Adjacent-PR collision advisory (no change to the evaluation above)

    A duplicate-fix scan of all open PRs (self-authored PRs excluded, 104 open) found active work on the same sandbox-async-write-after-release race reported here:

    Consequence for the /approve offer above: a generated fix would collide in SandboxLifecycleMiddleware / SandboxBackedFilesystem / HarnessAgent with #3094 and #2833, which is exactly the duplicate-fix collision our supersession notices close windows elsewhere to avoid. We are not closing this window — none of the four PRs fixes the reported failure: #3094/#3039 drain only session-mirror tasks, #3106 only transcript writes, and #2833 makes the flush asynchronous without draining it before lease release — but we will not file a competing PR unless the community tells us which seam to build on.

    Preferred decision for anyone replying: (a) extend #3094's SandboxMirrorReleaseCoordinator to cover memory-flush tasks, or (b) take direction (2) from the evaluation above — copy the payload into a sandbox-independent buffer before flush — which is collision-free against all four PRs. Option (b) is the only one that can land without a merge conflict against #3094/#2833.

    This is supplementary context only — the evaluation and its proposed directions are unchanged, and the reply window stays open.


    Automated evaluation by github-manager-bot

  6. BEN5890 commented on Sep 12, 2026

    @BEN5890
    Author

    I support Option (b) — copying the memory payload into a sandbox-independent buffer before flush. This avoids conflicts with #3094 and #2833 while fixing the root cause.

  7. oss-maintainer commented on Sep 12, 2026

    @oss-maintainer
    Collaborator

    Reply-window advisory — option preference recorded, no change to the evaluation above

    Thanks @BEN5890 — noted that option (2)/(b) (snapshot the memory payload into a sandbox-independent buffer before the flush, instead of draining in-flight tasks before the lease release) is the preferred shape. That is the first reply on this window, and it is recorded as reporter preference, not as an approval to generate code: the offer in the evaluation comment above asks a maintainer to approve explicitly, so this window stays open unchanged.

    Two collision facts refreshed against current main (c5db8f72), both of which bear on that choice:

    Summary: the seam question is effectively answered (option b), #3094 does not cover this report, and the only remaining blocker to an automated proposal is an explicit maintainer approval on this thread. This is supplementary context only — the evaluation and its directions are unchanged, and the reply window stays open until 2026-09-15T02:05Z.


    Automated evaluation by github-manager-bot

  8. birdie7761 commented on Sep 12, 2026

    @birdie7761
    Contributor

    I've opened a fix following option (b) — the direction recorded above as the preferred shape: memory-file IO is routed to a sandbox-independent host-side store whenever the filesystem serving those paths is the per-call sandbox proxy, mirroring the treatment task records received in #2803.

    Branch: birdie7761/agentscope-java fix/3110-memory-flush-sandbox-independent — PR incoming right after this comment.

    Design decisions worth flagging up front:

    1. Whole-family routing: flush, consolidation, and the memory tools (memory_save / memory_get / memory_search) all go through one memory-scoped IO surface, so listing, reads and writes can never split between the sandbox copy and the host store.
    2. User isolation is preserved: the host-side location is the context's runtime-data namespace (resolveRuntimeDataPath) — the same namespaced layout RemoteFilesystem applies to memory paths in distributed deployments. Memory filenames carry no per-user keying, so the directory namespace is their only isolation mechanism.
    3. The consolidation watermark read/write pair is symmetric on the same store (an asymmetric pair would have silently re-merged all historical ledgers on every run).
    4. No file overlap with fix(harness): defer self-managed sandbox shutdown until session mirro… #3094 (sandbox-mirror path) — and fix(harness): avoid blocking stream completion on transcript persistence #3106's quiescence pattern is untouched; this fix composes with both.
  9. oss-maintainer commented on Sep 15, 2026

    @oss-maintainer
    Collaborator

    Status: 72 h feedback window expired — no automated PR will be generated, this proposal window here is closed

    The evaluation above went 72 hours without an /approve, /revise or /reject, so per our workflow the window is closed and no competing PR will be generated. No action is needed from anyone.

    That turned out to be the easy case, because the direction recorded in this thread was picked up by the community:

    As of this check #3113 is MERGEABLE with reviewDecision=APPROVED and a green check rollup (build ubuntu-latest / build windows-latest, Check License, Check Module Sync, license/cla) at head df3e8e1e5. #3113 stays the active path for this issue and needs a maintainer to merge it, not another implementation.

    Thanks @BEN5890 for stating the option preference and @birdie7761 for building it. If maintainers would still like an independent second proposal here, say so on this issue and we will re-evaluate.

    Automated by github-manager-bot

  10. added a commit that references this issue on Oct 29, 2026
    269ccd1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/harnessbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions