Skip to content

fix(session): Codex counts as installed before its first session; session pull leaves _index.json unchanged - #1141

Merged
jeff-r2026 merged 2 commits into
Tencent:mainfrom
SaulMoro:fix/session-codex-install-index-updated
Oct 15, 2026
Merged

jeff-r2026 merged 2 commits into
Tencent:mainfrom
SaulMoro:fix/session-codex-install-index-updated

Conversation

@SaulMoro

Copy link
Copy Markdown
Collaborator

Summary

Two session fixes.

  • session migrate -t codex failed with "not installed" for anyone who had installed Codex but never run a session, because readiness required ~/.codex/sessions/. Codex is now a target when ~/.codex exists or codex is on PATH. The write already creates sessions/YYYY/MM/DD/.
  • Every session pull rewrote sessions/repos/<repo>/_index.json, so the team checkout stayed modified, and the next pull that brought index changes failed with "Your local changes ... would be overwritten by merge". Three things differed from what push writes: a fresh top-level updatedAt, each entry's updatedAt (push records the session's own, the rebuild used pushedAt), and entry order (push appends, the rebuild used directory order). The rebuild now keeps each entry's updatedAt and order from the current index, and the index is not written when its content is unchanged.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature causing existing behavior to change)
  • Documentation only
  • Refactor / internal cleanup

Test Plan

  • npx tsc --noEmit passes
  • npm run lint passes
  • npx vitest run: the session, sync and Codex files pass (27 files, 497 tests). The full run has two failures outside session code: mcp-reconcile (git EAGAIN under load; passes on its own) and gitlab-clone-realspawn (hangs locally).
  • Added/updated tests for the change (both failed on main first)
    • session-codex-install.test.ts: migrate into Codex with only ~/.codex; Codex listed as installed with only the CLI on PATH; not listed with neither; listing with no sessions/ returns empty.
    • session-sync.test.ts: a bare remote and two clones; push, then pull twice, and git status is clean; a second push, then a pull merges and stays clean.

Real CLI after npm run build, isolated HOME:

Fix 1, HOME with only ~/.codex/, a planted Claude session, codex not on PATH:

main:   codex: ✗ not installed
        ✗ Migration failed: Target platform "codex" is not installed or its storage directory was not found. ... (available: claude-code).
branch: codex: ✓ installed
        ✓ Migration successful
        Target file: $HOME/.codex/sessions/2026/10/01/rollout-2026-10-01T10-00-00-aaaaaaaa-....jsonl

With codex-cli 0.162.1 on PATH, codex exec resume <id> opens the migrated session (session id: aaaaaaaa-...) and then stops at 401 Unauthorized, because the test HOME has no auth.

Fix 2, alice runs session push and git push, bob runs session pull twice:

main:   git status → M sessions/repos/github.com%2Forg%2Falpha/_index.json
        after alice pushes again: Error: git pull failed ...: Command failed: git pull origin main
branch: git status → clean
        after alice pushes again: ✓ Pulled and indexed 2 session(s), git status → clean

Not run locally: the other agents and the gitlab/github providers (left to CI).

Related Issues

Follow-up to #593. The _index.json problem showed up while working on #1139.

Notes for Reviewers

Codex creates ~/.codex/sessions on its first session, so a member who installed Codex but never ran it failed 'session migrate -t codex' with 'not installed'. Codex is now ready when its root exists or the codex CLI is on PATH; the write already creates sessions/YYYY/MM/DD.
…ing new

Every session pull rebuilt _index.json with a fresh top-level updatedAt, each entry's updatedAt taken from meta pushedAt (push records the session's own updatedAt), and entries in directory order (push appends). The team checkout stayed modified, so the next pull that brought index changes refused to merge. The rebuild now keeps the entry updatedAt and order it cannot derive from disk, and the write is skipped when the content is unchanged.
@github-actions

Copy link
Copy Markdown

No actionable findings in the specified diff.

The PR description satisfies the testing requirement: it records real-CLI verification after npm run build for both fixes. Deferring other agents and providers to CI is permitted.

Review was read-only; I did not run, build, or install anything from the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants