Skip to content

feat(agent-composer): add message identity and queue cancel APIs - #5537

Merged
iscekic merged 4 commits into
mainfrom
agent-composers-c07a
Aug 28, 2026
Merged

feat(agent-composer): add message identity and queue cancel APIs#5537
iscekic merged 4 commits into
mainfrom
agent-composers-c07a

Conversation

@iscekic

@iscekic iscekic commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Cloud sessions support canceling one waiting message without stopping the current task. Canceled messages disappear from the conversation and stay removed after reconnecting.

SessionMessageQueue.cancelQueuedMessage drops only queued work, repairs legacy state when possible, and leaves accepted or terminal messages untouched. SessionMessageCompletionSourceSchema adds canceled, keeping canceled IDs terminal, rejecting readmission, and excluding them from reconnect catch-up. Retries after completed cancellation return { dropped: true } so CloudAgentSession can persist one cloud.message.canceled event; unknown IDs return { dropped: false }.

Files
  • services/cloud-agent-next/src/session/session-message-queue.ts — modified source; 56 changed lines; records cancellation before deleting the pending row, without scheduling a cloud.message.failed event.
  • services/cloud-agent-next/src/session/session-message-state.ts — modified source; 1 changed line; accepts canceled as a completion source without changing existing states.
  • services/cloud-agent-next/src/persistence/CloudAgentSession.ts — modified source; 36 changed lines; stores and broadcasts a unique cancellation event for live delivery and replay.
  • services/cloud-agent-next/src/session/session-message-queue.test.ts — modified test; 106 changed lines; expands the message queue tests.
  • services/cloud-agent-next/test/integration/session/pending-messages.test.ts — modified test; 85 changed lines; expands the pending-message integration tests.

The personal and organization cancelQueuedMessage mutations return { dropped: boolean } after ownership checks; organization calls also require membership. baseCancelQueuedMessageNextSchema and CancelQueuedMessageInput carry sessionId and a canonical messageId; organization requests also require organizationId. CloudAgentNextTRPCClient.cancelQueuedMessage forwards authenticated requests; the worker validates MessageIdSchema, rechecks current access, and retries the Durable Object call.

Files
  • apps/web/src/lib/cloud-agent-next/cloud-agent-client.ts — modified source; 29 changed lines; adds the cancellation input, typed mutation, and client method with error reporting and propagation.
  • apps/web/src/routers/cloud-agent-next-router.ts — modified source; 17 changed lines; adds cancellation with personal ownership checks and a boolean result.
  • apps/web/src/routers/cloud-agent-next-schemas.ts — modified source; 6 changed lines; requires the canonical message ID for cancellation requests.
  • apps/web/src/routers/organizations/organization-cloud-agent-next-router.ts — modified source; 25 changed lines; adds organization-scoped cancellation with membership and ownership checks.
  • services/cloud-agent-next/src/router/handlers/session-management.ts — modified source; 45 changed lines; adds guarded cancellation with durable retries and removes a comment spacer.
  • apps/web/src/routers/cloud-agent-next-router.test.ts — modified test; 29 changed lines; updates the personal router tests.
  • apps/web/src/routers/cloud-agent-next-schemas.test.ts — modified test; 23 changed lines; updates the request-schema tests.
  • apps/web/src/routers/organizations/organization-cloud-agent-next-router.test.ts — modified test; 35 changed lines; updates the organization router tests.

The software development kit (SDK) adds CloudAgentSession.cancelQueuedMessage and SessionManager.cancelQueuedMessage through optional Transport.dropQueuedMessage and CloudAgentApi.cancelQueuedMessage hooks. Legacy providers remain compatible; unsupported calls fail without interrupting, and the manager does nothing without an active session. ServiceEvent and cloudMessageCanceledDataSchema validate cloud.message.canceled, which removes the pending entry and local message and invokes onMessageCanceled through ServiceStateConfig and CloudAgentSessionConfig.

