Skip to content

[Bug]: Durable AG-UI adapter drops HITL interact, leaving the run stream open #4254

Open

Description

@chcodex

AgentScope-Java Version

2.1.0-SNAPSHOT, based on upstream/main at c1d482900.

Description

DurableAguiEventAdapter.committed() maps run.started, run.ended, step.started/step.ended, message.completed and tool.call.updated, but drops the committed interaction.requested event through default -> List.of().

When a native tool needs human input, BackendThreadJournal emits a public interaction.requested event with:

{ "id", "requestId", "turnId", "key", "kind", "status": "pending",
  "call": { "name", "arguments" }, "automatic" }

and parks the Turn in WAITING.

Symptoms

  1. AG-UI clients never receive RUN_FINISHED with an interrupt outcome, so they cannot render the question card or obtain the interruptId required for a resume.
  2. The committed order is run.ended (STOPPED, reason such as TOOL_SUSPENDED for a suspended tool, or PERMISSION_ASKING when a permission hook parks the Turn) followed by turn.waiting. A parked run.ended is not the terminal AG-UI frame, so without turn.waiting the client has no supported way to end the run at the interrupt and resume from it.

WAITING semantics are correct

WAITING needs no change. The adapter commits TurnStatus.WAITING, DurableRuntime releases the lease, and readyAt() returns -1 when waiting.deadline() == 0. No worker thread or lease is held while waiting. The defect is only the missing terminal AG-UI event.

Multiple pending interactions

A Turn can wait on more than one interaction at the same time: a confirmation plus an external-execution request, for example (UserApiContract asserts pendingInteractions().size() == 2). AG-UI 1.0 requires one terminal event per run and allows the interrupt outcome to carry a non-empty interrupts array, so all pending interactions must be delivered in one RUN_FINISHED.

Proposed fix

  • Extend the committed turn.waiting event with the Turn's pending interactions array, so one committed event carries the whole wait set.
  • Map turn.waiting to exactly one RUN_FINISHED whose RunFinishedInterruptOutcome.interrupts contains every pending interaction. Individual interaction.requested events are not terminal and are not mapped on their own.
  • Treat STOPPED parked reasons (suspended, PERMISSION_ASKING, TOOL_SUSPENDED) as non-terminal, and end the parked native Run quietly so no extra run.ended competes with turn.waiting.
  • Use the Durable interaction id (data.id = hash(turnId, requestId)) as interrupt.id; AguiInterrupts.externalExecution must not regenerate it because the resume request would not match the pending interaction. Use requestId (the tool call id) as interrupt.toolCallId.
  • Close the steps, messages and tool calls the Run opened before the terminal event; reset adapter state per Run; provide the confirmation responseSchema; map non-suspended stopped Runs to the AG-UI cancelled outcome.
  • Add regression tests for single and multiple interactions, open-item closing, cancelled Runs, repeated waiting events, and failure after an interrupt.

Verification: mvn -B -ntp -pl agentscope-durable/durable-adapters/durable-adapter-agui test, the Durable runtime/JDBC contract tests, and spotless:check.

Activity

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