Repository navigation
Description
环境
| agentscope-harness | v2.0.2-95-gb4361103(当前 main) |
| store | agentscope-extensions-mysql(JdbcStore → MySQL 8.0) |
| filesystem | RemoteFilesystemSpec with IsolationScope.USER |
| 场景 | 非 sandbox,CompositeFilesystem + 远程 store |
问题
在 v2.0.2 中,session JSONL 会走 MemoryFlushMiddleware → offloadMessages → SessionTree.scheduleMirror(),最终通过 RemoteFilesystem.uploadFiles() 写入 MySQL 的 agentscope_store 表。
当前 main 分支引入了 TranscriptStore 体系,默认使用 ObjectStoreTranscriptStore:
// HarnessAgent.java ~L2410
if (effectiveTranscriptStore == null) {
if (wsManager.getFilesystem() != null) {
effectiveTranscriptStore = new ObjectStoreTranscriptStore(wsManager.getFilesystem());
} else {
effectiveTranscriptStore = new FilesystemTranscriptStore(...);
}
}ObjectStoreTranscriptStore.appendSegment() 生成的 key 为:
default/{agentId}/{sessionId}/events/{seqStart}-{seqEnd}-{writerId}.jsonl
而 RemoteFilesystemSpec 注册的路由是:
routes.put("agents/" + effectiveAgentId + "/sessions/", overlayRoute(...));default/{agentId}/{sessionId}/... 与 agents/{agentId}/sessions/... 不匹配,因此 CompositeFilesystem.routeForPath() 会 fallback 到 defaultBackend(LocalFilesystem),session segment 只写本地 workspace,不进 RemoteFilesystem,不进 MySQL。
复现
HarnessAgent.builder()
.agentId("agent-qa")
.name("agent-qa")
.distributedStore(new MysqlDistributedStore(dataSource))
.filesystem(new RemoteFilesystemSpec())
.build();运行一次完整对话后:
SELECT * FROM agentscope_store WHERE namespace_path LIKE '%sessions%';
-- 预期:有 agents␟agent-qa␟users␟...␟sessions␟ 前缀的记录
-- 实际:没有 session 相关记录本地 workspace 会出现:
workspace/<uid>/default/agent-qa/<sessionId>/events/0-5-xxx.jsonl
根因
ObjectStoreTranscriptStore的 segment key layout 是{tenant}/{agentId}/{sessionId}/events/...,与RemoteFilesystemSpec的{agents}/{agentId}/sessions/路由前缀不一致。- 即使手动调整 key 前缀去匹配
agents/{agentId}/sessions/,USERscope 下还带有users/{userId}层级,而TranscriptRef中没有userId,难以正确构造命中路由的 key。 - 框架目前没有内置基于 JDBC/MySQL 的
TranscriptStore实现,用户无法通过.transcriptStore(...)直接接入已有 DataSource。
影响
- 升级到当前 main 后,原先 v2.0.2 能写入 MySQL 的 session 历史会"静默丢失"到本地盘。
- 在 K8s / emptyDir / 多副本场景下,本地 workspace 随 Pod 销毁,session 无法跨副本恢复。
- 用户配了
RemoteFilesystemSpec + JdbcStore后,会误以为 session 已持久化到 MySQL,但实际上没有。
建议
任一即可:
-
官方提供
JdbcTranscriptStore/RdbmsTranscriptStore实现
直接通过 JDBC 同步写入独立表(如agentscope_transcript_segments),不依赖RemoteFilesystemSpec路由匹配。 -
调整默认
ObjectStoreTranscriptStore的 key layout 以匹配RemoteFilesystemSpec路由
默认生成agents/{agentId}/sessions/{sessionId}/events/...或兼容IsolationScope的 key,并确保TranscriptMiddleware传入的RuntimeContext携带userId以支持 USER scope。 -
至少提供配置开关
例如.transcriptStore(TranscriptStore.legacyMirror())或.disableTranscriptStore(),让用户能显式选择行为,避免静默降级到本地盘。
相关
- [Bug]:agentName参数影响了session/ 文件的目录位置 #2297 —
agentName与agentId不一致导致 v2.0.2 session 路由失败 - [Bug]:配了远程 store 后 session 仍写本地工作副本,且该副本的路径与路由下层不一致、无人可读 #2691 — v2.0.2 中 session 写本地副本 + 异步 mirror 的设计缺陷
Activity
CryoThrust commentedon Aug 31, 2026
I would like to investigate this regression. The interaction between ObjectStoreTranscriptStore key layout, CompositeFilesystem routing, and USER-scope path construction looks important to preserve before proposing code. I plan to reproduce with a minimal in-memory backend first, then confirm whether the intended fix is a routing-compatible key layout or an explicit JDBC transcript store, without silently changing persistence semantics.
CryoThrust commentedon Sep 4, 2026
I traced the reported regression to a routing contract mismatch rather than a MySQL write failure:
ObjectStoreTranscriptStoreemits segment keys underdefault/{agentId}/{sessionId}/events/....RemoteFilesystemSpecroutes session data underagents/{agentId}/sessions/(and USER isolation adds the user namespace).CompositeFilesystemtherefore falls back to its local backend, so the transcript can be written successfully but never reach the configured remote store.Before preparing a patch, could maintainers confirm the intended ownership of transcript persistence?
TranscriptStore?A focused regression test can assert that a
RemoteFilesystemSpec-backed transcript write reaches the remote store and does not silently fall back to local storage. I can implement once the compatibility direction is confirmed.allendata0706 commentedon Sep 4, 2026
v2.0.2 中
但 MemoryFlushMiddleware 和 CompactionMiddleware 使用String agentId = agent.getName() 构造 Session 路径:
生成的路径 :agents/妙妙/sessions/.jsonl,session文件就无法卸载到远程文件系统里。
应该使用 agentId = agentId.getAgentId(); 这样才可以写到远程文件系统中。见: #2297
对于 master分支,ObjectStoreTranscriptStore 需要解决写入 mysql key 匹配问题。
oss-maintainer commentedon Sep 14, 2026
Issue Evaluation
Category:
bug| Area:area/harness| Status: Confirmed (verified against currentmain)Root Cause:
ObjectStoreTranscriptStore.appendSegmentwrites segment keys underdefault/{agentId}/{sessionId}/events/..., whileRemoteFilesystemSpeconly overlays paths matchingagents/{agentId}/sessions/.CompositeFilesystem.routeForPaththerefore falls back to the local default backend and session transcript segments never reach the remote (MySQL) store.Impact: Session history is silently not persisted with
RemoteFilesystemSpec+IsolationScope.USER; migrating from the v2.0.2SessionTreemirror path loses replayability.Severity: high
A concise fix would align the transcript segment key layout with the
RemoteFilesystemSpecrouting prefix (or make the routing prefix configurable per store). An automated fix proposal can be generated on request.Automated evaluation by github-manager-bot
aiyili commentedon Oct 1, 2026
Hi, I'd like to work on this. The segment-key format produced by
ObjectStoreTranscriptStore.appendSegmentdoesn't match the routing prefixesRemoteFilesystemSpecregisters, so transcript writes fall to the default backend instead of the sharedagents/<id>/sessions/route. I'll align the key layout (or add a route) with tests asserting writes land in the routed store namespace. PR coming shortly.aiyili commentedon Nov 27, 2026
Picking this up again for the
2.0.xbranch. The code that #3386 changed still exists there and the mismatch is still reproducible: on2.0.x(50886798)ObjectStoreTranscriptStore.appendSegmentstill writes{tenant}/{agentId}/{sessionId}/events/...(default tenantdefault), which does not match theagents/{agentId}/sessions/route thatRemoteFilesystemSpecregisters, so segments fall through to the default backend.Plan, as a PR against
2.0.xonly. It is the final state of #3386, with the three items from the 10-02 review:agents/{agentId}/sessions/{sessionId}), built from the builder's stable agent id, the one the routes are built with, threaded throughTranscriptMiddlewareintoSessionTranscriptWriter.awaitMirrorQuiescenceand covers the split case (agentIddifferent from the display name).transcriptTenantjavadoc updated, and the behavior for segments written under the old key layout stated in the PR: they stayed on the local disk of the node that wrote them (that is the bug), the local context file remains the primary copy there, and they are not migrated.aiyili commentedon Nov 27, 2026
Opened #4450 against
2.0.x.On unmodified
2.0.xaHarnessAgentbuilt withRemoteFilesystemSpecleaves its transcript segments on the local disk:ObjectStoreTranscriptStorewrites{tenant}/{agentId}/{sessionId}/events/..., which matches none of the routes, soCompositeFilesystemsends it to the default backend. A second mismatch sits behind it: the route is keyed on the builder'sagentId, while the transcript middleware is registered on the innerReActAgentand keys the transcript on the display name.The PR does what #3386 ended with: a ref of
agents/{agentId}/sessions/{sessionId}for that store, built fromresolvedAgentId, whichHarnessAgenthands toTranscriptMiddlewareand on to the writer. An end-to-end test builds an agent whoseagentIddiffers from its display name and checks that the segments reach the store underagents/<agentId>/...and that nothing is left under the display name or on the local disk.Segments written before the change are not migrated. They only ever existed on the local disk of the node that wrote them, where the local context file remains the primary copy.
fix(harness): keep the tenant layout for a transcript store the build…
fix(harness): key transcript segments on the sessions route on 2.0.x (#…
aiyili commentedon Dec 2, 2026
Merged into
2.0.xasad8e2146(#4450, including the review-scoped follow-up: only the builder's default store is keyed on the sessions route; a store supplied throughtranscriptStore(...)keeps its prefix and tenant layout).On
mainthis code no longer exists — #3441 removed it — so there is nothing left to fix there. Closing this as completed on the maintenance branch seems right; maintainer's call.