perf(mobile): pause elapsed-time timers on hidden thread screens - #15397
Draft
juliusmarminge wants to merge 1 commit into
Draft
juliusmarminge wants to merge 1 commit into
juliusmarminge wants to merge 1 commit into
Conversation
juliusmarminge
added this pull request to stack #15249
October 3, 2026 23:58
Contributor
Thread transfer impact✅ Thread transfer remains within every enforced ceiling.
Baseline: unavailable · PR result: Scenario and decoded snapshot size10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed. |
Retained thread routes kept their 1s working/subagent timers running while unfocused or backgrounded. useVisibleSecondClock ticks only while enabled, focused and active, and re-reads the clock before paint on resume. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
juliusmarminge
force-pushed
the
t3code/mobile-perf/pause-hidden-thread-timers
branch
from
October 4, 2026 23:25
56fac3d to
4b291fc
Compare
This branch has not been deployed
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
Mobile keeps thread routes mounted after you navigate away. The working-duration label (
WorkingTimer) and the live subagent status (ProviderSubagentBar) each ran an ungated 1 ssetInterval. It kept firing while the screen was unfocused, while the app was backgrounded or inactive, and re-rendered the hidden screen 60 times a minute.Fix
A new hook,
useVisibleSecondClock(enabled), ticks once a second only whileenabled && focused && AppState === "active". When ticking resumes it re-readsDate.now()in a layout effect, so the label shows the true elapsed time on the first frame after you return. Both labels use the hook. Nothing else changes: the visible tick rate and interval phase stay the same.The hook also re-reads
AppState.currentStateafter its listener is attached. This closes a small race where a change between the first render and the passive subscription would otherwise be missed. A focused regression test covers it, and that test fails without the re-read.jsdomis now declared as anapps/mobiledevDependency, matchingapps/web's^30.0.1. The new test file uses it. Before this, it resolved only through the workspace's Vite+ peer. The lockfile change is three lines on the mobile importer and pulls in no new packages.Before / after
Measured with an instrumented Vitest test that uses fake timers in jsdom. Navigation focus and
AppStateare mocked, and each scenario runs for 60 simulated seconds. "Before" is the parent commit's timer code, copied verbatim.Evidence (sanitized):
Screenshots don't apply: the visible label looks the same before and after. The change is in how often it ticks while hidden.
Limits
Verification
vp test run apps/mobile/src/features/threads/use-visible-second-clock.test.tsx: 9/9 pass, including the new AppState race test, which fails without the fix.apps/mobiletypecheck passes. Targeted lint shows 0 errors (the warnings are already on base, in untouched code). Format passes.Stack: #15096 → #15248 → #15385 → this PR.
Implemented with Claude Opus 5.5 (1M context) in Claude Code via T3 Code.
🤖 Generated with Claude Code