Files
  • packages/cloud-agent-sdk/src/transport.ts — modified source; 16 changed lines; adds optional cancellation contracts so existing transports and providers still compile.
  • packages/cloud-agent-sdk/src/cloud-agent-transport.ts — modified source; 6 changed lines; binds cancellation to the cloud session and rejects calls without the provider hook.
  • packages/cloud-agent-sdk/src/session-manager.ts — modified source; 12 changed lines; delegates cancellation and passes errors through without falling back to interruption.
  • packages/cloud-agent-sdk/src/session.ts — modified source; 14 changed lines; exposes cancellation and its callback, then deletes the local message when the cancellation event arrives.
  • packages/cloud-agent-sdk/src/normalizer.ts — modified source; 23 changed lines; validates cancellation events with a message ID and an optional execution ID.
  • packages/cloud-agent-sdk/src/service-state.ts — modified source; 13 changed lines; removes the pending entry, invokes the cancellation callback, and notifies subscribers.
  • packages/cloud-agent-sdk/src/cloud-agent-transport.test.ts — modified test; 15 changed lines; updates the cloud transport tests.
  • packages/cloud-agent-sdk/src/session-manager.test.ts — modified test; 18 changed lines; updates the session manager tests.
  • packages/cloud-agent-sdk/src/session-transport.test.ts — modified test; 32 changed lines; updates the session transport tests.

send_message now includes messageID when the caller supplies one, keeping queued turns tied to the caller's identity. drop_queued_message sends { protocolVersion: 1, messageID } to the current owner, and the relay permits that command. Calls without a message ID keep the old send shape; unsupported remotes return CLI_UPGRADE_REQUIRED rather than triggering interrupt.

Files
  • packages/cloud-agent-sdk/src/cli-live-transport.ts — modified source; 6 changed lines; forwards prompt identity and sends the cancellation command to the current owner.
  • services/session-ingest/src/dos/UserConnectionDO.ts — modified source; 4 changed lines; allows cancellation and maps the exact unsupported-command reply to the upgrade-required error.
  • packages/cloud-agent-sdk/src/cli-live-transport.test.ts — modified test; 68 changed lines; updates the remote transport tests.

Tests: 9 test files modified, totaling 411 changed lines across the named router, schema, transport, session, queue, and integration tests.
Generated: 0 files changed.


Visual Changes

Visual Changes: N/A

Verification

E2E report not attached. Runtime verification (E2E, user advocacy, simplify) runs on the tip PR over every level of this 6-level stack, so this level carries no manual verification.

The cumulative report belongs to tip PR 5617.

Human steps

No new environment values, secrets, database migrations, or data backfills are required.

Reviewer Notes

This is level 1 of a 6-level stacked set of PRs. Merge bottom to top. Runtime verification (E2E, user advocacy, simplify) runs on the tip PR over every level.

Cumulative runtime verification and its limits are recorded in #5617.

Current-head CI and Kilobot approve this PR.

This level adds message identity and cancellation contracts, without new interface controls or the remote sender implementation.

The comparison contains 25 modified files: 16 source files and 9 test files, with 717 insertions and 3 deletions. Each file size counts changed lines from the supplied statistics, not its full length.

Repository Worktree Scope
Kilo-Org/cloud /Users/igor/Projects/.worktrees/agent-composers-c07a Describe only origin/main...5b47fbea5fd57ceb366bc033e094bf8906f6c53c; the checkout is on agent-composers-c07a-s6.
Kilo-Org/kilocode /Users/igor/Projects/.worktrees/agent-composers-c07a-kilocode Reference only; branch agent-composers-c07a; remote sender PR 13496.

Stacked PRs — merge bottom to top. Each level shows only its own diff.

Runtime verification (E2E, user advocacy, simplify) runs on the tip PR over every level.
Every level keeps its own checks, its own bot review, and its own threads; each one is answered on its own PR.
Each level is its own deliverable: it builds and passes its own checks alone.
A finding on a level is repaired on that level, then carried upward with stack.sh forward.

  1. agent-composers-c07afeat(agent-composer): add message identity and queue cancel APIs #5537
  2. agent-composers-c07a-s2feat(mobile): pre-upload attachments and release abandoned files #5538
  3. agent-composers-c07a-s3feat(mobile): reorder composer attachments with drag and a11y moves #5540
  4. agent-composers-c07a-s4feat(agent-composer): render sent messages immediately and cancel queued ones #5589
  5. agent-composers-c07a-s5feat(mobile): keep agent composers editable during live dictation #5607
  6. agent-composers-c07a-s6feat(mobile): adapt agent composers for keyboard, height, and preferences #5617 (tip)

