Derive boot sidebar active account from routing mode and preserve live session state - #128
Conversation
There was a problem hiding this comment.
All reported issues were addressed across 3 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 4 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 4 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 4 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
77481fe to
8563459
Compare
8563459 to
3db8746
Compare
3db8746 to
934a7ff
Compare
|
The latest version typechecks and its focused tests pass, but one cross-process race remains in the core mechanism.
Please make the final routing decision against a sidebar snapshot read after the asynchronous storage load, or use a version/CAS/lock scheme that cannot overwrite a newer writer. Add an interleaving regression where process B writes a new route while process A's storage load is paused, then assert A preserves B's route. The same-process preservation behavior is useful; this needs the cross-process write ordering fixed before merge. |
934a7ff to
882becf
Compare
|
Fixed in 882becf. Boot now completes the asynchronous account-storage load first and only then reads the sidebar snapshot for the preserved-route decision, so a peer's authoritative publish during the load can no longer be overwritten by a pre-load capture. The 10-minute freshness window and active-account validation are unchanged and still evaluate against fresh-loaded storage; the subsequent write remains non-authoritative and re-reads under the existing lock. Added your exact interleaving as a regression: process A's storage load is paused via a test hook, process B publishes a newer authoritative route mid-pause, A resumes — B's route survives in the file. Red on the pre-fix ordering (sidebar captured at sequence 1, storage completed at sequence 2), green after. |
d479727 to
9554b68
Compare
|
The original ordering issue is fixed: the new interleaving regression confirms that storage loading completes before the preserved sidebar snapshot is read, so a peer's route written during the load survives. One current-main integration failure remains. On a merge with v1.16.0: The failing test is The fixture uses ordinary |
9554b68 to
de51f1a
Compare
|
Rebased onto current main (v1.16.0) — Full gates on the rebase: opencode 866, e2e 21, typecheck/lint clean. |
…nd preserve live session state Boot seeding, quota-only refreshes, and command paths no longer clobber the sidebar activeId written by a live routing session. Routing-authoritative writes are distinguished from display-only writes; the serialized write chain re-reads the file before merging, and cross-process writes are guarded by an mkdir directory lock (atomic rename-claim eviction, jittered retry, file-based ownerId release). On lock-budget exhaustion against an active contender the write is skipped — never performed unlocked. The commit path is fenced: ownership is re-verified adjacent to the rename and again after it; on detected post-rename loss, one bounded locked repair republishes only the frame's routing-authoritative fields into the successor's fresh state. Boot resolves preserved routing only after the asynchronous account-storage load completes, so a peer's authoritative publish during the load cannot be overwritten by a pre-load snapshot. The residual window is a process freeze exactly between the final ownership stat and the rename — accepted for a display-only file whose frames self-heal.
de51f1a to
d6d3de6
Compare
On boot the sidebar always showed
mainas the active account, even withrouting.mode: fallback-first— and a freshly launched session clobbered the shared sidebar-state file'sactiveIdthat another live session's routing had legitimately written. The display only self-corrected after the new session's first real request.Three contributing sites in
packages/opencode/src/index.ts:activeId: 'main', route: 'main'lastSidebarRoutingdefault also started at'main', so background quota refreshes kept re-writing it/claude-*command reset the displayed active accountFix
New
resolveInitialSidebarRouting(storage)used to seed both the boot write andlastSidebarRouting:activeId(recentlastUpdated, id still present among enabled accounts), preserve it — that's another live session's routing decision.fallback-firstwith at least one enabled OAuth fallback → that fallback, elsemain.The command path now reuses
lastSidebarRouting(the pattern the mutation-refresh path already used). Real routing decisions keep overwritinglastSidebarRoutingexactly as before.Verification
Six red-first tests: fallback-first boot derives the fallback; a fresh cross-session
activeIdis preserved; stale or invalid file state falls back to derivation;/claude-quotano longer resets the active account; main-first boot unchanged. Full suite: core 37 / opencode 812 / pi 48, typecheck + biome clean, repo-rootbun run testgreen.Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.Summary by cubic
Derives the sidebar’s active account on boot from routing mode and preserves a live session’s selection across boots and display-only refreshes. Cross-process writes are serialized and atomic to prevent clobbering.
activeId; otherwise derive from routing (fallback-first→ first enabled OAuth, elsemain). Ignores stale/unknown ids and keeps existing routing if storage reload fails.lastSidebarRoutingwhen preserved. Real routing decisions stay authoritative; commands now reuselastSidebarRouting.Written for commit d6d3de6. Summary will update on new commits.
Greptile Summary
This PR keeps sidebar routing aligned with the current routing mode and live session state. The main changes are:
Confidence Score: 5/5
This looks safe to merge.
Important Files Changed
Reviews (17): Last reviewed commit: "fix(opencode): derive boot sidebar activ..." | Re-trigger Greptile
Context used: