Skip to content

fix: align session health notice with send/rebind authority - #1062

Merged
Astro-Han merged 5 commits into
mainfrom
fix/1038-health-notice-send-authority
Jul 16, 2026
Merged

Astro-Han merged 5 commits into
mainfrom
fix/1038-health-notice-send-authority

Conversation

@Astro-Han

@Astro-Han Astro-Han commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #1038.

After #1032/#1035 the composer-adjacent health notice decided from a renderer-side proxy (defaultConnection exists && enabled) plus lastTestStatus, which disagreed with the authoritative send/rebind path in both directions:

  • Locked sessions (has user messages) hid the notice behind a ready-looking default even though connectionLocked blocks silent rebind and the send will fail.
  • Enabled-but-secretless default hid the notice even though the rebind walk cannot succeed.
  • Deleted session connection showed a destructive notice even when another persisted connection could serve the send.
  • 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:

  • Main send gate (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-running assertSessionCanSend on 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.
  • Renderer notice feeds the projection from the connection list, the default slug, a connections:hasSecret probe, and an effective connectionLocked. The probe uses the read-only hasConnectionSecret (stored-credential presence — observing it never refreshes OAuth tokens; send/test/fetch-models keep the refreshing path) and re-runs on connectionsRevision, which bumps on every successful connection refresh, so credential-only changes (external credentials.json edits that don't bump updatedAt) also re-probe. The effective lock is the summary bit (newly exposed on SessionSummary) 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/rebind stay silent (refactor(desktop): move session health feedback into the conversation flow #1032); blocked maps the reason to destructive copy naming the failing connection and pointing at the right Settings section.
  • lastTestStatus contract (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: true on first read (storage §5.2), so the visual-smoke stale-sessions fixture exercises exactly the locked case from the issue.

Verification

  • Root 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).
  • Desktop npm run typecheck (main + renderer + storybook): clean. biome lint: clean.
  • E2E (playwright test): 25/25, including the session-health-notice.spec.ts journey 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 · 模型.
  • Characterization safety net: the chat-readiness.test.ts send-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-only hasConnectionSecret probe, revision-driven re-probe, transcript-derived effective lock).
  • Two adversarial review rounds (Codex + Claude, independent): all first-round findings fixed and verified closed on re-review; the one surviving re-review finding (rebind walk short-circuit) is fixed in this PR.
  • Not run: screenshot baselines (stale-sessions has no committed baseline; the notice visibility change is locked by the E2E text assertions instead).

Follow-ups

  • Storage list() could project the same effective lock as readHeader self-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.
  • The Settings · 账号 credential probe (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 same connectionsRevision.
  • A runtime token that expires without any connection change can still leave the notice optimistic until the next refresh event — inherent to a TTL-based credential with no change signal; the send gate remains the authoritative check.

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.
@Astro-Han
Astro-Han merged commit c4af61d into main Jul 16, 2026
3 checks passed
@Astro-Han
Astro-Han deleted the fix/1038-health-notice-send-authority branch July 16, 2026 05:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(desktop): align session health notice with send/rebind authority

1 participant