Repository navigation
fix: align session health notice with send/rebind authority - #1062
Merged
Merged
Conversation
The composer health notice decided from a renderer-side proxy (default exists && enabled) plus lastTestStatus, which disagreed with the actual send gate in both directions (#1038): - locked sessions (has history) hid the notice behind a ready-looking default even though the send cannot rebind and will fail; - an enabled-but-secretless default hid it even though rebind fails; - a deleted connection showed a destructive notice even when another persisted connection could serve the send; - lastTestStatus=error rendered as a destructive hard block even though it never gates send (E4). The send/rebind decision now lives in a single pure core projection (projectSessionSendOutcome) shared by both sides: the desktop send gate resolves the async facts, delegates the decision, and keeps only the side effects (rebind mutation, canonical error copy); the notice maps the same outcome to actionable copy. SessionSummary exposes connectionLocked so the renderer works from the same facts, and a connections:hasSecret probe replaces the exists-and-enabled proxy. lastTestStatus stays as an intentional pre-send reminder: warning tone only, copy that never claims send is blocked, and silent when the projection rebinds away from the connection.
…stic Review on PR #1062 found that ensureSessionCanSendOrRebind gathered facts with a single Promise.all over every candidate connection: - an unrelated connection's getApiKey failure rejected an otherwise healthy send; - every send triggered OAuth near-expiry network refreshes for all connections just to compute readiness; - a getDefaultSlug/listConnectionSlugs failure could drop the session's own connection from the candidate set, misjudge it as connection_missing, and silently rebind a healthy session; - parallel push made the rebind winner depend on async completion order instead of the persisted connection order. The gate now resolves facts in two phases: phase 1 checks only the session's own connection (via the new sessionOwnConnectionBlockReason export) and returns early when it is usable, so a healthy send never consults the default slug, the connection list, or other connections' secrets; phase 2 walks candidates in deterministic [default, ...list] order with per-item failure isolation and assembles them before running the projection, so the rebind winner follows the persisted order and a single unreadable candidate is skipped rather than failing the send.
Review on PR #1062 found three freshness/observation problems around the notice's secret-presence probe: - connections:hasSecret used the network-refreshing resolveConnectionSecret, so a read-only status read could refresh OAuth tokens just by being observed. It now uses the read-only hasConnectionSecret (stored-credential presence); send/test/ fetch-models keep the refreshing path and the send gate stays authoritative. Contract tests re-pin the read-only invariant. - Storage self-heals connectionLocked only on readHeader/readMessages, so a just-opened legacy session's summary can still read unlocked and the notice could treat it as rebindable until the next summary refresh. The renderer now derives the effective lock as the summary bit OR a user message in the loaded transcript — the same primary evidence storage heals from. - A credential-only change (external credentials.json edit) emits connection_list_changed without bumping updatedAt, so connectionsEqual kept the list identity and the probe never re-ran. useShellConnections now exposes connectionsRevision, bumped on every successful refresh, and the probe effect depends on it.
Re-review of the staged send gate found that phase 2 still resolved every candidate with one Promise.all: even when the default connection was already usable, the gate waited on — and probed — all later candidates, so a slow or hanging OAuth refresh on an unrelated connection could stall the rebind recovery path (reproduced with a never-resolving secret read behind a ready default: the gate never settled). The pre-projection walk short-circuited on the first ready candidate; this restores that behavior. Candidates are now probed one at a time in the same deterministic [default, ...list] order, re-running the core projection over the resolved prefix after each step and stopping on ready/rebind. The winner is identical to a full assembly because the projection picks the first ready candidate in that same order; blocked only continues the walk. Also documents why getDefaultSlug fails closed while the list read fails open to []. Regression test: a hanging later candidate neither blocks the rebind to a ready default nor gets probed.
The notice's freshness depends on glue no type error would catch if deleted: the connectionsRevision bump past the connectionsEqual dedup, the secret probe effect's dependency on it, and the effective connectionLocked (summary bit OR user message in the loaded transcript). Source-grep contract, matching the repo convention used for the read-only hasSecret pin.
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.
Summary
Closes #1038.
After #1032/#1035 the composer-adjacent health notice decided from a renderer-side proxy (
defaultConnection exists && enabled) pluslastTestStatus, which disagreed with the authoritative send/rebind path in both directions:connectionLockedblocks silent rebind and the send will fail.lastTestStatus: 'error'rendered as a destructive hard block even though lastTestStatus never gates send (E4).The send/rebind decision now lives in a single pure core projection,
projectSessionSendOutcome(packages/core/src/session-send-projection.ts), over the same facts on both sides:ensureSessionCanSendOrRebind) resolves facts in two staged phases and delegates the decision to the projection, keeping only the side effects — the rebind mutation and the canonical error copy (produced by re-runningassertSessionCanSendon the blocked path). Phase 1 checks only the session's own connection and returns early when it is usable, so a healthy send never consults the default slug, the connection list, or other connections' secrets (no OAuth network refresh just to send). Phase 2 probes candidates one at a time in deterministic[default, ...list]order with per-item failure isolation and the historical short-circuit — it stops at the first candidate the projection can decide on, so a slow or hanging OAuth refresh on an unrelated connection can neither fail nor stall the send, and the rebind winner follows the persisted order rather than async completion order. Codex normalization moved to core so both sides share it.connections:hasSecretprobe, and an effectiveconnectionLocked. The probe uses the read-onlyhasConnectionSecret(stored-credential presence — observing it never refreshes OAuth tokens; send/test/fetch-models keep the refreshing path) and re-runs onconnectionsRevision, which bumps on every successful connection refresh, so credential-only changes (externalcredentials.jsonedits that don't bumpupdatedAt) also re-probe. The effective lock is the summary bit (newly exposed onSessionSummary) OR a user message in the loaded transcript — the same primary evidence storage heals from, closing the window where a just-opened legacy session's summary still reads unlocked.ready/rebindstay silent (refactor(desktop): move session health feedback into the conversation flow #1032);blockedmaps the reason to destructive copy naming the failing connection and pointing at the right Settings section.lastTestStatuscontract (product decision in the issue): kept as an intentional pre-send reminder — warning tone only, copy that states plainly it does not intercept send, shown only when the projection says the session's own connection will serve (ready); silent when the send rebinds away.One behavior note discovered while testing: stale sessions with user messages self-heal to
connectionLocked: trueon first read (storage §5.2), so the visual-smoke stale-sessions fixture exercises exactly the locked case from the issue.Verification
npm test(all workspaces): 9 suites, 7589 tests, 0 failures — including the 17-case projection matrix, the rewritten 15-case notice suite, and the staged send-gate regression suite (unrelated secret-read failure no longer rejects a healthy send, healthy sends never consult default/list facts, rebind follows persisted order rather than completion order, unreadable candidates are skipped, and a hanging later candidate neither blocks nor gets probed by the rebind walk).npm run typecheck(main + renderer + storybook): clean.biome lint: clean.playwright test): 25/25, including thesession-health-notice.spec.tsjourney on the stale-sessions fixture: locked fake + locked legacy sessions show the notice even with a ready default (the case-1 fix), and the notice click-through lands in Settings · 模型.chat-readiness.test.tssend-gate suite passes against the delegated implementation; the sticky-model, credential-IPC, and notice-freshness source contracts pin the new authority locations and the renderer wiring (projection, staged gate, read-onlyhasConnectionSecretprobe, revision-driven re-probe, transcript-derived effective lock).stale-sessionshas no committed baseline; the notice visibility change is locked by the E2E text assertions instead).Follow-ups
list()could project the same effective lock asreadHeaderself-heals, so the notice never depends on the transcript-derived OR. Deferred:list()is a hot path and the renderer OR already closes the observable window.account-settings-page.tsx) has the same staleness class the notice probe fixed here: its effect keys only on the connection list identity, so an external credential-only edit leaves its status stale until remount. Pre-existing, out of scope for this PR; the natural fix is feeding it the sameconnectionsRevision.