Skip to content

fix(web): preserve host identity across same-server re-pairing - #11575

Closed
dongwook-chan wants to merge 1 commit into
stablyai:mainfrom
dongwook-chan:dongwook-chan/fix-web-repair-session-identity
Closed

dongwook-chan wants to merge 1 commit into
stablyai:mainfrom
dongwook-chan:dongwook-chan/fix-web-repair-session-identity

Conversation

@dongwook-chan

Copy link
Copy Markdown

Summary

Preserve a paired web runtime's execution-host ID when a new pairing offer proves it is the same server by pinned public key. The endpoint and device token still refresh, but existing worktree ownership and mirrored terminal handles keep one host identity.

This prevents existing AI CLI terminal sessions from failing closed with:

Workspace identity is ambiguous across hosts. Refresh projects and try again.

A different pinned key still creates a new web-* environment ID.

Root Cause

Runtime-scope browser access links auto-import on every visit. createStoredWebRuntimeEnvironment() minted a new web-* ID for each import, even for the same pinned server key.

Worktree catalogs then used the new ID while existing mirrored PTY handles could still carry the old ID. PTY routing interpreted those browser-generated IDs as distinct execution hosts and rejected the existing session as ambiguous.

Screenshots

No visual change.

Testing

  • Focused identity test failed before the fix and passes after it
  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/web/web-preload-api.test.ts src/renderer/src/web/web-workspace-session.test.ts src/renderer/src/runtime/web-session-tabs-sync.test.ts src/renderer/src/components/terminal-pane/pty-connection.test.ts (695 passed)
  • pnpm run typecheck:web
  • touched-file oxlint
  • touched-file oxfmt --check
  • git diff --check

pnpm run check:code-quality:changed could not run under the installed Node 22 because the repository requires Node 24 and the engine warning corrupts that script's JSON parser. The same touched-file lint and format checks run by the commit hook passed.

AI Review Report

Reviewed same-key and different-key pairing boundaries, existing compatible-selector behavior, web startup auto-pairing, session partition ownership, mirrored PTY routing, and current ambiguity fixes. The change is limited to the browser environment constructor and preserves the existing ID only when the pinned public key matches.

Cross-platform review found no platform-specific paths, shells, keyboard behavior, native modules, Git behavior, or Electron APIs. The browser identity rule is the same on macOS, Linux, and Windows and applies to SSH-hosted server worktrees without assuming local execution.

Security Audit

The pinned public key was already the trust boundary for compatibleEnvironmentIds; this change uses the same proof for stable identity. Device tokens and endpoints continue to rotate from the new offer. Different keys cannot reuse an existing ID. No credentials are logged or exposed, and no auth, IPC, command execution, filesystem, or dependency surface changes.

Notes

This fixes browser-generated execution-host churn for one paired server. It does not merge distinct physical servers or unrelated SSH/project host records.

Closes #11574

})

expect(paired.environment.id).toBe('web-server-a')
expect(paired.environment).not.toHaveProperty('compatibleEnvironmentIds')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Non-informative assertion on redacted field

redactStoredWebRuntimeEnvironment (called inside addFromPairingCode at line 1366 of web-preload-api.ts) unconditionally strips compatibleEnvironmentIds before returning. The assertion therefore passes regardless of what the internal StoredWebRuntimeEnvironment contains, so it does not verify the fix. The meaningful guard already exists on the preceding line (id === 'web-server-a'). If the intent is to confirm the internal representation has an empty compatibleEnvironmentIds list, the stored value (globals.storage.getItem('orca.web.runtimeEnvironment.v1')) would need to be parsed and inspected directly.

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!

@greptile-apps

greptile-apps Bot commented Jul 30, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes host-identity churn for same-server browser re-pairings. Previously, every call to createStoredWebRuntimeEnvironment minted a new web-* ID and placed the old one in compatibleEnvironmentIds; now the existing environment is returned as-is when the pinned public key matches, preserving the ID, creation timestamp, and any accumulated compatibility IDs. A different public key still produces a fresh ID.

  • web-runtime-environment.ts: getCompatibleEnvironmentIds is replaced by getSameServerEnvironment, which returns the full previous environment on a key match. createStoredWebRuntimeEnvironment then reuses id and createdAt from that environment while still refreshing the endpoint (URL + device token) and resetting runtimeId/lastUsedAt.
  • web-preload-api.test.ts: A new focused test asserts paired.environment.id === 'web-server-a' after re-pairing with the same key, plus a secondary assertion on compatibleEnvironmentIds absence that is always true due to redaction (see inline comment).

