Skip to content

Commit 511a3a5

Browse files
maria-rcksclaude
andcommitted
fix(server): existing managed Codex installs update to the raised pin on startup
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent cb917ec commit 511a3a5

2 files changed

Lines changed: 32 additions & 3 deletions

File tree

‎apps/server/src/provider/CodexInstallation.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,33 @@ it.effect("requires an update before running an older activated managed installa
359359
}).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
360360
);
361361

362+
it.effect("updates an older supported managed installation to the pinned release on startup", () =>
363+
Effect.gen(function* () {
364+
const first = yield* makeHarness();
365+
yield* first.installation.start;
366+
yield* terminalState(first.installation);
367+
const executable = yield* first.installation.resolve();
368+
const oldDirectory = `${first.installation.managedDirectory}/0.156.0`;
369+
yield* first.fs.rename(executable.managedVersionDirectory!, oldDirectory);
370+
for (const name of ["codex-package.json", ".install-complete.json"]) {
371+
const file = `${oldDirectory}/${name}`;
372+
yield* first.fs.writeFileString(
373+
file,
374+
(yield* first.fs.readFileString(file)).replaceAll("0.156.1", "0.156.0"),
375+
);
376+
}
377+
yield* first.fs.writeFileString(
378+
`${first.installation.managedDirectory}/active.json`,
379+
'{"version":"0.156.0"}',
380+
);
381+
const restarted = yield* makeHarness({ baseDir: first.baseDir });
382+
expect((yield* restarted.installation.state).operationId).not.toBeNull();
383+
expect((yield* terminalState(restarted.installation)).phase).toBe("succeeded");
384+
expect((yield* restarted.installation.resolve()).version).toBe("0.156.1");
385+
expect(restarted.downloads()).toBe(1);
386+
}).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
387+
);
388+
362389
it.effect("rejects corrupted downloads without publishing a runtime", () =>
363390
Effect.gen(function* () {
364391
const { installation, fs } = yield* makeHarness({

‎apps/server/src/provider/CodexInstallation.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
type ServerProviderCompatibilityAdvisory,
66
} from "@t3tools/contracts";
77
import { cliArchiveTarCommand } from "@t3tools/shared/cliRelease";
8+
import { compareSemverVersions } from "@t3tools/shared/semver";
89
import * as HostProcess from "@t3tools/shared/HostProcess";
910
import { resolveCommandPath, resolveSpawnCommand } from "@t3tools/shared/shell";
1011
import * as Clock from "effect/Clock";
@@ -655,14 +656,12 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function
655656
}
656657
const operationId = yield* random.uuidV4();
657658
const next: ProviderInstallState = {
658-
driver: DRIVER,
659+
...current,
659660
operationId,
660661
phase: "downloading",
661662
downloadedBytes: 0,
662663
totalBytes: asset.archiveBytes,
663664
version: asset.version,
664-
installedVersion: current.installedVersion,
665-
canRemove: current.canRemove,
666665
message: "Downloading Codex.",
667666
};
668667
yield* SubscriptionRef.set(state, next);
@@ -807,6 +806,9 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function
807806
source: "managed",
808807
}) satisfies ProviderInstallState,
809808
);
809+
// A supported older runtime still resolves, so a raised pin needs its own update.
810+
if (asset && compareSemverVersions(installed.version, asset.version) < 0)
811+
yield* start.pipe(Effect.ignore);
810812
}).pipe(
811813
Effect.catch(() =>
812814
SubscriptionRef.update(

0 commit comments

Comments
 (0)