Skip to content

fix(dashboard): hide ask-the-agent while the gateway is unreachable - #20223

Merged
iamwhatever merged 2 commits into
mainfrom
replace/10680
Oct 14, 2026
Merged

iamwhatever merged 2 commits into
mainfrom
replace/10680

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Replaces #10680 by @rubencu — thank you for the fix and its design. This re-ports it onto main's hooks/websocket/* split (#15082); the fix commit keeps @rubencu as author.

Problem / Motivation

Goal: "Ask the agent" is not offered while the gateway is unreachable, and comes back when it reconnects.

While the gateway is down, every error surface still shows Ask the agent (banner links and the menu-item form in kebab/dropdown menus). The agent runs on the gateway, so the hand-off lands in a composer that cannot send ("gateway offline — message will not send"). The error on screen then is usually the connectivity failure itself.

Why it matters

Every user who sees an error during a gateway outage or restart is offered an action that cannot work. A dead call to action next to "Failed to fetch" reads as one more broken thing.

Not a goal

  • Changing the hand-off's label or copy.
  • Adding a new offline hint or reconnect line in place of the hidden link (the existing "gateway offline" indicators stay the place that says so).
  • Changing how the store's connected flag is computed (sseStatus keeps its own write).

What changed (motivation → approach → change)

  • Symptom: AskAgentButton (components/AskAgentButton.tsx) and ErrorNoticeMenuItem (components/ErrorNotice.tsx) only checked for a message/report, never connectivity.
  • Approach: the button must mount outside the store Provider (ErrorBoundary fallbacks), so it cannot read dashboardSlice.connected. The flag is mirrored into a context-free seam in utils/errorReport.ts (setGatewayConnected / isGatewayConnected / subscribeGatewayConnected, default connected), the same shape as the existing installSoftNavigate seam. Both components subscribe via useSyncExternalStore and return null while disconnected; error text and dismiss stay.
  • New owner hooks/websocket/gatewayConnectivity.ts holds markGatewayConnected / markGatewayDisconnected, which move the store flag and the seam together. They replace the raw dispatches in connection.ts (handleClose) and reconnectCatchUp.ts (first connect + reconnect). useWebSocket.ownership.test.ts lists the new owner and its two edges.
  • Re-port vs fix(dashboard): hide the ask-the-agent hand-off while the gateway is unreachable #10680: same design; only the call sites moved, since refactor(website): split useWebSocket into hooks/websocket owners #15082 split useWebSocket.ts.
  • website/scripts/capture-20215-ask-agent-offline.mjs: screenshot harness for the banner scenes below.

Backwards compatibility

Compatible: no API, store shape or prop changes; the seam defaults to connected, so surfaces that never mount the socket behave as before.

Reader: website/src/components/AskAgentButton.tsx:AskAgentButton -- chat|crew page|app -- hidden only while the socket is down; errorToAgent.test.tsx "hides the button while the gateway is unreachable and restores it on reconnect"
Reader: website/src/components/ErrorNotice.tsx:ErrorNoticeMenuItem -- chat|crew page -- same gate; errorToAgent.test.tsx "the menu-item hand-off hides while disconnected too"
Reader: website/src/components/ErrorBoundary.tsx (fallback hand-off) -- release -- no socket mounted, seam stays connected; errorToAgent.test.tsx "defaults to connected"

Tests

  • test/errorToAgent.test.tsx: button, ErrorNotice and menu item hidden while offline, visible when online, restored on reconnect; defaults to connected.
  • hooks/websocket/gatewayConnectivity.test.tsx: the helpers dispatch the store action and flip the rendered button.
  • test/gatewayConnectedPairing.test.ts: no raw sseConnected/sseDisconnected dispatch outside the helpers.
  • All fail on base (the seam does not exist there).

Manual verification

  • Local: full frontend vitest (2929 files) pass, npm run typecheck clean, eslint clean on touched files.
  • Screenshots below from the built SPA and the isolated kebab-menu capture entry.

Screenshots / video

Banner: built SPA, POST /api/channels fails at the network layer; the /api/ws stub closes (offline) or stays open (online). Harness: website/scripts/capture-20215-ask-agent-offline.mjs.

