fix(code): fire completion notifications for cloud tasks#2344
Merged
richardsolomou merged 3 commits intoMay 25, 2026
Conversation
Local sessions notify on turn completion via the JSON-RPC `stopReason: "end_turn"` response, but cloud sessions never see that response — their canonical "turn done" signal is the `_posthog/turn_complete` event. The cloud branch of `updatePromptStateFromEvents` was clearing `isPromptPending` on `turn_complete` but never calling `notifyPromptComplete`, so cloud tasks silently finished with no desktop notification, dock badge, or completion sound. Fire `notifyPromptComplete` from the cloud `turn_complete` branch, gated by a new `isLive` parameter on `updatePromptStateFromEvents` so hydration and gap-fill replays of historical logs don't re-fire notifications for turns that already completed in past app runs. Also skip when the queue still has messages — those will start a new turn, mirroring the local `!hasQueuedMessages` check. Generated-By: PostHog Code Task-Id: 093f7d4f-c637-40d7-921c-74e609bdb206
Contributor
Prompt To Fix All With AIFix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
apps/code/src/renderer/features/sessions/service/service.ts:1189-1195
The cloud `turn_complete` notification path is missing the `taskViewedApi.markActivity` call that the local session path makes at line 1311 immediately after `notifyPromptComplete`. Without it, completing a cloud task turn doesn't update `lastActivityAt`, which can leave the sidebar task ordering stale and unread-badge logic inconsistent compared to local sessions.
```suggestion
if (isLive && session.messageQueue.length === 0) {
notifyPromptComplete(
session.taskTitle,
"end_turn",
session.taskId,
);
taskViewedApi.markActivity(session.taskId);
}
```
Reviews (1): Last reviewed commit: "fix(code): fire completion notifications..." | Re-trigger Greptile |
Mirror the local `stopReason: "end_turn"` path which calls `taskViewedApi.markActivity(taskId)` after `notifyPromptComplete`. Without this, completing a cloud turn doesn't bump `lastActivityAt`, leaving sidebar ordering stale and the unread-badge state inconsistent with local sessions. Gate the activity bump on `isLive` for the same reason as the notification — hydration / gap-fill replays must not stamp activity for turns that finished in past app runs. Also collapse the multi-line `notifyPromptComplete` call so biome ci passes. Generated-By: PostHog Code Task-Id: 093f7d4f-c637-40d7-921c-74e609bdb206
k11kirky
approved these changes
May 25, 2026
Contributor
k11kirky
left a comment
There was a problem hiding this comment.
Nits:
-
Comments are too long. 1183-1189 is seven lines explaining what the next nine lines do — about half of it ("Gate on isLive so hydration/gap-fill replays…") is self-evident from the surrounding code structure. The real why — "queued messages start a new turn, so suppress notify" — is the only part that earns a comment. Trim to 1 line.
-
Positional boolean at call sites. updatePromptStateFromEvents(taskRunId, [acpMsg], true) is opaque. An options object ({ isLive: true }) or a named const at the call site would be clearer. Minor.
Generated-By: PostHog Code Task-Id: 5fb5d72d-177e-4557-94f5-82145111de52
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
Cloud tasks never fired completion notifications (desktop notification, dock badge, completion sound) when a turn finished. Local sessions worked because they listen for the JSON-RPC
stopReason: "end_turn"response inhandleSessionEventand callnotifyPromptCompletefrom there. Cloud sessions never see that response — their canonical "turn done" signal is the_posthog/turn_completeevent, and the cloud branch ofupdatePromptStateFromEventswas clearingisPromptPendingonturn_completebut never callingnotifyPromptCompleteortaskViewedApi.markActivity.Permission-request notifications already worked for cloud tasks (via
handleCloudPermissionRequest), so the infrastructure was wired — completion just got missed.Changes
isLiveparameter (defaultfalse) toupdatePromptStateFromEvents.turn_completebranch, whenisLive:notifyPromptComplete(taskTitle, "end_turn", taskId)when the message queue is empty (mirrors the local!hasQueuedMessagesgate — queued messages will start a new turn).taskViewedApi.markActivity(taskId)unconditionally so sidebar ordering and unread badges stay consistent with local sessions.isLive: truefrom the two live entry points:handleSessionEvent(local) andhandleCloudTaskUpdate(cloud delta updates).hydrateCloudTaskSession) and gap-fill (reconcileCloudLogGap) call sites on the defaultfalse, so replaying historical logs after app restart doesn't re-notify or re-stamp activity for turns that completed in past app runs.How did you test this?
pnpm --filter code typecheck) — clean.pnpm exec biome ci apps/code/src/renderer/features/sessions/service/service.ts) — clean.pnpm --filter code test) — all 1436 non-environmental tests pass; the only failures are pre-existingarchive/service.integration.test.tscases that fail because the sandbox blocks unsignedgit commit, unrelated to this change.Publish to changelog?
no