Skip to content

feat(cloud-agent-next): report pre-dispatch failures durably - #6069

Open
eshurakov wants to merge 2 commits into
mainfrom
eshurakov/tidy-fern
Open

feat(cloud-agent-next): report pre-dispatch failures durably#6069
eshurakov wants to merge 2 commits into
mainfrom
eshurakov/tidy-fern

Conversation

@eshurakov

Copy link
Copy Markdown
Contributor

Summary

An accepted control-plane message could fail during preparation, attachment, or dispatch and never appear in cloud_agent_session_runs: only the legacy CloudAgentSession DO emitted run.state reports, and its emitter swallowed queue-send failures. Operators could not identify the session/message that failed before the wrapper started.

This adds a durable, alarm-driven report obligation to the control-plane SandboxSession DO. The obligation is committed in the same DO transaction as admission, the accepted/terminal common commit, and deletion snapshots, and carries the latest cumulative lifecycle snapshot (identity, queued/accepted/terminal timestamps, evidence-based classification). Delivery reuses the existing report queue and cloud_agent_session_runs projection; a bounded outbox handles retry, capacity, and expiry without changing dispatch/alarm timing or failing a healthy run. A trusted first-admission anchor lets the consumer create the reporting parent for empty/worktree chats, and report snapshots/alarms survive both deletion purge paths.

Key design points:

  • One producer map (telemetry/control-plane-failure.ts); the classifying transition owns the decision. Wrapper/operation-result failure reasons are untrusted text and fall through to unknown/unclassified.
  • Observed vs inferred acceptance is preserved: dispatchAcceptedAt is never fabricated from applyMessageOutcome's completion-time acceptedAt.
  • The outbox CAS token is a unique obligation identity, so an older in-flight send cannot delete a newer terminal snapshot after capacity eviction.
  • Admission atomically rolls back message state if the report obligation cannot be written.

Verification

Manual E2E against a real wrangler dev worker (restarted after the last edit), the in-process report queue consumer, and real Postgres:

  • POST /trpc/start for workspace_355fb352… / msg_08d5046a… with the sandbox killed during preparation. cloud_agent_session_runs showed status=failed, queued_at/terminal_at set, dispatch_accepted_at NULL, failure_stage=pre_dispatch, failure_code=sandbox_connect_failed, failure_responsibility=platform, failure_reason=sandbox_connectivity, and a bounded diagnostic with future expiry. Reproduced on a second session.
  • A baseline no-fault run produced a completed row with dispatch_accepted_at populated.
  • Lazy parent: an empty clone/worktree chat went from 0 to 1 cloud_agent_sessions row on first admission, with created_at = run queued_at and initial_message_id = the first message.
  • Admin listHealthErrorSessions returned both failed sessions with the classification.

Automated (not manual): worker-utils 662 passed, cloud-agent-next focused unit 467 passed, full integration 664 passed, typecheck and lint clean.

Note: the missing_metadata variant is unreachable through the real create API, so the pre-dispatch path was exercised via environment_failed → sandbox_connect_failed.

Visual Changes

N/A

Reviewer Notes

  • Main risk area is outbox concurrency (identity-guarded CAS) and obligation-persistence atomicity; both have focused unit and integration coverage.
  • report-store identity/conflict behavior is covered with a faked DB chain, not real SQL.
  • Capacity/retry bounds are deliberate; this does not claim lossless delivery beyond the existing queue/DLQ policy.

A message admitted through the control-plane API could fail during
preparation, attachment, or dispatch without ever appearing in
cloud_agent_session_runs, because only the legacy DO emitted run.state
reports and its emitter swallowed the send. Operators could not identify
the accepted session/message that had failed before the wrapper started.

Add a durable, alarm-driven report obligation to the control-plane
SandboxSession DO and commit it in the same transaction as admission,
the accepted/terminal common commit, and deletion snapshots. The
obligation carries the latest cumulative lifecycle snapshot and is
delivered through the existing report queue; a bounded outbox handles
retry, capacity, and expiry without changing dispatch or alarm timing or
failing a healthy run. Failures are classified from bounded cause facts
at the committing transition, observed acceptance is never fabricated,
and a trusted first-admission anchor lets the consumer create the
reporting parent for empty/worktree chats. Report snapshots and alarms
are preserved through both deletion purge paths.