@iscekic iscekic self-assigned this Aug 27, 2026
@kilo-code-bot

kilo-code-bot Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (25 files)
  • apps/web/src/lib/cloud-agent-next/cloud-agent-client.ts
  • apps/web/src/routers/cloud-agent-next-router.test.ts
  • apps/web/src/routers/cloud-agent-next-router.ts
  • apps/web/src/routers/cloud-agent-next-schemas.test.ts
  • apps/web/src/routers/cloud-agent-next-schemas.ts
  • apps/web/src/routers/organizations/organization-cloud-agent-next-router.test.ts
  • apps/web/src/routers/organizations/organization-cloud-agent-next-router.ts
  • packages/cloud-agent-sdk/src/cli-live-transport.test.ts
  • packages/cloud-agent-sdk/src/cli-live-transport.ts
  • packages/cloud-agent-sdk/src/cloud-agent-transport.test.ts
  • packages/cloud-agent-sdk/src/cloud-agent-transport.ts
  • packages/cloud-agent-sdk/src/normalizer.ts
  • packages/cloud-agent-sdk/src/service-state.ts
  • packages/cloud-agent-sdk/src/session-manager.test.ts
  • packages/cloud-agent-sdk/src/session-manager.ts
  • packages/cloud-agent-sdk/src/session-transport.test.ts
  • packages/cloud-agent-sdk/src/session.ts
  • packages/cloud-agent-sdk/src/transport.ts
  • services/cloud-agent-next/src/persistence/CloudAgentSession.ts
  • services/cloud-agent-next/src/router/handlers/session-management.ts
  • services/cloud-agent-next/src/session/session-message-queue.test.ts
  • services/cloud-agent-next/src/session/session-message-queue.ts
  • services/cloud-agent-next/src/session/session-message-state.ts
  • services/cloud-agent-next/test/integration/session/pending-messages.test.ts
  • services/session-ingest/src/dos/UserConnectionDO.ts
Previous Review Summaries (2 snapshots, latest commit c347899)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit c347899)

Status: 2 Issues Found | Recommendation: Address before merge

Fix these issues in Kilo Cloud

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
services/cloud-agent-next/src/session/session-message-queue.ts 1228 Cancel is not idempotent under withDORetry; a lost success response retries as { dropped: false } and skips the canceled replay event
services/cloud-agent-next/src/session/session-message-queue.ts 1252 { dropped: true } is returned for any leftover pending row, including accepted or terminal messages, so clients can delete a running or finished turn
Files Reviewed (24 files)
  • apps/web/src/lib/cloud-agent-next/cloud-agent-client.ts - 0 issues
  • apps/web/src/routers/cloud-agent-next-router.test.ts - 0 issues
  • apps/web/src/routers/cloud-agent-next-router.ts - 0 issues
  • apps/web/src/routers/cloud-agent-next-schemas.test.ts - 0 issues
  • apps/web/src/routers/cloud-agent-next-schemas.ts - 0 issues
  • apps/web/src/routers/organizations/organization-cloud-agent-next-router.test.ts - 0 issues
  • apps/web/src/routers/organizations/organization-cloud-agent-next-router.ts - 0 issues
  • packages/cloud-agent-sdk/src/cli-live-transport.test.ts - 0 issues
  • packages/cloud-agent-sdk/src/cli-live-transport.ts - 0 issues
  • packages/cloud-agent-sdk/src/cloud-agent-transport.test.ts - 0 issues
  • packages/cloud-agent-sdk/src/cloud-agent-transport.ts - 0 issues
  • packages/cloud-agent-sdk/src/normalizer.ts - 0 issues
  • packages/cloud-agent-sdk/src/service-state.ts - 0 issues
  • packages/cloud-agent-sdk/src/session-manager.test.ts - 0 issues
  • packages/cloud-agent-sdk/src/session-manager.ts - 0 issues
  • packages/cloud-agent-sdk/src/session-transport.test.ts - 0 issues
  • packages/cloud-agent-sdk/src/session.ts - 0 issues
  • packages/cloud-agent-sdk/src/transport.ts - 0 issues
  • services/cloud-agent-next/src/persistence/CloudAgentSession.ts - 0 issues
  • services/cloud-agent-next/src/router/handlers/session-management.ts - 0 issues
  • services/cloud-agent-next/src/session/session-message-queue.ts - 2 issues
  • services/cloud-agent-next/src/session/session-message-state.ts - 0 issues
  • services/cloud-agent-next/test/integration/session/pending-messages.test.ts - 0 issues
  • services/session-ingest/src/dos/UserConnectionDO.ts - 0 issues

