GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(pi): the T3 MCP extension file is written atomically by rishabhx29 · Pull Request #32231 · pingdotgg/t3code

fix(pi): the T3 MCP extension file is written atomically #32231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Yash-Singh1 merged 3 commits into pingdotgg:main from rishabhx29:fix/pi-extension-atomic-write
Nov 7, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

fix(pi): the T3 MCP extension file is written atomically #32231

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
3 commits
Select commit Hold shift + click to select a range
b6f506e
fix(pi): the T3 MCP extension file is written atomically
rishabhx29 Nov 6, 2026
902d06f
Merge remote-tracking branch 'github/main' into fix/pi-extension-atom…
maria-rcks Nov 7, 2026
8c91638
fix(pi): concurrent materializations use separate staging files
maria-rcks Nov 7, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

65 changes: 63 additions & 2 deletions 65 packages/provider-pi/src/server/mcpInjection.test.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert, describe, it } from "@effect/vitest";
import { assert, describe, expect, it } from "@effect/vitest";
import { EnvironmentId, ProviderInstanceId, ThreadId } from "@t3tools/contracts";

import {
Expand All @@ -7,7 +7,18 @@ import {
T3_PI_RUNTIME_MODE_ENV,
T3_PI_MCP_EXTENSION_PATH_ENV,
} from "./mcpExtensionSource.ts";
import { buildPiRpcLaunch, resolvePiLaunchArgs } from "./mcpInjection.ts";
import * as Effect from "effect/Effect";
import * as Fiber from "effect/Fiber";
import * as Option from "effect/Option";
import * as NodePath from "effect/Path";
import * as NodeFS from "effect/FileSystem";
import * as NodeServices from "@effect/platform-node/NodeServices";
import {
buildPiRpcLaunch,
materializePiT3McpExtension,
resolvePiLaunchArgs,
} from "./mcpInjection.ts";
import { PI_T3_MCP_EXTENSION_SOURCE } from "./mcpExtensionSource.ts";

const threadId = ThreadId.make("thread-pi-t3-mcp");

Expand Down Expand Up @@ -145,3 +156,53 @@ describe("pi T3 MCP injection", () => {
assert.isTrue(resolvePiLaunchArgs("--model deepseek/v4").ok);
});
});

describe("materializePiT3McpExtension", () => {
// A pi launch concurrent with the materialize reads the extension file from
// disk; a truncate-then-write exposes an empty or partial file mid-write and
// the launch loads a broken extension.
it.live("never exposes a torn extension file to a concurrent reader", () =>
Effect.gen(function* () {
const fs = yield* NodeFS.FileSystem;
const path = yield* NodePath.Path;
const directory = yield* fs.makeTempDirectoryScoped({ prefix: "t3-pi-atomic-" });
const anomalies: Array<string> = [];
const stopAfter = 120;
const writer = yield* Effect.forkChild(
Effect.gen(function* () {
for (let index = 0; index < stopAfter; index += 1) {
yield* fs
.remove(path.join(directory, "pi-t3-mcp-extension.ts"), { force: true })
.pipe(Effect.ignore);
yield* Effect.all(
[materializePiT3McpExtension(directory), materializePiT3McpExtension(directory)],
{ concurrency: "unbounded" },
);
}
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
);
const reader = yield* Effect.forkChild(
Effect.forever(
Effect.gen(function* () {
const text = yield* fs
.readFileString(path.join(directory, "pi-t3-mcp-extension.ts"))
.pipe(Effect.option);
if (Option.isNone(text)) return; // Missing between writes: legitimate.
// A read that SUCCEEDS must return the full extension: an empty or
// partial read means the writer truncated the file mid-write.
if (text.value.length === 0) {
anomalies.push("empty: truncated mid-write");
} else if (text.value.length !== PI_T3_MCP_EXTENSION_SOURCE.length) {
anomalies.push(
`partial: ${text.value.length} of ${PI_T3_MCP_EXTENSION_SOURCE.length} chars`,
);
}
}),
),
);
yield* Fiber.join(writer);
yield* Fiber.interrupt(reader);
expect(anomalies).toEqual([]);
}).pipe(Effect.provide(NodeServices.layer)),
);
});
11 changes: 10 additions & 1 deletion 11 packages/provider-pi/src/server/mcpInjection.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,16 @@ export const materializePiT3McpExtension = Effect.fn("materializePiT3McpExtensio
const dest = piT3McpExtensionDestPath(cacheDir);
const existing = yield* fs.readFileString(dest).pipe(Effect.orElseSucceed(() => ""));
if (existing !== PI_T3_MCP_EXTENSION_SOURCE) {
yield* fs.writeFileString(dest, PI_T3_MCP_EXTENSION_SOURCE);
// Concurrent pi launches read this file: stage it in a per-call directory
// and rename so readers and other writers never see a partial file.
yield* Effect.scoped(
Effect.gen(function* () {
const stagingDir = yield* fs.makeTempDirectoryScoped({ directory: cacheDir });
const staging = `${stagingDir.replace(/\\/g, "/")}/${PI_T3_MCP_EXTENSION_FILENAME}`;
yield* fs.writeFileString(staging, PI_T3_MCP_EXTENSION_SOURCE);
yield* fs.rename(staging, dest).pipe(Effect.retry({ times: 3 }));
Comment thread
Yash-Singh1 marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

}),
);
}
return dest;
});
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.