Banner Offline Online
Before (main) before offline before online
After after offline after online

Menu item: the session kebab menu (capture/mute-sessions-kebab-item.html?scene=error, real SessionActionsMenu + ErrorNoticeMenuItem), offline set through the seam. On main there is no offline state for the item, so it always shows.

Kebab menu Offline Online
Before (main) before menu offline before menu online
After after menu offline after menu online

Related Issues

Fixes #20215
Replaces #10680

Pattern harvest

Not generalizable: a one-off gap in one hand-off control; the seam plus the pairing test already stop the store flag and the mirror drifting.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 377096d8fea778c04c0a18c8d3d4d4425eb9c192 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 377096d

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 377096d8fea778c04c0a18c8d3d4d4425eb9c192: <one-sentence reason>

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS

UX-level review of 377096d8fea778c04c0a18c8d3d4d4425eb9c192 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

UX-Verdict: PASS

Check that "Ask the agent" doesn't flicker out from under the cursor during short socket reconnects, since the link now unmounts on every handleClose.

[UX-REVIEWED] 377096d

Description read

[DESCRIPTION-READ] 0c22872df427bb2ae764d57ea67f15ee1e62a6626c5aa5006606164d4a01866d

That sha256 names everything this verdict read: the PR description, plus the 11 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 377096d8fea778c04c0a18c8d3d4d4425eb9c192 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 377096d

Verdict parsed from the review's SHA-scoped output markers for commit 377096d8fea778c04c0a18c8d3d4d4425eb9c192.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 377096d8fea778c04c0a18c8d3d4d4425eb9c192: <one-sentence reason>

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 14, 2026
@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — 🟡 CONCERNS

Premise-level review of 377096d8fea778c04c0a18c8d3d4d4425eb9c192 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: CONCERNS

The new connectivity mirror is a second copy of dashboardSlice.connected, and the store singleton can already be read without a Provider.

Not justified as shipped

  • Item 3 — duplicate of website/src/store/index.ts:store (dashboard.connected): the mirror exists because the button "cannot read dashboardSlice.connected" outside the Provider. A direct module import needs no Provider, though, and 2 components already do it this way: components/SessionColorSwatches.tsx:59 calls store.getState().dashboard... and components/MarkdownPanel.tsx:28 does the same. The mirror also introduces a split that the PR itself pins: "sseStatus sets the store flag on its own, leaving the seam apart".
    Subtraction: delete setGatewayConnected/isGatewayConnected/subscribeGatewayConnected/__resetGatewayConnectedForTests in utils/errorReport.ts, hooks/websocket/gatewayConnectivity.ts, test/gatewayConnectedPairing.test.ts and the two useWebSocket.ownership.test.ts edges. Both components then read useSyncExternalStore(store.subscribe, () => store.getState().dashboard.connected).
    Clears when: the mirror is removed, or the description names a boundary case where importing the store module fails while the seam still works.
Inventory (5 items) — 2 justified

Intent: stop offering "Ask the agent" while the gateway is unreachable. FIX.

  1. Banner/inline "Ask the agent" button hidden while offline, back on reconnect — justified
  2. Kebab/dropdown "Ask the agent" menu item hidden while offline — justified
  3. New context-free connectivity flag in errorReport plus paired markGateway* helpers replacing raw dispatches — duplicate of store dashboard.connected
  4. Source-scan test banning raw sseConnected/sseDisconnected dispatches — rides along; exists only to guard item 3's split
  5. Screenshot harness capture-20215-ask-agent-offline.mjs — rides along; follows the existing 7 issue-numbered capture-NNNN scripts

[FIRST-PRINCIPLES-REVIEWED] 377096d

Description read

[DESCRIPTION-READ] 441067096039307623b702ce5048e25d6b89dd060bfb4d6a659d394d4e3bc23f

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 377096d8fea778c04c0a18c8d3d4d4425eb9c192 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Nothing to check.

Suggestions

  • Drop the mirror: AskAgentButton can call useSyncExternalStore(store.subscribe, () => store.getState().dashboard.connected) against the module singleton (reconnectCatchUp.ts already imports it). That needs no <Provider>, so the seam, the pairing test and the documented sseStatus divergence all go away.

