Skip to content

Fix brain CRDT sync packaging + surface remote runtime integrations#542

Merged
arul28 merged 2 commits into
mainfrom
ade/chat-20260608-035907-f6d87573
Jun 8, 2026
Merged

Fix brain CRDT sync packaging + surface remote runtime integrations#542
arul28 merged 2 commits into
mainfrom
ade/chat-20260608-035907-f6d87573

Conversation

@arul28

@arul28 arul28 commented Jun 8, 2026

Copy link
Copy Markdown
Owner

Summary

Bundles several related fixes landed on this lane:

  • Ship cr-sqlite into the static/headless brain. The native tarball (package-native-deps.mjs) now copies crsqlite.<ext> from the desktop vendor dir, and crsqliteExtension.ts resolves it from <ADE_HOME>/runtime/<target>/. Without this the installed brain — the default sync host — had no CRR engine and crashed on crsql_internal_sync_bit for every CRR-table write.
  • Exclude config-snapshot tables (process_definitions, stack_buttons, test_suites) from CRR. Their delete+reinsert rebuild fired CRR triggers; they must never replicate.
  • Classify crsql / "not callable" RPC errors as app-level, not transport-level, so a single markCallFailure helper keeps the remote connection green instead of tearing it down. Collapses 9 duplicated catch blocks.
  • Surface a remote machine's Linear/GitHub/AI when bound to a remote runtime: LinearQuickViewButton no longer suppresses on remote (routes to the remote daemon), LinearSection steers remote to API-key entry (OAuth loopback can't cross remote), plus a new RemoteContextBadge.
  • Don't wipe open project tabs on a transient null project state during remote rebind.

Test plan

  • crsqliteExtension / kvDb CRR-exclusion unit tests (kvDb.test.ts) — 15/15
  • remoteConnectionService error-classification tests — 14/14
  • TopBar Linear remote-visibility tests — 34/34
  • apps/desktop typecheck + eslint clean
  • CI green across shards + build

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added visual indicators in Settings to identify when projects are bound to remote runtimes, with guidance on using API keys instead of browser-based authentication.
  • Bug Fixes

    • Fixed transient "no project" state appearing during remote project binding.
    • Fixed unintended tab clearing when switching between local and remote projects.
    • Improved error handling to distinguish between connection failures and application-level errors.
    • Enhanced Linear integration to work properly with remote projects.
  • Tests

    • Added regression tests for project tab preservation during remote transitions.

Greptile Summary

This PR bundles five related fixes: ships the cr-sqlite native extension into the static brain package so CRDT replication works on headless installs, excludes config-snapshot tables (process_definitions, stack_buttons, test_suites) from CRR to stop delete+reinsert rebuilds from firing missing-extension crashes, collapses nine duplicated catch blocks into a single markCallFailure helper that distinguishes app-level RPC errors from genuine transport failures, and surfaces the remote machine's Linear/GitHub/AI integrations in the UI while blocking OAuth loopback flows that can't cross a remote boundary.

  • Packaging & extension resolution: package-native-deps.mjs copies crsqlite.<ext> from the desktop vendor dir; crsqliteExtension.ts adds <ADE_HOME>/runtime/<target>/ as a candidate path, with matching directory structure between packager output and resolver input.
  • Remote connection hygiene: markCallFailure skips mergeStatus(error) for app-level errors (crsql, "not callable"), preventing false "host unreachable" toasts and reconnect loops; nine prior duplicated catch blocks now delegate to this helper.
  • Tab preservation: main.ts drops the redundant emitProjectChangedToWindow(null) precursor during remote bind; TopBar.tsx removes the tab-wiping branch from the !rootPath effect (delegating to closeProject() in appStore) and changes session restore to merge rather than replace tabs.

Confidence Score: 5/5

Safe to merge — all five fix areas are well-scoped, explicitly commented, and covered by targeted regression tests.

The changes are surgical and each is backed by a concrete test that reproduces the original failure. The markCallFailure refactor correctly preserves the existing isImplicitConnectionFailure gate before touching connection state. The tab-management changes remove a side-effect that was firing too broadly and rely on closeProject() in appStore for authoritative tab clearing — an assumption the new TopBar tests validate directly. The CRR exclusion list additions and the crsqlite packaging path are structurally straightforward. No regressions were found across the changed paths.

No files require special attention.

Important Files Changed

Filename Overview
apps/ade-cli/scripts/package-native-deps.mjs Adds copyCrsqliteExtension that copies crsqlite. from the desktop vendor dir; hard-fails for CRSQLITE_REQUIRED_TARGETS (darwin-arm64 only), warns-and-skips for unvendored targets.
apps/desktop/src/main/main.ts Removes two emitProjectChangedToWindow(null) precursor calls during remote bind/restore so the renderer never sees a transient project==null state that would clear open tabs.
apps/desktop/src/main/services/remoteRuntime/remoteConnectionService.ts Introduces markCallFailure helper that skips connection-state mutation for app-level errors; collapses nine duplicated catch blocks.
apps/desktop/src/main/services/state/kvDb.ts Adds process_definitions, stack_buttons, and test_suites to LOCAL_ONLY_CRR_EXCLUDED_TABLES with detailed inline comment.
apps/desktop/src/renderer/components/app/TopBar.tsx Tab management overhauled: removes tab-wiping from the !rootPath effect, changes session restore from replace to merge, tightens the clear-on-empty-session guard.
apps/desktop/src/renderer/components/settings/RemoteContextBadge.tsx New file exporting useRemoteRuntimeContext hook, RemoteSettingsBanner, and MachineScopeBadge. Clean and minimal.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[RPC call over established connection throws] --> B{isImplicitConnectionFailure?}
    B -->|No - app-level error| C[markCallFailure returns early]
    C --> D[Connection stays connected]
    B -->|Yes - transport failure| E[mergeStatus: state=error]
    E --> F[Connection flips to error]
    D --> G[Error rethrown to caller]
    F --> G
Loading

Comments Outside Diff (1)

  1. apps/desktop/src/renderer/components/settings/LinearSection.tsx, line 765 (link)

    P2 useRemoteRuntimeContext for settings scope — minor consistency nit

    LinearSection reads s.projectBinding?.kind === "remote" directly from the store while this PR adds the shared useRemoteRuntimeContext hook in RemoteContextBadge.tsx for exactly this purpose. The two are functionally equivalent, but using the hook here would keep the remote-context read consistent across all settings sections and make the hook easier to evolve (e.g. if the condition gains more nuance).

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: apps/desktop/src/renderer/components/settings/LinearSection.tsx
    Line: 765
    
    Comment:
    `useRemoteRuntimeContext` for settings scope — minor consistency nit
    
    `LinearSection` reads `s.projectBinding?.kind === "remote"` directly from the store while this PR adds the shared `useRemoteRuntimeContext` hook in `RemoteContextBadge.tsx` for exactly this purpose. The two are functionally equivalent, but using the hook here would keep the remote-context read consistent across all settings sections and make the hook easier to evolve (e.g. if the condition gains more nuance).
    
    How can I resolve this? If you propose a fix, please make it concise.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

    Fix in Claude Code

Reviews (2): Last reviewed commit: "ship: harden crsqlite packaging per revi..." | Re-trigger Greptile

Bundles several related fixes on this lane:

- Ship cr-sqlite into the static/headless brain. The native tarball
  (package-native-deps.mjs) now copies crsqlite.<ext> from the desktop
  vendor dir, and crsqliteExtension.ts resolves it from
  <ADE_HOME>/runtime/<target>/. Without this the installed brain (the
  default sync host) had no CRR engine and crashed on
  crsql_internal_sync_bit for every CRR-table write.

