refactor(managed-agent): narrow EmbeddedRuntimeBroker to SessionQueryStore (#16216)

* refactor(managed-agent): narrow EmbeddedRuntimeBroker to SessionQueryStore

The broker holds the store only to forward it into WorkspaceRuntimeResolver
and ManagedRuntimeCoordinator (resolver static + constructor), which both
take SessionQueryStore, and makes no direct store call. Narrow the field and
all eight constructor overloads from the AgentStateStore composite to
SessionQueryStore; the sole caller RuntimeBrokerConfiguration still passes an
AgentStateStore, assignable to the role, so it is unchanged. Type-only.

Update the structure-review ledger in both languages: the broker moves from
candidate into the single-role audit (query group), tally 22 -> 23.

Full real Spring context boot (ManagedAgentServerIntegrationTest, 57 tests)
resolves the narrowed bean with no ambiguity; ModuleArchitectureTest and
Checkstyle clean; all modules compile.

Co-authored-by: Qwen-Coder <[email protected]>

* refactor(managed-agent): drop EmbeddedRuntimeBroker's write-only store field

Address review R1-1: the store field was never read — this.store = store was
its only occurrence besides the declaration, and the three forwarding sites
(WorkspaceRuntimeResolver, ManagedRuntimeCoordinator.resolver and constructor)
read the constructor parameter, which shadows the field. Remove the field and
the assignment; every constructor stays narrowed to SessionQueryStore and the
forwarding is unchanged. The broker still depends on SessionQueryStore through
its constructor, so the ledger entry stands.

Full real Spring context boot (57 tests) + ModuleArchitectureTest + 0
Checkstyle; all modules compile, confirming no read of the removed field.

Co-authored-by: Qwen-Coder <[email protected]>

---------

Co-authored-by: Qwen-Coder <[email protected]>
This commit is contained in:
Shaojin WenandQwen-Coder authored and GitHub committed 2026-11-04 01:38:18 +08:00
1 parent 44e5c646ee
commit 8d8217aeee
3 files changed
+17 -19

No files matched your search

@@ -194,7 +194,7 @@ cross-cutting "how the system works today" tour.
nested records/constants resolve through inheritance (imports of nested
types must name the owning role). A role-composition pin keeps the
composite empty and owns no surface of its own. Consumer audit
(call-level, corrected after review): 22 single-role consumers inject
(call-level, corrected after review): 23 single-role consumers inject
their role directly — lifecycle (`RenameEvidence`, `TurnInputEvidence`,
`ChildLifecycleAdmissions`, `ActionResponseCoordinator`,
`ContextCompressionCoordinator`, `ContextCompressionService`,
@@ -202,7 +202,7 @@ cross-cutting "how the system works today" tour.
query (`ManagedRuntimeCoordinator`,
`SessionRecoveryService`, `ManagedExtensionCommandVerifier`,
`ManagedSessionStore`, `ChildWorkspaceService`, `WorkspaceRuntimeResolver`,
`ManagedAutomationService`), policy (`ManagedMcpManagementService`,
`ManagedAutomationService`, `EmbeddedRuntimeBroker`), policy (`ManagedMcpManagementService`,
`ManagedExtensionManagementService`), event projection
(`MessageMaterializer`, `ReplayFloorAdvancer`, `ManagedToolResultStore`),
and turn execution (`SessionWorktreeService`). Most of the remaining
@@ -210,8 +210,8 @@ cross-cutting "how the system works today" tour.
and keep the composite. The broker wiring is no longer one of them:
`EmbeddedRuntimeBroker` forwards the store only into
`WorkspaceRuntimeResolver` and `ManagedRuntimeCoordinator`, which both
take `SessionQueryStore`, so it is itself a candidate for the same
narrowing. Four of these — `ChildWorkspaceService`,
take `SessionQueryStore`, and it now injects `SessionQueryStore` itself.
Four of these — `ChildWorkspaceService`,
`WorkspaceRuntimeResolver`, `ManagedAutomationService` and
`TaskCancelCoordinator` — were initially deferred because their
`this(...)` calls are constructor delegation within the same class rather
@@ -168,7 +168,7 @@ sweep 管理这个陷阱。各字段的单位本身是一份被钉住的绑定
`AgentStateStore` 保留为继承它们的组合接口,实现与测试继续使用完整
表面,嵌套 record/常量经继承解析(嵌套类型的 import 必须写拥有它的
角色)。角色组合 pin 保证组合接口自身为空、不拥有任何表面。消费方
审计(调用级,评审后更正):22 个单角色消费方已直接注入其角色——
审计(调用级,评审后更正):23 个单角色消费方已直接注入其角色——
生命周期(`RenameEvidence`、`TurnInputEvidence`、
`ChildLifecycleAdmissions`、`ActionResponseCoordinator`、
`ContextCompressionCoordinator`、`ContextCompressionService`、
@@ -176,14 +176,14 @@ sweep 管理这个陷阱。各字段的单位本身是一份被钉住的绑定
(`ManagedRuntimeCoordinator`、
`SessionRecoveryService`、`ManagedExtensionCommandVerifier`、
`ManagedSessionStore`、`ChildWorkspaceService`、`WorkspaceRuntimeResolver`、
`ManagedAutomationService`)、策略(`ManagedMcpManagementService`、
`ManagedAutomationService`、`EmbeddedRuntimeBroker`)、策略(`ManagedMcpManagementService`、
`ManagedExtensionManagementService`)、事件投影
(`MessageMaterializer`、`ReplayFloorAdvancer`、`ManagedToolResultStore`)、
Turn 执行(`SessionWorktreeService`)。其余消费方多数跨角色,或把
store 透传给多角色依赖,继续使用组合接口。broker 装配已不在其列:
`EmbeddedRuntimeBroker` 只把 store 转发给 `WorkspaceRuntimeResolver` 与
`ManagedRuntimeCoordinator`,二者都收 `SessionQueryStore`,故它本身也是
同样收窄的候选。其中四个——`ChildWorkspaceService`、
`ManagedRuntimeCoordinator`,二者都收 `SessionQueryStore`,它本身现已注入
`SessionQueryStore`。其中四个——`ChildWorkspaceService`、
`WorkspaceRuntimeResolver`、`ManagedAutomationService`、
`TaskCancelCoordinator`——起初因 `this(...)` 是本类构造委托而非透传
而暂缓,已在 #15962 的后续中收窄。
@@ -2,7 +2,7 @@ package com.alibaba.qwen.code.managedagent.config.runtime;
import com.alibaba.qwen.code.managedagent.adapters.workspace.ChildWorktreeGit;
import com.alibaba.qwen.code.managedagent.config.ManagedAgentProperties;
import com.alibaba.qwen.code.managedagent.contracts.session.AgentStateStore;
import com.alibaba.qwen.code.managedagent.contracts.session.SessionQueryStore;
import com.alibaba.qwen.code.managedagent.contracts.workspace.ChildWorkspaceProvider;
import com.alibaba.qwen.code.managedagent.contracts.workspace.RuntimeWarmer;
import com.alibaba.qwen.code.managedagent.persistence.ExternalStorageRegistrationStore;
@@ -55,7 +55,6 @@ public class EmbeddedRuntimeBroker implements RuntimeWarmer, AutoCloseable {
private final RuntimeBrokerService service;
private final RuntimeBrokerHttpServer server;
private final RuntimeRecoveryCoordinator recovery;
private final AgentStateStore store;
private final WorkspaceRuntimeResolver workspaces;
private final ChildWorkspaceProvider childWorkspaces;
private final com.alibaba.qwen.code.managedagent.contracts.workspace.ResidentWorkspaceCatalog residents;
@@ -68,7 +67,7 @@ public class EmbeddedRuntimeBroker implements RuntimeWarmer, AutoCloseable {
private final RuntimeBindingRepository extensionBindings;
private final HttpRuntimeTransport extensionTransport;
public EmbeddedRuntimeBroker(AgentStateStore store,
public EmbeddedRuntimeBroker(SessionQueryStore store,
ManagedAgentProperties properties,
RuntimeBindingRepository bindingRepository,
RuntimeSessionRepository sessionRepository,
@@ -76,7 +75,7 @@ public class EmbeddedRuntimeBroker implements RuntimeWarmer, AutoCloseable {
this(store, properties, bindingRepository, sessionRepository, executionRepository, null);
}
public EmbeddedRuntimeBroker(AgentStateStore store,
public EmbeddedRuntimeBroker(SessionQueryStore store,
ManagedAgentProperties properties,
RuntimeBindingRepository bindingRepository,
RuntimeSessionRepository sessionRepository,
@@ -86,7 +85,7 @@ public class EmbeddedRuntimeBroker implements RuntimeWarmer, AutoCloseable {
executionRepository, workspaceExecutionStore, null, null);
}
public EmbeddedRuntimeBroker(AgentStateStore store,
public EmbeddedRuntimeBroker(SessionQueryStore store,
ManagedAgentProperties properties,
RuntimeBindingRepository bindingRepository,
RuntimeSessionRepository sessionRepository,
@@ -98,7 +97,7 @@ public class EmbeddedRuntimeBroker implements RuntimeWarmer, AutoCloseable {
workspaceExecutionStore, publications, publicationData, null, null, null, null);
}
public EmbeddedRuntimeBroker(AgentStateStore store,
public EmbeddedRuntimeBroker(SessionQueryStore store,
ManagedAgentProperties properties,
RuntimeBindingRepository bindingRepository,
RuntimeSessionRepository sessionRepository,
@@ -111,7 +110,7 @@ public class EmbeddedRuntimeBroker implements RuntimeWarmer, AutoCloseable {
workspaceExecutionStore, publications, publicationData, null, null, null, ssh);
}
public EmbeddedRuntimeBroker(AgentStateStore store, ManagedAgentProperties properties,
public EmbeddedRuntimeBroker(SessionQueryStore store, ManagedAgentProperties properties,
RuntimeBindingRepository bindingRepository, RuntimeSessionRepository sessionRepository,
ToolExecutionRepository executionRepository, WorkspaceExecutionStore workspaceExecutionStore,
ToolPublicationStore publications, ToolPublicationDataStore publicationData,
@@ -121,7 +120,7 @@ public class EmbeddedRuntimeBroker implements RuntimeWarmer, AutoCloseable {
workspaceExecutionStore, publications, publicationData, jdbc, manager, null, null);
}
public EmbeddedRuntimeBroker(AgentStateStore store, ManagedAgentProperties properties,
public EmbeddedRuntimeBroker(SessionQueryStore store, ManagedAgentProperties properties,
RuntimeBindingRepository bindingRepository, RuntimeSessionRepository sessionRepository,
ToolExecutionRepository executionRepository, WorkspaceExecutionStore workspaceExecutionStore,
ToolPublicationStore publications, ToolPublicationDataStore publicationData,
@@ -131,7 +130,7 @@ public class EmbeddedRuntimeBroker implements RuntimeWarmer, AutoCloseable {
workspaceExecutionStore, publications, publicationData, jdbc, manager, null, ssh);
}
EmbeddedRuntimeBroker(AgentStateStore store, ManagedAgentProperties properties,
EmbeddedRuntimeBroker(SessionQueryStore store, ManagedAgentProperties properties,
RuntimeBindingRepository bindingRepository, RuntimeSessionRepository sessionRepository,
ToolExecutionRepository executionRepository, WorkspaceExecutionStore workspaceExecutionStore,
ToolPublicationStore publications, ToolPublicationDataStore publicationData,
@@ -142,14 +141,13 @@ public class EmbeddedRuntimeBroker implements RuntimeWarmer, AutoCloseable {
workspaceExecutionStore, publications, publicationData, jdbc, manager, residentProvisioner, null);
}
private EmbeddedRuntimeBroker(AgentStateStore store, ManagedAgentProperties properties,
private EmbeddedRuntimeBroker(SessionQueryStore store, ManagedAgentProperties properties,
RuntimeBindingRepository bindingRepository, RuntimeSessionRepository sessionRepository,
ToolExecutionRepository executionRepository, WorkspaceExecutionStore workspaceExecutionStore,
ToolPublicationStore publications, ToolPublicationDataStore publicationData,
org.springframework.jdbc.core.JdbcTemplate jdbc,
org.springframework.transaction.PlatformTransactionManager manager,
RuntimeProvisioner residentProvisioner, SshWorkspaceService ssh) {
this.store = store;
this.ssh = ssh;
ManagedAgentProperties.RuntimeBroker broker =
properties.getRuntimeBroker();