GeezerVison is showing github.com — fix(pi): short-lived Pi processes no longer lose rotated OAuth tokens… · pingdotgg/t3code@8be19ed
File treeExpand file treeCollapse file tree Open diff view settings packages/provider-pi/src/server
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/provider-pi/src/server/adapter.test.ts +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1591,6 +1591,9 @@ describe("PiAdapterV2", () => { | 1591 | 1591 | arg === "--extension" ? [spawn.args[index + 1]] : [], | 1592 | 1592 | ); | 1593 | 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); | 1594 | 1597 | assert.isTrue(extensions.some((path) => path?.endsWith("pi-t3-mcp-extension.ts"))); | 1595 | 1598 | assert.equal(spawn.env.T3_MCP_URL, "http://127.0.0.1:43123/mcp"); | 1596 | 1599 | assert.equal(spawn.env.T3_MCP_BEARER_TOKEN, "secret-pi-token"); | @@ -1891,6 +1894,7 @@ describe("PiAdapterV2", () => { | 1891 | 1894 | assert.equal(args[args.indexOf("--fork") + 1], FAKE_SESSION_FILE); | 1892 | 1895 | assert.include(args, "--no-extensions"); | 1893 | 1896 | assert.include(args, "--no-tools"); | | 1897 | + assert.include(args, "--offline"); | 1894 | 1898 | assert.notInclude(args, "--no-session"); | 1895 | 1899 | assert.deepEqual( | 1896 | 1900 | forkFake | |
Collapse file Copy file name to clipboardExpand all lines: packages/provider-pi/src/server/adapter.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3103,6 +3103,7 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* ( | 3103 | 3103 | environment: options.environment, | 3104 | 3104 | mcpSession: undefined, | 3105 | 3105 | extensionPath: undefined, | | 3106 | + shortLived: true, | 3106 | 3107 | disableExtensions: true, | 3107 | 3108 | disableTools: true, | 3108 | 3109 | }); | |
Collapse file Copy file name to clipboardExpand all lines: packages/provider-pi/src/server/driver.test.ts +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -169,6 +169,17 @@ it.layer(layerTest)("PiDriver workspace discovery", (it) => { | 169 | 169 | ["--approve", "--skill", "extra skill", "--no-session"], | 170 | 170 | ); | 171 | 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 | + } | 172 | 183 | }).pipe(Effect.scoped), | 173 | 184 | ); | 174 | 185 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/provider-pi/src/server/mcpInjection.test.ts +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -102,6 +102,7 @@ describe("pi T3 MCP injection", () => { | 102 | 102 | extensionPath: "/tmp/cache/pi-t3-mcp-extension.ts", | 103 | 103 | sessionPath: "/fake/persisted.jsonl", | 104 | 104 | ephemeral: true, | | 105 | + shortLived: true, | 105 | 106 | disableExtensions: true, | 106 | 107 | disableTools: true, | 107 | 108 | }); | @@ -111,9 +112,19 @@ describe("pi T3 MCP injection", () => { | 111 | 112 | "--no-session", | 112 | 113 | "--provider", | 113 | 114 | "anthropic", | | 115 | + "--offline", | 114 | 116 | "--no-extensions", | 115 | 117 | "--no-tools", | 116 | 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"]); | 117 | 128 | assert.deepInclude(resolvePiLaunchArgs("--mode text"), { | 118 | 129 | ok: false, | 119 | 130 | message: "Pi launch argument '--mode' is controlled by T3 Code and cannot be overridden.", | |
Collapse file Copy file name to clipboardExpand all lines: packages/provider-pi/src/server/mcpInjection.ts +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -244,6 +244,9 @@ export function buildPiRpcLaunch(input: { | 244 | 244 | readonly extensionPath: string | undefined; | 245 | 245 | readonly sessionPath?: string | undefined; | 246 | 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; | 247 | 250 | readonly disableExtensions?: boolean; | 248 | 251 | readonly disableTools?: boolean; | 249 | 252 | readonly runtimeMode?: "approval-required" | "auto-accept-edits" | "auto" | "full-access"; | @@ -268,6 +271,7 @@ export function buildPiRpcLaunch(input: { | 268 | 271 | ? ["--session", input.sessionPath] | 269 | 272 | : []), | 270 | 273 | ...launchArgs, | | 274 | + ...(input.shortLived === true && !launchArgs.includes("--offline") ? ["--offline"] : []), | 271 | 275 | // Restrictions must follow launch args so user flags cannot re-enable unattended tools/extensions. | 272 | 276 | ...(input.disableExtensions === true ? ["--no-extensions"] : []), | 273 | 277 | ...(input.disableTools === true ? ["--no-tools"] : []), | |
Collapse file Copy file name to clipboardExpand all lines: packages/provider-pi/src/server/status.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -150,6 +150,7 @@ const makePiDiscoveryConnection = Effect.fnUntraced(function* ( | 150 | 150 | mcpSession: undefined, | 151 | 151 | extensionPath: undefined, | 152 | 152 | ephemeral: true, | | 153 | + shortLived: true, | 153 | 154 | }); | 154 | 155 | const connection = yield* makePiRpcConnection({ | 155 | 156 | command: piSettings.binaryPath || "pi", | |
Collapse file Copy file name to clipboardExpand all lines: packages/provider-pi/src/server/textGeneration.test.ts +30Lines changed: 30 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -7,6 +7,7 @@ import * as Queue from "effect/Queue"; | 7 | 7 | import * as Schema from "effect/Schema"; | 8 | 8 | import * as Sink from "effect/Sink"; | 9 | 9 | import * as Stream from "effect/Stream"; | | 10 | +import * as ChildProcess from "effect/process/ChildProcess"; | 10 | 11 | import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner"; | 11 | 12 |
| 12 | 13 | import { makePiTextGeneration } from "./textGeneration.ts"; | @@ -68,6 +69,35 @@ const makeFakePi = ( | 68 | 69 | return { spawner, received }; | 69 | 70 | }); | 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 | + | 71 | 101 | it.effect("names the model and the disabled extensions when Pi cannot load it", () => | 72 | 102 | Effect.gen(function* () { | 73 | 103 | const pi = yield* makeFakePi("", "Model not found: demo/demo-model"); | |
Collapse file Copy file name to clipboardExpand all lines: packages/provider-pi/src/server/textGeneration.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -47,6 +47,7 @@ export const makePiTextGeneration = Effect.fn("makePiTextGeneration")(function* | 47 | 47 | mcpSession: undefined, | 48 | 48 | extensionPath: undefined, | 49 | 49 | ephemeral: true, | | 50 | + shortLived: true, | 50 | 51 | disableExtensions: true, | 51 | 52 | // Background naming/content helpers must never mutate the workspace. | 52 | 53 | disableTools: true, | |
|