Repository navigation
Conversation
默认 ObjectStoreTranscriptStore 的 key 布局 {tenant}/{agentId}/{sessionId}
(默认 tenant "default")与 RemoteFilesystemSpec 注册的路由前缀
agents/{agentId}/sessions/ 结构性不匹配:segment 写入落到 default
backend(本地 workspace),配了 JdbcStore 的用户以为 session 已持久化
到 MySQL,实际 K8s 多副本场景下随 Pod 销毁(agentscope-ai#2918)。
- SessionTranscriptWriter 对 ObjectStoreTranscriptStore 使用路由对齐
的 TranscriptRef("agents", agentId, "sessions/"+sessionId),segment
key 命中 sessions 路由进入分布式 store;其他 TranscriptStore 实现
保持调用方 tenant 布局(transcriptTenant 仅对非路由化实现生效)
- 集成测试:InMemoryStore + CompositeFilesystem 断言 segment 落在
路由 namespace 且不泄漏到 namespaced default backend
Fixes agentscope-ai#2918
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
First review of a #2918 fix: SessionTranscriptWriter now builds a route-aligned TranscriptRef (agents/{agentId}/sessions/{sessionId}) when the store is ObjectStoreTranscriptStore, plus a routing test.
This PR makes SessionTranscriptWriter build a route-aligned TranscriptRef ("agents"/agentId/"sessions/"+sessionId) when the store is ObjectStoreTranscriptStore, so transcript segment keys should land on the sessions route RemoteFilesystemSpec registers instead of falling through to the local default backend (#2918), and adds SessionTranscriptStoreRoutingTest.
The direction is right and the test is a useful reproduction, but the fix only aligns the key shape: the id used in the ref still comes from the caller (TranscriptMiddleware passes agent.getName()/HarnessAgent#getAgentId()), not from the stable builder agentId that RemoteFilesystemSpec uses for the route, so configurations that pin builder.agentId(...) - e.g. agentscope-service, which builds with b.agentId(instanceId) and a separate display name - still miss the sessions route, and the new test hardcodes equal ids so it cannot detect this.
Secondary concerns: the test asserts against an asynchronous mirror without awaiting SessionTree.awaitMirrorQuiescence (flake risk), segments written with the old prefix become unreachable (no legacy fallback), and the now-ignored transcriptTenant is not reflected in the public builder javadoc.
Findings
- [CRITICAL]
agentscope-harness/src/main/java/io/agentscope/harness/agent/memory/session/SessionTranscriptWriter.java:103— The route match only works if the caller-supplied agentId equals the id used to build the route, but the routing id and the writer's id come from different sources: RemoteFilesystemSpec keys the route on RemoteFilesystemSpec.toFilesystem(workspace, agentId, ...) = the builder's stable agentId (resolvedAgentId, HarnessAgent.java:2390/2456), whereas the only production caller, TranscriptMiddleware, passes agent.getName() (or HarnessAgent#getAgentId(), the delegate's internal UUID, when the agent is a HarnessAgent) - see TranscriptMiddleware.java:98-104. Any deployment that pins builder.agentId(...) to a value different from the display name (agentscope-service does exactly this: b.agentId(instanceId); b.name(name) in HarnessAgentBuildService) therefore still writes agents//sessions//events/... and still misses the agents//sessions/ route, so #2918 is not fixed for that - multi-replica - configuration; the new test cannot catch this because it passes the same literal "agent-a" to both the route and the writer. Resolve the ref from the same stable id the routes use (thread the resolved agent id into SessionTranscriptWriter/TranscriptMiddleware) or add an end-to-end test that builds a real HarnessAgent with a pinned agentId plus RemoteFilesystemSpec. - [WARNING]
agentscope-harness/src/test/java/io/agentscope/harness/agent/memory/session/SessionTranscriptStoreRoutingTest.java:87— This assertion races with the asynchronous segment upload: SessionTree.flush() hands the payload to the shared daemon MIRROR_EXECUTOR via scheduleSegmentMirror (SessionTree.java:341-343, 563-573), and neither WorkspaceManager.close() nor the end of appendMessages waits for it - the sibling test SessionTranscriptWriterTest deliberately sleeps 300ms for this reason, and on a loaded CI the store may still be empty here (while the assertFalse below then passes trivially). Wait on SessionTree.awaitMirrorQuiescence(...) before asserting so the test deterministically proves the routed write happened. - [WARNING]
agentscope-harness/src/main/java/io/agentscope/harness/agent/memory/session/SessionTranscriptWriter.java:96— Changing the segment prefix breaks read continuity for existing data: ObjectStoreTranscriptStore.listSegments/readSegment/compact/delete are keyed purely off the ref, and SessionTree.syncFromTranscriptStore also lists only the new prefix, so segments written before the upgrade under the old {tenant}/{agentId}/{sessionId}/events/... prefix become unreachable and are never compacted or deleted - in a store-only (ephemeral local disk) deployment the persisted history simply disappears from the reader's view after upgrading. Consider listing the legacy prefix as a read-only fallback during sync, or at minimum document the key migration in the PR/release notes. - [INFO]
agentscope-harness/src/main/java/io/agentscope/harness/agent/memory/session/SessionTranscriptWriter.java:102— transcriptTenant is now silently ignored for ObjectStoreTranscriptStore (the default store whenever a filesystem is present, HarnessAgent.java:2560-2562), yet the public builder javadoc still states "Tenant segment used in transcript object keys (default "default")" (HarnessAgent.java:2276) and the tenant was the only tenant discriminator in the key for isolation scopes that share a store namespace. Update the transcriptTenant/transcriptStore javadoc (and the matching docs/v2 pages) to state that the routed agents//sessions layout overrides the tenant for the object-store implementation.
Automated review by github-manager-bot
| // RemoteFilesystemSpec registers, so segment keys hit the sessions route and | ||
| // persist to the distributed store instead of the default backend (#2918). | ||
| // Note: transcriptTenant only applies to non-routed store implementations. | ||
| return new TranscriptRef("agents", agentId, "sessions/" + sessionId); |
There was a problem hiding this comment.
The route match only works if the caller-supplied agentId equals the id used to build the route, but the routing id and the writer's id come from different sources: RemoteFilesystemSpec keys the route on RemoteFilesystemSpec.toFilesystem(workspace, agentId, ...) = the builder's stable agentId (resolvedAgentId, HarnessAgent.java:2390/2456), whereas the only production caller, TranscriptMiddleware, passes agent.getName() (or HarnessAgent#getAgentId(), the delegate's internal UUID, when the agent is a HarnessAgent) - see TranscriptMiddleware.java:98-104. Any deployment that pins builder.agentId(...) to a value different from the display name (agentscope-service does exactly this: b.agentId(instanceId); b.name(name) in HarnessAgentBuildService) therefore still writes agents//sessions//events/... and still misses the agents//sessions/ route, so #2918 is not fixed for that - multi-replica - configuration; the new test cannot catch this because it passes the same literal "agent-a" to both the route and the writer. Resolve the ref from the same stable id the routes use (thread the resolved agent id into SessionTranscriptWriter/TranscriptMiddleware) or add an end-to-end test that builds a real HarnessAgent with a pinned agentId plus RemoteFilesystemSpec.
| .search(List.of("agents", "agent-a", "users", "user-1", "sessions"), 50, 0) | ||
| .stream() | ||
| .anyMatch(item -> item.key().contains("/events/")); | ||
| assertTrue(foundInRoute, "segment must land in the routed store namespace"); |
There was a problem hiding this comment.
This assertion races with the asynchronous segment upload: SessionTree.flush() hands the payload to the shared daemon MIRROR_EXECUTOR via scheduleSegmentMirror (SessionTree.java:341-343, 563-573), and neither WorkspaceManager.close() nor the end of appendMessages waits for it - the sibling test SessionTranscriptWriterTest deliberately sleeps 300ms for this reason, and on a loaded CI the store may still be empty here (while the assertFalse below then passes trivially). Wait on SessionTree.awaitMirrorQuiescence(...) before asserting so the test deterministically proves the routed write happened.
| * local disk on multi-replica deployments (#2918). Other {@link TranscriptStore} | ||
| * implementations keep the caller-supplied tenant layout. | ||
| */ | ||
| private TranscriptRef transcriptRefFor( |
There was a problem hiding this comment.
Changing the segment prefix breaks read continuity for existing data: ObjectStoreTranscriptStore.listSegments/readSegment/compact/delete are keyed purely off the ref, and SessionTree.syncFromTranscriptStore also lists only the new prefix, so segments written before the upgrade under the old {tenant}/{agentId}/{sessionId}/events/... prefix become unreachable and are never compacted or deleted - in a store-only (ephemeral local disk) deployment the persisted history simply disappears from the reader's view after upgrading. Consider listing the legacy prefix as a read-only fallback during sync, or at minimum document the key migration in the PR/release notes.
| // Route-aligned layout: matches the "agents/{agentId}/sessions/" prefix that | ||
| // RemoteFilesystemSpec registers, so segment keys hit the sessions route and | ||
| // persist to the distributed store instead of the default backend (#2918). | ||
| // Note: transcriptTenant only applies to non-routed store implementations. |
There was a problem hiding this comment.
transcriptTenant is now silently ignored for ObjectStoreTranscriptStore (the default store whenever a filesystem is present, HarnessAgent.java:2560-2562), yet the public builder javadoc still states "Tenant segment used in transcript object keys (default "default")" (HarnessAgent.java:2276) and the tenant was the only tenant discriminator in the key for isolation scopes that share a store namespace. Update the transcriptTenant/transcriptStore javadoc (and the matching docs/v2 pages) to state that the routed agents//sessions layout overrides the tenant for the object-store implementation.
|
Fair catch — the route-matching id and the writer's id do come from different sources, and the agentscope-service configuration (builder |
|
Thanks for the honest scoping note — the diagnosis is right: threading the stable resolved agent id (the one When the next round lands we will re-review. Please make sure it covers:
No further action needed from us meanwhile. Automated reply by github-manager-bot |
- CRITICAL 修复:resolvedAgentId(builder agentId 回退显示名——路由装配
用的正是它)经 TranscriptMiddleware 新参数线程化到
SessionTranscriptWriter;路由对齐 ref 的 agentId 改用 stable id——
agentscope-service 型配置(agentId=instanceId + name=显示名)不再
写 agents/<显示名>/... 而漏掉路由;调用方 id 未与路由对齐时仍回退
- 测试:awaitMirrorQuiescence 替代竞态断言(复审 WARNING);分离 id
用例(stable=agent-a vs caller=agent-qa-display)证明 stable id 命中
路由
- Info:transcriptTenant builder javadoc 说明对象存储路由布局下无
tenant 段;旧前缀 {tenant}/{agentId}/{sessionId}/events 的可读性
迁移问题在 PR 描述与 javadoc 中显式记录(升级后旧 segment 不可达,
需迁移或接受只读历史)
|
All three items addressed in f94059b:
Also covered the Info: Module suite matches the upstream baseline (0 failures, only the two known Windows symlink-privilege environment errors). |
|
@oss-maintainer Closing as obsolete: #3441 ( Your review of 10-01 was of an implementation that no longer exists on
So there is nothing to rebase onto: the route mismatch this PR fixed has no remaining call site. #2918 should be closable on the same grounds. One thing I have not done: audit the journal path against your four points. The first of them — the routing id and the writer's id coming from different sources ( The head is kept on |
…2918) (#4450) Fixes #2918 on `2.0.x`, where the code involved still exists. This is the final state of #3386, which targeted `main` and was closed when #3441 removed that code there. ## Problem With a remote filesystem, session history silently stays on the local disk. `ObjectStoreTranscriptStore`, the default transcript store whenever a filesystem is present, writes each segment through the `AbstractFilesystem` under `{tenant}/{agentId}/{sessionId}/events/...`, with a default tenant of `default`. `RemoteFilesystemSpec` routes `agents/{agentId}/sessions/` to the remote store. The two never match, so `CompositeFilesystem` sends every segment to the default backend. There is a second mismatch behind the first one. The route is keyed on the builder's `agentId`. The transcript middleware is registered on the inner `ReActAgent`, so it keys the transcript on the agent's display name. Where the two differ, even a correctly prefixed segment would miss the route. ## Fix - `SessionTranscriptWriter` builds the ref as `agents/{agentId}/sessions/{sessionId}` for the store the builder installs by default, so segment keys hit the sessions route. The builder creates that store through the new `ObjectStoreTranscriptStore.onSessionsRoute(filesystem)`, and only a store created that way is keyed on the route. A store supplied through `transcriptStore(...)`, whatever its class, keeps the layout it was configured with. - The ref uses the id the routes were built with. `HarnessAgent` passes `resolvedAgentId` through a new `TranscriptMiddleware` constructor argument to the writer. Callers that do not pass it keep using their own agent id. - The Javadoc of `transcriptStore`, `transcriptTenant`, `TranscriptStore` and `TranscriptRef` says which store uses which layout: `transcriptTenant` applies to every supplied store, and the default store's layout has no tenant segment. **Scoped after review.** The first version keyed every `ObjectStoreTranscriptStore` on the route, because the writer tested the class. A store supplied explicitly would have been re-keyed as well, from `{rootPrefix}{tenant}/{agentId}/{sessionId}` to `{rootPrefix}agents/{agentId}/sessions/{sessionId}`: segments already written under its tenant prefix would no longer be listed, and tenants sharing a backend with the same agent and session ids would have shared one namespace. The default store is the only one re-keyed now. ## Tests `SessionTranscriptStoreRoutingTest` (new, 10 cases). The default store, built the way the builder builds it: - segments reach the store behind the sessions route when the routing id differs from the caller's display name; - the same when no routing id is given and the caller's id is the routed one; - a blank routing id is treated like none; - a `TranscriptMiddleware` built with the three-argument constructor, which passes no routing id, keys the segments on the agent's name; - end to end: a built `HarnessAgent` with `agentId("agent-qa")`, a different display name and a `RemoteFilesystemSpec` puts its segments into the store under `agents/agent-qa/...`, nothing under the display name, and no `events` directory on the local disk. What must not change: - a `TranscriptMiddleware` built with the one-argument constructor, which has no transcript store, writes the local session log and nothing else; - a store that is not an `ObjectStoreTranscriptStore` keeps the tenant layout; - a supplied `ObjectStoreTranscriptStore` keeps its prefix and the tenant layout, behind the same routes: `tenants/acme/team-a/agent-a/session-1/events`, where the previous head wrote `tenants/acme/agents/agent-a/sessions/session-1/events`; - two tenants on one supplied store keep separate namespaces, with the same agent and session ids: the previous head wrote both into one directory on the route; - end to end: the same agent as above, built with `transcriptStore(new ObjectStoreTranscriptStore(...))` and a tenant, keeps the tenant layout and puts nothing on the sessions route: the previous head's segments reached the store of the route. On unmodified `2.0.x` the two route tests and the end-to-end test of the default store fail, and the tenant-layout test passes before and after. The three supplied-store cases fail on the previous head, `287609b5`. Where the other cases stand is placed by the mutants below, since they need the store factory and cannot run on unmodified code. Each piece of the fix was then broken on its own: | Broken piece | Caught by | | --- | --- | | writer keeps the tenant layout for every store | the two route tests and the end-to-end test of the default store | | writer keys every `ObjectStoreTranscriptStore` on the route (the code before the scoping) | the three supplied-store cases | | builder installs a plain store instead of the one on the route | `segmentsOfABuiltAgentReachTheSessionsRouteOfItsAgentId` | | factory does not mark the store as on the route | the five default-store cases | | `isOnSessionsRoute()` answers false for every store | the five default-store cases | | `isOnSessionsRoute()` answers true for every store | the three supplied-store cases | | the one-argument constructor marks a supplied store as on the route | `segmentsOfABuiltAgentWithASuppliedStoreKeepTheTenantLayout` | | the three-argument constructor marks a supplied store as on the route | `aStoreSuppliedToTheBuilderKeepsItsPrefixAndTheTenantLayout`, `tenantsOfASuppliedStoreKeepSeparateNamespaces` | | writer ignores the routing id | `segmentsHitTheSessionsRouteOfTheRoutingId`, end to end | | writer falls back to the tenant when no routing id is given | `segmentsHitTheSessionsRouteOfTheCallersIdWhenNoRoutingIdIsGiven` | | writer does not treat a blank routing id as absent | `aBlankRoutingId_fallsBackToTheCallersId` | | `HarnessAgent` passes the display name instead of `resolvedAgentId` | end to end | | `HarnessAgent` does not thread the id | end to end | | `TranscriptMiddleware` does not hand the id to the writer | end to end | | the three-argument constructor of the middleware passes the tenant on as routing id | `aMiddlewareWithoutARoutingId_keysTheSegmentsOnTheAgentsName` | All are caught. The three that break the threading between `HarnessAgent` and the writer are caught by the end-to-end test alone, which is why it is there. `withRuntimeContext` and `withFilesystem` carry the mark over to their copies; nothing reads it from a copy, so no test can tell and no mutant is listed. Every line this PR adds to production code is covered on Linux, branches included. ## Segments written before this change They are not migrated. They were written to the default backend, which is the local disk of the node that wrote them; that is the bug. The local context file remains the primary copy on that node. Nothing reads the old segment files afterwards, since the store lists, compacts and deletes by ref and the ref now points at the new layout, so they stay in place until the workspace is removed. Only the default store is affected. A supplied store writes where it always did. ## Verification The full `agentscope-harness` suite was run before and after the change on Windows and in a Linux container. The failing lists are identical; the only difference is the added tests. The Windows numbers are from before the last two commits, which add tests and scope the change to the default store; the current head passes the Windows job in CI. | Environment | Before | After | Failing before and after | | --- | --- | --- | --- | | Windows | 1619 run, 5 F + 12 E | 1623 run, 5 F + 12 E (1629 with the last two commits, green in CI) | Windows path checks (`Sandbox workspace root must be an absolute path`), 2 × `MemoryConsolidatorCommitGateTest`, `MemoryFlushSandboxIndependenceTest` | | Linux container (`maven:3.9-eclipse-temurin-17`) | 1619 run, 3 F + 1 E | 1629 run, 3 F + 1 E | 3 × `BaseSandboxFilesystemTest.edit_*` (`python3: not found` in the image), `MarketplaceStagerOrphanGcTest.unreadableEntryDoesNotFailStage` | No existing test depends on the old key layout of the default store. **CI.** The first run of this PR was red for reasons that lay in the base branch: since the backports of 2026-11-13, every PR against `2.0.x` failed the Windows job, at first in `agentscope-core`, and had its Ubuntu job cancelled. Those causes are fixed by #4454 and #4461, merged into `2.0.x` on 2026-11-27; the harness part went in with #4461. The runs since, including the one on the current head, are green on both systems. One Windows run in between, on `108fae28`, stopped on `HttpSelfRegistrationTest` in `agentscope-extensions-aistio`: the shutdown race of that module (#3132), unrelated to this change; the next run passed. The local before/after runs recorded above were made before the fixes existed, which is why the "before" column lists failures that the branch no longer has.
Fixes #2918
Problem
The default
ObjectStoreTranscriptStorebuilds segment keys as{tenant}/{agentId}/{sessionId}/events/...(default tenantdefault), whileRemoteFilesystemSpecregisters the routeagents/{agentId}/sessions/. The layouts are structurally incompatible:CompositeFilesystem.routeForPathnever matches, transcript segments fall to the default backend (local workspace), and session history silently stops persisting to the distributed store — invisible until a multi-replica deployment loses sessions with pod recycling, even though the user configured a JDBC store.Fix
SessionTranscriptWriternow builds a route-alignedTranscriptRefwhen the store is the object-store implementation:("agents", agentId, "sessions/" + sessionId), producing keys likeagents/agent-a/sessions/session-1/events/0-5-writer.jsonlthat hit the sessions route and land in the distributed store's sessions namespace. OtherTranscriptStoreimplementations keep the caller-supplied tenant layout (transcriptTenantapplies to non-routed implementations only — noted in the javadoc).Test
SessionTranscriptStoreRoutingTestreproduces the issue scenario end-to-end: aCompositeFilesystem(namespaced local default backend +RemoteFilesystemSpec-shaped sessions route over anInMemoryStore), a realSessionTranscriptWriter+ObjectStoreTranscriptStoreappend — then asserts the segment lands in the routed store namespace (the SQLLIKE '%sessions%'check from the issue, at the store API level) and does not leak into the namespaced default backend directory.