Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix(agentic-ide): resume the last session, not every folder ever opened
Ruben Lütkea61fab80120d
diff --git a/jarvis/agentic_ide/resume_store.py b/jarvis/agentic_ide/resume_store.pyindex 824ee91b22..61f31ad566 100644--- a/jarvis/agentic_ide/resume_store.py+++ b/jarvis/agentic_ide/resume_store.py@@ -181,6 +181,13 @@ class SnapshotWorkspace:)+# Two workspaces belong to the same save when their stamps are this close.+# `snapshot_now` gives every LIVE workspace one identical timestamp, so this is+# an exact-match test in practice; the tolerance only guards against a float+# surviving a JSON round trip a hair off.+_SAME_SAVE_EPSILON = 0.001++@dataclass(slots=True)class Snapshot:"""Everything that was open, ready to be offered back.@@ -194,6 +201,12 @@ class Snapshot:agent. Panes only launch when a pane connects, and only the workspace onscreen has panes mounted, so five workspaces in the bar are five folderswaiting, not five folders' worth of coding agents.++ **The file holds MORE than the last session** — see ``_merged_with_stored``:+ folders closed days ago stay remembered so a new workspace cannot erase+ them. Which of them was actually open last is therefore a question the+ consumer has to ask, not something the list answers by existing:+ :meth:`last_session` is that question."""saved_at: float@@ -208,6 +221,40 @@ class Snapshot:def terminal_count(self) -> int:return sum(len(w.terminals) for w in self.workspaces)+ def last_session(self) -> list[SnapshotWorkspace]:+ """Only the workspaces that were OPEN when this file was last written.++ **The bug this exists for.** Remembering closed folders (so opening one+ new workspace could not wipe out the twelve panes you shut down an hour+ ago) turned the restore point into an archive of the last ten folders+ ever opened — and "Resume all sessions" reopened all ten. Restarting+ therefore brought back Tuesday's folders beside today's, each one+ carrying the same call-signs out of the same pool, so the deduplicator+ renamed the collisions and the screen filled with "Alex", "Alex 2",+ "Alex 3". Reported as "it duplicates my terminals and restores stuff+ from days ago" — one root cause, both symptoms.++ Telling the two apart needs no extra bookkeeping: ``snapshot_now``+ stamps every live workspace with ONE instant, and a workspace that was+ merely remembered keeps the older stamp it had when it was last open.+ So "was open at the last save" is exactly "carries the newest stamp".++ A file whose workspaces carry no stamp at all (written before per+ workspace stamps existed, or hand-built in a test) cannot be split, so+ all of it counts as the last session — the old behaviour, unchanged.+ """+ newest = max((w.saved_at for w in self.workspaces), default=0.0)+ if newest <= 0.0:+ return list(self.workspaces)+ return [w for w in self.workspaces if newest - w.saved_at <= _SAME_SAVE_EPSILON]++ def is_from_last_session(self, workspace: SnapshotWorkspace) -> bool:+ """Was ``workspace`` open at the last save (rather than just remembered)?"""+ newest = max((w.saved_at for w in self.workspaces), default=0.0)+ if newest <= 0.0:+ return True+ return newest - workspace.saved_at <= _SAME_SAVE_EPSILON+def to_dict(self) -> dict[str, Any]:return {"version": SCHEMA_VERSION,@@ -339,13 +386,13 @@ def _merged_with_stored(snapshot: Snapshot) -> Snapshot:stamped = [w if w.saved_at else _restamp(w, snapshot.saved_at) for w in snapshot.workspaces]- live_folders = {_folder_key(w.folder) for w in stamped}+ live_folders = {folder_key(w.folder) for w in stamped}try:stored = load()except Exception: # noqa: BLE001 - a broken file must not block the writestored = Nonekept = (- [w for w in stored.workspaces if _folder_key(w.folder) not in live_folders]+ [w for w in stored.workspaces if folder_key(w.folder) not in live_folders]if stored is not Noneelse [])@@ -371,8 +418,13 @@ def _restamp(workspace: SnapshotWorkspace, when: float) -> SnapshotWorkspace:)-def _folder_key(folder: str) -> str:- """Comparable form of a folder path — the same one twice must not be two."""+def folder_key(folder: str) -> str:+ """Comparable form of a folder path — the same one twice must not be two.++ Public because the registry compares the same paths when it decides whether+ a remembered workspace is already open; two different notions of "the same+ folder" would be a second bug waiting for a symlinked checkout.+ """try:return os.path.normcase(str(Path(folder).expanduser().resolve()))except OSError:@@ -428,6 +480,13 @@ def offer(snapshot: Snapshot | None, *, installed: set[str]) -> dict[str, Any]:an instruction has the first and not the second — and promising twelverestored conversations that all turn out to be empty is exactly the lie thisscreen is meant to prevent.++ **The counts describe what resuming will actually do**, which is the LAST+ SESSION and not the whole file (see :meth:`Snapshot.last_session`). Every+ remembered workspace is still listed — a folder from Tuesday is worth+ seeing, and each carries ``in_last_session`` plus its own ``saved_at`` so+ the screen can separate "what you had open" from "also remembered" instead+ of presenting a ten-folder archive as one restart's worth of work."""if snapshot is None:return {@@ -436,6 +495,7 @@ def offer(snapshot: Snapshot | None, *, installed: set[str]) -> dict[str, Any]:"workspace_count": 0,"terminal_count": 0,"resumable_count": 0,+ "earlier_count": 0,"workspaces": [],}@@ -482,16 +542,26 @@ def offer(snapshot: Snapshot | None, *, installed: set[str]) -> dict[str, Any]:"folder_exists": folder_exists,"available": folder_exists and any(p["available"] for p in panes),"resumable_count": sum(1 for p in panes if p["resumable"]),+ # When this workspace was last open, and whether that was the+ # session being offered back. Both belong on screen: a card that+ # says "last open 2 minutes ago" over a folder nobody has+ # touched since Tuesday is the misreport this feature was+ # accused of.+ "saved_at": space.saved_at,+ "in_last_session": snapshot.is_from_last_session(space),"terminals": panes,})+ coming_back = [w for w in workspaces if w["in_last_session"]]return {- "available": any(w["available"] for w in workspaces),+ "available": any(w["available"] for w in coming_back),"saved_at": snapshot.saved_at,- "workspace_count": len(workspaces),- "terminal_count": sum(len(w["terminals"]) for w in workspaces),- "resumable_count": sum(w["resumable_count"] for w in workspaces),+ "workspace_count": len(coming_back),+ "terminal_count": sum(len(w["terminals"]) for w in coming_back),+ "resumable_count": sum(w["resumable_count"] for w in coming_back),+ # Remembered, but NOT part of what resuming reopens.+ "earlier_count": len(workspaces) - len(coming_back),"workspaces": workspaces,}@@ -530,6 +600,7 @@ __all__ = ["SnapshotTerminal","SnapshotWorkspace","clear",+ "folder_key","load","offer","save",diff --git a/jarvis/agentic_ide/session.py b/jarvis/agentic_ide/session.pyindex 6b9a6df92b..a366782fc8 100644--- a/jarvis/agentic_ide/session.py+++ b/jarvis/agentic_ide/session.py@@ -306,6 +306,18 @@ def _requested_account(entry: dict[str, Any]) -> str | None:return str(value).strip() or None if isinstance(value, str) else None+def _restore_key(space: resume_store.SnapshotWorkspace) -> str:+ """Stable identity of ONE remembered workspace, for "did I already reopen it?".++ Folder alone is not it: two workspaces may share a folder on purpose, and+ collapsing them would silently drop one. The id alone is not it either —+ older snapshots carry none. Together they identify the record, and the+ folder is compared in the store's own normalized form so a symlinked or+ differently-cased path cannot read as a second folder.+ """+ return f"{space.session_id}|{resume_store.folder_key(space.folder)}"++def _spawn_env(term: Terminal) -> dict[str, str] | None:"""The child environment that puts this pane on its own subscription.@@ -524,6 +536,12 @@ class Session:# loop cannot garbage-collect one mid-flight, and per session rather than# per registry so closing one workspace cannot cancel another's.lookups: set[asyncio.Task[None]] = field(default_factory=set)+ # Which remembered workspace this one came back from, empty when it was+ # opened rather than restored. It is what makes restoring idempotent: a+ # second "Resume all sessions" (a stale offer card in another window, a+ # double-submit) recognises what is already on screen instead of opening a+ # second copy of it with every call-sign renamed around the collision.+ restored_from: str = ""def find(self, wanted: str) -> Terminal | None:"""Terminal by key, call-sign, or a spoken phrase containing one."""@@ -868,15 +886,31 @@ class Registry:workspaces is cheap: none of them launches anything until a paneconnects, and only the workspace on screen has panes mounted.- All of them rather than the front one, because "resume all sessions" is- what was asked for and somebody with four folders open had four.+ All of the last session rather than the front one, because "resume all+ sessions" is what was asked for and somebody with four folders open had+ four — but the LAST SESSION, not the whole file. The store deliberately+ remembers folders closed days ago so a new workspace cannot erase them+ (``resume_store._merged_with_stored``); reopening that archive wholesale+ is what made a restart come back with Tuesday's folders beside today's,+ every one of them carrying the same call-signs out of the same pool, so+ the deduplicator renamed the collisions into "Alex 2" / "Alex 3" and the+ result read as "it duplicated my terminals". ``last_session`` is the+ line between the two; the older folders stay on offer and are reopened+ from the picker, one deliberate click at a time.++ Restoring the same restore point TWICE is a no-op for whatever it+ already brought back. A workspace remembers which record it came from,+ so a stale offer card in a second window cannot open a duplicate of a+ workspace that is on screen right now.A workspace that cannot come back does not stop the others: a deleted- folder is reported, an already-open folder is left running (reopening it- would kill live agents to replace them with restarted ones), and the- workspace limit stops the rest with a reason. What could not be restored- comes back in ``skipped`` so the caller can say so out loud instead of- quietly returning less than it promised.+ folder is reported, and the workspace limit stops the rest with a+ reason. What could not be restored comes back in ``skipped`` so the+ caller can say so out loud instead of quietly returning less than it+ promised. A folder that is already open in a workspace opened by hand is+ NOT one of those cases — two workspaces may share a folder deliberately,+ and the remembered one comes back beside the live one rather than+ replacing agents that are working.A pane whose CLI is no longer installed IS restored. It shows up as anerror the moment it tries to connect, which is a far better outcome than@@ -885,11 +919,14 @@ class Registry:async with self._lock:if not snapshot.workspaces:raise SessionError("There is nothing in that restore point.")+ wanted = self._restore_set_locked(snapshot)+ if not wanted:+ raise SessionError("Everything in that restore point is already open.")restored: list[Session] = []skipped: list[tuple[str, str]] = []was_on_screen: Session | None = None- for space in snapshot.workspaces:+ for space in wanted:try:session = await self._restore_one_locked(space)except SessionError as exc:@@ -921,6 +958,51 @@ class Registry:)return RestoreResult(sessions=restored, skipped=skipped)+ def _restore_set_locked(+ self, snapshot: resume_store.Snapshot+ ) -> list[resume_store.SnapshotWorkspace]:+ """Which remembered workspaces this restore should actually reopen.++ Three things are dropped here, and each of them showed up on screen as a+ duplicated terminal:++ 1. **Folders that were merely remembered**, not open at the last save.+ See ``Snapshot.last_session`` for why the file holds both.+ 2. **Records already restored in this process** — a second click on a+ stale offer card must recognise what is on screen, not open it again.+ Two checks, because restoring rewrites the file: right after a+ restore the record still names the id it was restored FROM, and once+ the workspace has saved itself it names the live workspace's own id.+ 3. **The same record twice inside one file**, which a merge could leave+ behind. Two workspaces sharing a folder are legitimate and keep+ distinct ids, so only a genuinely identical record collapses.++ Caller holds ``self._lock``.+ """+ already = {s.restored_from for s in self._sessions.values() if s.restored_from}+ wanted: list[resume_store.SnapshotWorkspace] = []+ seen: set[str] = set()+ for space in snapshot.last_session():+ key = _restore_key(space)+ if key in already or space.session_id in self._sessions:+ logger.info(+ "Agentic IDE: {} is already open from this restore point — not reopening it",+ space.folder,+ )+ continue+ if key in seen:+ continue+ seen.add(key)+ wanted.append(space)+ earlier = len(snapshot.workspaces) - len(snapshot.last_session())+ if earlier:+ logger.info(+ "Agentic IDE: {} remembered workspace(s) predate the last session — "+ "left on offer instead of reopened",+ earlier,+ )+ return wanted+async def _restore_one_locked(self, space: resume_store.SnapshotWorkspace) -> Session | None:"""Reopen one remembered workspace. Caller holds the lock."""root = Path(space.folder).expanduser() # noqa: ASYNC240@@ -962,6 +1044,9 @@ class Registry:# label moves; the resume handle underneath it continues the conversation.self._dedupe_names(terminals)session = await self._open_locked(root, terminals, name=space.name or None)+ # Which record this came back from, so a second restore of the same file+ # recognises it rather than opening a duplicate.+ session.restored_from = _restore_key(space)# Pack the grid: a snapshot can carry gaps if it was written between a# close and its renumbering, and a gap renders as a blank stripe.self._renumber(session)diff --git a/jarvis/ui/web/agentic_ide_routes.py b/jarvis/ui/web/agentic_ide_routes.pyindex b967935742..7a1bec5f57 100644--- a/jarvis/ui/web/agentic_ide_routes.py+++ b/jarvis/ui/web/agentic_ide_routes.py@@ -417,11 +417,27 @@ class ResumeWorkspace(BaseModel):default=0,description="How many of its panes bring their conversation back.",)+ saved_at: float = Field(+ default=0.0,+ description="When this workspace was last open, which is NOT the file's stamp.",+ )+ in_last_session: bool = Field(+ default=True,+ description=(+ "True when this workspace was open at the last save, so resuming reopens it. "+ "False for a folder that is only remembered from an earlier session."+ ),+ )terminals: list[ResumeTerminal] = Field(default_factory=list)class ResumeOffer(BaseModel):- """Everything that was open, re-checked against this machine as it is now."""+ """Everything that was open, re-checked against this machine as it is now.++ The counts describe what resuming will actually reopen — the LAST session,+ not every folder the store still remembers. ``workspaces`` lists both, each+ flagged with ``in_last_session``.+ """available: bool = Field(description="False when there is nothing to reopen, or nothing that could run."@@ -433,6 +449,10 @@ class ResumeOffer(BaseModel):default=0,description="How many panes across all workspaces continue their conversation.",)+ earlier_count: int = Field(+ default=0,+ description="Remembered folders from earlier sessions, which resuming does NOT reopen.",+ )workspaces: list[ResumeWorkspace] = Field(default_factory=list)diff --git a/jarvis/ui/web/frontend/src/components/agentic/ResumeCard.tsx b/jarvis/ui/web/frontend/src/components/agentic/ResumeCard.tsxindex 24e7ec1c3c..32690cfaf3 100644--- a/jarvis/ui/web/frontend/src/components/agentic/ResumeCard.tsx+++ b/jarvis/ui/web/frontend/src/components/agentic/ResumeCard.tsx@@ -24,6 +24,15 @@* With many panes the list is summarised instead of printed in full: a hundred* chips is not information, it is wallpaper. The call-signs of the first few are* what someone recognises their workspace by; the rest are a count.+ *+ * ## Why the list is in two parts+ *+ * The store remembers folders from earlier sessions too, so that opening one new+ * workspace cannot erase the twelve panes you shut down an hour ago. Resuming+ * reopens the LAST session only — reopening the whole archive is what once+ * brought last week's folders back beside today's. So what the button will do+ * comes first, and what is merely remembered sits below it, plainly labelled and+ * reopened from the folder picker one deliberate click at a time.*/import { AlertCircle, FolderGit2, RotateCcw, Terminal } from "lucide-react";import { cn } from "@/lib/utils";@@ -82,6 +91,7 @@ function WorkspaceRow({ space }: { space: ResumeWorkspaceOffer }) {const shown = space.terminals.slice(0, NAMES_SHOWN);const hidden = space.terminals.length - shown.length;const fresh = space.terminals.length - space.resumable_count;+ const when = savedAgo(space.saved_at ?? 0);return (<lidata-testid={`resume-workspace-${space.folder_name}`}@@ -90,6 +100,7 @@ function WorkspaceRow({ space }: { space: ResumeWorkspaceOffer }) {space.available? "border-border bg-card/60": "border-amber-500/40 bg-amber-500/10",+ space.in_last_session === false && "opacity-70",)}><div className="flex flex-wrap items-baseline gap-x-2 gap-y-1">@@ -101,6 +112,12 @@ function WorkspaceRow({ space }: { space: ResumeWorkspaceOffer }) {{space.terminals.length} terminal{space.terminals.length === 1 ? "" : "s"}{space.resumable_count > 0 && ` · ${space.resumable_count} continuing`}{fresh > 0 && ` · ${fresh} starting fresh`}+ {/*+ Per workspace, not per file. A card that says "last open 2 minutes+ ago" over a folder nobody has touched since last week is exactly the+ misreport that made resuming feel broken.+ */}+ {when && ` · ${when}`}</span></div><code className="mt-0.5 block truncate font-mono text-[11px] text-muted-foreground">@@ -148,6 +165,10 @@ function WorkspaceRow({ space }: { space: ResumeWorkspaceOffer }) {export function ResumeCard({ offer, busy, onResume, onDismiss }: ResumeCardProps) {const when = savedAgo(offer.saved_at);+ // An older backend sends neither flag and reopened everything, so a missing+ // one reads as "part of the last session" rather than as "earlier".+ const coming = offer.workspaces.filter((w) => w.in_last_session !== false);+ const earlier = offer.workspaces.filter((w) => w.in_last_session === false);return (<sectiondata-testid="resume-card"@@ -168,14 +189,39 @@ export function ResumeCard({ offer, busy, onResume, onDismiss }: ResumeCardProps</div></div>+ {/*+ Keyed by session id, not by folder: two workspaces may point at the same+ folder on purpose, and a duplicated React key renders one of them+ unpredictably.+ */}<ul className="mt-4 space-y-2">- {offer.workspaces.map((space) => (- <WorkspaceRow key={space.folder} space={space} />+ {coming.map((space, index) => (+ <WorkspaceRow key={space.session_id || `${space.folder}#${index}`} space={space} />))}</ul><p className="mt-3 text-xs text-muted-foreground">{resumeSummary(offer)}</p>+ {earlier.length > 0 && (+ <div className="mt-4" data-testid="resume-earlier">+ <p className="text-xs font-medium text-muted-foreground">+ Also remembered, from earlier sessions+ </p>+ <p className="text-xs text-muted-foreground">+ Resuming does not reopen these — open one from the folder picker when+ you want it back.+ </p>+ <ul className="mt-2 space-y-2">+ {earlier.map((space, index) => (+ <WorkspaceRow+ key={space.session_id || `${space.folder}#${index}`}+ space={space}+ />+ ))}+ </ul>+ </div>+ )}+<div className="mt-4 flex flex-wrap items-center justify-end gap-2"><buttontype="button"diff --git a/jarvis/ui/web/frontend/src/lib/agenticIdeApi.ts b/jarvis/ui/web/frontend/src/lib/agenticIdeApi.tsindex 82722d1204..cf8dbb5b70 100644--- a/jarvis/ui/web/frontend/src/lib/agenticIdeApi.ts+++ b/jarvis/ui/web/frontend/src/lib/agenticIdeApi.ts@@ -175,15 +175,26 @@ export interface ResumeWorkspaceOffer {available: boolean;/** How many of its panes bring their conversation back. */resumable_count: number;+ /** When THIS workspace was last open — not the file's stamp. Absent on an older backend. */+ saved_at?: number;+ /**+ * True when it was open at the last save, so resuming reopens it. False for a+ * folder that is only remembered from an earlier session. Absent on an older+ * backend, which reopened everything — so absent reads as true.+ */+ in_last_session?: boolean;terminals: ResumeTerminalOffer[];}export interface ResumeOffer {available: boolean;saved_at: number;+ /** Counts describe the LAST session — what resuming actually reopens. */workspace_count: number;terminal_count: number;resumable_count: number;+ /** Remembered folders from earlier sessions, which resuming does NOT reopen. */+ earlier_count?: number;workspaces: ResumeWorkspaceOffer[];}diff --git a/jarvis/ui/web/frontend/src/views/AgenticIdeView.test.tsx b/jarvis/ui/web/frontend/src/views/AgenticIdeView.test.tsxindex 219a8f14f6..8770517b69 100644--- a/jarvis/ui/web/frontend/src/views/AgenticIdeView.test.tsx+++ b/jarvis/ui/web/frontend/src/views/AgenticIdeView.test.tsx@@ -158,6 +158,7 @@ const PREVIOUS_WORKSPACE: api.ResumeOffer = {session_id: "ide_old",folder: "/work/project",folder_name: "project",+ name: "",folder_exists: true,available: true,resumable_count: 1,diff --git a/tests/unit/agentic_ide/test_resume_session.py b/tests/unit/agentic_ide/test_resume_session.pyindex d41e677db1..874251391c 100644--- a/tests/unit/agentic_ide/test_resume_session.py+++ b/tests/unit/agentic_ide/test_resume_session.py@@ -425,6 +425,78 @@ async def test_restoring_a_folder_that_is_still_open_adds_the_remembered_workspaassert len(registry.sessions) == 2+async def test_a_folder_from_an_earlier_session_is_not_reopened_beside_todays(+ registry: ide.Registry, tmp_path: Path+) -> None:+ """The reported bug, end to end: yesterday's folder must stay put.++ The store remembers a folder you closed days ago on purpose, so opening one+ new workspace cannot erase it. Reopening that archive wholesale is what made+ a restart come back with old folders beside the current one — and, because+ every workspace draws call-signs from the same pool, with a screen full of+ "Alex" and "Alex 2".+ """+ old, today = tmp_path / "last-week", tmp_path / "today"+ old.mkdir()+ today.mkdir()+ await registry.start(str(old), [{"agent": "claude"}, {"agent": "claude"}])+ await registry.end()+ await registry.start(str(today), [{"agent": "claude"}])++ stored = resume_store.load()+ assert stored is not None+ # Both are still remembered — the offer keeps them.+ assert len(stored.workspaces) == 2++ fresh = ide.Registry(pty_manager=FakePtyManager())+ result = await fresh.restore(stored)++ assert [s.folder for s in result.sessions] == [str(today)]+ assert [t.name for s in result.sessions for t in s.terminals] == ["Alex"]+++async def test_workspaces_closed_one_by_one_still_come_back_together(+ registry: ide.Registry, tmp_path: Path+) -> None:+ """Closing for the day is not "an earlier session" — all of it comes back."""+ folders = [tmp_path / "one", tmp_path / "two", tmp_path / "three"]+ for folder in folders:+ folder.mkdir()+ await registry.start(str(folder), [{"agent": "claude"}])+ while await registry.end():+ pass++ stored = resume_store.load()+ assert stored is not None+ fresh = ide.Registry(pty_manager=FakePtyManager())+ result = await fresh.restore(stored)++ assert {s.folder for s in result.sessions} == {str(f) for f in folders}+++async def test_restoring_the_same_restore_point_twice_opens_nothing_new(+ registry: ide.Registry, tmp_path: Path+) -> None:+ """A stale offer card in a second window must not duplicate the workspace."""+ await registry.start(str(tmp_path), [{"agent": "claude"}, {"agent": "claude"}])++ stored = resume_store.load()+ assert stored is not None+ fresh = ide.Registry(pty_manager=FakePtyManager())+ await fresh.restore(stored)+ names = [t.name for t in fresh.sessions[0].terminals]++ # Once more, with the file as it stands after the first restore rewrote it.+ with pytest.raises(ide.SessionError, match="already open"):+ await fresh.restore(resume_store.load())+ # And once more with the file as the second window still remembers it.+ with pytest.raises(ide.SessionError, match="already open"):+ await fresh.restore(stored)++ assert len(fresh.sessions) == 1+ assert [t.name for t in fresh.sessions[0].terminals] == names++async def test_restoring_another_folder_opens_it_beside_the_running_one(registry: ide.Registry, fake_pty: FakePtyManager, tmp_path: Path) -> None:diff --git a/tests/unit/agentic_ide/test_resume_store.py b/tests/unit/agentic_ide/test_resume_store.pyindex e7533afe2b..a8cfd967b9 100644--- a/tests/unit/agentic_ide/test_resume_store.py+++ b/tests/unit/agentic_ide/test_resume_store.py@@ -143,6 +143,58 @@ def test_the_offer_reports_each_workspace_separately(tmp_path: Path) -> None:assert view["workspaces"][1]["folder_exists"] is False+def _stamped(folder: str, when: float) -> resume_store.SnapshotWorkspace:+ space = _workspace(folder)+ space.saved_at = when+ return space+++def test_the_last_session_is_what_the_newest_stamp_says(tmp_path: Path) -> None:+ """A remembered folder is not part of the session being offered back."""+ now, earlier = 1000.0, 900.0+ snapshot = resume_store.Snapshot(+ saved_at=now,+ workspaces=[+ _stamped(str(tmp_path / "a"), now),+ _stamped(str(tmp_path / "b"), now),+ _stamped(str(tmp_path / "old"), earlier),+ ],+ )+ assert [w.folder for w in snapshot.last_session()] == [+ str(tmp_path / "a"),+ str(tmp_path / "b"),+ ]+++def test_a_file_without_stamps_counts_entirely_as_the_last_session(tmp_path: Path) -> None:+ """Older files cannot be split, so nothing is silently dropped from them."""+ snapshot = resume_store.Snapshot(+ saved_at=0.0,+ workspaces=[_workspace(str(tmp_path / "a")), _workspace(str(tmp_path / "b"))],+ )+ assert len(snapshot.last_session()) == 2+++def test_the_offer_counts_only_what_resuming_will_reopen(tmp_path: Path) -> None:+ """The card must not promise an archive's worth of folders."""+ alive, old = tmp_path / "alive", tmp_path / "old"+ alive.mkdir()+ old.mkdir()+ view = resume_store.offer(+ resume_store.Snapshot(+ saved_at=1000.0,+ workspaces=[_stamped(str(alive), 1000.0), _stamped(str(old), 900.0)],+ ),+ installed={"claude", "codex"},+ )+ assert view["workspace_count"] == 1+ assert view["terminal_count"] == 2+ assert view["earlier_count"] == 1+ # Both are still listed — an old folder is worth seeing, just not resuming.+ assert [w["in_last_session"] for w in view["workspaces"]] == [True, False]+ assert [w["saved_at"] for w in view["workspaces"]] == [1000.0, 900.0]++def test_a_pane_without_a_name_is_dropped_not_fatal(tmp_path: Path) -> None:"""One damaged entry must not cost the whole workspace."""resume_store.save(_snapshot(str(tmp_path)))