Skip to content

[codex] fix desktop profile project gateway routing - #86272

Open
vollegrewar wants to merge 2 commits into
NousResearch:mainfrom
vollegrewar:codex/fix-profile-project-route
Open

[codex] fix desktop profile project gateway routing#86272
vollegrewar wants to merge 2 commits into
NousResearch:mainfrom
vollegrewar:codex/fix-profile-project-route

Conversation

@vollegrewar

Copy link
Copy Markdown

Summary

Fix desktop profile switching when a profile has its own pooled gateway backend. The sidebar previously routed projects.tree to the primary/default gateway, so the selected profile could show no project folders or a partial tree from the wrong backend.

Root Cause

sharedPrimaryRoute() treated any connection descriptor with a profile field as a shared-primary route. Pooled profile descriptors also carry that field because it is needed to mint the profile-specific WebSocket URL. As a result, the renderer reused the default gateway instead of opening the selected profile's backend connection.

This change compares the selected profile's connection endpoint with the primary endpoint. Only an endpoint match is treated as shared; a distinct pooled endpoint opens and becomes the active profile socket.

Scope

  • Preserve the shared-global-remote behavior.
  • Route pooled profile project requests to their own gateway.
  • Add regression coverage for descriptors that carry profile on both shared and pooled routes.

This is complementary to #82823, which clears stale per-profile project cache state. This PR fixes the incorrect backend selection that produced the wrong project tree in the first place.

Validation

  • cd apps/desktop && npm run test -- gateway-shared-remote.test.ts
  • cd apps/desktop && npm run typecheck
  • Manual packaged-desktop verification on Windows: switching between novel-writer and regular_encoding loaded each profile's own project folders.

Closes #86107

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/desktop Electron desktop app (apps/desktop/*) area/profiles Multi-profile isolation, HERMES_HOME scoping sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state labels Aug 14, 2026
@vollegrewar
vollegrewar marked this pull request as ready for review August 14, 2026 19:04
@Enough1122

Copy link
Copy Markdown
Contributor

AI code review — automated review for reference, author can ignore or act on any point.

[codex] fix desktop profile project gateway routing

Comparing endpoints instead of the profile tag is the correct fix — pooled and shared descriptors both legitimately carry profile now. Observations:

  1. apps/desktop/src/store/gateway.ts (sharedPrimaryRoute): Promise.all requires BOTH getConnection(profile) and getConnection() (primary) to resolve. If the primary-descriptor call rejects while the profile connection succeeds, the whole function returns false and the caller dials a second socket — resurrecting the exact "poisoned gateway" failure the comment describes. Consider Promise.allSettled (or per-call error handling) so a primary-descriptor failure doesn't force the wrong route.

  2. connectionEndpoint compares endpoints as raw strings. A trailing slash, scheme case (https:// vs HTTPS://), or https:// vs wss:// difference between the two descriptors fails the match and causes a redundant second socket to be dialed. Normalizing (strip trailing /, lowercase the host) would make shared-primary detection more robust.

  3. Minor: connectionEndpoint returns null for unrecognized descriptor shapes and sharedPrimaryRoute then falls through to the pooled path. Conservative, but a debug/warn log on the unrecognized shape would help diagnose misrouting when a new descriptor field replaces the existing ones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/profiles Multi-profile isolation, HERMES_HOME scoping comp/desktop Electron desktop app (apps/desktop/*) P2 Medium — degraded but workaround exists sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Desktop — single explicit project entry vanishes from sidebar Projects list mid-session; survives restart (backend intact)

3 participants