The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 05:45 UTC
fix(pi): short-lived Pi processes no longer lose rotated OAuth tokens (#30187)
astarktc committed
Nov 3, 2026 at 10:27 UTC
8be19ed3f1f22837edb94dfd9324555fae042c24
8 files changed
+63
packages/provider-pi/src/server/adapter.test.ts
+4
@@ -1591,6 +1591,9 @@ describe("PiAdapterV2", () => {
1591
arg === "--extension" ? [spawn.args[index + 1]] : [],
1592
);
1593
assert.isFalse(spawn.args.includes("--no-extensions"));
1594
+ // A thread's long-lived process keeps Pi's startup model refresh unless the user opts out.
1595
+ assert.notInclude(spawn.args, "--offline");
1596
+ assert.isUndefined(spawn.env.PI_OFFLINE);
1597
assert.isTrue(extensions.some((path) => path?.endsWith("pi-t3-mcp-extension.ts")));
1598
assert.equal(spawn.env.T3_MCP_URL, "http://127.0.0.1:43123/mcp");
1599
assert.equal(spawn.env.T3_MCP_BEARER_TOKEN, "secret-pi-token");
@@ -1891,6 +1894,7 @@ describe("PiAdapterV2", () => {
1894
assert.equal(args[args.indexOf("--fork") + 1], FAKE_SESSION_FILE);
1895
assert.include(args, "--no-extensions");
1896
assert.include(args, "--no-tools");
1897
+ assert.include(args, "--offline");
1898
assert.notInclude(args, "--no-session");
1899
assert.deepEqual(
1900
forkFake
packages/provider-pi/src/server/adapter.ts
+1
@@ -3103,6 +3103,7 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* (
3103
environment: options.environment,
3104
mcpSession: undefined,
3105
extensionPath: undefined,
3106
+ shortLived: true,
3107
disableExtensions: true,
3108
disableTools: true,
3109
});
packages/provider-pi/src/server/driver.test.ts
+11
@@ -169,6 +169,17 @@ it.layer(layerTest)("PiDriver workspace discovery", (it) => {
169
["--approve", "--skill", "extra skill", "--no-session"],
170
);
171
assert.equal(workspaceLaunch!.options.env?.PI_CODING_AGENT_DIR, "/isolated-pi");
172
+ // Discovery processes are stopped as soon as they answer, so neither may start Pi's
173
+ // network refresh at launch.
174
+ for (const cwd of ["/machine", "/first"]) {
175
+ const discovery = launches.find(
176
+ (launch) => launch.options.cwd === cwd && launch.args.includes("--mode"),
177
+ );
178
+ assert.deepEqual(
179
+ discovery?.args.filter((arg) => arg === "--offline"),
180
+ ["--offline"],
181
+ );
182
+ }
183
}).pipe(Effect.scoped),
184
);
185
packages/provider-pi/src/server/mcpInjection.test.ts
+11
@@ -102,6 +102,7 @@ describe("pi T3 MCP injection", () => {
102
extensionPath: "/tmp/cache/pi-t3-mcp-extension.ts",
103
sessionPath: "/fake/persisted.jsonl",
104
ephemeral: true,
105
+ shortLived: true,
106
disableExtensions: true,
107
disableTools: true,
108
});
@@ -111,9 +112,19 @@ describe("pi T3 MCP injection", () => {
112
"--no-session",
113
"--provider",
114
"anthropic",
115
+ "--offline",
116
"--no-extensions",
117
"--no-tools",
118
]);
119
+ const alreadyOffline = buildPiRpcLaunch({
120
+ launchArgs: ["--offline"],
121
+ environment: {},
122
+ mcpSession: undefined,
123
+ extensionPath: undefined,
124
+ ephemeral: true,
125
+ shortLived: true,
126
+ });
127
+ assert.deepEqual(alreadyOffline.args, ["--mode", "rpc", "--no-session", "--offline"]);
128
assert.deepInclude(resolvePiLaunchArgs("--mode text"), {
129
ok: false,
130
message: "Pi launch argument '--mode' is controlled by T3 Code and cannot be overridden.",
packages/provider-pi/src/server/mcpInjection.ts
+4
@@ -244,6 +244,9 @@ export function buildPiRpcLaunch(input: {
244
readonly extensionPath: string | undefined;
245
readonly sessionPath?: string | undefined;
246
readonly ephemeral?: boolean;
247
+ // T3 stops these processes as soon as they answer. They run --offline because Pi's startup
248
+ // catalog refresh renews expired OAuth tokens, and a stop mid-request loses the rotated one.
249
+ readonly shortLived?: boolean;
250
readonly disableExtensions?: boolean;
251
readonly disableTools?: boolean;
252
readonly runtimeMode?: "approval-required" | "auto-accept-edits" | "auto" | "full-access";
@@ -268,6 +271,7 @@ export function buildPiRpcLaunch(input: {
271
? ["--session", input.sessionPath]
272
: []),
273
...launchArgs,
274
+ ...(input.shortLived === true && !launchArgs.includes("--offline") ? ["--offline"] : []),
275
// Restrictions must follow launch args so user flags cannot re-enable unattended tools/extensions.
276
...(input.disableExtensions === true ? ["--no-extensions"] : []),
277
...(input.disableTools === true ? ["--no-tools"] : []),
packages/provider-pi/src/server/status.ts
+1
@@ -150,6 +150,7 @@ const makePiDiscoveryConnection = Effect.fnUntraced(function* (
150
mcpSession: undefined,
151
extensionPath: undefined,
152
ephemeral: true,
153
+ shortLived: true,
154
});
155
const connection = yield* makePiRpcConnection({
156
command: piSettings.binaryPath || "pi",
packages/provider-pi/src/server/textGeneration.test.ts
+30
@@ -7,6 +7,7 @@ import * as Queue from "effect/Queue";
7
import * as Schema from "effect/Schema";
8
import * as Sink from "effect/Sink";
9
import * as Stream from "effect/Stream";
10
+import * as ChildProcess from "effect/process/ChildProcess";
11
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
12
13
import { makePiTextGeneration } from "./textGeneration.ts";
@@ -68,6 +69,35 @@ const makeFakePi = (
69
return { spawner, received };
70
});
71
72
+it.effect("runs Pi offline, since the process is stopped as soon as it answers", () =>
73
+ Effect.gen(function* () {
74
+ const pi = yield* makeFakePi(JSON.stringify({ subject: "Update README", body: "" }));
75
+ const launches: Array<ReadonlyArray<string>> = [];
76
+ const spawner = ChildProcessSpawner.make((command) => {
77
+ if (ChildProcess.isStandardCommand(command)) launches.push(command.args.map(String));
78
+ return pi.spawner.spawn(command);
79
+ });
80
+ const textGeneration = yield* makePiTextGeneration(
81
+ { enabled: true, binaryPath: "pi", launchArgs: "", customModels: [] },
82
+ {},
83
+ ).pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner));
84
+
85
+ const result = yield* textGeneration.generateCommitMessage({
86
+ cwd: process.cwd(),
87
+ branch: "main",
88
+ stagedSummary: "M README.md",
89
+ stagedPatch: "diff --git a/README.md b/README.md",
90
+ modelSelection: createModelSelection(ProviderInstanceId.make("pi"), "default"),
91
+ });
92
+
93
+ assert.equal(result.subject, "Update README");
94
+ assert.deepEqual(
95
+ launches.map((args) => args.filter((arg) => arg === "--offline")),
96
+ [["--offline"]],
97
+ );
98
+ }),
99
+);
100
+
101
it.effect("names the model and the disabled extensions when Pi cannot load it", () =>
102
Effect.gen(function* () {
103
const pi = yield* makeFakePi("", "Model not found: demo/demo-model");
packages/provider-pi/src/server/textGeneration.ts
+1
@@ -47,6 +47,7 @@ export const makePiTextGeneration = Effect.fn("makePiTextGeneration")(function*
47
mcpSession: undefined,
48
extensionPath: undefined,
49
ephemeral: true,
50
+ shortLived: true,
51
disableExtensions: true,
52
// Background naming/content helpers must never mutate the workspace.
53
disableTools: true,