fix(harness/examples): Fix the reading of historical sessions of the data agent in examples - #2946
Open
xy-ygz wants to merge 2 commits into
Open
fix(harness/examples): Fix the reading of historical sessions of the data agent in examples#2946xy-ygz wants to merge 2 commits into
xy-ygz wants to merge 2 commits into
Conversation
xy-ygz
force-pushed
the
fix/fix_historical_sessions_reading
branch
from
September 2, 2026 14:06
4888429 to
6f0f0ee
Compare
…data agent in examples
xy-ygz
force-pushed
the
fix/fix_historical_sessions_reading
branch
from
September 2, 2026 14:29
6f0f0ee to
86ddf8e
Compare
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AgentScope-Java Version
2.0.3-SNAPSHOT
Description
Background


After the data-agent is launched locally, clicking on the history session fails to display any information and remains blank. An error message "No active sandbox" is also displayed. Please refer to the attached image.:
Fixes #1626
Root causes:
There are issues throughout the entire read-write link. Looking at the current source code design, when writing messages, they are first written to the local workspace on the host machine, and then asynchronously segmented and written to the corresponding workspace in the sandbox. When reading, it starts by reading the sandbox, and if the sandbox cannot be read, it then reads the local fallback. The idea is fine, but there are flaws in the implementation:
Also, there is an inconsistency in AgentId used for sandbox operations:
HarnessAgent.getAgentId();"data agent"is used instead.Even if data is asynchronously written into the sandbox successfully, reading will return empty results due to this mismatched sandbox AgentId.
Repair Ideas
1.When writing the sandbox asynchronously, you can directly use the existing (userId, agentId) → sandbox registration table (WorkspaceManagerFactory) to get the corresponding sandbox for the session, without relying on the sandbox dependency bound by the Agent.call phase. Avoid the problem of No active sandbox
2.Supplement the
.jsonl/.log.jsonlsession content during asynchronous segmented writes to the sandbox environment, aligning with local file paths to prevent loss of sandbox session data.3.Make the agentId used by Gateway when mounting the sandbox consistent with
gatewayAgentIdused on the directory and UI side.Changes
Aligned with the repair approach above:
History read without call-bound sandbox
SessionControllerno longer uses the call-scoped sandbox FS forGET .../sessions/{key}. It borrows the live sandbox from the existing(userId, agentId)registry viaWorkspaceManagerFactory, so history HTTP never depends on an in-flightAgent.callbinding and no longer throwsNo active sandboxbefore host fallback. If the sandbox is empty/unavailable, it falls back to the namespaced host workspace path.Async write: keep segments, also mirror canonical session files
SessionTree.flushstill appendsTranscriptStoresegments, and also async-mirrors canonical.jsonl/.log.jsonl(same relative paths as local).PinnedSandboxFilesystem(+ObjectStoreTranscriptStore#withFilesystem) pins the sandbox at schedule time so the async upload can finish after call unbind. Window before the mirror lands is covered by local fallback.Same sandbox key for write and UI/history read
HarnessGatewayborrows the sandbox with catalog/UIgatewayAgentId(e.g.data-agent), not the internal harness UUID, so chat write and history/workspace read hit the same registry entry.After fixing the above issue, I discovered another bug related to session deletion: new‑session entries could not be added after deleting historical sessions, and clicking to create a new session had no response.When deleting a session, entries are only removed from
SessionAgentManager, while the in‑memory mappingcontextKeyToSessionKey(gateKey → sessionKey) is not cleared.This change also addresses this problem.
isSessionFreshnow treats deleted sessions as non‑fresh. Consequently, a new MAIN session will be re‑registered once the user clears history records, so the inbox can correctly display subsequent chat messages again.How to test
After fix:

Now the session‑history sidebar can display correctly after deleting old sessions and creating new ones.
How to test
mvn -pl agentscope-harness,agentscope-examples/agents/agentscope-dataagent -am test(or at least-Dtest=SessionTreeMirrorTest).No active sandbox).Checklist
Please check the following items before code is ready to be reviewed.
mvn spotless:applymvn test) — verified:mvn -pl agentscope-harness,agentscope-examples/agents/agentscope-dataagent -am test(BUILD SUCCESS)