Skip to content

spike: prove ctx.switchSession re-camps a live session #18

Description

@neilwashere

Before rewriting any transition, establish that an in-process switch actually delivers what a relaunch delivers. Everything downstream assumes it does.

Do this behind a flag on /worktree enter only: command-driven, human-initiated, already idle. Lowest possible blast radius.

Shape worth trying

Mirror the prior art's src/session.ts:

awaitctx.waitForIdle();constforked=SessionManager.forkFrom(sourceSessionFile,worktreePath);awaitctx.switchSession(forked.getSessionFile(),{withSession: async(ctx)=>{/* report from the replacement ctx only */},});

Then verify, in a real session, against a real worktree:

  • bash runs in the worktree — pwd reports the worktree path
  • read/edit resolve repo-relative paths against the worktree
  • the worktree's own .pi/ extensions load, and its skills and AGENTS.md are in context
  • conversation history survives the hop and the transcript is continuous
  • process.cwd() is unchanged — confirm the divergence exists and note everything that reads it
  • an ephemeral (--no-session) session survives; the prior art copies the active branch into a persisted target rather than losing it
  • a session with zero turns yet does not produce an empty or broken target (this is what fix: a hop from a session with no turns yet leaves a shell, not pi #11 was)
  • session_before_switch firing does not let an unrelated extension silently cancel our hop without us noticing
  • the same flow under -p / print mode, since modes/print-mode.js:71 wires switchSession too

Constraints

Flag-gated, no default behaviour change, no deletions. The relaunch path stays fully intact and reachable for the whole spike.

Deliverable is a findings note plus a go/no-go, not a merged feature. A red result on tool rebinding or resource reloading stops the epic; a red result on the ephemeral or zero-turn cases is a scope note, not a stop.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions