Repository navigation
Description
Component
agentscope-harness (HarnessAgent) / agentscope-core (ReActAgent state persistence)
Affected versions
v2.0.3, and still present at main = ed77530a (verified by reading the source, not the release notes).
English
Summary
ReActAgent has a ConflictPolicy for agent_state saves (OVERWRITE / FAIL / APPEND_MERGE), but HarnessAgent — the recommended production entry point — has no way to configure it, so every harness agent is pinned to silent last-writer-wins. Worse, HarnessAgent.Builder.fromAgent(ReActAgent) silently drops the policy that the source agent was explicitly built with.
Evidence
- The core API exists and is public:
agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java:5154—Builder.conflictPolicy(ConflictPolicy)ReActAgent.java:349— defaults toConflictPolicy.OVERWRITEwhen unsetReActAgent.java:4684—public ConflictPolicy getConflictPolicy()- The enum's own javadoc recommends opting out of the default: "FAIL — throw
ConcurrentSessionModificationExceptionand skip the write. Recommended when a distributed session turn gate is enabled."
HarnessAgent.javacontains zero occurrences ofconflictPolicy. Its builder forwards roughly thirty knobs to the innerReActAgent(agentscope-harness/src/main/java/io/agentscope/harness/agent/HarnessAgent.java:1510-1722— e.g.inner.stateStore(...)at :1635,inner.stopOnReject(...)at :1722) but never the conflict policy, sobuild()(:2358) always leaves the inner default in place.HarnessAgent.Builder.fromAgent(ReActAgent)(:1429) documents itself as inheriting the "inheritable subset" of observable configuration and does copyagent.getStateStore()(:1444), yet it does not copyagent.getConflictPolicy()— even though that value is exposed through a public getter. This is the part I would call a bug rather than a missing feature: wrapping an agent that was deliberately configured withFAILyields a harness agent that quietly behaves asOVERWRITE.
Reproduction
ReActAgent strict = ReActAgent.builder()
.name("assistant").model(model).stateStore(store)
.conflictPolicy(ConflictPolicy.FAIL)
.build();
assert strict.getConflictPolicy() == ConflictPolicy.FAIL;
HarnessAgent wrapped = HarnessAgent.fromAgent(strict).build();
// wrapped's delegate saves with OVERWRITE: a concurrent writer's newer agent_state
// is clobbered, no exception, and the only symptom is a stale/garbled session later.Impact
agent_state is written through a single CAS funnel (persistAgentStateCas → saveIfVersion), so the machinery to detect a concurrent writer already exists and ConcurrentSessionModificationException is already thrown for FAIL. Harness users simply cannot reach it. In any multi-writer deployment (replicas behind a load balancer, an in-flight conversational turn racing a compaction/summary or an admin write), the losing turn's write is discarded silently instead of failing the turn where the user can see it and retry. The only way to opt out today is to wrap the store in a delegating AgentStateStore that refuses unconditional agent_state writes — which works, but pushes the framework's own concurrency contract back onto the host application and turns a configurable policy into a store-level exception.
Proposed fix (small, backward compatible)
- Add
conflictPolicy(ConflictPolicy)toHarnessAgent.Builderand forward it to the inner builder inbuild(); leaving it unset keeps today'sOVERWRITEdefault, so no existing behaviour changes. - Make
fromAgent(ReActAgent)inheritagent.getConflictPolicy()alongside the state store it already copies. - Optionally add a passthrough
HarnessAgent.getConflictPolicy(), mirroring the existinggetStateStore()at:516, so hosts can assert what they actually got. - Unit tests for: default unchanged,
FAIL/APPEND_MERGEreaching the delegate, andfromAgentinheritance.
I'd like to send the PR for this (one main file + tests). One scope question before I do: should fromAgent copy the policy unconditionally, or only when the source agent's policy is non-default?
中文说明
问题概述
ReActAgent 为 agent_state 的写入提供了 ConflictPolicy(OVERWRITE / FAIL / APPEND_MERGE),但作为生产推荐入口的 HarnessAgent 完全无法配置它,于是所有 harness 用户都被锁在"静默后写覆盖"上。更严重的是,HarnessAgent.Builder.fromAgent(ReActAgent) 会悄悄丢掉源 agent 显式设置的策略。
证据
- 核心侧接口是齐的、且是 public:
ReActAgent.java:5154有Builder.conflictPolicy(...);:349未设置时默认OVERWRITE;:4684有getConflictPolicy()。枚举自身的 javadoc 就写着:"FAIL —— 抛出ConcurrentSessionModificationException并跳过写入;启用分布式会话轮次闸门时建议选它。" HarnessAgent.java里conflictPolicy出现 0 次。它的 Builder 把大约三十个开关逐个转发给内层ReActAgent(HarnessAgent.java:1510-1722,例如:1635的inner.stateStore(...)、:1722的inner.stopOnReject(...)),唯独不转发冲突策略,因此build()(:2358)永远保留内层默认值。Builder.fromAgent(ReActAgent)(:1429)自称继承"可继承的可观察配置子集",也确实抄了agent.getStateStore()(:1444),却没抄agent.getConflictPolicy()—— 而这个值有 public getter。我认为这一条属于 bug 而不是功能请求:一个明确配了FAIL的 agent,被包成 harness agent 之后静默降级成OVERWRITE。
影响
agent_state 的写入只有一个 CAS 漏斗(persistAgentStateCas → saveIfVersion),也就是说框架本来就能识别并发写入方、FAIL 策略本来就会抛 ConcurrentSessionModificationException,harness 用户只是够不到它。任何多写入方场景(多副本、正在生成的轮次与压缩/摘要或管理写入并发)里,失败一方的写入会被无声丢弃,用户看到的只是过一会儿会话变陈旧或错乱;唯一的绕法是给自己注入的 AgentStateStore 套一层代理、拒掉非 CAS 的 agent_state 写入 —— 这能work,但等于把框架自带的并发契约推回应用层,也把"可配置的策略"变成"存储层异常"。
建议改法(很小、且向后兼容)
HarnessAgent.Builder增加conflictPolicy(ConflictPolicy),在build()里转发给内层 builder;不设置时保持今天的OVERWRITE,行为零变化。fromAgent(ReActAgent)连同getConflictPolicy()一起继承。- (可选)加一个透传
HarnessAgent.getConflictPolicy(),与已有的getStateStore()(:516)对齐,方便宿主自检。 - 补单测:默认值不变、
FAIL/APPEND_MERGE确实传到内层、fromAgent会继承。
我准备把这个 PR 提上来(一个主文件 + 测试)。动手前确认一个范围问题:fromAgent 是无条件继承策略,还是只在源 agent 策略非默认时继承?
Activity
oss-maintainer commentedon Sep 23, 2026
Issue Evaluation
Category:
bug/area/harness,area/core/memory| Status: ConfirmedVerified against
main@ed77530a4(static source review, no code changes). All four claims hold:ReActAgent.Builder.conflictPolicy(ConflictPolicy)atagentscope-core/src/main/java/io/agentscope/core/ReActAgent.java:5154, thenull -> ConflictPolicy.OVERWRITEdefault at:348-349, andgetConflictPolicy()at:4683-4685.HarnessAgentnever forwards it —grep -c conflictPolicyonagentscope-harness/.../HarnessAgent.javareturns 0, while the builder forwards sibling knobs to the innerReActAgent.Builder(inner.stateStore(...)at:1635,inner.defaultSessionId(...)at:1657). Sobuild()(:2358) always leaves the inner default in place.fromAgent()drops it —HarnessAgent.java:1429copiesagent.getStateStore()(:1442-1444) andagent.getDefaultSessionId()(:1446-1448) but notagent.getConflictPolicy(), even though that value is exposed publicly. AFAILagent wrapped into a harness agent silently degrades toOVERWRITE— this is the part that reads as a bug rather than a missing feature.persistAgentStateCas(...)at:537callsstateStore.saveIfVersion(...)at:571, andConflictPolicy.FAILthrowsConcurrentSessionModificationExceptionat:606-608(ConflictPolicy.java:38-39). Harness users simply cannot reach an existing framework contract.Impact: in multi-writer deployments (replicas behind a LB, a live turn racing compaction/summary or an admin write) the losing turn's
agent_statewrite is discarded silently; the only visible symptom is a stale or garbled session later.Severity: high.
On the proposed fix: the shape is right and backward compatible — leaving
conflictPolicy(...)unset keeps today'sOVERWRITE, and the passthrough getter mirrors the existinggetStateStore(). Tests: extendHarnessAgentTestfor (a) default unchanged, (b)FAIL/APPEND_MERGEreaching the delegate, (c)fromAgentinheritance.On your scope question (
fromAgentunconditional vs only-when-non-default): inheriting unconditionally looks cleaner —getConflictPolicy()returns the effective policy of the source agent, so copying it unconditionally is what "inherit the observable configuration" should mean, and it avoidsfromAgentspecial-casing the enum's default value. That is a maintainer call though, flagging it for the harness owners rather than deciding it here.Since you have already written the reproduction and know the file layout, please go ahead and open the PR — this avoids a competing automated patch for the same fix. Thanks for the precise report.
Automated evaluation by github-manager-bot
Cshvee commentedon Sep 23, 2026
Thanks for the fast, precise evaluation and for the steer on scope.
Opened #3263 with the fix as proposed:
conflictPolicy(...)forwarded to the inner builder, the passthrough getter, andfromAgentinheriting unconditionally per the reasoning above (happy to flip it to non-default-only if the harness owners prefer that). Tests were added toHarnessAgentTestas suggested — default unchanged,FAILreaching the delegate,fromAgentinheritance.Note for whoever picks it up: #3259 is touching adjacent state-persistence code in
agentscope-core; this PR only editsagentscope-harness, so a rebase should be cheap if that lands first.fix(harness): expose and inherit ConflictPolicy on HarnessAgent.Builder