Repository navigation
feat(web): opt-in device priority for multi-device sessions - #864
HadrienKerlero wants to merge 2 commits into
Conversation
Add a synced Settings → System → Device priority switch (`uiPriorityEnabled`, off by default). While on, one browser tab per user holds a lease that gates tagged terminal input and resizes across all sessions, so a phone no longer shrinks the sessions open on a computer; other tabs pause behind a Take priority overlay. While off, every gate takes its legacy untagged path. - Server: UiPriorityRegistry (src/web/ui-priority.ts), GET /api/ui-priority, POST /api/ui-priority/claim, ui:priorityChanged SSE, NOT_PRIORITY_HOLDER (409) on input, send-key, resize and approval answers. - A refused sequenced WS frame stalls the socket (1013) so no later seq can pass the dedup watermark. - Client: per-tab identity frozen before transports start, pop-outs inherit their opener, refused input stays queued until an accepted snapshot resolves it. - Untagged API callers, CLI automation and `codeman tui` are never gated.
|
Thanks for this, Hadrien. The PR adds an opt-in Device priority setting: only one browser tab per user types into and resizes the terminals, so a phone no longer shrinks the sessions open on a computer. The server side is well built. Stalling the WS and closing it with 1013 after a refused seq is a sound answer, because no later frame can then move the dedup watermark past it. The partial-paste outcome and the revalidation in the wake buffer and the SubmitVerifier are handled with care, and the test suite is thorough. Typecheck, lint, format, the frontend checks and the full Separately from the review, one question is still open on my side. This is a large new subsystem that did not go through an issue or Discussion first, so whether it ships as a built-in feature is still my decision to make. The points below apply either way. Needs a fix before merge
Smaller items
Item 1 is the one that blocks the merge, and once it is fixed this is ready for another review. Items 2 to 6 are small. If you would rather leave 5 and 6, I can apply them at merge time. |
- Add @fileoverview to src/web/ui-priority.ts and src/web/routes/ui-priority-routes.ts. - Move the UI priority wire types to src/types/ui-priority.ts (barrel re-export). - Send resizes before the first priority snapshot (_uiMaySendResize) at all eight resize gates; input still waits for the snapshot. - Docs: per-tab dedup id and storage in reliable-input-delivery.md and CLAUDE.md; move the invariants section next to input delivery; list the always-on changes in the changeset. - Revert the local-path comment in gesture-codeman.js.
|
Thanks for the review, Ark0N. I pushed 75f39af with items 3 to 6 and the resize half of item 2. For item 1, and the startup wait that depends on it, I'd like your call before building, because the safe version is bigger than the sketch suggests. Details below. Fixed in 75f39af
Checks on 75f39af: Item 1: a question before I build it You're right on all counts: a fresh tab id strands the unACKed input of a closed tab or a killed PWA, and the per-tab keys are never removed. Before writing it, I had the fix designed and then reviewed twice. Done literally, the sketch can type a command twice or lose input. Here is why:
That leaves two shapes:
Which would you prefer? Or would you rather keep item 1 out of this PR, or have this ship as something other than a built-in feature, given your open question about that? Once you choose, I'll build it with the close-then-reopen and pruning tests you asked for, and the remaining part of item 2: starting SSE, WS, tiles and |
|
Thanks for the quick follow-up, Hadrien. This PR adds an opt-in Device priority setting, so only one browser tab per user types into and resizes the terminals. 75f39af covers what you listed. Item 3 has the About your question on item 1: two decisions are still open on my side. One is from my earlier comment: whether Device priority ships as a built-in feature. The other is the shape of the item 1 store: A, B, or keeping it out of this PR. I checked your points 1, 2 and 4 against the code and they are accurate. Three small things from this pass. They can go in the same push:
Item 1 still blocks the merge. When the open decisions are made and item 1 plus the rest of item 2 are in, this is ready for another review. |
Problem
When a session is open on a computer and the same Codeman is then opened on a phone, both browsers send resizes and keystrokes into the same tmux panes. The phone shrinks the terminal under the computer, and the two devices fight over the geometry for as long as both are open.
Change
An opt-in Device priority setting under Settings → System → Device priority (synced
uiPriorityEnabled, off by default).While it is on, one browser tab per user holds the UI priority lease. Only that tab types into and resizes the terminals, across all sessions:
While it is off, every gate takes its legacy untagged path: no prompt, no overlay, every window types and resizes as in 1.52.0. Switching it applies immediately to every open window, without a reload.
Server
src/web/ui-priority.ts:UiPriorityRegistry, one in-memory lease per username (one global lease in single-user mode).setEnabledclears holders and broadcasts a neutral{ holder: null, enabled }state to every SSE client.GET /api/ui-priority,POST /api/ui-priority/claim, SSEui:priorityChanged, and error codeNOT_PRIORITY_HOLDER(409).X-Codeman-Tabon HTTP,tab=on WS/SSE): session/input,/send-key,/resize, and approval/answer.1013and applies no later frame, so no later seq can move the dedup watermark past the refused one. The browser reconnects and resends in order.409with "input was partially applied and Enter was withheld", and its seq stays consumed. That way a replay never types it twice.Client
src/web/public/ui-priority.js: tab identity is frozen (sessionStorage + BroadcastChannel duplicate check) before any transport starts, and reliable-input storage and dedup are scoped per tab.Not gated
API scripts, CLI automation, MCP, service-worker actions, and
codeman tuiattach send no tab id and behave exactly as before. This is cooperative UX between your own tabs, not a security boundary (documented as such).Docs
docs/api-reference.md,docs/architecture-invariants.md(#per-tab-ui-priority),docs/wiki/{Settings-Reference,Mobile-Guide,Multi-User-Mode,HTTP-API}.md,CLAUDE.md,src/web/CLAUDE.md, a README feature bullet, and aminorchangeset. No version bump, noCHANGELOG.mdedit.Verification (on
6db166f3, currentmaster)npm run typecheck,lint,format:check,check:frontend-syntax,check:browser-excludes, andnpm run buildpass.npm test: 17,913 passed, 4 failed, 13 skipped.frontend-public-tooling("Spreadsheet preview assets are missing") andspreadsheet-preview-workeralso fail on unmodified6db166f3on this machine.tui-e2etimed out once under full-suite load. It passed 3/3 on this branch and 2/2 on6db166f3when run alone.terminal-pty-geometrybroke because Prettier reflowed thesession.resize(...)call that it pins as text. The call is back on one line; that file and the other 24 that read the changed sources as text pass (856 tests).Known limits
codeman tuiattaches to tmux directly, so it can still type and resize.