diff --git a/FORK.md b/FORK.md index cd869822f0104..b56d0ab4810cd 100644 --- a/FORK.md +++ b/FORK.md @@ -59,14 +59,18 @@ Releases keep the `-preview..` naming, whatever the 1. Fetches the target (the newest stable tag; see above). If the integration branch already contains it, or is ahead of every stable tag, it verifies that the integration tree is published and retries an unfinished publication. 2. Merges a newer tag on a `sync/upstream-` branch, or re-checks an open `sync/upstream-*` PR (one a failed run opened, or an agent's conflict fix). `agentContextBudget.json` conflicts are taken from upstream and re-measured. 3. Runs format, lint, typecheck and the server tests. Every test must pass; pre-existing failures still block publication. -4. Builds the release in a container (`scripts/fork/build-release.sh`, the recipe every `v0.1.9-preview.*` release used) and smoke-tests it, then runs the built CLI's `__service-preflight` read-only against the live database for launcher protocols 3 and 4. The same output reports each configured Codex instance's shadow home; an instance whose shadow the new build would refuse to set up (`not-ready`) or could not inspect (`unknown`) stops the release, while `auto-settle` ones, which the build moves aside into a dated backup beside the shadow, do not. +4. Builds the release in a container (`scripts/fork/build-release.sh`, the recipe every `v0.1.9-preview.*` release used) and smoke-tests it, then runs the built CLI's `__service-preflight` read-only against the live database for launcher protocols 3 and 4. The release gate clears caller-provided `CODEX_HOME` and `CODEX_SQLITE_HOME` so an agent shell cannot redirect the check; per-instance environment from T3 settings still applies. The same output reports each configured Codex instance's shadow home; an instance whose shadow the new build would refuse to set up (`not-ready`) or could not inspect (`unknown`) stops the release. `auto-settle` conflicts are safe for setup: a legacy `memories_v2` link is removed without changing its shared target, while the shadow's own SQLite databases are moved to a dated backup beside the shadow. 5. When all of that and the hosted checks pass, it merges the PR and publishes `v-preview..` with the tarball and `SHA256SUMS` (`scripts/fork/publish-release.sh`). The host's update guard then installs it when no threads are running. A conflict opens (or updates) an issue labelled `upstream-sync`, or comments on the open sync PR. A failed check opens a PR that says what failed. Neither publishes anything. The scheduled agent watches a pending PR and resumes on CI/review completion, so publication need not wait until the next hourly check. An existing candidate is completed before newer upstream changes are added, preventing repeated CI resets. Exit codes: 0 done or nothing to do, 3 conflict, 4 failed check, 2 environment problem. To release by hand from a clean, merged integration commit: `scripts/fork/build-release.sh `, then `scripts/fork/publish-release.sh ""`. Versions must sort above every earlier fork release under `sort -V`, because the guard installs the newest one. -The host update guard that installs these releases lives in `scripts/fork/host/t3-update-guard/` (see its README). It waits up to 30 min for an idle server, then forces the update after a bounded wait for pending approvals and in-flight tool calls. It never stops the service while the kernel shows the exit hang, and it reports which interrupted threads continued. Change it here, run `test-guard.sh`, then install it. +The host update guard that installs these releases lives in `scripts/fork/host/t3-update-guard/` (see its README). It waits up to 30 min for an idle server, then forces the update after a bounded wait for pending approvals and in-flight tool calls. It never stops the service while the kernel shows the exit hang, and it reports which interrupted threads continued. It prefers builds with a positive Codex shadow preflight, but keeps a database-compatible build running if no safer fallback is known; a shadow conflict disables only that Codex instance. Change it here, run `test-guard.sh`, then install it. + +### Codex shadow compatibility + +New releases no longer link the shared `memories_v2` directory into Codex shadow homes. If a prior release has already created that link, the new release removes the link and keeps the shared contents; any real, instance-local `memories_v2` directory is left in place. After Codex creates local memories, an older release may treat that directory as an unsupported shadow conflict and refuse to start that Codex instance. The server can still serve other work, and the update guard keeps a database-compatible build running. Upgrade to a release that recognizes local `memories_v2` before expecting that provider instance to start; do not remove its local memories to make an older build run. The service's `T3CODE_RELEASE_BASE_URL` selects the fork feed for both metadata and self-update targets. An upstream desktop's exact nightly target resolves to the diff --git a/apps/server/src/cloud/codexShadowPreflight.test.ts b/apps/server/src/cloud/codexShadowPreflight.test.ts index 88b8a20d0ff42..b0a9b43b76cfa 100644 --- a/apps/server/src/cloud/codexShadowPreflight.test.ts +++ b/apps/server/src/cloud/codexShadowPreflight.test.ts @@ -5,6 +5,7 @@ import * as FileSystem from "effect/FileSystem"; import * as Path from "effect/Path"; import { symlinksSupported } from "@t3tools/shared/testing/symlinks"; +import * as HostProcess from "@t3tools/shared/HostProcess"; import { unmanagedProviders } from "../policy/managedProviders.ts"; import { unmanagedSettings } from "../policy/managedSettings.ts"; import { inspectConfiguredCodexShadowHomes } from "./codexShadowPreflight.ts"; @@ -255,6 +256,161 @@ it.layer(NodeServices.layer)("inspectConfiguredCodexShadowHomes", (it) => { }), ); + it.effect.skipIf(!symlinksSupported)( + "uses CODEX_HOME when the shadow path is configured without homePath", + () => + Effect.gen(function* () { + const fileSystem = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const stateDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3code-state-" }); + const home = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3code-home-" }); + const sharedHome = yield* fileSystem.makeTempDirectoryScoped({ + prefix: "t3code-codex-shared-", + }); + const shadowHome = yield* fileSystem.makeTempDirectoryScoped({ + prefix: "t3code-codex-shadow-", + }); + yield* fileSystem.writeFileString(path.join(sharedHome, "config.toml"), "shared"); + yield* fileSystem.writeFileString(path.join(shadowHome, "config.toml"), "local"); + yield* fileSystem.writeFileString( + path.join(stateDir, "settings.json"), + JSON.stringify({ + providerInstances: { + codex_work: { + driver: "codex", + config: { shadowHomePath: shadowHome }, + environment: [{ name: "CODEX_HOME", value: sharedHome }], + }, + }, + }), + ); + + const report = yield* inspectConfiguredCodexShadowHomes(stateDir).pipe( + Effect.provideService(HostProcess.HomeDirectory, home), + ); + + expect(report.status).toBe("not-ready"); + expect(report.instances).toEqual([ + { + instanceId: "codex_work", + shadowHomePath: shadowHome, + status: "not-ready", + conflicts: [ + { + entryName: "config.toml", + path: path.join(shadowHome, "config.toml"), + autoSettle: false, + }, + ], + }, + ]); + }), + ); + + it.effect.skipIf(!symlinksSupported)( + "uses CODEX_HOME when homePath contains only whitespace", + () => + Effect.gen(function* () { + const fileSystem = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const stateDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3code-state-" }); + const home = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3code-home-" }); + const sharedHome = yield* fileSystem.makeTempDirectoryScoped({ + prefix: "t3code-codex-shared-", + }); + const shadowHome = yield* fileSystem.makeTempDirectoryScoped({ + prefix: "t3code-codex-shadow-", + }); + yield* fileSystem.writeFileString(path.join(sharedHome, "config.toml"), "shared"); + yield* fileSystem.writeFileString(path.join(shadowHome, "config.toml"), "local"); + yield* fileSystem.writeFileString( + path.join(stateDir, "settings.json"), + JSON.stringify({ + providerInstances: { + codex_work: { + driver: "codex", + config: { homePath: " ", shadowHomePath: shadowHome }, + environment: [{ name: "CODEX_HOME", value: sharedHome }], + }, + }, + }), + ); + + const report = yield* inspectConfiguredCodexShadowHomes(stateDir).pipe( + Effect.provideService(HostProcess.HomeDirectory, home), + ); + + expect(report.status).toBe("not-ready"); + expect(report.instances[0]).toMatchObject({ + instanceId: "codex_work", + shadowHomePath: shadowHome, + status: "not-ready", + conflicts: [ + { + entryName: "config.toml", + path: path.join(shadowHome, "config.toml"), + autoSettle: false, + }, + ], + }); + }), + ); + + it.effect.skipIf( + !symlinksSupported || + HostProcess.Platform.defaultValue() === "win32" || + HostProcess.Username.defaultValue() === "root", + )("marks a shared memories_v2 link not-ready when its shadow directory is read-only", () => + Effect.gen(function* () { + const fileSystem = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const stateDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3code-state-" }); + const sharedHome = yield* fileSystem.makeTempDirectoryScoped({ + prefix: "t3code-codex-shared-", + }); + const shadowHome = yield* fileSystem.makeTempDirectoryScoped({ + prefix: "t3code-codex-shadow-", + }); + const sharedMemories = path.join(sharedHome, "memories_v2"); + const shadowMemories = path.join(shadowHome, "memories_v2"); + yield* fileSystem.makeDirectory(sharedMemories); + yield* fileSystem.symlink(sharedMemories, shadowMemories); + yield* fileSystem.writeFileString( + path.join(stateDir, "settings.json"), + JSON.stringify({ + providerInstances: { + codex_work: { + driver: "codex", + config: { homePath: sharedHome, shadowHomePath: shadowHome }, + }, + }, + }), + ); + yield* fileSystem.chmod(shadowHome, 0o555); + + const report = yield* inspectConfiguredCodexShadowHomes(stateDir).pipe( + Effect.ensuring(fileSystem.chmod(shadowHome, 0o755).pipe(Effect.orDie)), + ); + + expect(report.status).toBe("not-ready"); + expect(report.instances).toEqual([ + { + instanceId: "codex_work", + shadowHomePath: shadowHome, + status: "not-ready", + conflicts: [ + { + entryName: "memories_v2", + path: shadowMemories, + autoSettle: false, + }, + ], + }, + ]); + expect(yield* fileSystem.readLink(shadowMemories)).toBe(sharedMemories); + }), + ); + it.effect("is ready when there is no settings file", () => Effect.gen(function* () { const fileSystem = yield* FileSystem.FileSystem; diff --git a/apps/server/src/cloud/codexShadowPreflight.ts b/apps/server/src/cloud/codexShadowPreflight.ts index b182fadcf5fb5..6e9c90d1bb89e 100644 --- a/apps/server/src/cloud/codexShadowPreflight.ts +++ b/apps/server/src/cloud/codexShadowPreflight.ts @@ -21,7 +21,7 @@ import { decodeSettingsFileContents } from "../serverSettings.ts"; export interface CodexShadowHomeReport { readonly instanceId: string; readonly shadowHomePath: string; - /** `auto-settle`: setup will move the shadow's own databases aside; `not-ready`: setup will refuse. */ + /** `auto-settle`: setup can remove a shared link or move the shadow's own databases aside. */ readonly status: "ready" | "auto-settle" | "not-ready" | "unknown"; readonly conflicts: ReadonlyArray<{ readonly entryName: string; @@ -129,7 +129,7 @@ export const inspectConfiguredCodexShadowHomes = Effect.fn("inspectConfiguredCod config, ) : yield* resolveCodexHomeLayout( - !config.homePath && !config.shadowHomePath && environment.CODEX_HOME?.trim() + !config.homePath?.trim() && environment.CODEX_HOME?.trim() ? { ...config, homePath: environment.CODEX_HOME } : config, ); diff --git a/apps/server/src/provider/Drivers/CodexHomeLayout.test.ts b/apps/server/src/provider/Drivers/CodexHomeLayout.test.ts index 3d57a93133fd0..466ab671e0b52 100644 --- a/apps/server/src/provider/Drivers/CodexHomeLayout.test.ts +++ b/apps/server/src/provider/Drivers/CodexHomeLayout.test.ts @@ -459,11 +459,19 @@ it.layer(NodeServices.layer)("CodexHomeLayout", (it) => { yield* fileSystem.makeDirectory(path.join(sharedHome, "log")); yield* fileSystem.makeDirectory(path.join(sharedHome, "memories")); + yield* fileSystem.makeDirectory(path.join(sharedHome, "memories_v2")); yield* fileSystem.makeDirectory(path.join(sharedHome, "tmp")); yield* writeTextFile(path.join(sharedHome, "config.toml"), 'model = "gpt-5-codex"\n'); yield* writeTextFile(path.join(shadowHome, "auth.json"), '{"shadow":true}\n'); yield* fileSystem.makeDirectory(path.join(shadowHome, "log"), { recursive: true }); yield* fileSystem.makeDirectory(path.join(shadowHome, "memories"), { recursive: true }); + yield* fileSystem.makeDirectory(path.join(shadowHome, "memories_v2"), { + recursive: true, + }); + yield* writeTextFile( + path.join(shadowHome, "memories_v2", "memory_summary.md"), + "shadow memory", + ); yield* fileSystem.makeDirectory(path.join(shadowHome, "tmp"), { recursive: true }); const layout = yield* resolveCodexHomeLayout( @@ -482,17 +490,68 @@ it.layer(NodeServices.layer)("CodexHomeLayout", (it) => { const memoriesLinkResult = yield* fileSystem .readLink(path.join(shadowHome, "memories")) .pipe(Effect.result); + const memoriesV2LinkResult = yield* fileSystem + .readLink(path.join(shadowHome, "memories_v2")) + .pipe(Effect.result); const tmpLinkResult = yield* fileSystem .readLink(path.join(shadowHome, "tmp")) .pipe(Effect.result); + const memoriesV2Content = yield* fileSystem.readFileString( + path.join(shadowHome, "memories_v2", "memory_summary.md"), + ); expect(configTarget).toBe(path.join(sharedHome, "config.toml")); expect(logLinkResult._tag).toBe("Failure"); expect(memoriesLinkResult._tag).toBe("Failure"); + expect(memoriesV2LinkResult._tag).toBe("Failure"); + expect(memoriesV2Content).toBe("shadow memory"); expect(tmpLinkResult._tag).toBe("Failure"); }), ); + it.effect.skipIf(!symlinksSupported)( + "unlinks legacy memories_v2 links to the shared home without changing shared memory", + () => + Effect.gen(function* () { + const fileSystem = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const sharedHome = yield* makeTempDir("t3code-codex-shared-"); + const shadowRoot = yield* makeTempDir("t3code-codex-shadow-root-"); + const shadowHome = path.join(shadowRoot, "shadow"); + const sharedMemoriesV2 = path.join(sharedHome, "memories_v2"); + const shadowMemoriesV2 = path.join(shadowHome, "memories_v2"); + const sharedSummary = path.join(sharedMemoriesV2, "memory_summary.md"); + + yield* fileSystem.makeDirectory(sharedMemoriesV2, { recursive: true }); + yield* fileSystem.makeDirectory(shadowHome, { recursive: true }); + yield* writeTextFile(sharedSummary, "shared memory"); + yield* fileSystem.symlink(sharedMemoriesV2, shadowMemoriesV2); + + const layout = yield* resolveCodexHomeLayout( + decodeCodexSettings({ + homePath: sharedHome, + shadowHomePath: shadowHome, + }), + ); + + const conflicts = yield* inspectCodexShadowHome(layout, noSqliteHome); + expect(conflicts).toContainEqual({ + entryName: "memories_v2", + path: shadowMemoriesV2, + sqliteFiles: undefined, + autoSettle: true, + }); + expect(yield* fileSystem.readLink(shadowMemoriesV2)).toBe(sharedMemoriesV2); + + yield* materializeCodexShadowHome(layout, noSqliteHome); + + expect((yield* fileSystem.readLink(shadowMemoriesV2).pipe(Effect.result))._tag).toBe( + "Failure", + ); + expect(yield* fileSystem.readFileString(sharedSummary)).toBe("shared memory"); + }), + ); + it.effect("rejects shadow homes that point at the shared home", () => Effect.gen(function* () { const sharedHome = yield* makeTempDir("t3code-codex-shared-"); @@ -550,6 +609,33 @@ it.layer(NodeServices.layer)("CodexHomeLayout", (it) => { }), ); + it.effect.skipIf(!symlinksSupported)( + "leaves legacy shared memories_v2 links in place when another conflict refuses setup", + () => + Effect.gen(function* () { + const fileSystem = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const sharedHome = yield* makeTempDir("t3code-codex-shared-"); + const shadowRoot = yield* makeTempDir("t3code-codex-shadow-root-"); + const shadowHome = path.join(shadowRoot, "shadow"); + const sharedMemories = path.join(sharedHome, "memories_v2"); + const shadowMemories = path.join(shadowHome, "memories_v2"); + yield* writeTextFile(path.join(sharedHome, "config.toml"), 'model = "shared"\n'); + yield* writeTextFile(path.join(shadowHome, "config.toml"), 'model = "local"\n'); + yield* fileSystem.makeDirectory(sharedMemories, { recursive: true }); + yield* fileSystem.makeDirectory(shadowHome, { recursive: true }); + yield* fileSystem.symlink(sharedMemories, shadowMemories); + + const layout = yield* resolveCodexHomeLayout( + decodeCodexSettings({ homePath: sharedHome, shadowHomePath: shadowHome }), + ); + const error = yield* materializeCodexShadowHome(layout, noSqliteHome).pipe(Effect.flip); + + expect(error).toBeInstanceOf(CodexShadowHomeEntryConflictError); + expect(yield* fileSystem.readLink(shadowMemories)).toBe(sharedMemories); + }), + ); + // Codex wrote memories_v2_1.sqlite into the shadow before CODEX_SQLITE_HOME, and the // shared home gained its own copy later; the next setup failed every session. const ownDatabaseFiles = [ diff --git a/apps/server/src/provider/Drivers/CodexHomeLayout.ts b/apps/server/src/provider/Drivers/CodexHomeLayout.ts index ae40b0ad4294a..92eaca91c9261 100644 --- a/apps/server/src/provider/Drivers/CodexHomeLayout.ts +++ b/apps/server/src/provider/Drivers/CodexHomeLayout.ts @@ -36,7 +36,7 @@ const KNOWN_SHARED_DIRECTORIES = [ // auth.lock guards the shadow home's private auth.json. const PRIVATE_ENTRY_NAMES = new Set(["auth.json", "auth.lock", "models_cache.json"]); // Finder maintains metadata separately for each directory, including shadow homes. -const SHADOW_LOCAL_ENTRY_NAMES = new Set(["log", "memories", "tmp", ".DS_Store"]); +const SHADOW_LOCAL_ENTRY_NAMES = new Set(["log", "memories", "memories_v2", "tmp", ".DS_Store"]); // Shadow homes may create local runtime locks first; replace them with shared links because they guard shared state. const REPLACEABLE_SHARED_RUNTIME_ENTRIES = new Set([ "mcp-oauth-locks", @@ -548,6 +548,55 @@ const backupParentAccepts = Effect.fnUntraced(function* ( ); }); +const sharedMemoriesV2LinkPath = Effect.fn("CodexHomeLayout.sharedMemoriesV2LinkPath")( + function* (input: { + readonly fileSystem: FileSystem.FileSystem; + readonly sharedHomePath: string; + readonly effectiveHomePath: string; + }): Effect.fn.Return { + const path = yield* Path.Path; + const entryName = "memories_v2"; + const linkPath = path.join(input.effectiveHomePath, entryName); + const state = yield* readLinkState({ + ...input, + entryName, + linkPath, + }); + if (state._tag !== "Symlink") return undefined; + + const resolvedTarget = path.resolve(path.dirname(linkPath), state.target); + const sharedTarget = path.join(input.sharedHomePath, entryName); + return resolvedTarget === sharedTarget || + (yield* sameDirectory(input.fileSystem, path, resolvedTarget, sharedTarget)) + ? linkPath + : undefined; + }, +); + +const removeSharedMemoriesV2Link = Effect.fn("CodexHomeLayout.removeSharedMemoriesV2Link")( + function* (input: { + readonly fileSystem: FileSystem.FileSystem; + readonly sharedHomePath: string; + readonly effectiveHomePath: string; + }): Effect.fn.Return { + const linkPath = yield* sharedMemoriesV2LinkPath(input); + if (linkPath === undefined) return; + yield* input.fileSystem.remove(linkPath).pipe( + Effect.catchTags({ + PlatformError: (cause) => + new CodexShadowHomeFileSystemError({ + sharedHomePath: input.sharedHomePath, + effectiveHomePath: input.effectiveHomePath, + operation: "remove", + path: linkPath, + entryName: "memories_v2", + cause, + }), + }), + ); + }, +); + /** Read-only: what materializing this shadow home would have to move aside or refuse. */ export const inspectCodexShadowHome = Effect.fn("inspectCodexShadowHome")(function* ( layout: CodexHomeLayout, @@ -604,6 +653,21 @@ export const inspectCodexShadowHome = Effect.fn("inspectCodexShadowHome")(functi autoSettle: false, }); } + const sharedMemoriesV2Link = yield* sharedMemoriesV2LinkPath(context); + if (sharedMemoriesV2Link !== undefined) { + const shadowDirectoryWritable = yield* fileSystem + .access(effectiveHomePath, { writable: true }) + .pipe( + Effect.as(true), + Effect.orElseSucceed(() => false), + ); + conflicts.push({ + entryName: "memories_v2", + path: sharedMemoriesV2Link, + sqliteFiles: undefined, + autoSettle: shadowDirectoryWritable, + }); + } for (const entryName of shadowLinkEntryNames(sharedEntryNames)) { if (PRIVATE_ENTRY_NAMES.has(entryName)) continue; const entryPath = path.join(effectiveHomePath, entryName); @@ -798,20 +862,6 @@ const materializeCodexShadowHomeUnlocked = Effect.fn("materializeCodexShadowHome ); const entries = shadowLinkEntryNames(sharedEntryNames); - yield* Effect.forEach( - PRIVATE_ENTRY_NAMES, - (entryName) => - entryName === "auth.json" - ? Effect.void - : removePrivateSymlink({ - fileSystem, - sharedHomePath: layout.sharedHomePath, - effectiveHomePath, - entryName, - }), - { discard: true }, - ); - const conflicts = yield* inspectCodexShadowHome(layout, options); const platform = yield* HostProcess.Platform; const backupDirectory = backupDirectoryFor( @@ -819,7 +869,7 @@ const materializeCodexShadowHomeUnlocked = Effect.fn("materializeCodexShadowHome effectiveHomePath, yield* Clock.currentTimeMillis, ); - // Refuse before moving anything, so a failed setup leaves the shadow as it found it. + // Refuse before moving databases or unlinking entries. const blocker = conflicts.find((conflict) => !conflict.autoSettle); if (blocker !== undefined && blocker.sqliteFiles === undefined) { return yield* blocker.entryName === "auth.json" @@ -872,6 +922,28 @@ const materializeCodexShadowHomeUnlocked = Effect.fn("materializeCodexShadowHome ); } + yield* Effect.forEach( + PRIVATE_ENTRY_NAMES, + (entryName) => + entryName === "auth.json" + ? Effect.void + : removePrivateSymlink({ + fileSystem, + sharedHomePath: layout.sharedHomePath, + effectiveHomePath, + entryName, + }), + { discard: true }, + ); + + // Older releases linked this shared directory into every shadow. Remove only the link; the + // shared target and any real, instance-local memories_v2 directory remain untouched. + yield* removeSharedMemoriesV2Link({ + fileSystem, + sharedHomePath: layout.sharedHomePath, + effectiveHomePath, + }); + yield* settleShadowSqliteSidecars({ fileSystem, sharedHomePath: layout.sharedHomePath, diff --git a/scripts/fork/host/t3-update-guard/README.md b/scripts/fork/host/t3-update-guard/README.md index 7dec0221951b3..c31037f0a5fcb 100644 --- a/scripts/fork/host/t3-update-guard/README.md +++ b/scripts/fork/host/t3-update-guard/README.md @@ -22,6 +22,8 @@ Installing the guard does not restart the T3 service. ## When updates happen +- **Launch selection:** the guard prefers a build with a positive Codex shadow readiness report. It switches away from the active build only when that build positively reports a shadow conflict and another verified build reports ready. Missing or unknown shadow status keeps the active build when it can open the database. If an update launch is redirected to a compatible build because of a positive shadow conflict, the release is marked rejected on this host, not bad globally; fix the shadow conflict and retry with `t3-service-update `. + - **Idle server:** the guard updates once no thread has run for 15 min. - **Busy server:** threads nearly always run, so after 30 min of waiting (`MAX_DEFER_SECONDS`) the update is forced. - **Before a forced restart:** the guard waits up to 20 more minutes (`FORCE_GRACE_SECONDS`) while an approval or question is pending, or a tool call is still running. A restart cancels pending approvals, and a tool call cut off part-way can be repeated by its continuation. It checks again just before stopping. diff --git a/scripts/fork/host/t3-update-guard/guard b/scripts/fork/host/t3-update-guard/guard index 6a2bae7d811b5..262c5670d2258 100755 --- a/scripts/fork/host/t3-update-guard/guard +++ b/scripts/fork/host/t3-update-guard/guard @@ -9,9 +9,9 @@ # down twice on 2026-11-11. # # How: -# launch systemd ExecStart (drop-in). Starts the active build only if it is a verified -# release from a trusted repo; otherwise restores the newest build that has run -# here and starts that. +# launch systemd ExecStart (drop-in). Starts a verified active build when its database and +# Codex shadow homes are ready. A positive shadow conflict may select a known-ready +# build; unknown shadow status keeps the active database-compatible build running. # prove Run ~90 s after each start. Records the active build as healthy once it serves. # rollback systemd OnFailure. If a build that never proved healthy crash-loops, go back to # the newest healthy build and start it. @@ -341,16 +341,23 @@ trust() { log "trusted $v" } -# Whether build $1 says it can run on the current database. A release can migrate the -# database one way (e.g. the fork's migration-namespace repair), after which older builds -# refuse it; never fall back to one of those. Unknown answers count as yes. -can_open() { - local v="$1" proto out status +# Run build $1's launcher preflight against the current database. +service_preflight() { + local v="$1" proto proto=$(jq -r '.protocol // 3' "$GUARD_STATE/healthy/$v.json" 2>/dev/null) [[ "$proto" =~ ^[0-9]+$ ]] || proto=$(jq -r '.protocol // 3' "$STATE_FILE" 2>/dev/null) [[ "$proto" =~ ^[0-9]+$ ]] || proto=3 - out=$(timeout 120 "$(binary_of "$v")" __service-preflight --database-path "$DB" \ - --launcher-protocol "$proto" 2>/dev/null | tail -n1) + timeout 120 "$(binary_of "$v")" __service-preflight --database-path "$DB" \ + --launcher-protocol "$proto" 2>/dev/null | tail -n1 +} + +# Whether build $1 says it can run on the current database. A release can migrate the +# database one way (e.g. the fork's migration-namespace repair), after which older builds +# refuse it; never fall back to one of those. Unknown answers count as yes. Shadow-home +# readiness is deliberately not part of database compatibility: restoring a snapshot because +# of a shadow-only failure would discard database writes without fixing the shadow. +preflight_allows_database() { + local v="$1" out="$2" status status=$(jq -r '.status // empty' <<<"$out" 2>/dev/null) # The guard runs each build's own launcher, so a launcher-protocol refusal does not apply. if [[ "$status" == "blocked" ]] && ! jq -re '.reason | startswith("The installed service launcher speaks protocol")' <<<"$out" >/dev/null 2>&1; then @@ -360,10 +367,60 @@ can_open() { return 0 } -# Newest version that has served here, is installed, trusted, not excluded, and can open the -# current database. -newest_healthy_except() { +# Only a positive shadow-home report makes a build a preferred startup candidate. Return 1 for a +# positive shadow conflict, 2 for a database incompatibility, and 3 when shadow readiness is +# unknown. A missing or unknown report is not proof that an older build is safer. +can_start() { + local v="$1" out + out=$(service_preflight "$v") + preflight_allows_database "$v" "$out" || return 2 + if jq -e ' + .codexShadowHomes.status == "ready" and + all(.codexShadowHomes.instances[]?; .status == "ready" or .status == "auto-settle") + ' <<<"$out" >/dev/null 2>&1; then + return 0 + fi + if jq -e ' + any(.codexShadowHomes.instances[]?; .status == "not-ready") + ' <<<"$out" >/dev/null 2>&1; then + log "preflight: $v has a positively unready Codex shadow home" + return 1 + fi + log "preflight: $v shadow homes are unknown" + return 3 +} + +# Whether build $1 says it can run on the current database. +can_open() { + local v="$1" out + out=$(service_preflight "$v") + preflight_allows_database "$v" "$out" +} + +# Newest healthy, installed, trusted version with positively ready shadow homes. +newest_healthy_shadow_ready_except() { local skip="$1" f v + for v in $(for f in "$GUARD_STATE"/healthy/*.json; do + [[ -e "$f" ]] && basename "$f" .json + done | sort -rV); do + [[ "$v" == "$skip" ]] && continue + is_bad "$v" && continue + is_trusted "$v" || continue + can_start "$v" || continue + printf '%s\n' "$v" + return 0 + done +} + +# Prefer positively ready shadow homes, then keep service availability on any build that can +# open the current database. A shadow conflict only disables that Codex instance in the server. +newest_healthy_except() { + local skip="$1" preferred f v + preferred=$(newest_healthy_shadow_ready_except "$skip") + if [[ -n "$preferred" ]]; then + printf '%s\n' "$preferred" + return 0 + fi for v in $(for f in "$GUARD_STATE"/healthy/*.json; do [[ -e "$f" ]] && basename "$f" .json done | sort -rV); do @@ -396,7 +453,7 @@ exec_launcher() { } cmd_launch() { - local v fallback + local v fallback start_status v=$(active_version) if [[ -z "$v" ]]; then log "launch: no active version recorded" @@ -406,10 +463,29 @@ cmd_launch() { fi if installed "$v" && ! is_bad "$v" && { is_trusted "$v" || trust "$v"; }; then - can_open "$v" && exec_launcher "$v" + if can_start "$v"; then + exec_launcher "$v" + else + start_status=$? + fi + if [[ "$start_status" == 1 ]]; then + # A positive shadow conflict can justify switching to a known-ready build. + fallback=$(newest_healthy_shadow_ready_except "$v") + if [[ -n "$fallback" ]] && write_state_for "$fallback"; then + notify "$v shadow preflight was not ready. Started known-ready build $fallback instead." + exec_launcher "$fallback" + fi + log "launch: keeping database-compatible $v; no healthier shadow-ready build is known" + exec_launcher "$v" + fi + if [[ "$start_status" == 3 ]]; then + log "launch: keeping database-compatible $v; shadow readiness is unknown" + exec_launcher "$v" + fi + # A database-incompatible build may use any verified, compatible fallback. fallback=$(newest_healthy_except "$v") if [[ -n "$fallback" ]] && write_state_for "$fallback"; then - notify "$v refused this database at preflight. Started $fallback instead." + notify "$v cannot open the current database. Started compatible build $fallback instead." exec_launcher "$fallback" fi exec_launcher "$v" @@ -944,7 +1020,7 @@ cmd_update() { return fi if [[ -z "$target" && -e "$GUARD_STATE/rejected/$latest" ]]; then - log "update: $latest was rejected by the late canary; skipping (run t3-service-update $latest to retry)" + log "update: $latest was rejected on this host; skipping (run t3-service-update $latest to retry)" return 0 fi if is_bad "$latest" && [[ -z "$target" ]]; then @@ -1097,6 +1173,28 @@ cmd_update() { return 0 fi done + # A positive shadow conflict can intentionally redirect launch to a known-ready build. That + # keeps the service available, but does not mean the new release itself is broken. + local selected latest_start_status + selected=$(active_version) + up=$(service_uptime) || up=0 + if [[ "$selected" != "$latest" && -n "$selected" ]] && (( up >= 60 )) && + [[ "$(service_version)" == "$selected" ]] && is_trusted "$selected" && + is_healthy "$selected" && can_open "$selected"; then + if can_start "$latest"; then + latest_start_status=0 + else + latest_start_status=$? + fi + if [[ "$latest_start_status" == 1 ]]; then + mkdir -p "$GUARD_STATE/rejected" + date -Is >"$GUARD_STATE/rejected/$latest" + log "update: $latest has a positive shadow conflict; database-compatible $selected is serving" + notify "T3 update $latest was not selected because its Codex shadow preflight is not-ready. $selected remains serving; fix the shadow conflict and retry with t3-service-update $latest." + report "$latest was not selected because its Codex shadow preflight is not-ready; $selected remains serving. Fix the shadow conflict, then retry with t3-service-update $latest." + return 1 + fi + fi date -Is >"$GUARD_STATE/bad/$latest" # Reported once the rollback has decided (below), so the report never delays a stop or restart. local outcome diff --git a/scripts/fork/host/t3-update-guard/test-guard.sh b/scripts/fork/host/t3-update-guard/test-guard.sh index d40c12aaa268e..3e693edeebce2 100755 --- a/scripts/fork/host/t3-update-guard/test-guard.sh +++ b/scripts/fork/host/t3-update-guard/test-guard.sh @@ -9,6 +9,140 @@ sed '/^case "${1:-}" in/,$d' "$original" > "$root/functions" source "$root/functions" pass() { echo "PASS: $1"; } fail() { echo "FAIL: $1"; exit 1; } +# Database compatibility and Codex shadow readiness are separate rollback/startup checks. +real_binary_of=$(declare -f binary_of) +cat >"$root/fake-preflight" <<'EOF' +#!/bin/bash +printf '%s\n' "$PREFLIGHT_OUTPUT" +EOF +chmod +x "$root/fake-preflight" +binary_of() { echo "$root/fake-preflight"; } +export PREFLIGHT_OUTPUT='{"status":"ready","codexShadowHomes":{"status":"not-ready","instances":[{"status":"not-ready"}]}}' +can_open 1 || fail 'shadow readiness made a database-compatible build look incompatible' +if can_start 1; then fail 'startup selected a build with a known-unready Codex shadow home'; else + [[ "$?" == 1 ]] || fail 'known shadow conflict did not return its distinct status' +fi +export PREFLIGHT_OUTPUT='{"status":"ready","codexShadowHomes":{"status":"ready","instances":[]}}' +can_open 1 || fail 'database compatibility rejected a build with ready Codex shadow homes' +can_start 1 || fail 'startup rejected a build with ready Codex shadow homes' +export PREFLIGHT_OUTPUT='{"status":"not-ready","codexShadowHomes":{"status":"not-ready","instances":[{"status":"unknown"}]}}' +can_open 1 || fail 'an unknown secret-backed shadow made a database-compatible build unusable' +if can_start 1; then fail 'an unknown secret-backed shadow was treated as positively ready'; else + [[ "$?" == 3 ]] || fail 'unknown shadow readiness did not return its distinct status' +fi +export PREFLIGHT_OUTPUT='{"status":"ready"}' +can_open 1 || fail 'legacy preflight without shadow status made a database-compatible build unusable' +if can_start 1; then fail 'legacy preflight without shadow status was treated as positively ready'; else + [[ "$?" == 3 ]] || fail 'legacy shadow readiness did not return its distinct status' +fi +export PREFLIGHT_OUTPUT='{"status":"blocked","reason":"migration unavailable"}' +if can_start 1; then fail 'database-incompatible build was selected'; else + [[ "$?" == 2 ]] || fail 'database incompatibility did not return its distinct status' +fi +eval "$real_binary_of" +unset PREFLIGHT_OUTPUT +pass 'database compatibility, positive shadow conflicts, and unknown shadow status stay distinct' + +# Exercise the service-launch and crash-loop paths, including an older build that has no +# shadow preflight report. Shadow readiness is a preference; database compatibility keeps T3 up. +# A known-unready active build stays up when the only older build has no shadow report. +( + exec 9>&- + export T3_GUARD_DRY_RUN=1 + mkdir -p "$GUARD_STATE/healthy" "$root/versions/1" "$root/versions/2" + printf '{"protocol":4}\n' >"$GUARD_STATE/healthy/1.json" + for v in 1 2; do + cat >"$root/versions/$v/t3" </dev/null) + [[ "$out" == *"/versions/2/t3"* ]] || exit 1 +) || fail 'launch downgraded a database-compatible build to a legacy build without shadow status' +pass 'launch keeps a database-compatible active build when a legacy fallback has no shadow report' + +# An unknown active shadow report does not justify downgrading to an older ready build. +( + exec 9>&- + export T3_GUARD_DRY_RUN=1 + mkdir -p "$GUARD_STATE/healthy" "$root/versions/1" "$root/versions/2" + printf '{"protocol":4}\n' >"$GUARD_STATE/healthy/1.json" + cat >"$root/versions/1/t3" <<'EOF' +#!/bin/bash +echo '{"status":"ready","codexShadowHomes":{"status":"ready","instances":[]}}' +EOF + cat >"$root/versions/2/t3" <<'EOF' +#!/bin/bash +echo '{"status":"ready"}' +EOF + chmod +x "$root/versions/1/t3" "$root/versions/2/t3" + binary_of() { echo "$root/versions/$1/t3"; } + installed() { return 0; }; is_trusted() { return 0; }; is_bad() { return 1; } + active_version() { echo 2; } + out=$(cmd_launch 2>/dev/null) + [[ "$out" == *"/versions/2/t3"* ]] || exit 1 +) || fail 'launch downgraded an active build when its shadow preflight was unknown' +pass 'launch keeps the database-compatible active build when shadow readiness is unknown' + +# A positive shadow conflict can select an older build whose shadow homes are known ready. +( + exec 9>&- + export T3_GUARD_DRY_RUN=1 + mkdir -p "$GUARD_STATE/healthy" "$root/versions/1" "$root/versions/2" + printf '{"protocol":4}\n' >"$GUARD_STATE/healthy/1.json" + cat >"$root/versions/1/t3" <<'EOF' +#!/bin/bash +echo '{"status":"ready","codexShadowHomes":{"status":"ready","instances":[]}}' +EOF + cat >"$root/versions/2/t3" <<'EOF' +#!/bin/bash +echo '{"status":"ready","codexShadowHomes":{"status":"not-ready","instances":[{"status":"not-ready"}]}}' +EOF + chmod +x "$root/versions/1/t3" "$root/versions/2/t3" + binary_of() { echo "$root/versions/$1/t3"; } + installed() { return 0; }; is_trusted() { return 0; }; is_bad() { return 1; } + active_version() { echo 2; } + out=$(cmd_launch 2>/dev/null) + [[ "$out" == *"/versions/1/t3"* ]] || exit 1 +) || fail 'launch did not switch from a positively unready build to a known-ready fallback' +pass 'launch switches to an older build only after a positive shadow conflict' + +( + exec 9>&- + export T3_GUARD_DRY_RUN=1 + mkdir -p "$GUARD_STATE/healthy" "$GUARD_STATE/bad" + printf '{"protocol":4}\n' >"$GUARD_STATE/healthy/1.json" + binary_of() { echo "$root/versions/$1/t3"; } + printf '%s\n' '#!/bin/bash' 'echo '\''{"status":"ready","codexShadowHomes":{"status":"not-ready","instances":[{"status":"not-ready"}]}}'\''' >"$root/versions/1/t3" + chmod +x "$root/versions/1/t3" + is_healthy() { [[ -f "$GUARD_STATE/healthy/$1.json" ]]; } + is_bad() { [[ -f "$GUARD_STATE/bad/$1" ]]; } + is_trusted() { return 0; } + active_version() { echo 2; } + restart_on() { echo "$1" >"$root/rollback-fallback"; } + outage_begin() { :; } + notify() { :; } + report() { :; } + last_fatal() { :; } + rm -f "$GUARD_STATE/last-rollback" "$root/rollback-fallback" + cmd_rollback >/dev/null 2>&1 + [[ "$(cat "$root/rollback-fallback")" == 1 ]] +) || fail 'crash-loop rollback did not use a database-compatible fallback with a shadow conflict' +pass 'crash-loop rollback preserves a database-compatible fallback when its Codex shadow is unready' + +rm -f "$GUARD_STATE/healthy/1.json" "$GUARD_STATE/bad/2" "$GUARD_STATE/last-rollback" "$root/rollback-fallback" + # No real service calls, installs, or network calls below. manager_ready() { echo manager >> "$root/calls"; return 0; } active_version() { echo 1; }; is_trusted() { return 0; }; latest_release() { echo 1; } @@ -272,6 +406,120 @@ unset -f provider_canary service_version() { echo 1; }; active_version() { echo 1; } rm -f "$AUTO_HOLD" "$GUARD_STATE/bad/2" +# A shadow-only preflight failure on the old build must not restore the pre-update database. +real_manager_ready=$(declare -f manager_ready); real_release_binary_sha=$(declare -f release_binary_sha) +real_write_state_for=$(declare -f write_state_for); real_installed=$(declare -f installed) +real_is_healthy=$(declare -f is_healthy); real_active_runs=$(declare -f active_runs) +real_quiet_seconds=$(declare -f quiet_seconds); real_record_pre_restart=$(declare -f record_pre_restart) +real_systemctl=$(declare -f systemctl); real_svc=$(declare -f svc); real_snapshot_db=$(declare -f snapshot_db) +real_outage_begin=$(declare -f outage_begin); real_restore_db=$(declare -f restore_db) +real_restart_on=$(declare -f restart_on); real_notify=$(declare -f notify); real_report=$(declare -f report) +real_wait_for_continuations=$(declare -f wait_for_continuations) +real_recovery_summary=$(declare -f recovery_summary); real_last_fatal=$(declare -f last_fatal) +real_binary_for_shadow_rollback=$(declare -f binary_of) +latest_release() { echo 2; }; active_runs() { echo 0; }; quiet_seconds() { echo 99999; } +manager_ready() { return 0; }; active_version() { echo 1; }; is_trusted() { return 0; } +is_healthy() { return 1; }; release_binary_sha() { echo 1234; }; record_pre_restart() { :; } +kernel_hang_signs() { return 1; }; write_state_for() { :; }; systemctl() { echo active; } +service_version() { echo ''; }; installed() { return 0; }; wait_inactive() { return 0; } +outage_begin() { :; }; svc() { echo "$*" >> "$root/shadow-rollback-svc"; return 0; } +snapshot_db() { echo "$root/snap"; }; restore_db() { echo restored > "$root/shadow-restore"; return 0; } +binary_of() { echo "$root/shadow-rollback-cli"; } +cat >"$root/shadow-rollback-cli" <<'EOF' +#!/bin/bash +case "${1:-}" in + __service-preflight) + echo '{"status":"ready","codexShadowHomes":{"status":"not-ready","instances":[{"status":"not-ready"}]}}' + ;; + update) exit 0 ;; + *) exit 1 ;; +esac +EOF +chmod +x "$root/shadow-rollback-cli" +restart_on() { echo "$1" > "$root/shadow-rollback-restart"; return 0; } +notify() { :; }; report() { :; }; wait_for_continuations() { :; } +recovery_summary() { :; }; last_fatal() { :; } +rm -f "$root/shadow-rollback-svc" "$root/shadow-restore" "$root/shadow-rollback-restart" "$AUTO_HOLD" +HEALTH_WAIT_SECONDS=0 cmd_update >/dev/null 2>&1 && fail 'shadow-only startup failure reported as success' +[[ ! -e "$root/shadow-restore" ]] || fail 'shadow-only startup failure restored the pre-update database' +[[ "$(cat "$root/shadow-rollback-restart")" == 1 ]] || fail 'database-compatible old build was not restarted' +pass 'shadow-only rollback failure restarts the database-compatible build without restoring its snapshot' + +# A positive shadow redirect keeps the previous build serving without marking the release bad. +# Earlier cmd_update cases keep their service-change lock on fd 9 until the test process closes it. +exec 9>&- +( + source "$root/functions" + sim_active_version=1 + manager_ready() { return 0; } + latest_release() { echo 2; } + active_runs() { echo 0; } + quiet_seconds() { echo 99999; } + active_version() { echo "$sim_active_version"; } + write_state_for() { sim_active_version="$1"; } + is_trusted() { return 0; } + is_healthy() { [[ "$1" == 1 ]]; } + is_bad() { return 1; } + release_binary_sha() { echo 1234; } + record_pre_restart() { :; } + kernel_hang_signs() { return 1; } + systemctl() { echo active; } + service_version() { echo "$sim_active_version"; } + service_uptime() { echo 100; } + installed() { return 0; } + wait_inactive() { return 0; } + outage_begin() { :; } + snapshot_db() { echo "$root/snap"; } + binary_of() { echo "$root/versions/$1/t3"; } + svc() { + echo "$*" >>"$root/redirect-svc" + [[ "$1" != restart ]] || sim_active_version=1 + return 0 + } + notify() { echo "$*" >>"$root/redirect-notify"; } + report() { echo "$*" >>"$root/redirect-report"; } + mkdir -p "$root/versions/1" "$root/versions/2" + cat >"$root/versions/1/t3" <<'EOF' +#!/bin/bash +case "${1:-}" in + __service-preflight) echo '{"status":"ready","codexShadowHomes":{"status":"ready","instances":[]}}' ;; + update) exit 0 ;; +esac +EOF + cat >"$root/versions/2/t3" <<'EOF' +#!/bin/bash +case "${1:-}" in + __service-preflight) echo '{"status":"ready","codexShadowHomes":{"status":"not-ready","instances":[{"status":"not-ready"}]}}' ;; + update) exit 0 ;; +esac +EOF + chmod +x "$root/versions/1/t3" "$root/versions/2/t3" + rm -f "$AUTO_HOLD" "$GUARD_STATE/bad/2" "$GUARD_STATE/rejected/2" "$root/redirect-svc" + if HEALTH_WAIT_SECONDS=0 cmd_update >"$root/redirect-output" 2>&1; then + fail 'shadow redirect reported the new release as serving' + fi + exec 9>&- + [[ -e "$GUARD_STATE/rejected/2" ]] || fail 'shadow redirect was not rejected on this host' + [[ ! -e "$GUARD_STATE/bad/2" ]] || fail 'shadow redirect marked the release globally bad' + [[ "$(grep -c '^stop --no-block t3code.service$' "$root/redirect-svc")" == 1 ]] || + fail 'guard stopped the already-serving fallback again' + [[ "$(grep -c '^restart t3code.service$' "$root/redirect-svc")" == 1 ]] || + fail 'guard restarted the already-serving fallback again' + grep -q 'Codex shadow preflight is not-ready' "$root/redirect-report" || + fail 'shadow redirect was not reported with its cause' +) || fail 'shadow redirect was mishandled by cmd_update' +pass 'shadow redirect is host-rejected and reported without marking the release bad or restarting the fallback' + +eval "$real_manager_ready"; eval "$real_release_binary_sha"; eval "$real_write_state_for"; eval "$real_installed" +eval "$real_is_healthy"; eval "$real_active_runs"; eval "$real_quiet_seconds"; eval "$real_record_pre_restart" +eval "$real_systemctl"; eval "$real_svc"; eval "$real_snapshot_db"; eval "$real_outage_begin" +eval "$real_restore_db"; eval "$real_restart_on"; eval "$real_notify"; eval "$real_report" +eval "$real_wait_for_continuations"; eval "$real_recovery_summary"; eval "$real_last_fatal" +eval "$real_binary_for_shadow_rollback" +rm -f "$root/shadow-rollback-svc" "$root/shadow-rollback-cli" "$AUTO_HOLD" "$GUARD_STATE/bad/2" +rm -f "$GUARD_STATE/rejected/2" +active_version() { echo 1; }; latest_release() { echo 1; }; service_version() { echo 1; } + # A deploy onto an idle server is checked again on later ticks; a late break holds and reports. sqlite3 "$DB" "delete from orchestration_v2_projection_runs; delete from orchestration_v2_projection_turn_items;" rm -f "$AUTO_HOLD"; active_version() { echo 7; } diff --git a/scripts/fork/publish-release.sh b/scripts/fork/publish-release.sh index 0d2b3426f4046..cb17bf719eb59 100755 --- a/scripts/fork/publish-release.sh +++ b/scripts/fork/publish-release.sh @@ -10,6 +10,9 @@ set -euo pipefail version=${1:?version}; artifacts=${2:?artifacts dir}; target=${3:?target commit}; notes=${4:?notes} repo_slug=${T3_FORK_REPO:-chrisohearn/t3code} archive="t3-$version-linux-x64.tar.gz" +if [[ "$notes" != *"Codex shadow compatibility:"* ]]; then + notes+=$'\n\nCodex shadow compatibility: older fork releases may refuse to start a Codex instance after it creates local memories_v2 data. This release preserves that local data and removes only legacy links to the shared directory.' +fi built=$(cut -d' ' -f2 "$artifacts/../build.txt") [[ "$(git rev-parse "$built^{tree}")" == "$(git rev-parse "$target^{tree}")" ]] || { echo "target $target does not have the tree that was built ($built)" >&2; exit 1; } diff --git a/scripts/fork/test-upstream-stable-tag.sh b/scripts/fork/test-upstream-stable-tag.sh index 2af006475c464..a068772b31263 100755 --- a/scripts/fork/test-upstream-stable-tag.sh +++ b/scripts/fork/test-upstream-stable-tag.sh @@ -112,4 +112,60 @@ check "open PR within the tag continues" "$(run_guard "$D" "$E" v1)" "rc=0 comme check "open PR beyond the tag: exit 4, comment, worktree removed" "$(run_guard "$E" "$D" v1)" "rc=4 comments=1 worktree=removed" check "open PR beyond the tag, dry run: no comment" "$(run_guard "$E" "$D" v1 1)" "rc=4 comments=0 worktree=removed" check "open PR with no stable tag is refused" "$(run_guard "$D" "" "")" "rc=4 comments=1 worktree=removed" + +# Every publication path carries the local memories_v2 compatibility note. +release_repo="$tmp/release-repo" +release_remote="$tmp/release-origin.git" +git init -q --bare -b integration "$release_remote" +git init -q -b integration "$release_repo" +git -C "$release_repo" config user.name t +git -C "$release_repo" config user.email t@t +printf 'release tree\n' >"$release_repo/tree.txt" +git -C "$release_repo" add tree.txt +git -C "$release_repo" commit -q -m release +git -C "$release_repo" remote add origin "$release_remote" +git -C "$release_repo" push -q -u origin integration +git -C "$release_repo" fetch -q origin +release_commit=$(git -C "$release_repo" rev-parse HEAD) +release_version=0.1.10-preview.20261119.2 +release_artifacts="$tmp/release/artifacts" +mkdir -p "$release_artifacts" "$tmp/release-bin" +printf 'build %s\n' "$release_commit" >"$tmp/release/build.txt" +printf 'archive\n' >"$release_artifacts/t3-$release_version-linux-x64.tar.gz" +(cd "$release_artifacts" && sha256sum "t3-$release_version-linux-x64.tar.gz" >SHA256SUMS) +cat >"$tmp/release-bin/gh" <<'SH' +#!/usr/bin/env bash +set -euo pipefail +if [[ "${1:-}" == release && "${2:-}" == create ]]; then + shift 2 + while (($#)); do + if [[ "$1" == --notes ]]; then + shift + printf '%s' "$1" >"$GH_NOTES" + exit 0 + fi + shift + done + exit 1 +fi +if [[ "${1:-}" == release && "${2:-}" == view ]]; then + echo '{"isPrerelease":true,"assets":[]}' + exit 0 +fi +exit 1 +SH +chmod +x "$tmp/release-bin/gh" +( + cd "$release_repo" + GH_NOTES="$tmp/release-notes" T3_FORK_REPO=test/fork T3_FORK_BRANCH=integration \ + PATH="$tmp/release-bin:$PATH" bash "$here/publish-release.sh" "$release_version" \ + "$release_artifacts" "$release_commit" 'Upstream sync test note.' +) +if grep -Fq 'Upstream sync test note.' "$tmp/release-notes" && + grep -Fq 'Codex shadow compatibility:' "$tmp/release-notes"; then + echo 'ok published notes retain caller notes and explain Codex shadow compatibility' +else + echo 'FAIL published notes omit the Codex shadow compatibility note' + fail=1 +fi exit $fail diff --git a/scripts/fork/upstream-sync.sh b/scripts/fork/upstream-sync.sh index 47c4ef6c20b6d..2d0c1ca47c68f 100755 --- a/scripts/fork/upstream-sync.sh +++ b/scripts/fork/upstream-sync.sh @@ -277,12 +277,14 @@ section = result if sys.argv[2] == "." else (result.get(sys.argv[2]) or {}) print(section.get("status", ""))' "$1" "$2" } for protocol in 3 4; do - "$cli" __service-preflight --database-path "$LIVE_DB" --launcher-protocol "$protocol" \ + env -u CODEX_HOME -u CODEX_SQLITE_HOME "$cli" __service-preflight \ + --database-path "$LIVE_DB" --launcher-protocol "$protocol" \ >"$logs/preflight-$protocol.json" 2>&1 || true [[ $(preflight_status "$logs/preflight-$protocol.json" .) == ready ]] || fail "service preflight on the live database (launcher protocol $protocol)" "preflight-$protocol.json" done -# Codex shadow homes the new build would refuse to set up; `auto-settle` ones it moves aside itself. +# Caller-only Codex home variables are cleared so an agent shell cannot redirect the release gate. +# `auto-settle` conflicts can be safely unlinked or moved aside by setup. [[ $(preflight_status "$logs/preflight-4.json" codexShadowHomes) == ready ]] || fail "Codex shadow home preflight (an instance's shadow conflicts with its shared home)" preflight-4.json