Repository navigation
fix(embed): keep a /embed/chat/:slug deep link on its chat - #21788
Conversation
EmbedTabStrip restored its tabs on mount without looking at the URL, so a page opened on /embed/chat/<key> in a fresh window was sent to /embed/sessions. Whether the page came back to the chat depended on the order of the first activeSlot changes, which made the embed chat e2e spec flaky. The deep-linked slug is now the active tab: an open tab holding it is selected, a Sessions tab becomes it, otherwise it is added. Closes #21449
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Check that the host plugin handles one extra [DESIGN-REVIEWED] 9225887 Description read[DESCRIPTION-READ] 04b7b2ef1ada1d015b5fbc300b6ecd0062c52a66c30ba32cead6307836cebeb1 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 |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS On a deep link, the mount now sends the host plugin a What this change shipsInventory (6 items) — 5 justifiedIntent: an embedded host that opens
[FIRST-PRINCIPLES-REVIEWED] 9225887 Description read[DESCRIPTION-READ] 7ac7209ac47a39be7f5b49f5e5f129fab37e9e35e1c916165a0f391941fc04ad That sha256 names the PR description this verdict read. Recompute it with |
UX Review (Opus 5.5) — ✅ PASSUX-level review of UX-Verdict: PASS Check that a deep-linked chat added to the end of an overflowing tab strip scrolls into view on mount; only new-tab creation calls [UX-REVIEWED] 9225887 Description read[DESCRIPTION-READ] 630a6836579356a293aad824181f51d860a8cd2b8a303ef84ed5b24b65e707d9 That sha256 names everything this verdict read: the PR description, plus the 4 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 |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Tier 1 auto-approve: fix (4 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: an /embed/chat/:slug deep link keeps its chat as the active tab when EmbedTabStrip restores tabs on mount; storage writes made non-fatal; tests added. Spec files changed as a ride-along (a minority of the diff on both file count and changed lines), not reviewed as a design decision: docs/system-specs/modules/learn-cron-dashboard.md.
Problem / Motivation
Goal: A page opened on
/embed/chat/<key>always shows that chat, so the embed chat e2e spec stops failing on a retry.embed-popout.spec.ts > Embed route tree — /embed/* > embed chat renders the chat view for a sessionfailed its first attempt on many unrelated PRs and onmain. The retry ceiling is 0, so each failure turned the E2E job red. In the failed attempt the tab strip is there, but the page shows the Sessions list with no composer.Why it matters
The E2E job is a required check. This one spec turned unrelated PRs red and made
mainred on 2026-10-17. Users see the same bug: an embedded host that opens a chat link in a new window can land on the Sessions list instead of the chat.Not a goal
/embed/settingsstill cannot be reached by URL. The spec's FINDING comment covers that separately, and this PR does not change it.What changed (motivation → approach → change)
page.goto('/embed/chat/<key>?sid=<key>')the page sometimes sits on/embed/sessions.EmbedTabStripbuilds its first tabs from sessionStorage, then tabs the host plugin injects, thenchat.activeSlot. It never reads the URL. In a fresh window all three are empty, so the tab list is one Sessions tab. The mount effect then callsnavigate('/embed/sessions', { replace: true })and drops the deep link. The page only got back to the chat if the[activeSlot]effect sawChatPage's switch to the key as a second change. That effect skips the first change as hydration, so the outcome depended on effect ordering.initialTabs()reads the slug from/embed/chat/:slugonce at mount and makes it the active tab. An open tab holding it is selected, an active Sessions tab becomes it, and otherwise it is added at the end. When a link was present, the mount effect saves the tabs to sessionStorage and the host event, so storage matches what is shown.persist()now writes through the existingsafeSetSessionItemhelper, so storage that is full or denied in a host iframe cannot throw out of the mount effect and crash the embed before it navigates. URLs without a chat slug (/embed/sessions,/embed/chat/,/embed/settings) keep the old restore order.docs/system-specs/modules/learn-cron-dashboard.md(Routing) now says how the embed tab strip treats a deep link.Backwards compatibility
Compatible: only a URL with a chat slug changes behaviour, and it now opens the chat the URL names. Every other embed URL restores tabs exactly as before.
Removes nothing: no tab, key, route or stored field is removed. A deep link only adds or selects a tab.
Tests
website/src/test/EmbedTabStripCoverage.test.tsx, new block "opened on a chat link":/embed/sessions;sessionStorage.setItemthrowingQuotaExceededError, the linked chat still opens, navigates and sends the host event (red ifpersist()goes back to a rawsetItem);/embed/chat/with no slug still restores the tabs (guard, passes on base too).The first four fail on
origin/mainand pass with the fix. Removing the newpersistcall turns three of them red./embed/chat/chat-1by default. That value was arbitrary. They now mount at/embed/sessions, so the existing restore tests still check the restore order they were written for.makeStore({ activeSlot: null })now really gives a null active slot.npx vitest run src/test/EmbedTabStripCoverage.test.tsx src/test/EmbedComponents.test.tsx src/test/EmbedTabStrip.scrollEdges.test.tsx: 69 passed.tsc -p tsconfig.app.jsonand eslint on the changed files are clean.Manual verification
Repeat runs against the same harness gateway CI uses (
spawn_feature_gateway(fixture="minimal")plus the fake ACP backend), Chromium,--retries 0 --workers 1, frontend built from each tree:origin/mainembed-popout.spec.tsThe page snapshot of the failed base run shows
tab "Sessions" [selected]and the Sessions region, which is the mechanism above. This Linux host resolveslocalhostto::1only, so the local runs pinnedlocalhostto127.0.0.1in Chromium and Node so the gateway's IP-pinned session matched. That setup is local only and is not part of the diff. Windows and macOS were not run; the change is platform-neutral routing code.Screenshots / video
After:
/embed/chat/<key>opened in a fresh window shows the chat as the active tab with its composer.Before: in the failing case the same URL showed the Sessions list (from the base run's page snapshot):
Related Issues
Closes #21449
Pattern harvest
Rule candidate: review-prompt
Pattern: a component that restores state on mount and then calls
navigate(..., { replace: true })must read the current route first, or it silently drops the deep link it was opened with.Decision for the owner
The decision is whether an
/embed/chat/:slugURL should win over the restored embed tabs on mount. This draft makes the linked chat the active tab, so the spec and real deep links are deterministic. The alternative was to wait in the spec for the chat to win the race, which would hide a real user bug.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.