Skip to content

fix(code): fire completion notifications for cloud tasks#2344

Merged
richardsolomou merged 3 commits into
mainfrom
posthog-code/fix-cloud-task-completion-notifications
May 25, 2026
Merged

fix(code): fire completion notifications for cloud tasks#2344
richardsolomou merged 3 commits into
mainfrom
posthog-code/fix-cloud-task-completion-notifications

Conversation

@richardsolomou
Copy link
Copy Markdown
Member

@richardsolomou richardsolomou commented May 25, 2026

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 in handleSessionEvent and call notifyPromptComplete from there. Cloud sessions never see that response — their canonical "turn done" signal is the _posthog/turn_complete event, and the cloud branch of updatePromptStateFromEvents was clearing isPromptPending on turn_complete but never calling notifyPromptComplete or taskViewedApi.markActivity.

Permission-request notifications already worked for cloud tasks (via handleCloudPermissionRequest), so the infrastructure was wired — completion just got missed.

Changes

  • Add an isLive parameter (default false) to updatePromptStateFromEvents.
  • In the cloud turn_complete branch, when isLive:
    • Fire notifyPromptComplete(taskTitle, "end_turn", taskId) when the message queue is empty (mirrors the local !hasQueuedMessages gate — queued messages will start a new turn).
    • Call taskViewedApi.markActivity(taskId) unconditionally so sidebar ordering and unread badges stay consistent with local sessions.
  • Pass isLive: true from the two live entry points: handleSessionEvent (local) and handleCloudTaskUpdate (cloud delta updates).
  • Leave hydration (hydrateCloudTaskSession) and gap-fill (reconcileCloudLogGap) call sites on the default false, 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?

  • Typecheck (pnpm --filter code typecheck) — clean.
  • Biome (pnpm exec biome ci apps/code/src/renderer/features/sessions/service/service.ts) — clean.
  • Unit tests (pnpm --filter code test) — all 1436 non-environmental tests pass; the only failures are pre-existing archive/service.integration.test.ts cases that fail because the sandbox blocks unsigned git commit, unrelated to this change.
  • Did NOT exercise the full Electron app end-to-end. Worth a manual smoke test before merging: run a cloud task to completion and confirm desktop notification, dock badge, completion sound, and sidebar activity bump all fire.

Publish to changelog?

no

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
@richardsolomou richardsolomou requested a review from a team May 25, 2026 03:46
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 25, 2026

Prompt To Fix All With AI
Fix 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

Comment thread apps/code/src/renderer/features/sessions/service/service.ts Outdated
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
Copy link
Copy Markdown
Contributor

@k11kirky k11kirky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nits:

  1. 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.

  2. 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
@richardsolomou richardsolomou enabled auto-merge (squash) May 25, 2026 11:52
@richardsolomou richardsolomou merged commit 750d4ae into main May 25, 2026
15 checks passed
@richardsolomou richardsolomou deleted the posthog-code/fix-cloud-task-completion-notifications branch May 25, 2026 11:58
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.

2 participants