Skip to content

--session-id with an unknown id silently creates a new session (unlike --session/--fork) #6407

Description

@glifocat

What happened?

If you run pi --session-id <id> and no session with that id exists, pi quietly creates a new session with that id. No error, no warning. In --mode rpc there is also nothing in the protocol that tells you "this is not your old chat, this is a fresh one".

The other flags don't do this. --session and --fork print No session found matching '<arg>' and exit. Only --session-id falls through: createSessionManager looks up the id, doesn't find it, and lands on the SessionManager.create(cwd, sessionDir, { id: parsed.sessionId }) at the end (packages/coding-agent/src/main.ts, main @ 351efc8).

Why it matters to us: we drive pi --mode rpc from another program. It saves the session id and reuses it after restarts. If the session file is gone (cleanup, volume swap), pi silently starts fresh, and the agent answers as if the past conversations never happened. We catch it today by calling get_state after start and checking for messageCount === 0 — an extra round-trip, and it still can't tell "old chat lost" from "new chat on purpose".

Steps to reproduce

pi --session-id 00000000-aaaa-bbbb-cccc-000000000000 -p "what did we discuss?"
# → new session created under that id, no warning, answer with no memory

Also with -ne.

Expected behavior

Creating a session with an id you picked is a real feature (#6070 asked for it), so an error is probably wrong. We just need a way to know. Any of these would do:

  1. print a warning when the id wasn't found and a new session was created;
  2. a flag that says "the session must already exist" (fail like --session does);
  3. a "this session is new" marker in the session header / RPC state.

We would use option 2, but any of the three makes the failure visible. Happy to implement the one you pick.

Version

0.80.3

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions