Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
d35592b
merge dev into main for the v2.32.1 release
lidge-jun Aug 25, 2026
71c57ea
release: v2.32.1
lidge-jun Aug 25, 2026
d560ac6
merge dev into main for the v2.33.0 release
lidge-jun Aug 25, 2026
08ada6f
Merge pull request #2553 from lidge-jun/codex/promote-main-2330
lidge-jun Aug 25, 2026
ec51e42
release: v2.33.0
lidge-jun Aug 25, 2026
e25b653
merge dev into main for the v2.34.0 release
lidge-jun Aug 27, 2026
80fff9a
Merge pull request #2760 from lidge-jun/codex/promote-main-2340
lidge-jun Aug 27, 2026
fc4de77
Merge pull request #2826 from lidge-jun/codex/promote-main-2350
lidge-jun Aug 28, 2026
c7d8407
Merge pull request #3002 from lidge-jun/codex/promote-main-2360
lidge-jun Aug 30, 2026
54e2274
Merge pull request #3037 from lidge-jun/codex/promote-main-2370
lidge-jun Aug 31, 2026
2c4dca1
merge dev into the promotion branch for v2.38.0
lidge-jun Aug 31, 2026
a34e8b7
merge dev into the promotion branch for v2.38.0 (picks up the ReDoS fix)
lidge-jun Aug 31, 2026
ebb4d55
Merge pull request #3073 from lidge-jun/codex/promote-main-2380
lidge-jun Aug 31, 2026
682112e
Merge remote-tracking branch 'origin/dev' into codex/promote-main-2390
lidge-jun Sep 1, 2026
af6113a
merge dev into main for the v2.39.0 release
lidge-jun Sep 1, 2026
847f4f1
merge dev into main for the v2.40.0 release
Sep 2, 2026
ac78647
Merge pull request #3261 from lidge-jun/codex/promote-main-2400
lidge-jun Sep 2, 2026
aaa9eaf
fix(release): pass the bump job's permissions through the reusable-wo…
lidge-jun Sep 2, 2026
35ff3a4
Merge pull request #3263 from lidge-jun/codex/promote-main-2400-relfix
lidge-jun Sep 2, 2026
995c19f
fix(connect): serialize fresh config bootstrap
luvs01 Sep 3, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ jobs:
bump-dev-version:
needs: publish
if: ${{ inputs.dry-run != true }}
# A reusable-workflow CALL cannot grant the callee more than the calling job holds,
# and GitHub refuses the whole run at startup when the called workflow's own job
# declares permissions the caller did not pass down ("startup_failure", runs
# 33615174183 / 33615177849 — the first dispatches since #3129 wired this call).
# The callee's job declares exactly these two; nothing else in this file gains them.
permissions:
contents: write
pull-requests: write
uses: ./.github/workflows/dev-version-bump.yml
with:
released-version: v${{ inputs.version }}
Expand Down
20 changes: 2 additions & 18 deletions src/client/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
getDefaultConfig,
mutatePersistedConfig,
readConfigDiagnostics,
saveConfig,
} from "../config";
import type { OcxClientConnectionConfig } from "../types";
import {
Expand Down Expand Up @@ -127,10 +126,7 @@ export function inspectClientRotationRecoveryGate(
return { kind: "clean" };
}

export function commitClientConnection(

state: OcxClientConnectionConfig,
): "committed" | "unchanged" {
export function commitClientConnection(state: OcxClientConnectionConfig): "committed" | "unchanged" {
const outcome = mutatePersistedConfig(config => {
const unchanged = config.runtimeRole === "client"
&& JSON.stringify(config.client) === JSON.stringify(state);
Expand All @@ -139,20 +135,8 @@ export function commitClientConnection(
config.client = structuredClone(state);
}
return { changed: !unchanged, value: undefined };
});
}, { createIfMissing: getDefaultConfig });
if (outcome.status === "committed" || outcome.status === "unchanged") return outcome.status;
if (outcome.status === "unavailable" && outcome.reason === "missing") {
// First ocx run on a fresh machine: ocx connect is the expected first command in
// client mode, so there is no config.json yet. mutatePersistedConfig correctly
// refuses to invent one (a lost config must fail closed), but a genuinely absent
// file is the bootstrap case, not corruption — seed defaults plus the client
// block atomically. Found on the first MacBook↔oracle dogfood connect.
const seeded = getDefaultConfig();
seeded.runtimeRole = "client";
seeded.client = structuredClone(state);
saveConfig(seeded);
return "committed";
}
throw new Error(`client state commit unavailable: ${"reason" in outcome ? outcome.reason : "unknown"}`);
}

Expand Down
30 changes: 27 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3000,8 +3000,19 @@ export type PersistedConfigMutationOutcome<T> =
| { status: "committed" | "unchanged"; value: T }
| { status: "unavailable"; reason: "missing" | "invalid" | "conflict" };

export type PersistedConfigMutationOptions = {
/** Seed a genuinely absent config while holding the shared mutation lock. */
createIfMissing?: () => OcxConfig;
};

const CONFIG_MUTATION_MAX_REBASE_ATTEMPTS = 3;
let persistedConfigMutationBeforeCommitForTests: (() => void) | null = null;
let persistedConfigMutationBeforeLockForTests: (() => void) | null = null;

