diff --git a/src/__tests__/opencode_cell_actions.spec.ts b/src/__tests__/opencode_cell_actions.spec.ts index 54ab25f..61f3216 100644 --- a/src/__tests__/opencode_cell_actions.spec.ts +++ b/src/__tests__/opencode_cell_actions.spec.ts @@ -1123,9 +1123,6 @@ describe('OpenCodeInlinePrompt', () => { { id: 'sess-B', title: 'second' }, ] }); - mockedSetActiveSession.mockResolvedValue({ - ok: true, notebookPath: 'foo.ipynb', activeSessionId: 'sess-B', - }); mockedBindExistingSession.mockResolvedValue({ ok: true, notebookPath: 'foo.ipynb', sessionId: 'sess-B', }); @@ -1144,7 +1141,11 @@ describe('OpenCodeInlinePrompt', () => { select.value = 'sess-B'; select.dispatchEvent(new Event('change')); await new Promise(r => setTimeout(r, 5)); - expect(mockedSetActiveSession).toHaveBeenCalled(); + // bind-existing is the single call (it does both bind AND set + // active on the server). Calling set_active first would 400 + // because the session is not yet bound. + expect(mockedBindExistingSession).toHaveBeenCalled(); + expect(mockedSetActiveSession).not.toHaveBeenCalled(); expect((prompt as any)._sessionId).toBe('sess-B'); }); diff --git a/src/components/opencode_cell_actions.ts b/src/components/opencode_cell_actions.ts index e19d061..ed8f272 100644 --- a/src/components/opencode_cell_actions.ts +++ b/src/components/opencode_cell_actions.ts @@ -30,7 +30,6 @@ import { callOpenCodeReplyPermission, callOpenCodeReplyQuestion, callOpenCodeSessionMessages, - callOpenCodeSetActiveSession, subscribeOpenCodeEvents, type OpenCodeEventSubscription } from '../api/opencode_client'; @@ -222,7 +221,12 @@ export class OpenCodeCellActions extends Widget { // Closing the SSE first ensures the old session's events stop // coming in while we transition. this._closeSse(); - const r = await callOpenCodeSetActiveSession( + // PUT /sessions/notebook binds AND sets active in one call. + // (The separate PUT /sessions/active is only for switching + // between sessions that are ALREADY bound; for a session the + // user just picked from the global list, we need to bind + // first — calling set_active before bind returns 400.) + const r = await callOpenCodeBindExistingSession( this._context.notebookPath, sessionId, _serverSettings @@ -230,14 +234,6 @@ export class OpenCodeCellActions extends Widget { if (!r.ok) { return false; } - // The session was not necessarily bound to this notebook yet. - // Bind it (idempotent; the server's PUT /sessions/notebook - // also sets it as active, so we don't need a separate call). - await callOpenCodeBindExistingSession( - this._context.notebookPath, - sessionId, - _serverSettings - ); this._prompt?.setSessionId(sessionId); return true; },