Extend focused queue/lifecycle, report-store, report-consumer, and
control-plane failure tests, plus a real DO reporting integration test.
Comment thread services/cloud-agent-next/src/telemetry/control-plane-failure.ts Outdated
Comment thread services/cloud-agent-next/src/sandbox-session/SandboxSession.ts
Comment thread services/cloud-agent-next/test/integration/sandbox-session-reports.test.ts Outdated
@kilo-code-bot

kilo-code-bot Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Overview

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

SUGGESTION

File Line Issue
services/cloud-agent-next/src/sandbox-session/SandboxSession.ts 3491 reportDueAt is read but never folded into the alarm target in armQueueRetry
Files Reviewed (7 files)
  • packages/worker-utils/src/cloud-agent-queue-report.ts
  • services/cloud-agent-next/src/sandbox-session/SandboxSession.ts - 1 issue
  • services/cloud-agent-next/src/sandbox-session/report-outbox.test.ts
  • services/cloud-agent-next/src/telemetry/control-plane-failure.test.ts
  • services/cloud-agent-next/src/telemetry/control-plane-failure.ts
  • services/cloud-agent-next/test/integration/sandbox-session-reports.test.ts
  • services/cloud-agent-next/test/integration/worktree-deletion.test.ts

Fix these issues in Kilo Cloud

Previous Review Summary (commit a1762eb)

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

Previous review (commit a1762eb)

Status: 3 Issues Found | Recommendation: Address before merge

Executive Summary

provider_unknown failures are misclassified as pre-dispatch even for already-accepted runs, producing reports that contain both dispatchAcceptedAt and a pre_dispatch failure stage.

Overview

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

WARNING

File Line Issue
services/cloud-agent-next/src/telemetry/control-plane-failure.ts 71 provider_unknown ignores dispatchState, emitting pre_dispatch alongside dispatchAcceptedAt for accepted runs

SUGGESTION

File Line Issue
services/cloud-agent-next/src/sandbox-session/SandboxSession.ts 3489 reportDueAt is read but never folded into the alarm target in armQueueRetry
services/cloud-agent-next/test/integration/sandbox-session-reports.test.ts 194 Tautological assertion that can never fail
Files Reviewed (18 files)
  • packages/worker-utils/src/cloud-agent-queue-report.test.ts
  • packages/worker-utils/src/cloud-agent-queue-report.ts
  • services/cloud-agent-next/src/sandbox-session/SandboxSession.ts - 1 issue
  • services/cloud-agent-next/src/sandbox-session/report-outbox.test.ts
  • services/cloud-agent-next/src/sandbox-session/report-outbox.ts
  • services/cloud-agent-next/src/sandbox-session/session-message-queue.test.ts
  • services/cloud-agent-next/src/sandbox-session/session-message-queue.ts
  • services/cloud-agent-next/src/sandbox-session/terminal-lifecycle.ts
  • services/cloud-agent-next/src/telemetry/control-plane-failure.test.ts
  • services/cloud-agent-next/src/telemetry/control-plane-failure.ts - 1 issue
  • services/cloud-agent-next/src/telemetry/queue-reports.ts
  • services/cloud-agent-next/src/telemetry/report-consumer.test.ts
  • services/cloud-agent-next/src/telemetry/report-consumer.ts
  • services/cloud-agent-next/src/telemetry/report-store.test.ts
  • services/cloud-agent-next/src/telemetry/report-store.ts
  • services/cloud-agent-next/test/integration/sandbox-control.test.ts
  • services/cloud-agent-next/test/integration/sandbox-session-reports.test.ts - 1 issue
  • services/cloud-agent-next/test/integration/worktree-deletion.test.ts

Fix these issues in Kilo Cloud


Reviewed by deepseek-v4.1-flash · Input: 0 · Output: 0 · Cached: 0

Review guidance: REVIEW.md from base branch main

… post-dispatch

An accepted run that failed as provider_unknown was reported as pre_dispatch/sandbox_connect_failed while also carrying dispatchAcceptedAt. Branch on the observed dispatch state like the sibling reasons, so an accepted run reports post_dispatch_no_activity/wrapper_disconnected.

Also drop a tautological assertion in the reports integration test and apply oxfmt to the files CI flagged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant