[Feature] Make `session/load` fail for an unknown session ID, like `session/resume`
Description
session/load with a session ID that doesn't exist creates an empty in-memory session, replays nothing and succeeds. session/resume with the same ID fails with Session not found on disk. A client therefore can't use session/load to find out that a session is missing.
I'd like session/load to fail for an unknown ID the same way session/resume does, or, if the maintainers prefer to keep the current behavior, to tell the client that a new session was created.
Tracked from Nano-Collective/nanocoder-desktop#12 (item 8). It is a nice-to-have there, because the desktop works around it by always using session/resume. This issue is also a question about whether the current behavior is intended.
Use Case
A client that has stored a session ID (an editor thread, or Nanocoder Desktop's durable threads) needs to know when that session no longer exists. For example, Nanocoder deletes sessions after 30 idle days or beyond 100 sessions by default, and a user can delete a session by hand.
With session/load, a missing session looks like success: the client gets an empty conversation and carries on as if history had been lost. Worse, if the client then sends a prompt, the turn is saved to disk under that ID, so a stored session now exists under an ID the client invented.
session/resume already reports this correctly. Nanocoder Desktop relies on that error: on Session not found on disk it marks the thread view-only and offers recovery actions. That is why the message (or a stable code) matters, and why it should be identical for load.
The difference between the two methods is easy to miss, and the ACP spec doesn't say which behavior is right.
Proposed Solution
In loadSession, when the ID is neither in memory nor on disk, throw the same error as resumeSession instead of registering a new session. Keep resumeSession exactly as it is, including its message, because clients already rely on it.
Behavior to keep:
- A session that is in memory still loads and replays its history.
- A session on disk still loads, replays and restores its messages.
newSession,resumeSessionandcloseSessionbehave as before.
Alternatives Considered
- Keep creating the session, but say so. Return
_meta: {"nanocoder/created": true}(or similar) fromsession/loadwhen the ID was unknown. It's non-breaking for any client that relies on the current behavior, but it leaves a way to create a session with an arbitrary ID. - Do nothing. Clients that need to detect a missing session use
session/resume, as Nanocoder Desktop does today. - Make both methods return a stable error code (for example the SDK's
RequestError.resourceNotFound, -32002) instead of a plainError. This is a separate improvement that helps both methods, see the questions below.
Additional Context
- [x] I have searched existing issues to ensure this is not a duplicate
- [x] This feature aligns with the project's goals (local-first AI assistance)
Current behavior, checked against main at fc01e23:
source/acp/acp-agent.ts(~L167-196):loadSessionreuses an in-memory session, or loads from disk (sessionManager.loadSession) and callsregisterSession(...)whether or not the file exists. It restores messages only when a persisted session was found, then replays history and returns modes and config options.source/acp/acp-agent.ts(~L674-705):resumeSessionthrowsError('Session not found on disk: <id>')whensessionManager.loadSessionreturns nothing, and otherwise evicts any stale in-memory session, registers it from the persisted working directory, and replays.source/acp/acp-agent.ts(~L471): after a turn,saveAcpSessionToDisk(session)runs infinally, so a prompt to an unknown loaded ID is saved to disk.source/acp/acp-agent.spec.ts(~L226): the test "AcpAgent.loadSession - creates a usable session for an unknown id" asserts the current behavior and sends a prompt to the new session.plugins/vscode/src/acp-client.ts: the VS Code extension calls onlyresumeSession, neversession/load.- The ACP session-setup docs describe replay for
session/loadbut don't say what either method should do for an unknown ID. Onlysession/closesays an agent MAY return an error when the session doesn't exist. - Both "not found" errors are plain
Errors, so a client can only recognize them by their message text.
Implementation Notes (optional)
The change is small: after sessionManager.loadSession(params.sessionId), if there is no persisted session and none in memory, throw before registerSession. The error text can reuse resume's Session not found on disk: <id> so clients that already recognize it keep working. #1889 will also touch loadSession, so the two changes should be coordinated.
Open questions for maintainers:
- Is the current behavior intended? The existing test suggests it was deliberate. If some client relies on
session/loadcreating a session, the_metaalternative above avoids breaking it. - Error shape. Keep the plain
Errormessage, or move bothloadandresumeto a stable error code so clients don't match message text? - Should
session/loadever create a session? ACP says onlysession/newcreates one.
Acceptance criteria:
- [ ]
session/loadwith an ID that is neither in memory nor on disk fails and creates no session, in memory or on disk. - [ ]
session/loadfor a session on disk still replays history and restores messages. - [ ]
session/loadfor a session in memory still replays its history. - [ ] The failure carries the same message as
session/resume's, so a client can treat them alike. - [ ]
session/resumebehavior and its error are unchanged. - [ ] The existing test that expects a usable session for an unknown ID is changed to expect the failure.
- [ ]
docs/features/acp.mddescribes whatloadandresumedo for an unknown ID.
Test plan:
- ACP spec:
loadSessionwith an unknown ID rejects, and a followingpromptfor that ID also fails with "Session not found". - ACP spec: no file is written for the unknown ID.
- ACP spec: loading a persisted session and an in-memory session still replay.
- ACP spec: both
loadSessionandresumeSessionreject an unknown ID with the same message, checked side by side so the two stay consistent.
Out of scope: how cwd is handled on load versus resume, whether resume should replay history, honoring mcpServers (#1889), and any change to session retention.