/** Test-only one-shot seam: inject a competing creation after observation, before lock acquisition. */
export function setPersistedConfigMutationBeforeLockForTests(hook: (() => void) | null): void {
persistedConfigMutationBeforeLockForTests = hook;
}

/** Test-only one-shot seam: inject a competing mutation after the first decision, before freshness revalidation. */
export function setPersistedConfigMutationBeforeCommitForTests(hook: (() => void) | null): void {
Expand All @@ -3017,22 +3028,35 @@ function unavailableConfigMutationReason(snapshot: ConfigFileSnapshot): "missing
* serialized; the callback is rerun on the newest snapshot so observed direct byte changes rebase
* and credential predicates are re-evaluated immediately before the atomic commit. A writer that
* ignores the coordinator can still change bytes after the final check because the filesystem has
* no portable conditional rename. Missing or malformed config always fails closed and is never
* recreated from a prior snapshot.
* no portable conditional rename. Malformed config always fails closed. Callers may explicitly
* seed a missing config; the factory and mutation then run under this same transaction.
*/
export function mutatePersistedConfig<T>(
mutate: (config: OcxConfig) => PersistedConfigMutation<T>,
options?: PersistedConfigMutationOptions,
): PersistedConfigMutationOutcome<T> {
// Avoid creating/opening the coordinator database for a read-path update that already knows
// there is no valid config. The same check runs again under the transaction for authority.
const observed = readConfigFileSnapshot();
if (observed.diagnostics.source !== "file" || observed.raw === undefined) {
return { status: "unavailable", reason: unavailableConfigMutationReason(observed) };
const reason = unavailableConfigMutationReason(observed);
if (reason !== "missing" || !options?.createIfMissing) {
return { status: "unavailable", reason };
}
}
const beforeLockHook = persistedConfigMutationBeforeLockForTests;
persistedConfigMutationBeforeLockForTests = null;
beforeLockHook?.();
return withConfigMutationLockSync(() => {
let base = readConfigFileSnapshot();
for (let attempt = 0; attempt < CONFIG_MUTATION_MAX_REBASE_ATTEMPTS; attempt += 1) {
if (base.diagnostics.source !== "file" || base.raw === undefined) {
if (unavailableConfigMutationReason(base) === "missing" && options?.createIfMissing) {
const seeded = options.createIfMissing();
const result = mutate(seeded);
if (persistConfigUnlocked(seeded)) bumpGenerationForCooperatingConfigWrite();
return { status: "committed", value: result.value };
}
return { status: "unavailable", reason: unavailableConfigMutationReason(base) };
}

Expand Down
51 changes: 51 additions & 0 deletions tests/client-connect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ import {
issueClientKey,
normalizeHubOrigin,
} from "../src/client/hub-client";
import { commitClientConnection } from "../src/client/state";
import { handleConnectCommand } from "../src/cli/connect";
import {
getDefaultConfig,
saveConfig,
setPersistedConfigMutationBeforeLockForTests,
} from "../src/config";
import { removeTreeWithRetry } from "./helpers/remove-tree";

const repoRoot = dirname(fileURLToPath(new URL("../package.json", import.meta.url)));
Expand Down Expand Up @@ -285,6 +291,51 @@ function runTransactionScenario(stage: "success" | "catalog" | "preflight" | "co
}

describe("connect transaction and offline disconnect", () => {
test("fresh connect rebases onto a config created before bootstrap lock acquisition", () => {
const home = mkdtempSync(join(tmpdir(), "ocx-client-bootstrap-race-"));
const previous = process.env.OPENCODEX_HOME;
process.env.OPENCODEX_HOME = home;
try {
const winner = getDefaultConfig();
winner.port = 24444;
winner.hostname = "127.0.0.2";
const admissionKey = `ocx_data_${"a".repeat(40)}`;
winner.apiKeys = [{
id: "preserved-key",
name: "Preserved admission key",
key: admissionKey,
createdAt: "2026-08-28T00:00:00.000Z",
}];
setPersistedConfigMutationBeforeLockForTests(() => saveConfig(winner));

expect(commitClientConnection({
serverUrl: "https://hub.example.test",
managementUrl: "https://hub.example.test",
managementTransport: "direct",
selectedClients: ["claude"],
tokenEnv: "OPENCODEX_API_AUTH_TOKEN",
apiKeyId: "client-key-1",
tokenFingerprint: "fingerprint",
protocolVersion: 1,
connectedAt: "2026-08-28T00:00:00.000Z",
})).toBe("committed");

const persisted = JSON.parse(readFileSync(join(home, "config.json"), "utf8"));
expect(persisted).toMatchObject({
port: 24444,
hostname: "127.0.0.2",
apiKeys: [{ id: "preserved-key", key: admissionKey }],
runtimeRole: "client",
client: { apiKeyId: "client-key-1" },
});
} finally {
setPersistedConfigMutationBeforeLockForTests(null);
if (previous === undefined) delete process.env.OPENCODEX_HOME;
else process.env.OPENCODEX_HOME = previous;
removeTreeWithRetry(home);
}
});

test("commits key id/state last, zeroes authority, and disconnects with the hub offline", () => {
const run = runTransactionScenario("success");
try {
Expand Down
Loading