Skip to content

fix(ai-vault): follow ZCode stored transcript order - #24584

Merged
nwparker merged 1 commit into
mainfrom
nwparker/integrations-zcode-1002
Oct 2, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/integrations-zcode-1002

Conversation

@nwparker

@nwparker nwparker commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​116 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​116
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​35 $\color{#cf222e}{\Huge{\mathbf{−}}}$​10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​25

ELI5

ZCode saves the order of conversation turns separately from their timestamps. Orca now follows that saved order, so an imported or forked conversation shows its actual first prompt and latest turns.

What Changed

First-prompt loading, session previews, and full-text transcript capture use ZCode's message and part sequence columns when present. Older databases and OpenCode keep their existing ordering. NULL sequence rows follow ZCode's legacy-row policy, and each table is checked independently.

Why

ZCode CLI 0.16.9 at upstream revision 29628c9acdb81b703bbd4080c207a0e7ce5e276e uses migration 0014_message_part_sequence and sequence-first readers. Sorting only by timestamps can select a later prompt as the first prompt and reverse text blocks. Extending Orca's existing SQLite reader keeps discovery, hidden-message filtering, and bounded previews together.

Linked Issue

Follow-up to the native ZCode integration requested in #21756 and history implementation #23513. This does not resolve GLM account setup #23803 or quota #18506/#21757.

Visual Proof

Both screenshots use Orca's real session-details component in a hidden Electron renderer, with results from a database created by upstream ZCode's own storage API and synthetic conversation text. The baseline result was produced from the unchanged HEAD reader; the current first-prompt value was also verified through the real Electron IPC path. This is component proof, not an end-to-end history discovery test.

Before:

Baseline history

After:

Correct history

Testing

  • I manually tested these changes locally
  • Automated tests added/updated

ORCA_BACKGROUND_LAUNCH=1 pnpm tc and ORCA_BACKGROUND_LAUNCH=1 pnpm run check:code-quality:changed pass. Targeted ZCode hooks, quota, readiness, and history checks: 85 tests passed; 3 pre-existing live tests skipped because their fixed-path fixtures are absent. Final shared-history rerun: 38 tests passed. The new regression failed before the fix. Coverage includes partially migrated schemas, legacy NULL sequence rows, hidden messages, OpenCode coexistence, and Windows resume-command construction.

Built upstream CLI 0.16.9 from pinned source in a task-owned clone; verified --version, --help, actual upstream SQLite store reads, and a real PTY resume launch in an isolated synthetic home. No authenticated quota request or paid model turn was performed. macOS was exercised; live Windows/Linux/SSH checks remain unverified.

AI Disclosure

Implemented and verified with Codex.

Review

No new storage, status producers, wire fields, or credential handling. SQLite reads remain on the execution host and read-only. Folder workspace proof used a non-git directory. OpenCode ordering is retained.

Agent skill upstream boundary

  • Not applicable: no upstream skill-installer content copied.

Notes

Current upstream CLI credentials have also moved to .zcode/v2/provider_config.json and the shared credential store; that separate quota/account migration remains follow-up work. The initial hidden app launch reconciled managed hooks before the isolated-profile safeguard was received; logs and scope are documented for the coordinator, and the owned app has been stopped.

Checklist

  • This PR is small and focused
  • User-facing behavior, mechanism, and approach explained
  • Before/after screenshots attached
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH, and folder-workspace impact considered
  • Full typecheck, changed-code gate, targeted tests, and development build pass; full CI matrix remains pending

@nwparker
nwparker marked this pull request as ready for review October 2, 2026 07:48
@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 10 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 64ca0130-d46d-4037-9877-2e3fbbed15c9

📥 Commits

Reviewing files that changed from the base of the PR and between b49abdb and 07f777a.

📒 Files selected for processing (4)
  • src/main/ai-vault/session-scanner-opencode-sqlite-capture.ts
  • src/main/ai-vault/session-scanner-opencode-sqlite.ts
  • src/main/ai-vault/session-scanner-zcode-order.ts
  • src/main/ai-vault/session-scanner-zcode.test.ts
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No critical issues — the ordering logic faithfully mirrors upstream ZCode's reader. Two low-stakes notes below.

Reviewed changes

  • New zcodeTranscriptOrder helper — builds a schema-aware ORDER BY fragment: when agent === 'zcode' and the table has a sequence column it orders by sequence IS NULL <dir>, sequence <dir>, time_created <dir>, <tiebreaker> <dir>, else it reproduces the pre-PR fragments exactly.
  • Capture, first-prompt, and preview readers — all three now order through the helper. Tie-breakers match upstream: rowid for sequenced messages, id for sequenced parts.
  • Preview window — the zcode subquery now projects m.rowid AS rowid, m.* so the outer DESC order can reference sequence/rowid; the non-zcode path is untouched. DESC reverses upstream's ascending key, so NULL-sequence rows sort newest-first, mirroring how upstream places them last when oldest-first.
  • Tests — cover partially migrated schemas (message, part, both), legacy NULL rows, and sequence-over-time ordering for first prompt, preview, and capture.

I verified the pinned upstream revision directly: migration 0014_message_part_sequence and 0015_message_part_sequence_backfill_and_guard define the intended NULL behavior, and the reader in repositories/messages.ts orders by sequence is null, sequence, time_created, rowid (messages) and sequence is null, sequence, time_created, id (parts). The helper reproduces these keys exactly, including the otherwise-surprising rowid-for-message / id-for-part split. OpenCode paths are unchanged. I also ran the ZCode test file (6 passed) and the related OpenCode AI Vault tests (36 passed).

ℹ️ Nitpicks

  • The partially-migrated test only drives kind: 'capture' (ASC), so the direction-dependent NULL branch in the preview (DESC) is untested. A mixed NULL/non-NULL session asserting the preview window would pin the one subtle branch the helper adds.
  • The helper comment "with legacy NULL rows last" holds only for ASC; with DESC the sequence IS NULL ${direction} term puts NULL rows first. Since the helper is direction-parameterized, a clause noting that would prevent a future "fix" to the intentional reversal.

Pullfrog  | Fix it ➔ | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker force-pushed the nwparker/integrations-zcode-1002 branch from b329456 to 07f777a Compare October 2, 2026 09:11
@nwparker
nwparker merged commit 7b1449a into main Oct 2, 2026
31 of 32 checks passed
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