Repository navigation
fix(mobile): no3y push only alerts finishes that need the owner - #585
Conversation
The Mac push service alerted every listed thread's finished turn, so a sprint sent ~300 pushes a day: quiet "Nothing to report." wakes, every child's finish (which the sprint then reports again) and turns the owner watched. A finish now stays off the phone when a bot's wake made no report, when it is a bot's work (its bot reports it), or when the owner started it and a client had the thread open as it finished. A finish within 2 minutes of the last sounding alert arrives passive. Waits and failures unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
NoahHendrickson
left a comment
There was a problem hiding this comment.
Code review of 33ffcdf6d4: one finding.
The rest checks out against the code it mirrors:
isQuietBotWakematches the desktop'sisQuietBotCompletionand thefork_bot_report_jsonprojection (newest settled, non-quiet final reply).- The bot-work rule matches the gates in
forkBotWorkReports.report: bot tag, not archived, not deleted (the tracker forgets deleted threads), listed lineage. - Judging on the latest shell when the hold ends is right.
threadVisitsdispatches a visit at once on an unseen completion (hasUnseenCompletion), so it lands well inside the 5 s hold. - The burst gate only records sounding sends, and waits and failures always sound and reset it.
CI was still pending when this was posted. I did not run the tests locally because this worktree has no node_modules.
🤖 Signed: Claude Opus 5.5 (claude-opus-5-5) via Claude Code
|
|
||
| /** The owner started the turn and a client had the thread open when it finished, the server's | ||
| "watched" test for work reports (forkBotWorkReports). An open thread records a visit at once. */ | ||
| function ownerWatchedFinish(thread: ObservedThread) { |
There was a problem hiding this comment.
An open window isn't a watched one, so this mutes the push the phone exists for. lastVisitedAt advances whenever any client has the thread mounted. On web that's ThreadVisitWatermark inside ChatView, and nothing checks document.visibilityState or window focus. The Electron app keeps its shell stream live while hidden or minimised.
Scenario: the owner sends a turn from the Mac, leaves the app on that thread, and walks away. The turn finishes. The desktop's tracker sees an unseen completion and dispatches a visit at once. By the end of the 5 s hold, lastVisitedAt >= latestRunCompletedAt, so this returns "the owner watched it" and the phone gets nothing. Before this PR it pushed.
It compounds on bot work. The server's ownerWasThere uses the same signal, so it sends the bot a watched report and tells it to reply "Nothing to report." With this PR, the work thread's own finish is also muted because its bot is present, so neither path reaches the phone.
The server tolerates this signal because its cost there is one quiet bot update. Here the cost is a missed alert. Possible fixes: gate this rule on a stronger signal (only clients that are visible or focused advance the watermark, which is a client-runtime change and outside this PR's fork-only scope), or drop the watched rule and let the 2-minute passive burst gate handle the noise from owner-started turns.
There was a problem hiding this comment.
Not changing this. It is the owner's decision. Before I wrote the code I asked them to confirm the rule, and the question gave this exact caveat for rule 4: "a thread left open on an unattended Mac counts as seen". It also offered "Proposed, without rule 4" as an option. They picked the rule with the watched skip. The bot-work case you point out comes from that same choice: an owner-started child turn with the window open counts as watched on both the server and the phone. I'll repeat the tradeoff to the owner when I hand back the PR, so they can drop rule 4 if it bites. Gating visits on focus would need a client-runtime change, which is out of scope for this fork-only fix.
NoahHendrickson
left a comment
There was a problem hiding this comment.
Code-quality review of 33ffcdf6d417ebcbb5f6f6ec55beeaa38394ba8d. I'm leaving comments, not approving.
The rules are a good fit for the problem, and the burst gate is small and direct. The structure needs work in a few places, most important first:
- There are now two silence pipelines. The service already had one place that decides whether an alert stays off the phone:
alertUnlessSilent, which logssilent "…" for …. This PR adds a second one inside the tracker's settle timer, plus a newTracker.onSilentcallback that defaults to a no-op and exists only to log. The tracker's job was to detect transitions, and policy came afternotify. Now policy is split across both layers, with two log formats. The tracker is the right place to capture the latest shell when the hold ends, but the decision should live in one gate. For example, put the shell-derived reason onAlertRun(or pass the end-of-hold shell along), and havealertUnlessSilentcheck it first using its existing log line. That removesonSilent, the fourthmakeTrackerparameter and its dead default. It also puts every silence rule in one function, which is also the natural thing to pull out into its own module as this 885-line file grows. - This re-implements canonical bot rules instead of sharing them.
isQuietBotWakeisisQuietBotCompletionfromapps/web/src/custom/bots/botThreads.tswith DateTime instead of ISO strings. The "its bot reports it" check is a narrower copy of the server'sforkBotWorkOwnerIdplus the guard at the top ofreport()inforkBotWorkReports.ts(bot tag, not archived, not deleted). Both are pure functions over tags, lineage and shell fields. They belong in@t3tools/shared/forkBotTags, used by the server, web and the push service. That is not a server behaviour change; it only means the three copies can't drift. The PR description says the desktop and server behave this way, so make that true by construction. - The "owner watched it" check is an inference that's documented as the server's test. The server decides from
message.createdBy === "user"on the run's ownuserMessageId. Here it's inferred fromlatestUserAuthoredMessageAt >= latestRunRequestedAt. Those come from different rows: the first is theupdated_atof the latest owner message, not of this run's message. One way they disagree: a wake is queued, the owner sends a message behind it, and the wake's run finishes first. Either say in the comment that this is an approximation, or carry the real fact. - The type boundary.
completion?: booleanis set through a conditional spread from its only constructor, andapnsPayloadtakes a positionalquiet = falseboolean. A requiredcompletion: state.phase === "completed"removes the optional and the spread.
Not blocking: the ?? thread fallback in the settle timer can't be reached, and silentCompletionReason is exported but nothing imports it. See the inline comments.
🤖 Signed: Claude Opus 5.5 (claude-opus-5-5) via Claude Code
| readonly threadId: string; | ||
| readonly deepLink: string; | ||
| /** A finished turn, which may arrive silently in a burst; waits and failures always sound. */ | ||
| readonly completion?: boolean; |
There was a problem hiding this comment.
This is optional only because of the conditional spread in notificationForState, its only constructor. A required readonly completion: boolean set to state.phase === "completed" removes both.
There was a problem hiding this comment.
Done in 9e0d784. completion is now required and set to state.phase === "completed". notificationForState isn't its only constructor: the pairing-expiry warning and the test command build one too. Both now pass completion: false.
| /** Called after every applied shell item; the Live Activity card is derived from the threads. */ | ||
| readonly onChange: () => void; | ||
| /** A held completion the rules kept off the phone. */ | ||
| readonly onSilent: (threadId: string, reason: string) => void; |
There was a problem hiding this comment.
This adds a second silence channel next to alertUnlessSilent, and it only exists to log. The default () => {} on makeTracker is never used: both callers pass a callback. Can the shell-derived reason go to the existing gate (for example on AlertRun), so every silence rule and its log line live in one place?
There was a problem hiding this comment.
Done in 9e0d784. The tracker now puts its reason on AlertRun.silentReason, and alertUnlessSilent checks that first (before its fetch) and logs it with its existing silent "…" for … line. onSilent, the fourth makeTracker parameter and its default are gone, and so is the export of silentCompletionReason.
| /** A bot's wake ended on "Nothing to report.": the server's report (latestVisibleMessage on a | ||
| bot's shell) skips quiet replies, so none is newer than the run. As the desktop's | ||
| isQuietBotCompletion. */ | ||
| function isQuietBotWake(thread: ObservedThread) { |
There was a problem hiding this comment.
This is isQuietBotCompletion (apps/web/src/custom/bots/botThreads.ts) written again. Can we move one version into @t3tools/shared/forkBotTags and call it from both, so the push service can never disagree with the desktop about what counts as a quiet wake?
There was a problem hiding this comment.
Leaving the copy here for now. Sharing it means changing the web's botThreads.ts. The web version also works on the presented thread's ISO strings, while this one reads shell DateTimes, so the shared signature has to give somewhere. The PR is scoped to the push service, so I've listed this as a follow-up. The doc comment names isQuietBotCompletion so the pair stays easy to find.
|
|
||
| /** The owner started the turn and a client had the thread open when it finished, the server's | ||
| "watched" test for work reports (forkBotWorkReports). An open thread records a visit at once. */ | ||
| function ownerWatchedFinish(thread: ObservedThread) { |
There was a problem hiding this comment.
The comment calls this "the server's watched test", but the server checks whether the run's own message has createdBy === "user". Here, "owner started it" is inferred by comparing the updated_at of the latest owner message with latestRunRequestedAt. Those come from different rows, so a queued wake that finishes before an owner message queued behind it counts as owner-started. Please describe it as an approximation, or base it on the run's actual origin. Also, DateTime.isGreaterThanOrEqualTo with early returns on null would read more directly than !isLessThan behind four != null checks.
There was a problem hiding this comment.
Done in 9e0d784. The comment and the manifest now say it is an approximation (the shell has no run origin, so an owner message at or after the run's request stands in for it), and it uses isGreaterThanOrEqualTo with an early return on null. In the queued-wake case you describe, the owner had just sent a message to the thread they had open, so skipping that finish seems acceptable. Carrying the real origin would need a new shell field, which means a contracts and server change.
| if (isForkBotThread(thread.tags) && isQuietBotWake(thread)) return "nothing to report"; | ||
| // The server wakes the bot with a work report for this finish, and the bot reports it. | ||
| const botId = forkBotWorkOwner(thread.tags); | ||
| const bot = botId === null ? undefined : tracker.threads.get(botId); |
There was a problem hiding this comment.
This is a narrower copy of the server's rule for whether a bot hears about this finish: forkBotWorkOwnerId plus the guard in report(), which also checks deletedAt. Those are pure functions over tags and lineage. Move them into @t3tools/shared/forkBotTags and reuse them here, so the "its bot reports it" claim stays true when the server rule changes.
There was a problem hiding this comment.
Leaving this for now. Moving forkBotWorkOwnerId and the report() guard into shared would mean editing apps/server, and this PR deliberately touches no server code. The check here already uses the shared forkBotWorkOwner and isForkBotThread. It also covers deletedAt, because the tracker forgets removed threads (thread.removed calls forgetThread), and it only runs for listed threads. I've listed the shared predicate as a follow-up.
| if (tracker.lastKeys.get(thread.id) === key) tracker.notify(notificationForState(state), run); | ||
| if (tracker.lastKeys.get(thread.id) !== key) return; | ||
| // An open thread's visit lands after the completion itself, so judge the latest shell. | ||
| const reason = silentCompletionReason(tracker, tracker.threads.get(thread.id) ?? thread); |
There was a problem hiding this comment.
?? thread can't be reached. forgetThread deletes threads and lastKeys together, so the lastKeys check on the line above has already returned. The fallback hides that invariant; I'd read tracker.threads.get(thread.id) and treat a missing shell as forgotten, or drop the fallback.
There was a problem hiding this comment.
Done in 9e0d784. The timer now reads tracker.threads.get(thread.id) and returns when it is missing, with a one-line note that forgetThread drops the shell and the key together.
Review follow-ups: the tracker puts its shell-derived reason on AlertRun and alertUnlessSilent drops it with its existing log line, so onSilent is gone. completion is a required field, the watched rule says it is an approximation, and the settle timer treats a forgotten shell as forgotten. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The phone gets far too many pushes during sprint work. The Mac push service (
apps/mobile/fork/push-service/no3yPush.mts) alerted every listed thread's finished turn. In 29 hours of one sprint it sent 302 pushes:The full audit is in the sprint library (
context/push-notification-audit.md).The rule below is the one the owner approved. Everything is judged on the latest thread shell when the existing 5 s completion hold ends.
latestVisibleMessage) is newer than the run. That report skips quiet replies, so a "Nothing to report." wake stays silent, as the desktop already does (isQuietBotCompletion).bot-work:<bot>thread never pushes a finish while its bot is present and unarchived.forkBotWorkReportswakes the bot to report that finish.lastVisitedAtat or after completion). This is the same "watched" test the server uses for work reports.interruption-level: passiveand no sound. It still shows on the lock screen.On the same 29 hours this projects to about 92 pushes, about 68 of them with sound. That is an upper bound on the savings, since it assumes the owner watched every turn they started.
The change is fork-only: the push service, its tests, and the
no3y-pushmanifest entry. Nothing in the server, contracts or web changes. The new tests fail on the base and pass here.vp run check:changedpasses. The service runs from the main checkout, so this takes effect aftercustomis pulled there and the login item restarts.Reviewed with sol-loop: 1 round with GPT-6.1 Sol on high. Sol verdict: approved
🤖 Signed: Claude Opus 5.5 (
claude-opus-5-5) via Claude Code🤖 Review: GPT-6.1 Sol (
gpt-6.1-sol) via Codex, one sol-loop round, approved with no findings🤖 Generated with Claude Code