rivet-dev / rivet-dev/agentos

Add an awaited terminal cancellation API for ACP prompts

Open
#1,760 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
4.6k
Forks
251
Avg merge
2d 15h
Merged PRs (30d)
34

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with crates/client/src/session.rs, packages/core/src/agent-os.ts, and crates/agentos-actor-plugin/src/actions/session.rs to trace cancellation, prompt producers, and terminal outcomes. Use the listed delayed, ignoring, permission, tool, race, repeated-call, and actor/direct-client scenarios as acceptance tests. Done means both clients and the actor action expose parity, quiescence or hard-close is awaited, and exactly one terminal result is emitted.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, typescript
Domain
api, backend, testing-qa
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.