Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
1783523
chore(release): open dev at 2.97.0 before releasing 2.96.0 (#8068)
github-actions[bot] Nov 1, 2026
6f1d3e6
fix(anthropic): show both 5-hour and weekly meters for Max and Team a…
lidge-jun Nov 2, 2026
52dd19f
fix(codex): place round-robin conversations on accounts with quota he…
lidge-jun Nov 2, 2026
affd840
fix(codex): honest affinity labels and opt-in request-owned conversat…
lidge-jun Nov 2, 2026
b14a35a
fix(claude): bind header-less Messages bridge turns to one Codex pool…
lidge-jun Nov 2, 2026
5cfd0ac
fix(codex): keep Codex pool session pins across proxy restarts (#8098)
lidge-jun Nov 2, 2026
fd81526
Serve an Ollama-compatible inbound API (#8099)
lidge-jun Nov 2, 2026
4948c04
feat(sync): Home ocx sync fans out to linked Children (sync.home-fano…
lidge-jun Nov 2, 2026
09b5585
fix: refuse links at SQLite store paths on Windows and rebalance CI s…
lidge-jun Nov 2, 2026
4d93716
feat(update): orchestrated ocx update plan/apply contract (update.orc…
lidge-jun Nov 2, 2026
ebcb664
Normalize upstream error details in request logs and Retry-After advi…
lidge-jun Nov 2, 2026
43e2e4e
fix(link): keep Windows containment refusal at 126; correct the #8100…
lidge-jun Nov 2, 2026
6f915d8
fix(ci): make the Windows batch shards green after #8103 (#8109)
lidge-jun Nov 3, 2026
c0e23c1
Normalize Chat Completions client error bodies (#8108)
lidge-jun Nov 3, 2026
2bd1958
fix(security): reject inherited writes at Windows creation parents (#…
luvs01 Nov 3, 2026
53ee609
fix(responses): preserve quota-code provenance across wrappers and po…
luvs01 Nov 3, 2026
f604efc
fix(advisor): honor web-search tool choice scope (#8018)
luvs01 Nov 3, 2026
f2c977c
fix(responses): scope tool authority to current turn (#8027)
luvs01 Nov 3, 2026
571e70a
fix: bound canonical patch prefix scanning (#8012)
luvs01 Nov 3, 2026
dabbce6
fix(codex): serialize automatic v1 reconciliation with CLI updates (#…
luvs01 Nov 3, 2026
9f1ed15
fix(codex): read Artificial Analysis free model list before sunset (#…
LilMGenius Nov 3, 2026
f7c2d32
fix(responses): authorize translated tool_search declared this turn (…
lidge-jun Nov 3, 2026
e35572f
fix(codex): retire a pool account's carried monthly window when WHAM …
lidge-jun Nov 3, 2026
8808155
fix(responses): route local compaction checkpoints (#8119)
lidge-jun Nov 3, 2026
ae0a6a3
fix(kimi): drop the unsupported output.encrypted_content include on K…
lidge-jun Nov 3, 2026
9c25b49
fix(ollama): report prompt_eval_cached_count as cache-read input (#81…
lidge-jun Nov 3, 2026
8a82a46
fix(server): account for normalized inbound JSON (#8026)
luvs01 Nov 3, 2026
edd46b5
fix(security): require paired dashboard session for CLI updates (#8008)
luvs01 Nov 3, 2026
363c0a1
fix(kimi): export declared effort ladder and default to Kimi Code (#8…
lidge-jun Nov 3, 2026
d156059
fix(antigravity): stop sibling discovery after revocation (#8024)
luvs01 Nov 3, 2026
60ac8ef
fix(claude): answer uncoded context-window refusals as prompt too lon…
lidge-jun Nov 3, 2026
bed14bf
fix(cli): attest Codex listener before token injection (#8007)
luvs01 Nov 3, 2026
83f7667
fix(kimi): report monthly Coding Plan quota (#8077)
zarv1k Nov 3, 2026
14692ab
fix(codex): keep profile keys OpenCodex does not manage (#8074)
codewith-aditya Nov 3, 2026
086f0ab
fix(kiro): report content-filter stops as non-retryable refusals (#8072)
dysasm Nov 3, 2026
491beb6
fix(command-code): avoid double charging live NDJSON buffers (#8047)
0disoft Nov 3, 2026
665cc48
fix(link): restore owned integrations before native signal exit (#8036)
luvs01 Nov 3, 2026
a143604
perf(devin): batch consumed stream chunk removal (#8049)
0disoft Nov 3, 2026
8c822dc
fix(codex): hold selection ownership through dashboard feature toggle…
luvs01 Nov 3, 2026
fde2e4c
fix(responses): keep untyped assistant messages inside their tool-cal…
fec123 Nov 3, 2026
3dc4022
fix(responses): unwrap one extra executable freeform body wrapper (#8…
nickdavis Nov 3, 2026
c0221fe
fix(kiro): resubmit a finished answer on the completion retry (#8070)
dysasm Nov 3, 2026
7b3bb7a
Fix non-ASCII Codex turn metadata headers (#8040)
visualbridge7188 Nov 3, 2026
a18953b
release: promote frozen tip 7b3bb7a257 to main as 2.97.0
lidge-jun Nov 3, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
233 changes: 214 additions & 19 deletions bin/ocx.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion desktop/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "opencodex-desktop"
version = "2.96.0"
version = "2.97.0"
description = "OpenCodex desktop shell"
authors = ["OpenCodex contributors"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion desktop/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "OpenCodex",
"version": "2.96.0",
"version": "2.97.0",
"identifier": "com.opencodex.desktop",
"build": {
"frontendDist": "../ui",
Expand Down
145 changes: 145 additions & 0 deletions devlog/_plan/261102_codex_affinity_persist/010_plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# 261102 Codex pool affinity persistence (Lane B) — 010 plan

Status: P (plan) — awaiting Terra audit.

## Problem

Codex pool session pins live only in memory, so a proxy restart re-places every ongoing conversation.
Two process-local facts cause it, and both must change:

1. `src/codex/routing/thread-affinity.ts` keeps `threadAccountMap` (conversation key -> scope -> binding) and
`conversationStateIssuerMap` (binding key -> account that minted carried encrypted state) in memory only.
2. The key those maps are indexed by is `codexConversationKeyFor()` in `src/codex/lineage.ts`:
`app:HMAC(CODEX_LINEAGE_KEY, family, thread)` where `CODEX_LINEAGE_KEY = randomBytes(32)` at module load.
After a restart the same conversation derives a different key, so a persisted map alone could never be
looked up again. (The lineage scope key `auth:HMAC(key, Authorization)` uses the same secret.)

Under round-robin most conversations move after a restart: the prompt cache goes cold and carried encrypted
state minted by the old account can fail with `invalid_encrypted_content`.

Reference implementation to mirror: `src/oauth/anthropic-session-affinity-store.ts` (#7813 / #7828) and its
structure section `structure/providers/anthropic-account-pool.md#durable-session-affinity`.

## Design

### A. Durable conversation-key secret — new `src/codex/affinity-key.ts`

- `codexAffinityKey(): Buffer` returns a 32-byte secret cached per resolved `getConfigDir()` (re-resolved when the
home changes, as the Claude store's scope does).
- Path: `<configHome>/codex-affinity-key`. Content: one line `v1:<base64url of 32 bytes>` (validated by regex).
- Hydration: `readBoundedRegularFileSync(path, 128)` (rejects symlinks/junctions/non-regular files and oversize).
Valid -> use. ENOENT -> `randomBytes(32)`, cache it, and persist asynchronously:
`trackBackgroundWork("codex-affinity-key-write", withConfigDirHardeningSettled(home, () => atomicWriteFileNoFollow(path, text, undefined, {}, { exclusive: true })))`.
If the exclusive publish loses a race (another process created it first), keep the in-memory key for this process
(its pins are lost at the next restart, same as today) — no overwrite. Invalid or unreadable -> identifier-free
`console.warn("[codex-affinity] key unavailable or invalid; affinity is process-local until it is replaced")`, generate
a fresh key and replace the file with a non-exclusive atomic write (a corrupt key must not disable persistence forever).
- The file is a secret: private mode via the atomic publisher (0600 on POSIX) and the config-dir Windows ACL barrier.
Never logged, never included in diagnostics.
- `src/codex/lineage.ts`: drop `CODEX_LINEAGE_KEY`; both HMACs call `codexAffinityKey()`. Update the LIFETIME doc block:
keys are now reproducible across restarts of one config home; lineage records themselves stay process-local.
Keep lineage a leaf: the new module imports only config/lib modules (no routing import, no cycle).
- `src/adapters/google-antigravity-wire.ts` comment that calls the key "process-random ... changes across a proxy restart":
reword only (the derivation there stays independent; it must survive loss of the key file too). No behavior change.

### B. Durable pin + issuer snapshot — new `src/codex/routing/thread-affinity-store.ts`

- File `<configHome>/codex-affinity.json`, `{ version: 1, threads: [...], issuers: [...] }`.
- thread row: `{ keyDigest, scope, accountId, generation, createdAt, lastUsedAt }`
- issuer row: `{ keyDigest, accountId, lastUsedAt }`
- `keyDigest = sha256hex("opencodex/codex-affinity/<thread|issuer>/v1\0" + key)`. Raw conversation keys, raw parent ids
(legacy keys) and binding keys never reach disk. Account ids are opaque pool ids (`isValidCodexAccountId` or `__main__`).
- Transient fields (`transientHoldSince`, `transientDetourAccountId`) and `lastReevalAt` are not persisted; restored
entries get `lastReevalAt = restore time`.
- Bounds: `MAX_FILE_BYTES = 1 MiB` on read; newest `CODEX_THREAD_AFFINITY_MAX_ENTRIES` (2048) rows per table on write and read;
rows idle longer than `CODEX_THREAD_AFFINITY_IDLE_TTL_MS` (24 h), future-dated rows, malformed rows are dropped.
Scope strings validated (`spark`/quota scopes, `legacy`, `model-detour:<scope>:<model>`, <= 512 bytes).
- Hydration is lazy per config home (first affinity read/write), synchronous and bounded, like the Claude store.
Restored rows are held in digest-keyed `restoredThreads` / `restoredIssuers` maps; they never enter
`threadAccountMap` until a request looks them up.
- Adoption: in `getThreadAffinityForScope(threadId, scope)` on a memory miss, and in `peekConversationStateIssuer`,
compute the digest, take the restored row, validate, and insert it into the in-memory map (removing it from the restored
map). Validation for thread rows = not expired AND `isThreadAffinityGenerationLive({accountId, generation})` (account record
exists, has a credential, not deleted, same credential generation; `__main__` must be generation 0). A failing row is
discarded and the request falls back to normal selection. Usability (paused, reauth, plan exclusion, quota, cooldown) is
NOT checked at restore: the existing resolve path already re-evaluates a bound account every request and releases it
with the usual reason. Issuer rows are restored after TTL validation only: an issuer for a deleted account still correctly
forces the account-change scrub.
- Writes: the snapshot is serialized from the live maps plus unadopted restored rows at flush time, so in-place mutations
elsewhere are captured. Structural changes (new bind, account change, delete, clear, per-account clear, hand-off,
prune/evict, issuer change) flush promptly; timestamp-only activity (bind of the same account, a binding read, an issuer
peek) schedules one coalesced flush after 1 s (unref'd timer). Reading a binding schedules the coalesced flush because
`src/codex/routing.ts` updates `lastUsedAt` in place after the read and that file is at its file-size cap.
- Publisher: `trackBackgroundWork("codex-affinity-write", withConfigDirHardeningSettled(home, () => atomicWriteFileNoFollow(path, json)))`,
revision counter re-flush exactly like `flushScope` in the Claude store, best-effort `registerOptionalShutdownHook("codex-affinity", ...)`,
identifier-free warnings (`[codex-affinity] snapshot persistence failed; using runtime affinity` /
`snapshot unavailable or invalid; using runtime affinity`). An observed config-home change retires the scope (memory
restored maps + pending timer), as in the Claude store.
- Exports: `flushCodexThreadAffinity()` (tests and shutdown), `resetCodexAffinityStoreMemoryForTests()`.

### C. Minimal hooks in `src/codex/routing/thread-affinity.ts`

- `getThreadAffinityForScope`: on miss, adopt from the store; on hit, schedule the coalesced touch flush.
- `bindThreadAffinityForScope`, `deleteThreadAffinityForScope`, `deleteThreadAffinitiesForAccount`,
`clearThreadAccountMapForAccount` (also purge restored rows for that account), `handOffThreadAffinityGeneration` (also
move restored rows fromGeneration -> toGeneration), prune/LRU paths, `rememberConversationStateIssuer`,
`peekConversationStateIssuer`, `clearConversationStateIssuerMap`, `clearThreadAccountMap` (also clears restored rows and
persists the empty snapshot, matching the Claude "explicit runtime selection clears bindings and persists the reset").
- Update the doc comments that promise process-local lifetime (issuer map comment, `adoptLegacyAffinityForScope` comment).
- Keep edits to call sites; do not touch the affinity log label (Lane D) or `src/codex/routing/selection.ts` (Lane C).
- Core-path boundary: the store imports only `src/config/*` and `src/lib/*`; no `src/lab/` reachability.

## Tests (new files; register each in `scripts/test-layout/layout.json` or its domain shard AND a `tests/fixtures/test-layout-expected*.json` shard)

`tests/codex-integration/codex-affinity-restart.test.ts` (temp `OPENCODEX_HOME` per test, `removeTreeWithRetry` cleanup):

1. Restart keeps the pin: build headers with `session-id`/`thread-id`, key = `codexPoolAffinityKey(headers)`, seed two pool
accounts, `bindThreadAffinity(key, B, now)`, `rememberConversationStateIssuer(key, B)`, flush, simulate restart
(reset in-memory affinity, store scope and key cache — NOT the files), recompute the key from the same headers: it is
identical, `getThreadAffinity(key)` returns B, `peekConversationStateIssuer(key)` returns B. Prefer one assertion through
the real resolver (`resolveCodexAccountForThread` or the existing public resolve used in `tests/codex-integration/codex-routing.test.ts`)
under round-robin, showing the restored binding wins over the strategy cursor.
MUST FAIL on old code (record output): the key differs after restart and the map is empty.
2. Dead pins fall back: account removed, credential generation bumped (re-login), and expired (>24 h) rows are dropped;
resolve returns a normal selection and the dropped row is gone from the next snapshot.
3. Privacy/bounds: the snapshot contains no raw session id, thread id or conversation key; key file is 0600 on POSIX;
oversized, malformed, future-dated and symlinked snapshots are ignored with an identifier-free warning (assert the
warning text contains no account id or key); more than 2048 rows keeps the newest.
4. `clearThreadAccountMap()` and `clearThreadAccountMapForAccount()` persist their removals (after restart the pin is gone).
5. Key file: reused across restart; a corrupt key file is replaced and a warning is emitted.

Existing suites to rerun: `tests/codex-integration/codex-routing*.test.ts`, `codex-affinity-debug.test.ts`,
`codex-idle-window.test.ts`, `codex-account-selection-atomicity.test.ts`, `codex-auth-release.test.ts`,
`tests/responses/responses-account-change-scrub.test.ts`, `tests/responses/responses-4546-incident-regression.test.ts`,
lineage tests (`rg -l lineage tests`), `tests/lab/core-lab-boundary.test.ts`, `tests/test-layout.test.ts`, file-size ratchet test.

## Docs

- `structure/providers/openai-tiers.md`: lineage section (lines ~105-160) — key is a per-config-home durable secret; add a
"Durable Codex pool affinity" paragraph parallel to the Anthropic one (file names, row shape, bounds, validation, flush policy,
test names). Run `bun run structure:check`; add the new src files to the owning manifest entry if the check asks.
- `docs-site/src/content/docs/reference/cli/providers-accounts.md` (~line 848): replace "proxy restart or affinity eviction can
also leave a task unbound" with: bindings survive a proxy restart for 24 h idle; eviction, account removal or re-login leave a
task unbound. Apply the equivalent edit in every locale copy that carries the sentence (`rg -l` across docs-site locales) so no
locale contradicts English; follow `docs-site/AGENTS.md`.
- `docs-site/src/content/docs/reference/configuration/providers.md` `accountPoolStrategy` row (~line 128) says a task "can become unbound after proxy restart or affinity reset"; update it (and locale copies) the same way.

Issue: https://github.com/lidge-jun/opencodex/issues/8091

## Verification

`bun test <new + listed files>`, `bun run typecheck`, `bun run structure:check`, `bun run privacy:scan`,
`bun scripts/test.ts --changed=dev --parallel=1`. Red-on-old proof: run test 1 against `origin/dev` sources (stash src changes) and record the failure.
`ci:full` label: yes — the change reaches on-disk files and docs the import graph cannot see.

## Out of scope

`src/codex/routing/selection.ts` (Lane C), `src/codex/auth-context.ts` and the affinity log label (Lane D),
`src/server/claude-*`, `src/server/caller-session-identity.ts` (Lane A). No change to selection policy.

## Risks

- Persisting the HMAC secret changes the documented "keys are unreproducible after restart" posture. The secret stays private
(same protection class as `admin-api-token`), and the snapshot holds only digests of keys derived from it.
- Two processes sharing one config home: exclusive create means the loser keeps a process-local key; acceptable and documented.
- Write amplification: at most one coalesced write per second while traffic flows, same as the Claude store.
Loading
Loading