Skip to content

Add an awaited terminal cancellation API for ACP prompts #1760

Description

@NathanFlurry

Problem

AgentOS currently exposes cancellation acknowledgement, not a reliable terminal/quiescence boundary.

When a prompt is pending, both clients resolve the local prompt and dispatch the real session/cancel in the background:

  • crates/client/src/session.rsAgentOs::cancel_session
  • packages/core/src/agent-os.tsAgentOs.cancelSession

The returned synthetic { via: "prompt-fallback" } result means only that cancellation was requested. It does not prove that the adapter stopped the turn, stopped emitting events, released tool/permission work, or can safely accept the next prompt.

The actor plugin also aborts its tracked prompt task before issuing cancellation in crates/agentos-actor-plugin/src/actions/session.rs. This can suppress the correlated terminal promptResult event, leaving callers without a clean completion signal.

A real Claude ACP reproduction acknowledged cancellation and appeared idle while the original turn remained active; an immediate follow-up then remained blocked for minutes. GigaCode currently compensates with a timer, an awaited session close, ACP-session recreation, and transcript handoff before reporting idle.

Proposed API

Expose an awaited terminal operation in both Rust and TypeScript, conceptually:

cancelPromptAndWait(sessionId, options?) ->
  { state: "quiescent", sessionReusable: true }
  { state: "closed", sessionReusable: false }
  { state: "timed_out", sessionReusable: false }

The exact naming and types can follow existing AgentOS conventions. If multiple in-flight turns become supported, the operation should also accept a turn/request ID.

Required semantics

  • Deliver ACP cancellation through a control/interrupt path that cannot queue behind the prompt being cancelled.
  • Do not discard the prompt producer before it publishes a terminal outcome.
  • Emit exactly one terminal prompt outcome: completed, cancelled, failed, or session closed.
  • Do not return quiescent until the old turn can no longer emit output, request permissions, run tools, or interfere with the next prompt.
  • Report whether the existing ACP session is reusable.
  • Support a bounded hard-cancel policy that closes the adapter session/process when cooperative cancellation does not quiesce.
  • Await adapter process teardown before returning closed.
  • Make repeated/concurrent cancellation calls idempotent.
  • Preserve parity between the Rust and TypeScript clients and the actor action surface.
  • Keep cancellation errors structured; do not collapse them into core/internal_error.

Acceptance tests

  • A delayed mock prompt cooperatively cancels, emits one cancelled terminal result, and the same session accepts an immediate follow-up.
  • An adapter that acknowledges but ignores cancellation reaches the deadline, is closed, and reports sessionReusable: false.
  • The hard-close path leaves no adapter process, prompt resolver, permission request, tool task, or event pump alive.
  • Cancellation while a permission request or tool call is pending settles that work before the API returns.
  • A completion racing cancellation still produces exactly one terminal result.
  • Repeated cancellation calls return a consistent result without duplicate cancellation/close operations.
  • Actor-backed and direct AgentOS clients pass the same lifecycle tests.

Outcome

Products should be able to report idle immediately after this operation returns without implementing their own cancellation timers, prompt listeners, process teardown, session recreation, or quiescence barriers.

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