[DESIGN-REVIEWED] 377096d

Description read

[DESCRIPTION-READ] f46f76f5bce05beb72767e913fb019cd138cbf928b0c70a3e637fc6f44deec37

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 14, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Closing and reopening to re-run CI against current main (picks up #20212, which fixes main's own ChatEmbed.optimisticSend failure).

@iamwhatever iamwhatever reopened this Oct 14, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Closing and reopening once more: the previous reopen still ran CI on the old merge base (e93ecd0); the merge ref is now current.

@iamwhatever iamwhatever reopened this Oct 14, 2026
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 14, 2026
@iamwhatever
iamwhatever marked this pull request as ready for review October 14, 2026 14:51
@iamwhatever
iamwhatever requested review from a team and KiroCrewCaptain as code owners October 14, 2026 14:51
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 14, 2026

@cruisercohen cruisercohen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of b083b88497aee53c9dd0ebc2d7bac1548db14b6f (merge base e4270cfcec).

The fix is right. Both hand-off surfaces named in #20215 now hide while the socket is down and come back on reconnect, and the error text and dismiss button stay. I put the two components and the two socket call sites back to the merge base and kept the new tests: 5 of the 6 new tests fail (the three gate tests in errorToAgent.test.tsx, gatewayConnectivity.test.tsx, and the pairing test). On this head, all 70 tests in the four touched test files pass. All checks are green on this head (87 pass, 0 fail).

Changes requested. Both are comment fixes; neither changes behaviour.

  1. website/src/components/AskAgentButton.tsx:37: "even though the component is no longer hook-free" narrates history. The comment rule in docs/system-specs/common/code-style.md ("Comments explain the WHY") bans "no longer" in every comment. Comments under website/ are held to that rule by review, because the script gate scans only Python. Suggested present-tense wording: "(useSyncExternalStore needs no context, so the hook keeps that constraint.)"

  2. website/src/utils/errorReport.ts:751-754 (and the same claim at line 739): the docstring says the writers are in useWebSocket and keep the mirror and the store flag together "so the two cannot drift". Both parts are wrong:

    • The writers are in hooks/websocket/gatewayConnectivity.ts.
    • sseStatus (website/src/store/dashboardSlice.ts:898) sets connected = true on its own.

    I ran a probe on this head: markGatewayDisconnected(store.dispatch) followed by store.dispatch(sseStatus({})) leaves store.getState().dashboard.connected === true while isGatewayConnected() === false. The boot api.status() call in App.tsx dispatches sseStatus. So if the socket closes before a successful status reply lands, the two flags disagree until the socket next opens or closes. Two ways to fix it:

    • Reword the docstring to say what the helpers guarantee, and note that sseStatus writes the store flag by itself.
    • Or extend the pairing test to cover sseStatus too.

Not blocking: whether to keep the mirror or read the store singleton through useSyncExternalStore(store.subscribe, ...) is a design call. The fail-open default before the first connect is a fair reason to keep the mirror.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: passed Eligible automated validation passed for the current revision labels Oct 14, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

@cruisercohen thanks, both fixed in 434474a (comments and one test case, no behaviour change):

  1. AskAgentButton.tsx: dropped "no longer"; it now reads "(useSyncExternalStore needs no context, so the hook keeps that constraint.)"
  2. errorReport.ts: the section comment and the setGatewayConnected docstring now name the helpers in hooks/websocket/gatewayConnectivity.ts as the writers, say what they guarantee (each dispatches the store action and sets the seam in one call), and note that sseStatus sets connected = true on its own, so the two flags can differ. The "cannot drift" claim is gone. gatewayConnectedPairing.test.ts gains a case pinning this: markGatewayDisconnected then sseStatus leaves the store at true and the seam at false.

Could you re-review when you have a moment?

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 14, 2026

@cruisercohen cruisercohen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review of 434474ad3cb047a5aac4a1f3e230c4ef1a656359. Thanks for the quick turn.

Both earlier points are fixed:

  • AskAgentButton.tsx: the added comment now reads in present tense.
  • errorReport.ts: the section comment and the setGatewayConnected docstring name hooks/websocket/gatewayConnectivity.ts as the writer and say the two flags can differ through sseStatus, and the new pairing case pins that.

Two things on this head still need a change:

  1. website/src/test/gatewayConnectedPairing.test.ts:23 imports markGatewayDisconnected directly from ../hooks/websocket/gatewayConnectivity. That breaks the existing invariant in website/src/test/useWebSocket.ownership.test.ts:178 ("outside the owner directory, only the facade imports an owner"):

    cd website && npx vitest run src/test/useWebSocket.ownership.test.ts
    × one public surface > outside the owner directory, only the facade imports an owner
      - []
      + [ "src/test/gatewayConnectedPairing.test.ts" ]
    

    With the pairing test as it was at b083b88497 the same run passes 9/9. Frontend Tests are still running on this head, so CI has not reported it yet. The facade does not export the helper, so the smallest fix may be to move this one case into hooks/websocket/gatewayConnectivity.test.tsx, inside the owner directory where the import is allowed, and leave the source-level scan where it is.

  2. PR Hygiene fails: "PR must contain 1 or 2 commits (has 3)". Folding the comment commit into one of the two earlier ones clears it.

The first two commits are identical to the head I reviewed before (range-diff), so the fix itself still stands. Happy to approve once these two are addressed and the checks are green.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

Note: PR Hygiene caps this PR at 2 commits, so the fix above is now folded into d7631ea (head 67987b7). Same tree as 434474a.

rubencu and others added 2 commits October 14, 2026 16:11
…unreachable

While the gateway is down, "Ask the agent" hands the error to a chat
composer that cannot send, and the error on screen is usually the
connectivity failure itself. Hide the hand-off (AskAgentButton and
ErrorNoticeMenuItem) while disconnected; it returns on reconnect.

The button must mount outside the store Provider (ErrorBoundary
fallbacks), so the store's connected flag is mirrored into a
context-free seam in utils/errorReport. The socket layer moves both
through markGatewayConnected/markGatewayDisconnected in
hooks/websocket/gatewayConnectivity.ts, called from connection.ts
(handleClose) and reconnectCatchUp.ts (first connect and reconnect).
A source-level test pins that no raw sseConnected/sseDisconnected
dispatch exists outside those helpers.

Re-ported from #10680 onto the hooks/websocket split from #15082.

Fixes #20215

Co-authored-by: Ruben Cuevas <rubencu@amazon.com>
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Update: the sseStatus case could not live in src/test/gatewayConnectedPairing.test.ts, because useWebSocket.ownership.test.ts forbids importing hooks/websocket/* from outside that directory. It now sits in the co-located hooks/websocket/gatewayConnectivity.test.tsx (markGatewayDisconnected, then sseStatus: store true, seam false), and the pairing test's header points to it. Head is now 377096d, folded into 006ee9f.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 14, 2026

@mbriones98 mbriones98 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checks green and readiness passed at 377096d; no behavior change.

@cruisercohen cruisercohen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review of 377096d8fea778c04c0a18c8d3d4d4425eb9c192 (2 commits on e4270cfcec).

Both points from the last round are fixed:

  • The sseStatus case now lives in hooks/websocket/gatewayConnectivity.test.tsx, inside the owner directory, so useWebSocket.ownership.test.ts passes. The pairing test keeps the source-level check, and its header points to the runtime case.
  • The PR has 2 commits and PR Hygiene passes.

Checked locally on this head: gatewayConnectivity.test.tsx, gatewayConnectedPairing.test.ts, errorToAgent.test.tsx and useWebSocket.ownership.test.ts pass 71/71 on three runs. The whole hooks/websocket/ directory plus those files pass 84/84 in shuffled order. The fix itself is unchanged since the first round, where putting the components and socket call sites back to the merge base made 5 of the 6 new tests fail. Every check from this head's push is green, including PR Readiness, and there are no code-scanning alerts.

Approving. This replaces my earlier change request.

@iamwhatever
iamwhatever merged commit ccbb8ca into main Oct 14, 2026
102 of 103 checks passed
@iamwhatever
iamwhatever deleted the replace/10680 branch October 14, 2026 23:38
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 14, 2026
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.

Ask the agent offered while the gateway is offline, where it cannot work

5 participants