Confidence Score: 4/5

Safe to merge — the change is narrow, well-tested, and confined to the browser-side environment constructor. Device tokens and endpoints still rotate on every pairing; only the stable identity fields are preserved on a key match.

The fix is narrowly scoped and the same-key identity preservation is directly tested. One secondary assertion in the new test is non-informative due to upstream redaction, leaving the internal compatibility-ID state unverified.

Files Needing Attention: The test in web-preload-api.test.ts has one non-informative assertion worth revisiting if the team wants to confirm the internal compatibleEnvironmentIds state is also correct post-fix.

Important Files Changed

Filename Overview
src/renderer/src/web/web-runtime-environment.ts Replaces getCompatibleEnvironmentIds with getSameServerEnvironment to reuse the previous environment's ID/createdAt when the pinned public key matches, instead of generating a new ID and recording the old one in a compatibility list. Logic is correct for same-key and different-key branches.
src/renderer/src/web/web-preload-api.test.ts Adds a focused regression test for same-key identity preservation. Core assertion id === 'web-server-a' is strong; the secondary not.toHaveProperty('compatibleEnvironmentIds') is always true because redactStoredWebRuntimeEnvironment strips that field unconditionally, making it non-informative.

Reviews (1): Last reviewed commit: "fix(web): preserve host identity across ..." | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Updated runtime environment creation to match pairing offers against existing endpoints by server public key. Matching environments retain their id and createdAt, while their existing compatibleEnvironmentIds are carried forward. New environments continue to receive generated identity data with an empty compatible-ID list. Added a preload API test covering re-pairing with the same server key.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: preserving host identity across same-server re-pairing.
Description check ✅ Passed The description follows the template well and covers summary, testing, AI review, security, screenshots, and notes.
Linked Issues check ✅ Passed The PR matches #11574 by preserving the ID for same pinned keys, refreshing endpoint/device token, and creating a new ID for different keys.
Out of Scope Changes check ✅ Passed The changes stay focused on web runtime identity and the new regression test, with no unrelated code paths introduced.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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.

🧹 Nitpick comments (1)
src/renderer/src/web/web-preload-api.test.ts (1)

350-363: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Cover the complete re-pairing contract.

This test checks only ID reuse and an empty compatibility list. Add assertions for the refreshed endpoint/device token and preserved createdAt, plus cases proving existing compatibleEnvironmentIds are retained and a different publicKeyB64 generates a new web-* ID.

[details]

Suggested assertions
     expect(paired.environment.id).toBe('web-server-a')
+    expect(paired.environment.createdAt).toBe(1)
+    expect(paired.environment.endpoints[0]).toMatchObject({
+      endpoint: 'wss://server.example:443',
+      deviceToken: 'server-token'
+    })
     expect(paired.environment).not.toHaveProperty('compatibleEnvironmentIds')

[/details]


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d3c76adb-7785-4ffb-b697-794f22ecb936

📥 Commits

Reviewing files that changed from the base of the PR and between ab665a3 and 68579a8.

📒 Files selected for processing (2)
  • src/renderer/src/web/web-preload-api.test.ts
  • src/renderer/src/web/web-runtime-environment.ts

@nwparker

Copy link
Copy Markdown
Contributor

Thanks @dongwook-chan for tracking this down and writing up the root cause so clearly. This is already fixed on main by #27197 (b80c420). createStoredWebRuntimeEnvironment now classifies a re-pair against the stored server's public keys and host pin, and when it's the same host it keeps the existing web-* id (and createdAt) and bumps the pairing revision. Existing mirrored terminals keep a single execution-host identity and no longer hit the ambiguous-host error. If you still see this on the latest build, please comment or reopen.

@nwparker nwparker closed this Oct 26, 2026
@dongwook-chan

Copy link
Copy Markdown
Author

Thanks for tracing this to #27197 and explaining the same-host identity handling. I understand why preserving the existing web environment ID and incrementing the pairing revision resolves the duplicate-host identity problem. I have no new reproduction on the latest build to report, so I am leaving this closed.

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]: Same-server web re-pairing changes execution-host identity and strands existing sessions

4 participants