Repository navigation
Description
Before submitting
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area
apps/server (packages/provider-pi/src/server/adapter.ts)
Steps to reproduce
-
Load a Pi extension with a command that starts a new session, for example:
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent"; export default function (pi: ExtensionAPI) { pi.registerCommand("handoff", { description: "Continue in a new child session", handler: async (_args, ctx) => { await ctx.newSession({ parentSession: ctx.sessionManager.getSessionFile() }); }, }); }
-
Start a Pi thread in T3 Code. Send prompt A and let the turn complete.
-
Send
/handoff. Pi now writes to a new session file whose header hasparentSessionset to the first file. -
Send prompt B and let the turn complete. It is written to the new file.
-
Restart the T3 server, or wait for the idle release, so that the Pi process ends.
-
Send prompt C.
Expected behavior
T3 Code resumes the session that Pi used last (the child file). Prompt C sees prompt B and its reply.
Actual behavior
T3 Code resumes the first session file. Prompt C does not see prompt B or anything else from the child session. The T3 timeline still shows B, so the user does not see that the model lost it.
Each later handoff then starts from the first file again, so every new child session also misses the previous child's history.
Analysis
When registerThread resumes a thread, it switches Pi to the stored native ref:
const resumeId = existing?.nativeThreadRef?.nativeId;
// ...
{ type: "switch_session", sessionPath: resumeId }nativeThreadRef is set only here, from get_state.sessionFile, when T3 attaches to Pi. Nothing updates it when Pi changes sessions during the thread. The settle probe already calls get_state after each turn, but it reads only isStreaming, isCompacting and pendingMessageCount. It ignores sessionFile.
Evidence from one affected thread (statev2.sqlite, orchestration_v2_projection_provider_threads.payload_json):
nativeThreadRef.nativeIdpoints at the first session file (created 2026-11-15T07:01Z).handoffIdsis[].- An extension created 6 child session files over about 20 hours. All have
parentSessionset to that first file. - The first file contains 7 reattach points (
model_changefollowed bysession_info). After each one, the user's next message went into the first file, not into the newest child. - In the last case, the user had merged a PR in the newest child session. After a restart, the thread resumed the first file, and the model reported that it was "working from an old state".
Related, but different:
- [Bug]: A Pi session rewound natively by an extension leaves T3's timeline and turn refs on the abandoned branch #13507 / fix(server): reconcile Pi native session rewinds #13839 handle rewinds inside one session. The closing comment lists "extension forks aren't tracked" as a known limit. This issue is the same class of bug for
newSession, and probably alsoforkandswitchSession, when they are called by an extension. - Pi: fork from a turn fails when the fork target's session entry lives in a previous Pi session #28377 shows that one thread can span several Pi session files, but it covers forking, not resuming.
- Pi: resumed thread runs its turn with an invalidated extension ctx — T3's own pi-t3-mcp-extension hooks throw 'stale after session replacement' on every provider call #12467 confirms the resume path (
switch_sessiontonativeThreadRef).
Possible fix: after each turn, compare get_state.sessionFile with nativeThreadRef.nativeId. If they differ, save the new file as the thread's native ref. The settle probe already has this data. Another option is for T3's injected Pi extension to report session_start events with reason new, fork or resume.
Impact
Major degradation or frequent failure
Version or commit
T3 Code 0.1.9 (desktop)
Environment
macOS 15.7.7, Apple silicon. Pi 1.5.2 (Homebrew). The extension starts a new child session at workflow boundaries with ctx.newSession({ parentSession }).
Logs or stack traces
No error is raised. The fault shows in the session files and in statev2.sqlite, as described above.
Workaround
After a restart, do not continue a thread that has switched sessions. Start a new thread and point it at the newest child session file.
Activity