Skip to content

feat(import): import and continue codex threads - #312

Merged
nixuuu merged 1 commit into
feat/cli-import-3from
feat/cli-import-4
Nov 7, 2026
Merged

nixuuu merged 1 commit into
feat/cli-import-3from
feat/cli-import-4

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Stage 4 of 5 of the CLI import (stack A). Design: docs/import.md.

What it ships

  • Codex history through the adapter's own CodexEventMapper (the one live threads use): turns from task_started … task_complete / turn_aborted, whole items from event_msg item_completed, shell calls and code cells from raw response_items, the prompt as the turn's input (no echo item). Older rollouts without item_completed get messages, reasoning summaries, shell calls and compaction from response_items and event_msg user_message. Injected context is never a prompt.
  • Native continue for Codex: the rollout prefix is copied into the instance's CODEX_HOME/sessions/YYYY/MM/DD/ (archived rollouts too); the thread resumes it with thread/resume by id. Undo removes the copy.
  • Codex threads become selectable on the import page.
  • Deviation from the design: older rollouts are read by our own mapping (tested on a synthetic old-format rollout) instead of a helper app-server on a copy — deterministic and no CLI process on user data.

Tests

  • apps/worker/src/import/codex-history.test.ts: fixture turns, command with output, reasoning, stable ids across page splits; synthetic older rollout (messages, reasoning, shell call, compaction, aborted and failed turns, broken line).
  • apps/worker/src/import/codex-resume.test.ts: the real Codex app-server resumes the copied rollout by id against the fake endpoint; the request carries both earlier prompts and the tool output.
  • tests/integration/import-codex.test.ts (fake app-server, now also resuming the real rollout layout): history without the prompt echo, command with output, reasoning, untouched rollouts; native import with copy and thread/resume on a Canopy turn.
  • Live (CANOPY_LIVE=1): a real Codex thread learns a code word, is imported and resumed in the private CODEX_HOME; the real model answers with the word. Passed on this machine.

Copy audit

No new UI strings beyond stage 2's (Codex rows reuse the same labels).

Review fixes

  • Codex rollouts use the confined reader, complete-record cursors, masked copies with the same writer and manifest, and the provider-checked home lookup.
  • Tests: partial trailing record; the real Codex resumes the masked copy without the secret.

Re-check fixes

  • Codex copies use the staged, identity-checked writer and the anchored Remove; Remove resolves the home per CLI.

Round 3 fixes

  • Codex reader no longer cuts text before masking (H1).

Round 4 fixes

  • R1: Codex records are masked as decoded values before they become commands, previews or patches. Test: a shell command and an apply_patch with an escaped secret in JSON.

Round 5 fixes

  • The Codex reader masks each record through the single entry point from stage 1 (maskedRecord); scan previews and titles mask the whole record first. Covered by masking.test.ts (all three CLIs) and the stage tests.

Final review fixes

@nixuuu
nixuuu added this pull request to stack #314 November 6, 2026 22:25
@nixuuu
nixuuu force-pushed the feat/cli-import-4 branch 4 times, most recently from aea8095 to 71b3f11 Compare November 7, 2026 01:00
@nixuuu
nixuuu force-pushed the feat/cli-import-4 branch from 71b3f11 to c6faba5 Compare November 7, 2026 02:03
@nixuuu
nixuuu force-pushed the feat/cli-import-4 branch from c6faba5 to 182b7fd Compare November 7, 2026 02:43
Codex rollouts become Canopy threads through the adapter's own mapper,
older rollouts without whole items included, and continue natively from a
copy in the instance's private CODEX_HOME.

See docs/import.md.
@nixuuu
nixuuu force-pushed the feat/cli-import-4 branch from 182b7fd to a27dca7 Compare November 7, 2026 03:14
@nixuuu
nixuuu marked this pull request as ready for review November 7, 2026 03:23
@nixuuu
nixuuu merged commit 1ca387a into dev Nov 7, 2026
10 checks passed
@nixuuu
nixuuu deleted the feat/cli-import-4 branch November 7, 2026 03:24
nixuuu added a commit that referenced this pull request Nov 7, 2026
…351)

Imported Codex threads can fail on their first Canopy turn because their
rollout names a custom CLI provider that does not exist in Canopy's
private `CODEX_HOME`.

Fixes: #312
Related: #345

## Cause and fix

- Keep the explicit `modelProvider` override from #345. Codex 0.164
accepts it, but 0.166 validates the saved provider before applying it.
The real 0.166 binary reproduces the reported “which is no longer
configured” refusal against a local fake API.
- Before cold resume, normalize only the manifest-owned private
rollout's session provider and its own settings snapshots to the
thread's Canopy connection (`openai` or `canopy_<instance id>`). Use the
existing staged, identity-checked copy writer and update the manifest,
preserving Undo. Session ID, history, messages and turn references stay
intact.
- Paginated Codex sessions also read their saved provider from SQLite,
including on path-based resume. Update only `threads.model_provider` in
the private index, matching both session ID and verified rollout path.
Do not create a database or change its schema; leave unknown schemas
alone. Reject symbolic/hard links and special files in the index and
SQLite companions. Source CLI files, configuration and databases remain
untouched. Codex still enforces managed requirements on the selected
connection.
- Classify the missing-provider refusal as `connection_changed`, reusing
the specific explanation and **Open provider settings** action from
#345. Retain the native harness error under **Show details**.
- Claude already receives the instance endpoint and selected model on
resume; Grok loads the copied history and explicitly selects the thread
model. Extend their real-CLI regressions with a conflicting source
endpoint/model and a retired source model respectively.

## Already-imported threads

The next cold resume repairs the existing private copy and its matching
index entry, including copies that already failed with 0.166. No
re-import, new conversation, history summary or gateway migration is
needed. Copies without valid ownership evidence are not rewritten;
harness refusals retain their specific classification.

## Validation

- Passed: `bun install`, `bun run gen:check`, `bun run typecheck`, `bun
run lint`, `bun run format:check`, and `bun run --cwd apps/web build`.
- Real Codex 0.166 against a local fake API plus copy/index security
regressions: **9 passed**, including native and proxy connections,
failed old-copy recovery, a second cold resume, complete history,
unchanged source and Undo. The standard installed Codex 0.164, Claude
and Grok adapters also pass against local fake APIs.
- Gateway↔worker import integration covers native continuation with the
same session ID/history and an impossible override classified as
`connection_changed`, retaining the native error and provider-settings
recovery.
- Full `bun run check:tmp`: **1772 passed, 161 skipped, 0 failed** (1933
tests across 317 files); no test temp-directory leaks. Its PostgreSQL
container and volume were removed. `CANOPY_LIVE` stayed unset; no paid
API calls or UI/E2E tests.
- Final self-review and `git diff --check` passed. CI and external
review are pending.

## Copy audit — docs/copy.md §8

Effective message before → after: “Canopy had an internal error. Retry.
If it happens again, copy the details and report them.” → “Codex could
not use this thread with the current connection. Restore its previous
connection in provider settings, then retry.” The missing-provider
variant now uses the existing actionable connection explanation; no new
UI string or layout is introduced.

| Checks | Result |
|---|---|
| 1–2: wording and glossary | Reuses #345's two short sentences,
sentence case, punctuation, thread and provider-settings terminology. No
native provider ID appears on the surface. |
| 3–4: actions and errors | Existing **Open provider settings** and
**Retry** actions; integration test verifies harness source, native
code/message and `connection_changed`. Technical details use the
existing **Show details** disclosure. |
| 5–8: states, repetition, dependencies and soul | No new empty state or
confirmation; no duplicate title/body fact; connection dependency and
recovery are explicit; no humour. |
| 9: text lengths and widths | No interpolated names, new labels, string
changes or layout changes. Uses the same notice as #345; no browser or
UI test was run in this task. |
| 10: accessibility | Existing visible explanation and action labels
convey meaning without colour, icon shape or position. |
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