Skip to content

Bridge legacy Codex sessions into runtime home - #2816

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/codex-session-bridge
May 26, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/codex-session-bridge

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented May 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Bridge legacy ~/.codex/sessions/**/*.jsonl files into Orca's managed Codex runtime home during Codex launch so old sessions remain resumable under Orca's CODEX_HOME.
  • Keep the bridge limited to session JSONL files; do not copy auth/config/hooks/SQLite state, and do not overwrite runtime-owned session files.
  • Use symlink/hardlink only for new session bridges. If both fail, skip bridging rather than creating an independent stale copy.
  • Deduplicate Codex usage scans for physical aliases and handle legacy copied-session markers without losing data or double-counting copied prefixes.

Design Review Outcome

  • Initial review found scanner double-counting and unsafe copy fallback behavior.
  • Follow-up reviews found copied-bridge divergence, legacy copied-marker migration, and total-only suffix edge cases.
  • All actionable findings were fixed. Remaining accepted risk: launch still synchronously walks ~/.codex/sessions; local measurement on this machine was 4,524 JSONL files / 157 dirs / 2.4 GB, with a 26 ms median and 63 ms max walk over 5 runs, but slow or remote home directories may be worse.

Implementation Notes

  • Added src/main/codex/codex-session-bridge.ts for session-specific bridge ownership, keeping codex-home-paths.ts focused on home/resource paths.
  • CodexRuntimeHomeService.prepareForCodexLaunch() now invokes the session bridge after resource/config sync.
  • src/main/codex-usage/scanner.ts now dedupes physical aliases by file identity and supports legacy copied-source suffix parsing to avoid counting copied prefixes twice.
  • Deviations from the original implementation: removed session copy fallback entirely for new bridges because resumable JSONL files can be appended independently and plain copies cannot be made safe without merge semantics.

Completeness Verification

  • Verified old system sessions are bridged before launch.
  • Verified runtime-owned sessions win on path conflicts.
  • Verified no auth/config/hooks/state files are bridged by the session bridge.
  • Verified symlink/hardlink failure does not create independent session copies.
  • Verified legacy copied markers are migrated safely or scanned without copied-prefix double counting.

Review Loop

  • Multiple review rounds were run with subagents.
  • Early rounds found actionable issues around double-counting, stale copied sessions, divergent copied sessions, delete-before-replace migration, and total-only suffix parsing.
  • Final Brennan validation returned: land, with known launch-scan performance risk accepted/tracked.

Validation

  • pnpm exec vitest run --config config/vitest.config.ts src/main/codex/codex-session-bridge.test.ts src/main/codex/codex-home-paths.test.ts src/main/codex-usage/scanner-paths.test.ts src/main/codex-usage/scanner.test.ts src/main/codex-accounts/runtime-home-service.test.ts passed: 5 files, 80 tests.
  • pnpm run typecheck:node passed.
  • pnpm run typecheck passed.
  • pnpm run lint passed.
  • git diff --check passed.

Assumptions / Risks

  • No live SSH validation was run because this does not touch SSH orchestration or remote runtime code directly.
  • On Windows/restricted filesystems, if symlink and hardlink both fail, old sessions remain visible to usage scanning from the system home but are not bridged into runtime CODEX_HOME.
  • The synchronous full-history session walk is accepted as a performance risk for this PR and should be revisited with an indexed/incremental migration if it shows up in telemetry or user reports.

Made with Orca 🐋

@brennanb2025
brennanb2025 merged commit 6f93989 into main May 26, 2026
2 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
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.

1 participant