mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-06 16:34:36 +00:00
fix(app): ignore stale History archive state for active agents
A cached History row can outlive a successful reopen. When the workspace exists, live session state now wins so an active agent is not interrupted by another refresh.
This commit is contained in:
@@ -87,7 +87,9 @@ function restoreArchivedWorkspace(target: HistoryWorkspaceRestore): void {
|
||||
// must restore even when its agent survived unarchived; an archived agent must
|
||||
// still reopen when its workspace survived.
|
||||
if (session.workspaces.has(workspaceId)) {
|
||||
if (agentArchived) {
|
||||
const liveAgent = session.agents.get(agentId) ?? session.agentDetails.get(agentId);
|
||||
const shouldReopenAgent = agentArchived && (!liveAgent || Boolean(liveAgent.archivedAt));
|
||||
if (shouldReopenAgent) {
|
||||
client.refreshAgent(agentId).catch((error) => {
|
||||
console.error("[HistoryRestore] Failed to reopen archived agent", {
|
||||
serverId,
|
||||
|
||||
@@ -297,6 +297,22 @@ describe("restoreArchivedWorkspace via navigateToAgent", () => {
|
||||
expect(status()).toBeNull();
|
||||
});
|
||||
|
||||
it("does not reopen an active agent from a stale archived History row", () => {
|
||||
const store = useSessionStore.getState();
|
||||
store.setAgents(SERVER_ID, (prev) => {
|
||||
const next = new Map(prev);
|
||||
next.set(AGENT_ID, agent(null));
|
||||
return next;
|
||||
});
|
||||
store.mergeWorkspaces(SERVER_ID, [workspace()]);
|
||||
refreshAgent.mockImplementation(() => new Promise(() => {}));
|
||||
|
||||
openFromHistory();
|
||||
|
||||
expect(refreshAgent).not.toHaveBeenCalled();
|
||||
expect(status()).toBeNull();
|
||||
});
|
||||
|
||||
it("is a no-op when a non-archived workspace descriptor is already present", () => {
|
||||
const store = useSessionStore.getState();
|
||||
store.setAgents(SERVER_ID, (prev) => {
|
||||
|
||||
Reference in New Issue
Block a user