Skip to content

agent/a2aagent: coordinate anonymous-cookie initialization across agent instances #2260

Description

@XnLemon

Background / 背景

PR #2163 serializes first anonymous-cookie initialization within a single A2AAgent instance and persists the acquired cookie through session state when a SessionService is available.

PR #2163 在单个 A2AAgent 实例内串行化首次 anonymous-cookie 初始化;当 SessionService 可用时,会通过 session state 持久化获取到的 Cookie。

However, this coordination is currently in-process only. Multiple A2AAgent instances, or multiple processes sharing the same SessionService, can still race during first anonymous-cookie initialization for the same logical session and remote cookie scope.

不过,当前协调只在单进程/单实例内生效。多个 A2AAgent 实例,或多个共享同一 SessionService 的进程,在同一个逻辑 session 和远端 Cookie scope 的首次 anonymous-cookie 初始化期间仍然可能发生竞争。

In that case, parallel first anonymous calls may acquire different remote anonymous principals before one persisted cookie wins.

在这种情况下,并发的首次匿名调用可能会在某个持久化 Cookie 最终生效前,分别获取到不同的远端 anonymous principal。

Scope / 范围

Add persistence-backed coordination for first anonymous-cookie initialization across agent instances/processes that share the same SessionService.

为共享同一 SessionService 的多个 agent 实例/进程增加基于持久化存储的首次 anonymous-cookie 初始化协调机制。

Possible directions:

可能方向:

  • Add a lease or CAS-style state transition around the anonymous-cookie state key.
  • 围绕 anonymous-cookie state key 增加 lease 或 CAS 风格的状态转换。
  • Use logical session identity plus remote cookie state key as the coordination key.
  • 使用逻辑 session identity 加远端 Cookie state key 作为协调 key。
  • Ensure contenders reload persisted cookie state after acquiring or observing the coordination state.
  • 确保竞争方在获取或观察协调状态后重新加载已持久化的 Cookie state。
  • Define timeout/cleanup behavior for abandoned initialization leases.
  • 定义被遗弃初始化 lease 的超时和清理行为。

Acceptance Criteria / 验收标准

  • Concurrent first anonymous invocations from separate A2AAgent instances converge on one remote anonymous principal.
  • 来自不同 A2AAgent 实例的并发首次匿名调用最终收敛到同一个远端 anonymous principal。
  • Coordination works when instances share the same SessionService.
  • 当多个实例共享同一个 SessionService 时,协调机制生效。
  • Failed or canceled initialization does not leave the session permanently locked.
  • 初始化失败或取消不会让 session 永久处于锁定状态。
  • The anonymous cookie remains private session state and is not emitted through public event deltas.
  • anonymous cookie 仍然保留在私有 session state 中,不会通过公开 event delta 发出。
  • Tests cover cross-instance concurrency and cancellation/lease cleanup behavior.
  • 测试覆盖跨实例并发以及取消/lease 清理行为。

Related / 关联

Follow-up from PR #2163.

来自 PR #2163 的 follow-up。

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions