fix(cloud-agent-next): reconcile completed kilo turns on wrapper death - #5087
Merged
Conversation
Contributor
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (3 files)
Previous Review Summary (commit 114b3f5)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit 114b3f5)Status: No Issues Found | Recommendation: Merge Files Reviewed (3 files)
Reviewed by kimi-k3 · Input: 67K · Output: 6.4K · Cached: 528.4K Review guidance: REVIEW.md from base branch |
When the wrapper dies after wrapper_finalizing but before its terminal complete, the liveness watchdog (ping/no-output deadline) and disconnect grace expiry blanket-failed all accepted messages as wrapper_failure — even when the DO's own event store already held the completed assistant message (ingest is FIFO, so receiving wrapper_finalizing implies the terminal kilocode events were persisted). Both death paths now reconcile each accepted message against the stored kilocode events first: a terminal assistant error settles as assistant_error (reusing the sealed-batch classification), an assistant reply with time.completed settles as completed via idle_reconciliation, and anything without positive terminal evidence falls back to the previous wrapper_failure behavior unchanged.
eshurakov
force-pushed
the
medieval-clarinet
branch
from
August 6, 2026 12:25
114b3f5 to
431e056
Compare
Contributor
Author
|
Ran manual generic cloud agent verification |
jeanduplessis
approved these changes
Aug 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When the wrapper OOM-dies after emitting
wrapper_finalizingbut before sendingcomplete, the DO liveness watchdog (handleUnhealthyWrapperviawrapper_ping_timeout) and the disconnect-grace expiry terminalize all accepted messages aswrapper_failure— even though the turn actually completed. Incident: 8 sessions posted their work but were reported as failed.Why the DO can settle this itself
Ingest is a single FIFO channel, and the wrapper only emits
wrapper_finalizingaftermessage.updated(time.completed)andsession.idlehave already been sent. Kilo events with an entity id are upserted last-wins into the DO'seventstable, so receivingwrapper_finalizingimplies the DO already holds the terminal assistant state. (Verified via deadline arithmetic on the incident: 7 of 8 sessions provably reachedwrapper_finalizing.)Change
Both wrapper-death paths (ping/no-output deadline, disconnect-grace expiry) now reconcile each accepted message against the DO's stored kilocode events before failing:
info.error→failed/assistant_errorwith the existingclassifyAssistantFailureclassification (extracted into a shared helper also used bysettleSealedBatch)info.time.completedpresent →completedwith the assistant message id,completionSource: 'idle_reconciliation'wrapper_failure/wrapper_disconnectedbehavior, unchangedUnlike the sealed-batch path, bare assistant-message presence is not sufficient here — no wrapper
completevouches for turn finality, so the same completion marker the wrapper itself uses (time.completedor terminal error) is required. Emits a warn log with reconciled/fallback counts for observability.Residual gap: if the final
message.updatednever reached ingest at all, the store has no evidence and the outcome iswrapper_failureas today; closing that needs a live Kilo terminal query or an HTTP terminal assertion (separate work).Verification
cloud-agent-nextunit suite: 2451 passed; death-path integration tests in Workers runtime: 30 passedtsgo --noEmit,oxlint,oxfmtcleanservices/cloud-agent-next/AGENTS.mdinvariant bullet updated