Skip to content

Commit c45085c

Browse files
fix(session): hide reverted messages immediately (anomalyco#564)
* fix(session): hide reverted messages immediately Apply session.revert.messageID as a UI visibility boundary and update local session state from revert/unrevert responses so undo/redo takes effect without waiting for SSE. * fix(session): abort before undo/redo Attempt session.abort before revert/unrevert to avoid 'Session is busy' errors when local status is stale.
1 parent c5fde8b commit c45085c

4 files changed

Lines changed: 42 additions & 8 deletions

File tree

115 KB
Loading
178 KB
Loading

‎packages/app/src/app/app.tsx‎

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,34 @@ export default function App() {
952952
return "";
953953
};
954954

955+
const upsertLocalSession = (next: Session | null | undefined) => {
956+
const id = (next as { id?: string } | null)?.id ?? "";
957+
if (!id) return;
958+
959+
const current = sessions();
960+
const index = current.findIndex((session) => session.id === id);
961+
if (index === -1) {
962+
setSessions([...current, next as Session]);
963+
return;
964+
}
965+
const copy = current.slice();
966+
copy[index] = next as Session;
967+
setSessions(copy);
968+
};
969+
970+
// OpenCode keeps reverted messages in the log and uses `session.revert.messageID`
971+
// as the visibility boundary. OpenWork mirrors that behavior by filtering the
972+
// displayed transcript.
973+
const visibleMessages = createMemo(() => {
974+
const list = messages();
975+
const revert = selectedSession()?.revert?.messageID ?? null;
976+
if (!revert) return list;
977+
return list.filter((message) => {
978+
const id = messageIdFromInfo(message);
979+
return Boolean(id) && id < revert;
980+
});
981+
});
982+
955983
const restorePromptFromUserMessage = (message: MessageWithParts) => {
956984
const text = message.parts
957985
.filter((part) => part.type === "text")
@@ -965,9 +993,10 @@ export default function App() {
965993
const sessionID = (selectedSessionId() ?? "").trim();
966994
if (!c || !sessionID) return;
967995

968-
if (selectedSessionStatus() !== "idle") {
969-
await (c.session as any).abort({ sessionID }).catch(() => undefined);
970-
}
996+
// Revert is rejected while the session is busy. We *usually* have an accurate
997+
// session status via SSE, but to be resilient to transient desync we attempt
998+
// an abort even when we think we're idle.
999+
await (c.session as any).abort({ sessionID }).catch(() => undefined);
9711000

9721001
const revertMessageID = selectedSession()?.revert?.messageID ?? null;
9731002
const users = messages().filter((message) => {
@@ -990,7 +1019,8 @@ export default function App() {
9901019
const messageID = messageIdFromInfo(target);
9911020
if (!messageID) return;
9921021

993-
unwrap(await (c.session as any).revert({ sessionID, messageID }));
1022+
const next = unwrap(await (c.session as any).revert({ sessionID, messageID }));
1023+
upsertLocalSession(next as Session);
9941024
restorePromptFromUserMessage(target);
9951025
}
9961026

@@ -999,6 +1029,8 @@ export default function App() {
9991029
const sessionID = (selectedSessionId() ?? "").trim();
10001030
if (!c || !sessionID) return;
10011031

1032+
await (c.session as any).abort({ sessionID }).catch(() => undefined);
1033+
10021034
const revertMessageID = selectedSession()?.revert?.messageID ?? null;
10031035
if (!revertMessageID) return;
10041036

@@ -1013,15 +1045,17 @@ export default function App() {
10131045
});
10141046

10151047
if (!next) {
1016-
unwrap(await (c.session as any).unrevert({ sessionID }));
1048+
const session = unwrap(await (c.session as any).unrevert({ sessionID }));
1049+
upsertLocalSession(session as Session);
10171050
setPrompt("");
10181051
return;
10191052
}
10201053

10211054
const messageID = messageIdFromInfo(next);
10221055
if (!messageID) return;
10231056

1024-
unwrap(await (c.session as any).revert({ sessionID, messageID }));
1057+
const nextSession = unwrap(await (c.session as any).revert({ sessionID, messageID }));
1058+
upsertLocalSession(nextSession as Session);
10251059

10261060
let prior: MessageWithParts | null = null;
10271061
for (let idx = users.length - 1; idx >= 0; idx -= 1) {
@@ -4543,7 +4577,7 @@ export default function App() {
45434577
workspaceSessionGroups: sidebarWorkspaceGroups(),
45444578
openRenameWorkspace,
45454579
selectSession: selectSession,
4546-
messages: activeMessages(),
4580+
messages: visibleMessages(),
45474581
todos: activeTodos(),
45484582
busyLabel: busyLabel(),
45494583
developerMode: developerMode(),

‎packages/app/src/app/pages/session.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,7 @@ export default function SessionView(props: SessionViewProps) {
12591259
let sessionId = props.selectedSessionId;
12601260
if (!sessionId) {
12611261
// Auto-create a session when none is selected (same pattern as sendPrompt)
1262-
sessionId = await props.createSessionAndOpen();
1262+
sessionId = (await props.createSessionAndOpen()) ?? null;
12631263
if (!sessionId) return;
12641264
}
12651265
props.setSessionAgent(sessionId, agent);

0 commit comments

Comments
 (0)