- Exclude config-snapshot tables (process_definitions, stack_buttons,
  test_suites) from CRR — their delete+reinsert rebuild fired CRR
  triggers; they must never be replicated.

- Classify crsql / "not callable" RPC errors as app-level, not
  transport-level, so a single markCallFailure helper keeps the remote
  connection green instead of tearing it down. Collapses 9 duplicated
  catch blocks.

- Surface a remote machine's Linear/GitHub/AI when bound to a remote
  runtime: LinearQuickViewButton no longer suppresses on remote (routes
  to the remote daemon), LinearSection steers remote to API-key entry
  (OAuth loopback can't cross remote), plus a RemoteContextBadge.

- Don't wipe open project tabs on a transient null project state during
  remote rebind.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
ade Ignored Ignored Preview Jun 8, 2026 7:02pm

@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR improves remote runtime stability across native packaging, connection error handling, database schema management, and UI state restoration. It vendors the crsqlite extension, distinguishes transport-level from application-level remote call failures, prevents local tabs from being cleared during remote binding transitions, and adds UI indicators for remote-bound settings and credentials.

Changes

Remote runtime and session stability

Layer / File(s) Summary
Native crsqlite extension vendoring and resolution
apps/ade-cli/scripts/package-native-deps.mjs, apps/desktop/src/main/services/state/crsqliteExtension.ts
Script adds crsqliteExtensionFileName() and copyCrsqliteExtension() to package the extension; path resolution extends search candidates to include ADE_HOME-based runtime locations.
Remote project binding IPC ordering
apps/desktop/src/main/main.ts
Removes standalone projectChanged(null) emissions before remote binding updates to prevent transient "no project" state from clearing restored tabs.
Remote connection error classification and handling
apps/desktop/src/main/services/remoteRuntime/remoteConnectionService.ts, apps/desktop/src/main/services/remoteRuntime/remoteConnectionService.test.ts
Introduces markCallFailure() helper to classify transport vs. application-level errors; only transport failures trigger reconnection. All public method error handlers and shared callMachine() updated to use classification. Tests verify application-level errors keep connection "connected" and transport failures transition to "error".
CRR schema cleanup and local-only table exclusions
apps/desktop/src/main/services/state/kvDb.ts, apps/desktop/src/main/services/state/kvDb.test.ts
Adds process_definitions, stack_buttons, test_suites to CRR exclusion list; includes migration logic to remove CRR metadata from DBs incorrectly converted to replicated tables, with test coverage for both prevention and cleanup.
Remote runtime UI context and indicators
apps/desktop/src/renderer/components/settings/RemoteContextBadge.tsx
New module exports useRemoteRuntimeContext hook, RemoteSettingsBanner, and MachineScopeBadge components to mark settings regions as remote-bound or machine-specific.
TopBar tab persistence and session restoration
apps/desktop/src/renderer/components/app/TopBar.tsx, apps/desktop/src/renderer/components/app/TopBar.test.tsx
Prevents tab list wiping during remote bind/unbind by removing "wipe on null rootPath" logic; session hydration merges restored roots with existing local roots; wipe condition restricted to genuinely empty sessions. Regression tests verify local tabs persist across remote binding transitions and empty snapshots.
Settings page remote indicators and Linear OAuth gating
apps/desktop/src/renderer/components/app/SettingsPage.tsx, apps/desktop/src/renderer/components/settings/LinearSection.tsx, apps/desktop/src/renderer/components/settings/MobilePushPanel.tsx
Settings page renders RemoteSettingsBanner at top; LinearSection detects remote projects, blocks browser OAuth (routing to API-key), hides reconnect button, shows remote messages; MobilePushPanel renders MachineScopeBadge for local-only settings.
Linear quick-view visibility gating for remote projects
apps/desktop/src/renderer/components/app/LinearQuickViewButton.tsx
Auto-visibility checks now gate on activeProjectRoot (covers both local/remote) instead of disabling for remote; test coverage adds assertions that Linear checks run on remote-bound projects.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • arul28/ADE#353: Both PRs modify remoteConnectionService.ts to centralize/classify call failures and change pool-failure handling behavior at the same service layer.
  • arul28/ADE#368: Both PRs modify LinearQuickViewButton.tsx, with this PR's visibility gating changes directly overlapping the retrieved PR's Linear quick-view/resolve-flow refactor.

Suggested labels

desktop

🚥 Pre-merge checks | ✅ 4 | ❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title directly and clearly summarizes the two main changes: fixing brain CRDT sync packaging and surfacing remote runtime integrations.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ade/chat-20260608-035907-f6d87573

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 and usage tips.

@arul28 arul28 changed the title Chat 20260608 035907 Fix brain CRDT sync packaging + surface remote runtime integrations Jun 8, 2026
@arul28

arul28 commented Jun 8, 2026

Copy link
Copy Markdown
Owner Author

@copilot review but do not make fixes

Comment thread apps/ade-cli/scripts/package-native-deps.mjs

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/ade-cli/scripts/package-native-deps.mjs`:
- Around line 227-233: The current check that uses exists(source) returns false
and only logs a warning when the cr-sqlite extension is missing; change this to
fail fast by throwing an Error (or calling process.exit(1)) unless an explicit
env override is set (e.g. ALLOW_MISSING_CRSQLITE=true) so packaging never
produces a known-broken runtime; specifically replace the if (!(await
exists(source))) { ... return false; } block to log the missing source and then
throw new Error(...) when ALLOW_MISSING_CRSQLITE is not truthy, and update the
caller that currently ignores the return (the code at the later check around
line 304) to stop ignoring the outcome and allow the thrown error to propagate
(or check the return and abort) so packaging aborts on missing crsqlite by
default.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4a0b752d-474f-47e7-9eec-9cce9cf04b1e

📥 Commits

Reviewing files that changed from the base of the PR and between 8c7e79a and 13d98e7.

📒 Files selected for processing (14)
  • apps/ade-cli/scripts/package-native-deps.mjs
  • apps/desktop/src/main/main.ts
  • apps/desktop/src/main/services/remoteRuntime/remoteConnectionService.test.ts
  • apps/desktop/src/main/services/remoteRuntime/remoteConnectionService.ts
  • apps/desktop/src/main/services/state/crsqliteExtension.ts
  • apps/desktop/src/main/services/state/kvDb.test.ts
  • apps/desktop/src/main/services/state/kvDb.ts
  • apps/desktop/src/renderer/components/app/LinearQuickViewButton.tsx
  • apps/desktop/src/renderer/components/app/SettingsPage.tsx
  • apps/desktop/src/renderer/components/app/TopBar.test.tsx
  • apps/desktop/src/renderer/components/app/TopBar.tsx
  • apps/desktop/src/renderer/components/settings/LinearSection.tsx
  • apps/desktop/src/renderer/components/settings/MobilePushPanel.tsx
  • apps/desktop/src/renderer/components/settings/RemoteContextBadge.tsx

Comment thread apps/ade-cli/scripts/package-native-deps.mjs
- Hard-fail packaging when a required brain target (darwin-arm64) is
  missing its cr-sqlite extension, instead of silently shipping a runtime
  that crashes on every CRR write. Non-vendored targets still warn-and-skip.
- Replace the misleading silent ".so" fallback in the extension-filename
  map with an explicit throw for unsupported platforms.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@mintlify

mintlify Bot commented Jun 8, 2026

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
ade-ac1c6011 🟢 Ready View Preview Jun 8, 2026, 7:08 PM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@arul28 arul28 merged commit df190a8 into main Jun 8, 2026
27 checks passed
@arul28 arul28 deleted the ade/chat-20260608-035907-f6d87573 branch June 8, 2026 22:52
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