fix(mobile): stop false "task failed" notifications for stale/cancelled runs#2462
Draft
k11kirky wants to merge 1 commit into
Draft
fix(mobile): stop false "task failed" notifications for stale/cancelled runs#2462k11kirky wants to merge 1 commit into
k11kirky wants to merge 1 commit into
Conversation
…ed runs
Mobile fired "<task> failed" notifications for tasks the user had simply
finished with. Two causes:
1. mapTerminalStatus collapsed the backend "cancelled" status into "failed".
A cancelled run (sandbox stopped / user finished) is a normal lifecycle
end, not a failure, but it was surfaced as "Run failed" and pushed a
"<task> failed" notification. Cancelled is now a distinct terminal state
("Run stopped") and never pings as a failure.
2. The terminal-status notification fired on stale reconnects. awaitingPing
is deliberately preserved across snapshots, so reconnecting to a run that
ended (failed/cancelled) while the device was away re-fired a terminal
notification for a run the user had already moved on from. We now thread
the run's updated_at through status/snapshot updates and suppress the ping
when the terminal transition is older than 2 minutes (missing timestamp is
treated as fresh, so genuine just-happened alerts are never suppressed).
Adds taskSessionStore.test.ts covering: no ping for cancelled, ping for a
recent failure, no ping for a stale failure, no ping when not awaiting, and a
completion ping.
Generated-By: PostHog Code
Task-Id: 8bca0c4c-ff31-41f6-9f20-0fd2a4e91860
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
As a user of both the desktop and mobile apps, you frequently get "XYZ failed" push notifications from mobile for tasks that are stale with no activity — tasks that didn't fail, you'd simply finished with them.
The "XYZ failed" body is produced in
taskSessionStore.maybePresentLocalNotification, fired from the terminal-status branch of_handleCloudUpdate. Two design choices combined to cause false alerts:cancelledwas mislabeled asfailed.mapTerminalStatuscollapsed the backendcancelledstatus intofailed. When a cloud sandbox is stopped/reaped after you finish with a task, the run goescancelled— and the app showed "Run failed" and pushed "XYZ failed". (A genuine user cancel mid-turn comes back as_posthog/turn_complete, socancelledas a run status overwhelmingly means "stopped", not "failed".)Stale reconnects re-fired the notification. By design, snapshots don't clear
awaitingPingso the terminal-status block can own the terminal ping. But it didn't distinguish recent from long-ago: reconnecting to a run that ended while you were away, withawaitingPingstill armed from your last prompt, re-fired "XYZ failed" for something you finished with hours earlier.Changes
mapTerminalStatuskeepscancelledas a distinct terminal state instead of collapsing it intofailed. Cancelled runs now show a neutral "Run stopped" banner (success styling, "Continue" action) and never fire a failure notification.updated_at(already tracked aswatcher.lastStatusUpdatedAt) throughstatus/snapshotupdates asstatusUpdatedAt, and suppress the terminal ping when the transition is older than 2 minutes. A missing/unparseable timestamp is treated as fresh, so genuine just-happened terminal alerts are never suppressed.logspath (a_posthog/errorarriving while you're actively waiting) is unchanged — that's a real, just-happened failure and still notifies.TerminalStatusBannercomponent to cleanly handle the three states.Frontend behavior change (no screenshot — node/vitest env): cancelled runs render "Run stopped" instead of "Run failed".
How did you test this?
taskSessionStore.test.ts(5 cases): no ping for a cancelled run, ping for a recent failed run, no ping for a stale failed run (reconnect snapshot), no ping when not awaiting a ping, and a completion ping. All pass.npx vitest run src/features/tasks→ 20 files / 75 tests pass.npx tsc --noEmitclean for all changed source files;biome checkclean on changed files. (Pre-existing, unrelated tsc errors remain from test-infra typings and the unbuilt@posthog/sharedpackage.)Automatic notifications
Created with PostHog Code