Skip to content

Commit a3205ab

Browse files
committed
fix(ready): integrate readiness gate with dev startup sync (overtake)
Rebase the readiness PR onto current dev and resolve the two conflict surfaces against dev's modern startup path: - src/cli/index.ts: keep syncCodexOnStartIfEnabled (Codex toggle + #1046 stale app-server warning) and thread the readiness gate into it as the fourth argument, so /readyz reflects the real sync outcome without bypassing the toggle or the write-tracking contract. - src/codex/desired-state.ts: accept an optional readiness gate; mark ready immediately when the Codex integration is explicitly OFF (nothing to sync), otherwise drive the gate via runStartupReadinessSync from the raw sync outcome (ready only on ok=true with no nonempty warning). - src/server/readiness.ts: runStartupReadinessSync returns the raw sync outcome so callers keep the #1046 write flags without a second call. - structure/03_catalog-and-subagents.md: un-indent the pre-existing cache paragraph and fix the Startup readiness heading to top-level markdown. - tests/cli-ready.test.ts: update the source-level wiring guard to assert the new syncCodexOnStartIfEnabled(port, config, undefined, readinessGate) contract instead of the pre-rebase inline wiring.
1 parent e7c6d2a commit a3205ab

3 files changed

Lines changed: 17 additions & 15 deletions

File tree

‎src/cli/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { installCrashGuards } from "../lib/crash-guard";
2626
import { hasHelpFlag, printSubcommandUsage, printUsage, printVersion } from "./help";
2727
import { findAvailablePort, isAddrInUse, PortUnavailableError, shouldPersistSelectedPort, waitForPortAvailable } from "../server/ports";
2828
import { findLiveProxy, probeHostname, type LiveProxy } from "../server/proxy-liveness";
29-
import { createReadinessGate, runStartupReadinessSync } from "../server/readiness";
29+
import { createReadinessGate } from "../server/readiness";
3030
import { parseReadyArgs, runReady, type ReadyArgs } from "./ready";
3131
import { stopProxy } from "../lib/process-control";
3232
import { loadServiceTokenFromFile } from "../lib/service-secrets";

‎structure/03_catalog-and-subagents.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ bundled catalog never contains those rows.
2929

3030
Codex App model picker visibility comes from this shared catalog, not from patching the App.
3131

32-
Provider live-model lists are cached with a configured TTL (`src/codex/model-cache.ts`). Adding,
33-
deleting, or editing a provider's shape clears that per-provider cache; a disabled-only change
34-
deliberately does not, because a disabled provider is already excluded from the catalog gather
35-
instead. Codex's own `models_cache.json` is a different cache, invalidated by catalog refresh.
32+
Provider live-model lists are cached with a configured TTL (`src/codex/model-cache.ts`). Adding,
33+
deleting, or editing a provider's shape clears that per-provider cache; a disabled-only change
34+
deliberately does not, because a disabled provider is already excluded from the catalog gather
35+
instead. Codex's own `models_cache.json` is a different cache, invalidated by catalog refresh.
3636

37-
## Startup readiness
37+
## Startup readiness
3838

3939
Each `startServer` invocation owns a private, one-shot readiness gate created before the listener
4040
binds. `handleStart` supplies its gate and transitions it after the shared catalog sync settles.

‎tests/cli-ready.test.ts‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -611,26 +611,28 @@ describe("runReady --wait deadline correctness", () => {
611611
// A bounded source-level assertion reading ONLY src/cli/index.ts. It verifies
612612
// that the SAME identifier `readinessGate` is (1) created in handleStart via
613613
// createReadinessGate(), (2) passed to startServer in the retry path, and
614-
// (3) passed to runStartupReadinessSync wrapping syncModelsToCodex(port), in
615-
// that order. This catches a regression where the gate is wired to only one of
616-
// the two call sites. It complements the executable runStartupReadinessSync
617-
// outcome tests in tests/proxy-liveness.test.ts (no architecture refactor).
614+
// (3) threaded into the startup sync via syncCodexOnStartIfEnabled(..., gate),
615+
// in that order. The gate-drive itself lives in syncCodexOnStartIfEnabled (the
616+
// modern dev startup path, which respects the Codex integration toggle and the
617+
// #1046 write-tracking contract); this catches a regression where the gate is
618+
// wired to only one of the two call sites. It complements the executable
619+
// runStartupReadinessSync outcome tests in tests/proxy-liveness.test.ts.
618620
describe("handleStart readinessGate wiring (source-level)", () => {
619621
const cliSource = readFileSync(join(import.meta.dir, "../src/cli/index.ts"), "utf8");
620622

621-
test("readinessGate is created, threaded into startServer, and into runStartupReadinessSync — in order", () => {
623+
test("readinessGate is created, threaded into startServer, and into the startup sync — in order", () => {
622624
const createMatch = cliSource.match(/const\s+readinessGate\s*=\s*createReadinessGate\(\)/);
623625
expect(createMatch, "handleStart must create readinessGate via createReadinessGate()").not.toBeNull();
624626

625627
const startMatch = cliSource.match(/startServer\s*\(\s*port\s*,\s*\{\s*readinessGate\s*\}\s*\)/);
626628
expect(startMatch, "startServer must be called with { readinessGate } in the retry path").not.toBeNull();
627629

628630
const syncMatch = cliSource.match(
629-
/runStartupReadinessSync\s*\(\s*readinessGate\s*,\s*\(\s*\)\s*=>\s*syncModelsToCodex\s*\(\s*port\s*\)\s*\)/,
631+
/syncCodexOnStartIfEnabled\s*\(\s*port\s*,\s*config\s*,\s*undefined\s*,\s*readinessGate\s*\)/,
630632
);
631-
expect(syncMatch, "runStartupReadinessSync must wrap () => syncModelsToCodex(port) with readinessGate").not.toBeNull();
633+
expect(syncMatch, "syncCodexOnStartIfEnabled must receive readinessGate so the startup sync drives /readyz").not.toBeNull();
632634

633-
// Source order must be: create → startServer → runStartupReadinessSync.
635+
// Source order must be: create → startServer → startup sync.
634636
const createIdx = createMatch!.index!;
635637
const startIdx = startMatch!.index!;
636638
const syncIdx = syncMatch!.index!;
@@ -643,7 +645,7 @@ describe("handleStart readinessGate wiring (source-level)", () => {
643645
// call site references that identifier (no shadowing, no second local).
644646
const declarations = cliSource.match(/\breadinessGate\s*=/g);
645647
expect(declarations, "readinessGate must be assigned exactly once").toHaveLength(1);
646-
// Three references total: one declaration + startServer + runStartupReadinessSync.
648+
// Three references total: one declaration + startServer + startup sync.
647649
const references = cliSource.match(/\breadinessGate\b/g);
648650
expect(references?.length ?? 0).toBeGreaterThanOrEqual(3);
649651
});

0 commit comments

Comments
 (0)