Skip to content

fix(mobile): no3y push only alerts finishes that need the owner - #585

Merged
NoahHendrickson merged 3 commits into
customfrom
t3/reduce-sprint-push-notifications
Nov 29, 2026
Merged

NoahHendrickson merged 3 commits into
customfrom
t3/reduce-sprint-push-notifications

Conversation

@NoahHendrickson

Copy link
Copy Markdown
Owner

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:

  • 98 were sprint wakes that ended "Nothing to report."
  • 47 were sprint children finishing a turn. Each of those also wakes the sprint, which reports it again.
  • 55 were sprint turns the owner started and was likely watching.
  • 146 of the 302 arrived within a minute of the previous push.

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.

  • Bot wakes. A bot's wake (sprints are bots) pushes only when the server's report on its shell (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).
  • A bot's work. A bot-work:<bot> thread never pushes a finish while its bot is present and unarchived. forkBotWorkReports wakes the bot to report that finish.
  • Watched turns. A turn the owner started stays silent if a client had the thread open when it finished (lastVisitedAt at or after completion). This is the same "watched" test the server uses for work reports.
  • Bursts. A finish within 2 minutes of the last push that made a sound goes out with interruption-level: passive and no sound. It still shows on the lock screen.
  • Unchanged. Questions, approvals and failures. Coordinators and plain threads still push their finishes.

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-push manifest entry. Nothing in the server, contracts or web changes. The new tests fail on the base and pass here. vp run check:changed passes. The service runs from the main checkout, so this takes effect after custom is 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

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 NoahHendrickson left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Code review of 33ffcdf6d4: one finding.

The rest checks out against the code it mirrors:

  • isQuietBotWake matches the desktop's isQuietBotCompletion and the fork_bot_report_json projection (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. threadVisits dispatches 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) {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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 NoahHendrickson left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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:

  1. There are now two silence pipelines. The service already had one place that decides whether an alert stays off the phone: alertUnlessSilent, which logs silent "…" for …. This PR adds a second one inside the tracker's settle timer, plus a new Tracker.onSilent callback that defaults to a no-op and exists only to log. The tracker's job was to detect transitions, and policy came after notify. 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 on AlertRun (or pass the end-of-hold shell along), and have alertUnlessSilent check it first using its existing log line. That removes onSilent, the fourth makeTracker parameter 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.
  2. This re-implements canonical bot rules instead of sharing them. isQuietBotWake is isQuietBotCompletion from apps/web/src/custom/bots/botThreads.ts with DateTime instead of ISO strings. The "its bot reports it" check is a narrower copy of the server's forkBotWorkOwnerId plus the guard at the top of report() in forkBotWorkReports.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.
  3. 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 own userMessageId. Here it's inferred from latestUserAuthoredMessageAt >= latestRunRequestedAt. Those come from different rows: the first is the updated_at of 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.
  4. The type boundary. completion?: boolean is set through a conditional spread from its only constructor, and apnsPayload takes a positional quiet = false boolean. A required completion: 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;

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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;

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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) {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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) {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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);

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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);

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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.

@github-actions github-actions Bot added size:M vouch:trusted Author is trusted by repo permissions or the VOUCHED list. labels Nov 29, 2026
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>
@NoahHendrickson
NoahHendrickson merged commit 15373e6 into custom Nov 29, 2026
32 checks passed
@NoahHendrickson
NoahHendrickson deleted the t3/reduce-sprint-push-notifications branch November 29, 2026 06:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants