Repository navigation
fix(terminals): keep a terminal's last-used time across restarts - #1179
Merged
Merged
Conversation
Refs #1178 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A shell's only age was terminalForeground.changedAt: in memory, and stamped "now" on the first observation after any attach. Every restart pulls a foreground snapshot into empty runtimes, so every terminal read "active just now" and Close Old Agents could never find a shell unused for days. Terminals now carry SessionMeta.lastUsedAt, persisted with the workspace and moved only by real use: typing or pasting (TerminalLeaf, the one input path for plain shells), a real foreground transition, never the first observation after an attach. A record-less terminal gets a floor on first sighting, so a shell nobody touches after this ships can still become old. Writes are throttled to one a minute so typing does not autosave per key. Close Old Agents and Agent Activity both read the record, so a parked shell with no runtime ages too. Fixes #1178 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- A terminal nobody is observing yet (a parked tmux shell after a restart, never re-attached or polled) counts as possibly running. It now has an age, so Close Old Agents would otherwise have listed a shell that may be running a dev server as idle. The row says "not observed yet", and it is excluded unless Include running is ticked. - Ages read record + one throttle resolution, a true upper bound on the last use: the throttle drops uses within a minute of the record, so the bare record let a one-minute threshold call a shell used a second ago old. - Use is stamped from the user's keydown, composition and paste DOM events rather than xterm's onData, which also carries automatic terminal replies and returned early while the shell was waking. - Undo Close carries the record with the restored terminal. Refs #1178 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pi's review: it returns an upper bound (record + one throttle resolution), not the record, so the next caller that formats it as a timestamp would state a false minute. Also records the one known imprecision of the first-sample rule, which only ever errs toward keeping a shell open. Refs #1178 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Sep 25, 2026
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.
Fixes #1178
Problem
A terminal's only "last active" time was
runtime.terminalForeground.changedAt. It lived in memory and was stampednowon the first foreground observation after any attach. Every restart pulls a foreground snapshot into empty runtimes, so every terminal read "active just now" after a restart, and Close Old Agents could never find a shell nobody had touched in days. A command that finishes inside one poll (1 s) and plain typing never counted at all.What changes
SessionMeta.lastUsedAt(terminals) is persisted with the workspace, so it survives restarts.TerminalLeaf, the one input path for plain shells;cd).changedAtkeeps its other jobs: marking the pane unread when a command finishes, and the live status.Review round (one round: Codex, Pi)
Fixed:
onData:onDataalso carries automatic terminal replies, which counted as use (Codex, minor);terminalLastUsedUpperBoundfor what it returns (Pi).Accepted gap (Pi): dictating into a plain shell does not count as use until the dictated command runs (which the foreground change then catches). The dictation hook has no access to the workspace, and adding it isn't worth it here.
Not done, on purpose
tmux
session_activitywould only cover tmux-backed shells, and it counts output as activity, so a prompt clock ortail -fwould keep a forgotten shell "in use" forever.Verification
🤖 Generated with Claude Code