Previous review (commit 445fe65)

Status: 2 Issues Found | Recommendation: Address before merge

Fix these issues in Kilo Cloud

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
services/cloud-agent-next/src/session/session-message-queue.ts 1228 Cancel is not idempotent under withDORetry; a lost success response retries as { dropped: false } and skips the canceled replay event
services/cloud-agent-next/src/session/session-message-queue.ts 1252 { dropped: true } is returned for any leftover pending row, including accepted or terminal messages, so clients can delete a running or finished turn
Files Reviewed (24 files)
  • apps/web/src/lib/cloud-agent-next/cloud-agent-client.ts - 0 issues
  • apps/web/src/routers/cloud-agent-next-router.test.ts - 0 issues
  • apps/web/src/routers/cloud-agent-next-router.ts - 0 issues
  • apps/web/src/routers/cloud-agent-next-schemas.test.ts - 0 issues
  • apps/web/src/routers/cloud-agent-next-schemas.ts - 0 issues
  • apps/web/src/routers/organizations/organization-cloud-agent-next-router.test.ts - 0 issues
  • apps/web/src/routers/organizations/organization-cloud-agent-next-router.ts - 0 issues
  • packages/cloud-agent-sdk/src/cli-live-transport.test.ts - 0 issues
  • packages/cloud-agent-sdk/src/cli-live-transport.ts - 0 issues
  • packages/cloud-agent-sdk/src/cloud-agent-transport.test.ts - 0 issues
  • packages/cloud-agent-sdk/src/cloud-agent-transport.ts - 0 issues
  • packages/cloud-agent-sdk/src/normalizer.ts - 0 issues
  • packages/cloud-agent-sdk/src/service-state.ts - 0 issues
  • packages/cloud-agent-sdk/src/session-manager.test.ts - 0 issues
  • packages/cloud-agent-sdk/src/session-manager.ts - 0 issues
  • packages/cloud-agent-sdk/src/session-transport.test.ts - 0 issues
  • packages/cloud-agent-sdk/src/session.ts - 0 issues
  • packages/cloud-agent-sdk/src/transport.ts - 0 issues
  • services/cloud-agent-next/src/persistence/CloudAgentSession.ts - 0 issues
  • services/cloud-agent-next/src/router/handlers/session-management.ts - 0 issues
  • services/cloud-agent-next/src/session/session-message-queue.ts - 2 issues
  • services/cloud-agent-next/src/session/session-message-state.ts - 0 issues
  • services/cloud-agent-next/test/integration/session/pending-messages.test.ts - 0 issues
  • services/session-ingest/src/dos/UserConnectionDO.ts - 0 issues

Reviewed by grok-4.6 · Input: 149.4K · Output: 12.9K · Cached: 321.7K

Review guidance: REVIEW.md from base branch main

@iscekic iscekic added the human-ready The PR is ready for human review. label Aug 28, 2026
@iscekic
iscekic requested a review from eshurakov August 28, 2026 07:37
@eshurakov

Copy link
Copy Markdown
Contributor

@iscekic from what I remember cancellation is possible only while message is not sent to Kilo. For example when sandbox is being prepared. In all other cases a message is sent to Kilo and I'm not sure if we can cancel it at that moment

@iscekic

iscekic commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

@eshurakov Correct. cancelQueuedMessage drops a message only while its state is queued (worker-side hold, sandbox prep, or waiting behind the running turn). Once the runtime accepts it, the call returns { dropped: false } and the client falls back to interrupt. See services/cloud-agent-next/src/session/session-message-queue.ts (existing?.status !== 'queued' guard).

@iscekic
iscekic merged commit 5ef0c65 into main Aug 28, 2026
26 checks passed
@iscekic
iscekic deleted the agent-composers-c07a branch August 28, 2026 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

human-ready The PR is ready for human review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants