Elffuss BraidHub

kikocis/continue public

Refactor session snapshot handling to use getCompleteStateSnapshot (#7929)

* Refactor session snapshot handling to use getCompleteStateSnapshot

* fix: failing tests

* use main branch for review action

* chore: format

* fix: capture references
Changesete31fcddb0dec4eef0853ab5eb70e26e5f9375eff3f23eda23bdee6a2e311ac5c
AuthorNate Sesti <33237525+sestinj@users.noreply.github.com> · 2025-09-24 00:00 -07:00
CommitterGitHub <noreply@github.com> · 2025-09-24 00:00 -07:00
Parents78599bd09fb6

Browse the files at this changeset

6 files changed

modified .github/workflows/continue-detailed-review.yaml +1 −1
@@ -18,7 +18,7 @@
1818 timeout-minutes: 10
1919 steps:
2020 - name: Run Detailed PR Review
21- uses: continuedev/continue/actions/detailed-review@12e933bf9d13736c5f47728c436445ef4127fd52
21+ uses: continuedev/continue/actions/detailed-review@main
2222 with:
2323 continue-api-key: ${{ secrets.CONTINUE_API_KEY }}
2424 continue-org: continuedev
modified .github/workflows/continue-general-review.yaml +1 −1
@@ -18,7 +18,7 @@
1818 timeout-minutes: 10
1919 steps:
2020 - name: Run Continue PR Review Action
21- uses: continuedev/continue/actions/general-review@12e933bf9d13736c5f47728c436445ef4127fd52
21+ uses: continuedev/continue/actions/general-review@main
2222 with:
2323 continue-api-key: ${{ secrets.CONTINUE_API_KEY }}
2424 continue-org: "continuedev"
modified extensions/cli/src/commands/serve.ts +15 −8
@@ -16,7 +16,7 @@
1616 ConfigServiceState,
1717 ModelServiceState,
1818 } from "../services/types.js";
19-import { createSession, getSessionPersistenceSnapshot } from "../session.js";
19+import { createSession, getCompleteStateSnapshot } from "../session.js";
2020 import { messageQueue } from "../stream/messageQueue.js";
2121 import { constructSystemMessage } from "../systemMessage.js";
2222 import { telemetryService } from "../telemetry/telemetryService.js";
@@ -159,7 +159,13 @@
159159 storageOption: options.id,
160160 accessToken,
161161 syncSessionHistory,
162- getSessionSnapshot: () => getSessionPersistenceSnapshot(state.session),
162+ getCompleteStateSnapshot: () =>
163+ getCompleteStateSnapshot(
164+ state.session,
165+ state.isProcessing,
166+ messageQueue.getQueueLength(),
167+ state.pendingPermission,
168+ ),
163169 isActive: () => state.serverRunning,
164170 });
165171
@@ -181,12 +187,13 @@
181187 app.get("/state", (_req: Request, res: Response) => {
182188 state.lastActivity = Date.now();
183189 syncSessionHistory();
184- res.json({
185- session: state.session, // Return session directly instead of converting
186- isProcessing: state.isProcessing,
187- messageQueueLength: messageQueue.getQueueLength(),
188- pendingPermission: state.pendingPermission,
189- });
190+ const stateSnapshot = getCompleteStateSnapshot(
191+ state.session,
192+ state.isProcessing,
193+ messageQueue.getQueueLength(),
194+ state.pendingPermission,
195+ );
196+ res.json(stateSnapshot);
190197 });
191198
192199 // POST /message - Queue a message and potentially interrupt
modified extensions/cli/src/services/StorageSyncService.test.ts +10 −10
@@ -55,7 +55,7 @@
5555 storageOption: undefined,
5656 accessToken: "token",
5757 syncSessionHistory: vi.fn(),
58- getSessionSnapshot: vi.fn(),
58+ getCompleteStateSnapshot: vi.fn(),
5959 });
6060
6161 expect(result).toBe(false);
@@ -69,7 +69,7 @@
6969 storageOption: " ",
7070 accessToken: "token",
7171 syncSessionHistory: vi.fn(),
72- getSessionSnapshot: vi.fn(),
72+ getCompleteStateSnapshot: vi.fn(),
7373 });
7474
7575 expect(result).toBe(false);
@@ -86,7 +86,7 @@
8686 storageOption: "session-123",
8787 accessToken: null,
8888 syncSessionHistory: vi.fn(),
89- getSessionSnapshot: vi.fn(),
89+ getCompleteStateSnapshot: vi.fn(),
9090 });
9191
9292 expect(result).toBe(false);
@@ -98,7 +98,7 @@
9898
9999 it("starts syncing when presign succeeds", async () => {
100100 const syncSessionHistory = vi.fn();
101- const getSessionSnapshot = vi.fn().mockReturnValue({ foo: "bar" });
101+ const getCompleteStateSnapshot = vi.fn().mockReturnValue({ foo: "bar" });
102102
103103 fetchMock.mockResolvedValueOnce({
104104 ok: true,
@@ -114,13 +114,13 @@
114114 storageOption: "session-123",
115115 accessToken: "token",
116116 syncSessionHistory,
117- getSessionSnapshot,
117+ getCompleteStateSnapshot,
118118 isActive: () => true,
119119 });
120120
121121 expect(result).toBe(true);
122122 expect(syncSessionHistory).toHaveBeenCalledTimes(1);
123- expect(getSessionSnapshot).toHaveBeenCalledTimes(1);
123+ expect(getCompleteStateSnapshot).toHaveBeenCalledTimes(1);
124124 expect(fetchMock).toHaveBeenCalledTimes(3);
125125 const [presignUrl, presignOptions] = fetchMock.mock.calls[0];
126126 expect(presignUrl).toBeInstanceOf(URL);
@@ -152,7 +152,7 @@
152152 storageOption: "session-123",
153153 accessToken: "token",
154154 syncSessionHistory: vi.fn(),
155- getSessionSnapshot: vi.fn(),
155+ getCompleteStateSnapshot: vi.fn(),
156156 });
157157
158158 expect(result).toBe(false);
@@ -187,7 +187,7 @@
187187 storageOption: "session-123",
188188 accessToken: "token",
189189 syncSessionHistory: vi.fn(),
190- getSessionSnapshot: vi.fn().mockReturnValue({}),
190+ getCompleteStateSnapshot: vi.fn().mockReturnValue({}),
191191 });
192192
193193 expect(result).toBe(true);
@@ -235,7 +235,7 @@
235235
236236 it("includes server-side encryption header when required by signed headers", async () => {
237237 const syncSessionHistory = vi.fn();
238- const getSessionSnapshot = vi.fn().mockReturnValue({ test: "data" });
238+ const getCompleteStateSnapshot = vi.fn().mockReturnValue({ test: "data" });
239239
240240 // Mock presign response with server-side encryption in signed headers
241241 const sessionUrlWithSSE =
@@ -256,7 +256,7 @@
256256 storageOption: "session-123",
257257 accessToken: "token",
258258 syncSessionHistory,
259- getSessionSnapshot,
259+ getCompleteStateSnapshot,
260260 isActive: () => true,
261261 });
262262
modified extensions/cli/src/services/StorageSyncService.ts +9 −5
@@ -29,7 +29,7 @@
2929 accessToken: string;
3030 intervalMs?: number;
3131 syncSessionHistory: () => void;
32- getSessionSnapshot: () => unknown;
32+ getCompleteStateSnapshot: () => unknown;
3333 isActive?: () => boolean;
3434 }
3535
@@ -284,14 +284,18 @@
284284 return;
285285 }
286286
287+ // Capture references to prevent race condition with stop()
288+ const targets = this.targets;
289+ const options = this.options;
290+
287291 this.uploadInFlight = true;
288292
289293 try {
290- this.options.syncSessionHistory();
291- const snapshot = this.options.getSessionSnapshot();
294+ options.syncSessionHistory();
295+ const snapshot = options.getCompleteStateSnapshot();
292296 const sessionPayload = JSON.stringify(snapshot, null, 2);
293297 await this.uploadToPresignedUrl(
294- this.targets.sessionUrl,
298+ targets.sessionUrl,
295299 sessionPayload,
296300 "application/json",
297301 );
@@ -304,7 +308,7 @@
304308 this.missingRepoLogged = true;
305309 }
306310 await this.uploadToPresignedUrl(
307- this.targets.diffUrl,
311+ targets.diffUrl,
308312 diffResult.diff,
309313 "text/plain",
310314 );
modified extensions/cli/src/session.ts +24 −0
@@ -161,6 +161,30 @@
161161 return modifySessionBeforeSave(session);
162162 }
163163
164+/**
165+ * Get the complete state snapshot that matches the /state endpoint format
166+ */
167+export interface StateSnapshot {
168+ session: Session;
169+ isProcessing: boolean;
170+ messageQueueLength: number;
171+ pendingPermission: any;
172+}
173+
174+export function getCompleteStateSnapshot(
175+ session: Session,
176+ isProcessing: boolean = false,
177+ messageQueueLength: number = 0,
178+ pendingPermission: any = null,
179+): StateSnapshot {
180+ return {
181+ session: getSessionPersistenceSnapshot(session),
182+ isProcessing,
183+ messageQueueLength,
184+ pendingPermission,
185+ };
186+}
187+
164188 /**
165189 * Save the current session to file
166190 */