Repository navigation
fix(native-chat): read ZCode conversations in their recorded order - #27142
Conversation
…e SQLite reader ZCode's CLI persists an OpenCode-v1-shaped history in its own SQLite store (~/.zcode/cli/db/db.sqlite). The Agent Session History scan already lists those sessions, but opening one in the native chat found nothing: the chat transcript path had no ZCode awareness. Resolve a zcode transcript against the ZCode database (native home, then WSL homes) before any OpenCode install, tag every read (signal, page, subscribe) with the agent, and apply the same hidden-transcript filter the scan uses so ZCode's hidden bookkeeping rows stay out of chat renders.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: 🔵 Low · up to The focused workflow runs for this PR, but a future change limited to transcript routing or agent support would skip its cross-platform contract check. Hosted checks for this PR are reported passing, so the remaining risk is a bounded CI-coverage gap. Pre-merge checks |
|
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
30e82359-ce71-478e-b21d-83b841b8b8aa
📒 Files selected for processing (24)
config/scripts/vitest-sqlite-database-runtime-files.mjssrc/main/ai-vault/session-scanner-opencode-sqlite-dispatch.tssrc/main/ai-vault/session-scanner-opencode-sqlite-worker-protocol.tssrc/main/ai-vault/session-scanner-opencode-sqlite-worker-spawn.tssrc/main/native-chat/transcript-opencode-database.test.tssrc/main/native-chat/transcript-opencode-database.tssrc/main/native-chat/transcript-opencode-fingerprint-window.tssrc/main/native-chat/transcript-opencode-sqlite-query.tssrc/main/native-chat/transcript-opencode-subscribe.test.tssrc/main/native-chat/transcript-opencode-subscribe.tssrc/main/native-chat/transcript-opencode.test.tssrc/main/native-chat/transcript-opencode.tssrc/main/native-chat/transcript-read-cache.tssrc/main/native-chat/transcript-reader.tssrc/main/native-chat/transcript-tail-reader.tssrc/main/native-chat/transcript-watch.tssrc/main/native-chat/transcript-zcode.test.tssrc/main/runtime/rpc/methods/native-chat-rpc-page-bounds.tssrc/shared/native-chat-agent-support.test.tssrc/shared/native-chat-agent-support.tssrc/shared/native-chat-reasoning-order.test.tssrc/shared/native-chat-transcript-projection.tssrc/shared/native-chat-types.tstests/e2e/native-chat-zcode-transcript.spec.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
|
Final reviewed head: Recommend merge. All final hosted checks pass: five full Node test shards, Linux Electron transcript regression, relay integration, both packaging jobs, and Linux/Windows x64/Windows ARM persistence lanes. Local verification adds 168 focused transcript/rendering tests, a 34-test WSL preparation/discovery/client run, typecheck, changed-code quality, and hidden macOS before/after proof. The original reader author’s commit is retained. The replacement corrects session/agent propagation, recorded order and pagination, live reconciliation, native-first discovery, and ZCode-only WSL preparation. The separately proposed read-only “Resume in chat” overlay was excluded because it changed workspace/resume routing. The sequence-only polling concern was checked against the CLI write contract and its limitation is documented. Native Windows UI, an actual WSL read, SSH, and authenticated real-CLI resume were not exercised in this review. The change remains a medium-risk extension of shared transcript reading; no merge was performed. |
6b8df46 to
4c4b6e5
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
eb4dfc0c-1ec0-4ffe-96f0-5e95e714e449
📒 Files selected for processing (3)
.github/workflows/zcode-transcript-contract.ymlsrc/main/native-chat/transcript-opencode-semantic-fidelity.test.tstests/e2e/helpers/orca-app.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
| paths: | ||
| - 'src/main/ai-vault/session-scanner-zcode*' | ||
| - 'src/main/ai-vault/session-scanner-opencode*' | ||
| - 'src/main/ai-vault/opencode-wsl-runtime*' | ||
| - 'src/main/native-chat/transcript-opencode*' | ||
| - 'src/main/native-chat/transcript-zcode*' | ||
| - 'src/shared/native-chat-types.ts' | ||
| - 'src/shared/native-chat-transcript-projection*' | ||
| - '.github/workflows/zcode-transcript-contract.yml' |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Include transcript routing files in the workflow path filter.
If a PR changes only src/main/native-chat/transcript-reader.ts or src/shared/native-chat-agent-support.ts, this workflow does not run. Both files are part of the ZCode transcript routing covered by this contract. Add the routing and agent-support paths to the filter so those changes receive the cross-platform check.
ELI5
A saved ZCode conversation now opens in a terminal’s native chat view, with its messages in the order the agent recorded them. Hidden bookkeeping stays hidden, and new messages appear while the chat is open.
What Changed
Route ZCode through the existing SQLite transcript worker, using only its own database. Preserve the session ID and agent selection through full reads, pagination, and subscriptions. Check the native store before discovering WSL homes, and treat a missing installation as unavailable. WSL reader setup also recognizes a ZCode-only installation independently of OpenCode.
Reuse the scanner’s visibility and sequence rules. Keep pagination cursors attached to stable database rows; send an optional display-order field so the renderer does not reorder imported conversations by their timestamps. Live refreshes reconcile changes in sequence order, including visibility changes and deletions. The fingerprint-window policy is extracted to keep the live reader within the file-size limit.
Why
The session list already found these conversations, but native chat did not support their agent or discover their store. Extending the existing reader keeps its cancellation, read limits, and execution-host checks. A separate read-only tab under “Resume in chat” would change that action’s meaning and bypass its workspace routing, so this change uses the existing terminal/chat surface.
Credit to @star-nebula for reporting the bug and implementing the initial reader wiring in #27131. Their original authored commit is retained here; the follow-up fixes and tests address the failures found during review.
Linked Issue
Includes the separately reviewable lint prerequisite #27326. Merge that first; its identical cleanup is composed here so the final head can pass required checks.
Fixes #27130
Supersedes #27131.
Visual Proof
The same disposable ZCode database and real ZCode hook event were used in a hidden Electron app. No real provider login or paid request was involved.
Before, on main
16e4d32978f: switching the terminal to chat does not mount a conversation view. The regression test fails because the chat is absent.After, on this head: the saved conversation renders in recorded order.
An additional database message appears without reopening the view.
Testing
131 focused tests pass across 13 files after merging current main. Typecheck, changed-code quality, normal hooks, and the rebuilt hidden Electron flow pass on macOS arm64. The test emits the real host hook and verifies rendered ordered history plus a live database append. Historical failures on main establish the regression; previous-head CI is not claimed as current-head proof.
A differential probe against current main matched all 25,600 message-comparator pairs without the optional provider order and nine legacy page results across 1,000/10,000/50,000-message databases. The same indexed, synthetic databases returned 50-row ZCode pages in 1.26/9.16/48.88 ms median (50,000-row maximum 52.97 ms, 12 pages per size). These are local measurements, not a hardware-independent latency guarantee.
Added a macOS/Linux/Windows matrix for real SQLite fixtures, existing OpenCode v1/v2 readers, read budgets, ordering, subscription cleanup, and host routing. The first Windows run exposed a pre-existing fixture that seeded hundreds of individually committed rows; bulk seeding now uses one transaction, preserving every read assertion and the timeout. The matrix passes on all three desktop OSes at final head
09da57fe240d. Platform verification.All four proposed PRs merge into current main without conflicts. On the composed branch, 360 focused tests including the lint prerequisite, typecheck, full
pnpm lint, and all three rebuilt hidden Electron flows pass. No real provider requests or authentication. Actual WSL/SSH sessions and authenticated CLI resume are not exercised; WSL routing is covered by contracts and the database-presence script runs against disposable homes on POSIX hosts.Review
No credential writes, new process launch path, new stream opcode, or structured-session adapter. Live refresh follows the CLI write contract: same-scope sequences are immutable and rebinding updates timestamps; manual SQL resequencing without updating timestamps is outside that guarantee. The worker’s optional agent selector and message’s optional order field are additive. Existing SSH transcript restrictions still apply; loss of contact is not treated as an empty transcript. Folder workspaces use the existing terminal/chat path without new Git requirements.
Agent skill upstream boundary
Notes
Risk reduction: shared legacy behavior matches main in differential probes, large-session paging was measured, all proposed changes were tested together, and native SQLite contracts now run on every desktop OS. Low merge risk is conditional on the corrected head’s platform matrix and broader hosted checks passing. Runtime fields remain optional and existing host-routing restrictions remain in force.
Checklist