Desktop: assign each profile a runtime origin - #403
Merged
Conversation
priethor
force-pushed
the
priethor/desktop-ephemeral-runtime-origin
branch
from
July 29, 2026 12:59
0a0e69b to
5f3d085
Compare
listen(0) hands back a port from the ephemeral range, which is exactly where the kernel draws from for outbound sockets. That is right for a port that lives seconds and wrong for one we save across launches, since local servers and proxies churn through that range constantly. 9403-9498 is never handed out spontaneously, so only software that binds there explicitly can take a saved port. Port 0 stays as the last resort. Also fixes the collision note in the docs. Blocks with embedded media keep the previous origin in their markup, so those images do need re-inserting.
priethor
force-pushed
the
priethor/desktop-ephemeral-runtime-origin
branch
from
July 30, 2026 15:31
9ed56b2 to
4a01b44
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Cortext Desktop now gives each profile its own loopback port instead of assuming 9402. It takes the first free port in a fixed band, reuses it across launches, moves when that port is occupied, and rejects requests whose
Hostor suppliedOrigindoes not match. Starting Cortext again focuses the existing window instead of opening a second runtime against the same SQLite database.Why
Changing the port on every launch would discard origin-scoped preferences and strand the local Notion key. A saved port per profile avoids fixed-port collisions without resetting that state on normal restarts. The band exists for the same reason. A port assigned by the operating system comes from the range the kernel recycles for outbound sockets, which is a poor place to park a port we intend to keep.
How
127.0.0.1and retrying once if the selected port is claimed during startup.A collision that forces a new origin leaves browser-only preferences and the local Notion key under the old one. WordPress settings and uploads are unaffected, but blocks with embedded media keep the previous origin in their markup, so those images need re-inserting. Content stores absolute URLs today, which is also a problem for syncing documents with a remote site. This PR does not change that.
Testing Instructions
--user-data-dir. Confirm that the window opens on a port between 9403 and 9498.settings.json, change a browser-backed preference, quit, and relaunch the same profile. Confirm that the URL keeps the same port and the preference remains.curl -i <runtime-origin>/wp-includes/images/blank.gifwithout a token and confirm that it returns403 Forbidden.I used Claude to help implement these changes. I guided the work, then tested and reviewed the result.