Repository navigation
Closed
Labels
vouch:trustedAuthor is trusted by repo permissions or the VOUCHED list.
Description
Before submitting
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area
Not sure
Steps to reproduce
- Open a thread using Pi with an extension command that creates a new session and starts an agent response in that session.
- Run that extension command.
- Press Stop while the response in the new session is running.
- Restart T3 Code before sending another message.
- Reopen the thread and send a follow-up message.
Expected behavior
The follow-up continues in the session created by the extension, retaining its conversation context.
Actual behavior
The thread resumes the previous session, losing the conversation context from the handoff.
Impact
Minor bug or occasional failure. Users of Pi extensions that replace sessions can resume the wrong conversation whenever they stop the first response after a handoff and restart before another turn finishes.
Version or commit
main at 50717b8167. The cause is at packages/provider-pi/src/server/adapter.ts:2466.
Environment
Linux x64, the repository's own tests.
Logs or stack traces
expected '/fake/.pi/agent/sessions/--workspace-Automated repro
Fails in 2 of 2 runs on main: apply the patch with git apply, then run the command.
diff --git a/packages/provider-pi/src/server/adapter.test.ts b/packages/provider-pi/src/server/adapter.test.ts
index ff9f9c22ef..a32ee6c075 100644
--- a/packages/provider-pi/src/server/adapter.test.ts
+++ b/packages/provider-pi/src/server/adapter.test.ts
@@ -1,3 +1,4 @@
+import { expect } from "vite-plus/test";
import { assert, describe, it } from "@effect/vitest";
import * as NodeServices from "@effect/platform-node/NodeServices";
import {
@@ -2822,6 +2823,41 @@ describe("PiAdapterV2", () => {
}).pipe(Effect.scoped, Effect.provide(layerTest)),
);
+ it.effect("keeps the extension's session file when its handoff turn is stopped", () =>
+ Effect.gen(function* () {
+ const fake = yield* makeFakePi;
+ const { runtime, takeEvent } = yield* openRuntime(fake);
+ const providerThread = yield* runtime.ensureThread({
+ threadId: THREAD_ID,
+ modelSelection: modelSelection("default"),
+ runtimePolicy,
+ });
+ yield* startTurn(runtime, providerThread, "default", [], "/handoff");
+ yield* fake.takeRequest("prompt");
+ const running = yield* takeEvent((event) => event.type === "provider_turn.updated");
+ if (running.type !== "provider_turn.updated") return yield* Effect.die("Missing turn");
+ const childFile = "/fake/extension-child.jsonl";
+ fake.reloadExtensions(childFile);
+ fake.setStreaming(true);
+ yield* fake.emit({ type: "response", command: "prompt", success: true });
+ yield* fake.emit({ type: "agent_start" });
+ yield* runtime.interruptTurn({ providerThread, providerTurnId: running.providerTurn.id });
+ fake.setStreaming(false);
+ yield* fake.emit({ type: "agent_settled", aborted: true });
+ const idle = yield* takeEvent(
+ (event) =>
+ event.type === "provider_thread.updated" && event.providerThread.status === "idle",
+ );
+ const terminal = yield* takeEvent((event) => event.type === "turn.terminal");
+ expect(terminal.type === "turn.terminal" ? terminal.status : null).toBe("interrupted");
+ expect(
+ idle.type === "provider_thread.updated"
+ ? idle.providerThread.nativeThreadRef?.nativeId
+ : null,
+ ).toBe(childFile);
+ }).pipe(Effect.scoped, Effect.provide(layerTest)),
+ );
+
it.effect.each([false, true, "previous"] as const)(
"resets applied thinking when returning to Pi default (failed first restore: %s)",
(failFirstRestore) =>cd packages/provider-pi && pnpm exec vp test run --config ../../vite.config.ts src/server/adapter.test.ts -t "keeps the extension's session file when its handoff turn is stopped"Workaround
No response
Metadata
Metadata
Assignees
Labels
vouch:trustedAuthor is trusted by repo permissions or the VOUCHED list.
Activity