Skip to content

[Bug]: RequireUserConfirmEvent is published before agent_state is persisted — a crash in the window loses the durable ASKING #3621

Closed

Description

@richuV

Problem

When a permission gate suspends tool calls (pending non-empty), ReActAgent's acting path publishes RequireUserConfirmEvent to event subscribers in-stream (the Flux ends in .doOnNext(this::publishEvent)), while the ASKING transition is only persisted by saveStateToSession after the call completes.

Order today (agentscope-core, ReActAgent → actingStream):

  1. updateToolCallStates(...) marks ToolCallState.ASKING in the in-memory context
  2. persistPendingRequestReplyId(...) records the reply identity in Msg metadata
  3. RequireUserConfirmEvent + RequestStopEvent(PERMISSION_ASKING) are emitted — subscribers (SSE transports, dashboards) receive the approval prompt immediately
  4. Only later does the call tail run saveStateToSession → agent_state save

If the process dies between steps 3 and 4 — a sub-second window on local disk, but real under load or a remote state store — the approval prompt is already user-visible and durable in consumer-side transcripts, while the persisted agent_state contains no ASKING.

Why it matters

A host that restart-recovers pending approvals reads ASKING tool calls from agent_state. After such a crash:

  • The consumer-side transcript/audit already records the approval prompt (a user may even have clicked "approve" on a live frame).
  • The persisted runtime state has no suspended tool call — there is no resume owner.
  • The host must fail closed ("runtime lost") for a prompt it already surfaced, which reads to the user as an approval that can never be completed.

We hit this in a real acceptance run: killing the host immediately after the REQUIRE_USER_CONFIRM SSE frame arrives intermittently left agent_state.json without asking while the transcript contained the prompt row; post-restart the pending-approvals inbox still re-listed it, but continuation had to fail closed.

Same family as #3619 (fresh-runtime denied ConfirmResult not consumed): ASK-state persistence ordering vs. its visible surface.

Requested change

Make the suspension durable before it becomes observable — either:

  • persist agent_state (or at least the ASKING transition + reply identity) before RequireUserConfirmEvent is published, or
  • publish RequireUserConfirmEvent only after the suspension-state save completes (a durable-then-publish ordering for PERMISSION_ASKING stops).

Alternatively, an explicit hook where a host can force a checkpoint at suspension time (related to the mid-turn checkpoint seam requested in #3620) would also close the hole.

Activity

  1. xihongshichaojidan8 commented on Oct 21, 2026

    @xihongshichaojidan8
    Contributor

    我在当前 main(997c60ac)上验证了这个时序窗口:收到 RequireUserConfirmEvent 时,新建 Agent 尚无法恢复待授权工具;原调用结束后则可以。旧状态存储和原生 Session Log 两条路径结果一致,目前验证的是事件顺序,尚未做实际进程崩溃测试。

    我想尝试一个限定范围的修复:在权限暂停边界,先持久化 ASKING 状态和 replyId;原生日志同时提交待确认请求,再对外发布授权提示。不引入通用 checkpoint API。请问是否已有相关工作,以及这个修复边界是否合适?

  2. added a commit that references this issue on Nov 12, 2026
    cf9dc2a
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions