Skip to content

fix(sessions): notify cloud turn completions in either log order#3682

Merged
trunk-io[bot] merged 1 commit into
mainfrom
fix/cloud-completion-notifications
Jul 22, 2026
Merged

fix(sessions): notify cloud turn completions in either log order#3682
trunk-io[bot] merged 1 commit into
mainfrom
fix/cloud-completion-notifications

Conversation

@charlesvien

@charlesvien charlesvien commented Jul 22, 2026

Copy link
Copy Markdown
Member

Problem

Since #3572, desktop notifications for cloud task completions only fire when _posthog/turn_complete happens to land before the session/prompt response in the log stream. The two writes race in the agent's log stream, so roughly half of all cloud completions never notify at all: no banner, no sound, not even later.

The completedActiveTurn gate from #3572 treats a turn as already notified once currentPromptId is cleared, but the prompt response also clears it. When the response lands first, the turn is disarmed before turn_complete arrives and the notification is suppressed. The old comment claiming "Cloud sessions never see that response" is wrong: the agent taps both directions of the ACP stream into the log, and a survey of 33 completed turns in real session logs found 14 with the response first and 19 with turn_complete first.

Note: this is one of two issues behind the "notifs don't fire until I refocus the app" report. The other (notifications bursting on refocus instead of arriving while the app is backgrounded) is a delivery stall around App Nap and the cloud watcher's permanent give-up, and needs a separate fix.

Changes

Cloud sessions no longer disarm the turn on the session/prompt response; only _posthog/turn_complete does. The response still clears isPromptPending, so spinner behavior is unchanged, and local sessions are untouched. The turn_complete handler now reads the entry's real stopReason instead of hardcoding end_turn, so cancelled or failed turns no longer ring or speak "done". Keeping the turn start time intact until turn_complete also fixes completion sound duration scaling for cloud tasks, which the response previously wiped.

How did you test this?

  • New parameterised cases in cloudTaskUpdateNotifications.test.ts: response before and after turn_complete, duplicate turn_complete after a response-first turn, multi-turn with mixed orderings, a cancelled turn and a duration assertion.
  • Red/green verified: the response-first cases fail on main's sessionService.ts (4 failures) and pass with the fix.
  • @posthog/core: full suite (2490 tests), typecheck and biome lint clean. @posthog/ui: sessions and notifications suites (542 tests) pass after updating one hydration test that encoded the old disarm behavior; workspace typecheck clean.

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

@trunk-io

trunk-io Bot commented Jul 22, 2026

Copy link
Copy Markdown

😎 Merged successfully - details.

@github-actions

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit e72ba82.

@charlesvien
charlesvien marked this pull request as ready for review July 22, 2026 08:23
@greptile-apps

greptile-apps Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "keep cloud turn armed until turn_complet..." | Re-trigger Greptile

@charlesvien
charlesvien marked this pull request as draft July 22, 2026 08:26
@charlesvien
charlesvien marked this pull request as ready for review July 22, 2026 08:26

@richardsolomou richardsolomou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

my b

@greptile-apps

greptile-apps Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Reviews (2): Last reviewed commit: "keep cloud turn armed until turn_complet..." | Re-trigger Greptile

@richardsolomou

Copy link
Copy Markdown
Member

meep

@k11kirky

Copy link
Copy Markdown
Contributor

/trunk merge

@trunk-io
trunk-io Bot merged commit 79e156c into main Jul 22, 2026
44 of 45 checks passed
@trunk-io
trunk-io Bot deleted the fix/cloud-completion-notifications branch July 22, 2026 13:48
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.

3 participants