Skip to content

[Bug]: HarnessAgent cannot configure ConflictPolicy, and Builder.fromAgent() silently drops the source agent's policy #3260

Closed

Description

@Cshvee

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

  1. 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 to ConflictPolicy.OVERWRITE when unset
    • ReActAgent.java:4684 — public ConflictPolicy getConflictPolicy()
    • The enum's own javadoc recommends opting out of the default: "FAIL — throw ConcurrentSessionModificationException and skip the write. Recommended when a distributed session turn gate is enabled."
  2. HarnessAgent.java contains zero occurrences of conflictPolicy. Its builder forwards roughly thirty knobs to the inner ReActAgent (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, so build() (:2358) always leaves the inner default in place.
  3. HarnessAgent.Builder.fromAgent(ReActAgent) (:1429) documents itself as inheriting the "inheritable subset" of observable configuration and does copy agent.getStateStore() (:1444), yet it does not copy agent.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 with FAIL yields a harness agent that quietly behaves as OVERWRITE.

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)

  1. Add conflictPolicy(ConflictPolicy) to HarnessAgent.Builder and forward it to the inner builder in build(); leaving it unset keeps today's OVERWRITE default, so no existing behaviour changes.
  2. Make fromAgent(ReActAgent) inherit agent.getConflictPolicy() alongside the state store it already copies.
  3. Optionally add a passthrough HarnessAgent.getConflictPolicy(), mirroring the existing getStateStore() at :516, so hosts can assert what they actually got.
  4. Unit tests for: default unchanged, FAIL/APPEND_MERGE reaching the delegate, and fromAgent inheritance.

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 显式设置的策略。

证据

  1. 核心侧接口是齐的、且是 public:ReActAgent.java:5154 有 Builder.conflictPolicy(...);:349 未设置时默认 OVERWRITE;:4684 有 getConflictPolicy()。枚举自身的 javadoc 就写着:"FAIL —— 抛出 ConcurrentSessionModificationException 并跳过写入;启用分布式会话轮次闸门时建议选它。"
  2. HarnessAgent.java 里 conflictPolicy 出现 0 次。它的 Builder 把大约三十个开关逐个转发给内层 ReActAgent(HarnessAgent.java:1510-1722,例如 :1635 的 inner.stateStore(...)、:1722 的 inner.stopOnReject(...)),唯独不转发冲突策略,因此 build()(:2358)永远保留内层默认值。
  3. 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,但等于把框架自带的并发契约推回应用层,也把"可配置的策略"变成"存储层异常"。

建议改法(很小、且向后兼容)

  1. HarnessAgent.Builder 增加 conflictPolicy(ConflictPolicy),在 build() 里转发给内层 builder;不设置时保持今天的 OVERWRITE,行为零变化。
  2. fromAgent(ReActAgent) 连同 getConflictPolicy() 一起继承。
  3. (可选)加一个透传 HarnessAgent.getConflictPolicy(),与已有的 getStateStore()(:516)对齐,方便宿主自检。
  4. 补单测:默认值不变、FAIL/APPEND_MERGE 确实传到内层、fromAgent 会继承。

我准备把这个 PR 提上来(一个主文件 + 测试)。动手前确认一个范围问题:fromAgent 是无条件继承策略,还是只在源 agent 策略非默认时继承?

Activity

  1. oss-maintainer commented on Sep 23, 2026

    @oss-maintainer
    Collaborator

    Issue Evaluation

    Category: bug / area/harness, area/core/memory | Status: Confirmed

    Verified against main @ ed77530a4 (static source review, no code changes). All four claims hold:

    1. Core API exists and is public — ReActAgent.Builder.conflictPolicy(ConflictPolicy) at agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java:5154, the null -> ConflictPolicy.OVERWRITE default at :348-349, and getConflictPolicy() at :4683-4685.
    2. HarnessAgent never forwards it — grep -c conflictPolicy on agentscope-harness/.../HarnessAgent.java returns 0, while the builder forwards sibling knobs to the inner ReActAgent.Builder (inner.stateStore(...) at :1635, inner.defaultSessionId(...) at :1657). So build() (:2358) always leaves the inner default in place.
    3. fromAgent() drops it — HarnessAgent.java:1429 copies agent.getStateStore() (:1442-1444) and agent.getDefaultSessionId() (:1446-1448) but not agent.getConflictPolicy(), even though that value is exposed publicly. A FAIL agent wrapped into a harness agent silently degrades to OVERWRITE — this is the part that reads as a bug rather than a missing feature.
    4. The CAS machinery is already there — persistAgentStateCas(...) at :537 calls stateStore.saveIfVersion(...) at :571, and ConflictPolicy.FAIL throws ConcurrentSessionModificationException at :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_state write 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's OVERWRITE, and the passthrough getter mirrors the existing getStateStore(). Tests: extend HarnessAgentTest for (a) default unchanged, (b) FAIL/APPEND_MERGE reaching the delegate, (c) fromAgent inheritance.

    On your scope question (fromAgent unconditional 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 avoids fromAgent special-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

  2. added
    bug
    area/harness
    on Sep 23, 2026
  3. Cshvee commented on Sep 23, 2026

    @Cshvee
    ContributorAuthor

    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, and fromAgent inheriting unconditionally per the reasoning above (happy to flip it to non-default-only if the harness owners prefer that). Tests were added to HarnessAgentTest as suggested — default unchanged, FAIL reaching the delegate, fromAgent inheritance.

    Note for whoever picks it up: #3259 is touching adjacent state-persistence code in agentscope-core; this PR only edits agentscope-harness, so a rebase should be cheap if that lands first.

  4. added a commit that references this issue on Sep 23, 2026
    8a23dcb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/harnessbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions