Skip to content

feat(notifications): scale completion sound speed with task length#3026

Merged
frankh merged 4 commits into
mainfrom
posthog-code/scale-sound-with-task-length
Jun 30, 2026
Merged

feat(notifications): scale completion sound speed with task length#3026
frankh merged 4 commits into
mainfrom
posthog-code/scale-sound-with-task-length

Conversation

@frankh

@frankh frankh commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds an opt-in "Scale sound speed with task length" toggle to Settings → Notifications. When enabled, the completion sound's playback rate reflects how long the just-completed turn took:

  • ≤ 30s → ~3× faster (higher pitch)
  • 2–4 min → normal speed (the "normal" band)
  • ≥ 30 min → ~3× slower (lower pitch)
  • smooth log-interpolation across the two ramps, clamped to [1/3, 3]

Off by default, so existing behavior is unchanged unless the user turns it on. It uses HTMLAudioElement.playbackRate, so faster also means higher-pitched and slower means lower-pitched.

How it works

  • New playbackRateForTaskDuration(durationMs) helper in sounds.ts; playCompletionSound gains an optional playbackRate param.
  • The just-completed turn duration is computed in sessionService from acpMsg.ts - session.promptStartedAt (Immer keeps the pre-update snapshot, so the start time is still readable), plumbed through notifyPromptCompleteNotificationBus.notifyplayCompletionSound.
  • New scaleSoundWithTaskLength setting added to the settings store, the NotificationSettings contract, the desktop settings provider, and the Notifications settings UI (shown only when a sound is selected; included in "Reset to defaults").

Tests

  • sounds.test.ts: parametrized coverage of the duration→rate mapping across anchor/boundary points.
  • notifications.test.ts: asserts the scaled rate is applied when the toggle is on with a duration, and 1 when off or when no duration is available.

Created with PostHog Code

Add an opt-in "Scale sound speed with task length" toggle to Settings →
Notifications. When enabled, the completion sound's playback rate reflects
how long the just-completed turn took: a quick task (<30s) plays up to 3x
faster (higher pitch), the 2-4 min "normal" band plays at normal speed, and
a long task (>=30min) plays up to 3x slower (lower pitch), with smooth
log-interpolation across the ramps.

Off by default, so existing behavior is unchanged.

Generated-By: PostHog Code
Task-Id: e2191f70-e37c-4f84-b59f-54d458e496fd
@github-actions

github-actions Bot commented Jun 30, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit ef02594.

@frankh frankh requested a review from pauldambra June 30, 2026 13:51

@pauldambra pauldambra 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.

do more weird

@greptile-apps

greptile-apps Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "feat(notifications): scale completion so..." | Re-trigger Greptile

Comment thread packages/ui/src/features/notifications/notifications.test.ts Outdated
Comment thread packages/ui/src/utils/sounds.test.ts Outdated
frankh and others added 3 commits June 30, 2026 15:03
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Format the it.each block added by the code-review suggestions to satisfy
biome ci (collapse the callback onto the matcher line, wrap the long tuple
element).

Generated-By: PostHog Code
Task-Id: e2191f70-e37c-4f84-b59f-54d458e496fd
The cloud turn_complete path now forwards a per-turn durationMs (undefined
when no prompt-start was recorded, as in this harness). Update the
toHaveBeenCalledWith assertion to match the new arity.

Generated-By: PostHog Code
Task-Id: e2191f70-e37c-4f84-b59f-54d458e496fd
@frankh frankh merged commit 38d5b3e into main Jun 30, 2026
23 checks passed
@frankh frankh deleted the posthog-code/scale-sound-with-task-length branch June 30, 2026 14:32
Gilbert09 added a commit that referenced this pull request Jul 1, 2026
Ports the desktop feature from #3026 to the mobile app: the task-completion
sound now plays at a variable rate based on how long the turn ran — quick tasks
ring fast (higher pitch), long tasks drag slow (lower pitch). A new
"Scale sound speed with task length" setting gates the behavior, defaulting off.

- Add `playbackRateForTaskDuration` (verbatim from desktop) mapping duration to
  a playback rate, and thread an optional `playbackRate` through
  `playCompletionSound`, setting `rate`/`shouldCorrectPitch: false` on expo-av.
- Add the `scaleSoundWithTaskLength` preference (persisted, default off).
- Track prompt start time on the session and compute the rate at the ping sites.
- Add the settings toggle, shown only when a completion sound is enabled.

Generated-By: PostHog Code
Task-Id: dc58b11c-b3fc-4275-8102-9bffed29d638
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