From 05ffb6fca94e20f181b60669ceede210678d0324 Mon Sep 17 00:00:00 2001 From: bft-codebot Date: Wed, 29 Apr 2026 15:46:34 +0000 Subject: [PATCH] sync(bfmono): fix(gambit): fall back without host service token (+19 more) (bfmono@224cfdca6) This PR is an automated gambitmono sync of bfmono Gambit packages. - Source: `packages/gambit/` - Core: `packages/gambit/packages/gambit-core/` - bfmono rev: 224cfdca6 Changes: - 224cfdca6 fix(gambit): fall back without host service token - 668e393de feat(gambit): add browser introspection live commands - 4d8a6ad7b feat(workloop): bridge runtime Codex refresh to host services - 81ac0db58 feat(gambit): add live browser pointer refs - 62e132a24 chore(browser): move runtime out of Gambit - e6c80f928 test(gambit): remove legacy chat suites - 49c9b67e3 chore(gambit): remove dead chat provider adapters - 8b4af5051 fix(gambit): preserve responses continuation context - d9127ae36 feat(gambit): expose structured responses runtime - 522e10d5e feat(gambit): make provider execution responses-only - 13bfdfe34 fix(gambit): pass codex runtime tools - 477a6e8fa fix(gambit): preserve structured text spacing - c31a35389 fix(gambit): read workloop codex auth bundle env - ca19ea448 chore(workloop): rename desktop app from bfdesktop - 0715225a7 fix(gambit): parse mock Codex string ids portably - e4fad187d fix(browser-runtime): use repo-relative automation imports - 549d9dafa fix(browser-runtime): use explicit Deno exports - 46d961d01 fix(browser-runtime): detect stale live sessions - bd2b9d937 fix(bfdesktop): route Chief browser MCP tool calls - 63b35d1cc feat(bfdesktop): add Chief runtime browser tools Do not edit this repo directly; make changes in bfmono and re-run the sync. --- src/codex_preflight.test.ts | 18 ++++++++++++++++++ src/codex_preflight.ts | 25 +++++++++++++------------ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/codex_preflight.test.ts b/src/codex_preflight.test.ts index 584cc98d..54e000fb 100644 --- a/src/codex_preflight.test.ts +++ b/src/codex_preflight.test.ts @@ -8,6 +8,10 @@ import { MINIMUM_SUPPORTED_CODEX_CLI_VERSION, readCodexLoginStatus, } from "./codex_preflight.ts"; +import { + RUNTIME_HOST_SERVICE_SOCKET_ENV, + RUNTIME_HOST_SERVICE_TOKEN_ENV, +} from "./runtime_host_service.ts"; const SUPPORTED_FAKE_CODEX_VERSION = MINIMUM_SUPPORTED_CODEX_CLI_VERSION; const UNSUPPORTED_FAKE_CODEX_VERSION = "0.120.0"; @@ -113,6 +117,8 @@ done Deno.test("codex preflight responds to app-server refresh RPCs before account/read completes", async () => { const priorBin = Deno.env.get("GAMBIT_CODEX_BIN"); const priorBundle = Deno.env.get(CODEX_HOST_AUTH_BUNDLE_ENV); + const priorHostServiceSocket = Deno.env.get(RUNTIME_HOST_SERVICE_SOCKET_ENV); + const priorHostServiceToken = Deno.env.get(RUNTIME_HOST_SERVICE_TOKEN_ENV); const root = await Deno.makeTempDir({ prefix: "codex-preflight-refresh-rpc-", }); @@ -172,6 +178,8 @@ done await Deno.chmod(fakeCodexPath, 0o755); Deno.env.set("GAMBIT_CODEX_BIN", fakeCodexPath); + Deno.env.set(RUNTIME_HOST_SERVICE_SOCKET_ENV, join(root, "missing.sock")); + Deno.env.delete(RUNTIME_HOST_SERVICE_TOKEN_ENV); Deno.env.set( CODEX_HOST_AUTH_BUNDLE_ENV, JSON.stringify({ @@ -219,6 +227,16 @@ done } else { Deno.env.set(CODEX_HOST_AUTH_BUNDLE_ENV, priorBundle); } + if (priorHostServiceSocket == null) { + Deno.env.delete(RUNTIME_HOST_SERVICE_SOCKET_ENV); + } else { + Deno.env.set(RUNTIME_HOST_SERVICE_SOCKET_ENV, priorHostServiceSocket); + } + if (priorHostServiceToken == null) { + Deno.env.delete(RUNTIME_HOST_SERVICE_TOKEN_ENV); + } else { + Deno.env.set(RUNTIME_HOST_SERVICE_TOKEN_ENV, priorHostServiceToken); + } await Deno.remove(root, { recursive: true }).catch(() => undefined); } }); diff --git a/src/codex_preflight.ts b/src/codex_preflight.ts index 7178d3bf..badaa649 100644 --- a/src/codex_preflight.ts +++ b/src/codex_preflight.ts @@ -9,6 +9,7 @@ import { CODEX_REFRESH_HOST_SERVICE_METHOD, type CodexRefreshHostServiceResult, RUNTIME_HOST_SERVICE_SOCKET_ENV, + RUNTIME_HOST_SERVICE_TOKEN_ENV, } from "./runtime_host_service.ts"; const CODEX_BIN_ENV = "GAMBIT_CODEX_BIN"; @@ -75,6 +76,13 @@ function buildUnsupportedCodexVersionMessage(version: string | null): string { return `Codex CLI ${rendered} is too old; require >= ${MINIMUM_SUPPORTED_CODEX_CLI_VERSION} for Gambit's app-server transport.`; } +function hasRuntimeHostServiceRefreshConfig(): boolean { + return Boolean( + Deno.env.get(RUNTIME_HOST_SERVICE_SOCKET_ENV)?.trim() && + Deno.env.get(RUNTIME_HOST_SERVICE_TOKEN_ENV)?.trim(), + ); +} + async function appServerPreflightRequestResult(input: { bundle: NonNullable>; method: string; @@ -95,17 +103,10 @@ async function appServerPreflightRequestResult(input: { typeof input.params.reason === "string" && input.params.reason ? input.params.reason : "account/chatgptAuthTokens/refresh"; - const hostServiceSocket = Deno.env.get(RUNTIME_HOST_SERVICE_SOCKET_ENV) - ?.trim(); - const hostRefreshed = hostServiceSocket - ? await callRuntimeHostService({ - method: CODEX_REFRESH_HOST_SERVICE_METHOD, - params: { - previousAccountId, - reason, - }, - }) - : null; + const hostRefreshed = await refreshCodexPreflightViaHost({ + previousAccountId, + reason, + }); const refreshed = hostRefreshed ? { ...input.bundle, @@ -143,7 +144,7 @@ async function refreshCodexPreflightViaHost(input: { previousAccountId?: string | null; reason: string; }): Promise { - if (!Deno.env.get(RUNTIME_HOST_SERVICE_SOCKET_ENV)?.trim()) return null; + if (!hasRuntimeHostServiceRefreshConfig()) return null; return await callRuntimeHostService({ method: CODEX_REFRESH_HOST_SERVICE_METHOD, params: input,