Skip to content

fix(native-chat): read ZCode conversations in their recorded order - #27142

Merged
nwparker merged 10 commits into
mainfrom
nwparker/zcode
Oct 11, 2026
Merged

nwparker merged 10 commits into
mainfrom
nwparker/zcode

Conversation

@nwparker

@nwparker nwparker commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

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.

Before on main

After, on this head: the saved conversation renders in recorded order.

Ordered history

An additional database message appears without reopening the view.

Live update

Testing

  • Manually inspected the rendered screenshots from the hidden, isolated app.
  • Automated tests added and run.

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

  • Not applicable; this change copies no skill-installer material.

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

  • Small, focused behavior change; existing surfaces and reader reused.
  • Before/after, mechanism, and approach explained.
  • Before/after screenshots attached.
  • Reviewed correctness, cancellation, bounds, and performance assumptions.
  • Cross-platform, SSH, folder, and mixed-version impact considered.
  • Focused tests, typecheck, quality gate, and Electron build pass locally.
  • Final-head platform matrix passes on macOS, Linux, and Windows.
  • Broader hosted checks complete successfully.

star-nebula and others added 3 commits October 9, 2026 21:44
…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.
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fd3f11f1-d351-485d-bf2c-90fe8f1a6363



📥 Commits

Reviewing files that changed from the base of the PR and between 4c4b6e5 and 09da57f.




📒 Files selected for processing (4)
  • src/renderer/src/components/automations/use-automations-page-setup-state.ts
  • src/renderer/src/components/sidebar/folder-workspace-composer-submit-fixtures.ts
  • src/renderer/src/components/sidebar/folder-workspace-composer-submit-host-platform.test.ts
  • src/renderer/src/components/sidebar/folder-workspace-composer-submit.test.ts



Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.





📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The change adds ZCode as a supported native-chat agent and routes its transcript reads through the OpenCode SQLite reader. Database discovery checks the native ZCode database path and WSL homes. ZCode reads filter hidden messages and apply provider transcript ordering while retaining storage-row cursors. Subscription handling and tests cover transcript updates and display.





Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: 🔵 Low · up to 09da5

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 | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 28 functions across 33 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check Passed The PR meets the coding requirements in #27130. zcode is a supported native-chat agent and resolves to the existing OpenCode transcript reader. Discovery checks ~/.zcode/cli/db/db.sqlite before WS…
Out of Scope Changes check Passed The changes remain within the stated scope. Database discovery, WSL preparation, transcript ordering, pagination, live reconciliation, runtime projection, routing, and related tests directly support n…
Title check Passed The title clearly identifies the main change: reading ZCode conversations in their recorded order.
Description check Passed The description is complete and relevant. It covers the user impact, implementation, rationale, linked issues, visual proof, testing, platform scope, risks, and checklist status.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR














🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@coderabbitai coderabbitai 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.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 30e82359-ce71-478e-b21d-83b841b8b8aa
📥 Commits

Reviewing files that changed from the base of the PR and between 8452fc3 and aa7ee0b.

📒 Files selected for processing (24)
  • config/scripts/vitest-sqlite-database-runtime-files.mjs
  • src/main/ai-vault/session-scanner-opencode-sqlite-dispatch.ts
  • src/main/ai-vault/session-scanner-opencode-sqlite-worker-protocol.ts
  • src/main/ai-vault/session-scanner-opencode-sqlite-worker-spawn.ts
  • src/main/native-chat/transcript-opencode-database.test.ts
  • src/main/native-chat/transcript-opencode-database.ts
  • src/main/native-chat/transcript-opencode-fingerprint-window.ts
  • src/main/native-chat/transcript-opencode-sqlite-query.ts
  • src/main/native-chat/transcript-opencode-subscribe.test.ts
  • src/main/native-chat/transcript-opencode-subscribe.ts
  • src/main/native-chat/transcript-opencode.test.ts
  • src/main/native-chat/transcript-opencode.ts
  • src/main/native-chat/transcript-read-cache.ts
  • src/main/native-chat/transcript-reader.ts
  • src/main/native-chat/transcript-tail-reader.ts
  • src/main/native-chat/transcript-watch.ts
  • src/main/native-chat/transcript-zcode.test.ts
  • src/main/runtime/rpc/methods/native-chat-rpc-page-bounds.ts
  • src/shared/native-chat-agent-support.test.ts
  • src/shared/native-chat-agent-support.ts
  • src/shared/native-chat-reasoning-order.test.ts
  • src/shared/native-chat-transcript-projection.ts
  • src/shared/native-chat-types.ts
  • tests/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.

Comment thread src/main/native-chat/transcript-opencode-database.ts
Comment thread src/main/native-chat/transcript-opencode-sqlite-query.ts
@nwparker

Copy link
Copy Markdown
Contributor Author

Final reviewed head: 4c67d43f1eb2ac308bc3a85e02fdf0c5b7db9d2a.

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.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: eb4dfc0c-1ec0-4ffe-96f0-5e95e714e449
📥 Commits

Reviewing files that changed from the base of the PR and between 4c67d43 and 4c4b6e5.

📒 Files selected for processing (3)
  • .github/workflows/zcode-transcript-contract.yml
  • src/main/native-chat/transcript-opencode-semantic-fidelity.test.ts
  • tests/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.

Comment on lines +4 to +12
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'

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.

🎯 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.

@nwparker
nwparker merged commit 8b2c795 into main Oct 11, 2026
42 of 45 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.

[Bug]: Native chat cannot read ZCode session history (sessions list fine, transcript unreadable)

2 participants