Skip to content

fix(embed): keep a /embed/chat/:slug deep link on its chat - #21788

Merged
buluoray merged 2 commits into
mainfrom
fix/embed-deeplink-tab-21449
Oct 18, 2026
Merged

buluoray merged 2 commits into
mainfrom
fix/embed-deeplink-tab-21449

Conversation

@buluoray

@buluoray buluoray commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

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 session failed its first attempt on many unrelated PRs and on main. 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 main red 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/settings still cannot be reached by URL. The spec's FINDING comment covers that separately, and this PR does not change it.
  • No change to the spec, its timeouts or the retry ceiling.

What changed (motivation → approach → change)

  • Symptom: after page.goto('/embed/chat/<key>?sid=<key>') the page sometimes sits on /embed/sessions.
  • Root cause: EmbedTabStrip builds its first tabs from sessionStorage, then tabs the host plugin injects, then chat.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 calls navigate('/embed/sessions', { replace: true }) and drops the deep link. The page only got back to the chat if the [activeSlot] effect saw ChatPage's switch to the key as a second change. That effect skips the first change as hydration, so the outcome depended on effect ordering.
  • Change: a new initialTabs() reads the slug from /embed/chat/:slug once 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 existing safeSetSessionItem helper, 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.
  • Owning spec 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":
    • a fresh window stays on the linked chat and never navigates to /embed/sessions;
    • a restored tab that already holds the chat is selected;
    • an active Sessions tab becomes the linked chat;
    • the linked chat is added as the active tab when no restored tab can take it;
    • host-injected tabs keep their order and get no duplicate when the link names one of them;
    • with every sessionStorage.setItem throwing QuotaExceededError, the linked chat still opens, navigates and sends the host event (red if persist() goes back to a raw setItem);
    • /embed/chat/ with no slug still restores the tabs (guard, passes on base too).
      The first four fail on origin/main and pass with the fix. Removing the new persist call turns three of them red.
  • The two test wrappers used to mount at /embed/chat/chat-1 by 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.json and 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:

Tree Runs of the spec Failed
origin/main 50 1 (at line 154, Sessions tab selected)
this branch 50 + 150 0
this branch, whole embed-popout.spec.ts 3 × 14 tests 0

The page snapshot of the failed base run shows tab "Sessions" [selected] and the Sessions region, which is the mechanism above. This Linux host resolves localhost to ::1 only, so the local runs pinned localhost to 127.0.0.1 in 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.

embed chat deep link after the fix

Before: in the failing case the same URL showed the Sessions list (from the base run's page snapshot):

- tab "Sessions Close tab" [selected]
- button "New tab"
- region "Sessions"

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/:slug URL 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

  • 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.

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
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 18, 2026
@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Check that the host plugin handles one extra kirocrew-tab-update on mount when a deep link adds or replaces a restored tab.

[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 .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 18, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 9225887f3df5cd140173ece587d3f0b9266397c9 — 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: PASS

On a deep link, the mount now sends the host plugin a kirocrew-tab-update event before any user action. Check that the host plugin handles an event that early.

What this change ships

Inventory (6 items) — 5 justified

Intent: an embedded host that opens /embed/chat/<key> should always land on that chat, not on the Sessions list (#21449, flaky required E2E). This is a FIX.

  1. A page opened on /embed/chat/<key> selects the chat as the active tab when an open tab already holds it — justified
  2. When the restored active tab is Sessions, the linked chat takes its place — justified
  3. When no tab can take it, the linked chat is added at the end as the active tab — justified
  4. On a deep link, the mount now writes the shown tabs to sessionStorage and sends the host event — justified
  5. Tab persistence no longer throws when storage is full or denied: it uses the existing safeSetSessionItem — justified
  6. Frozen history-member inventory gains _dir_write_epoch(s) and warm_search — undeclared; the base already has these exact lines from test(history): list the members #21108 added in the frozen inventory #21792, so this is a stale-base artifact

[FIRST-PRINCIPLES-REVIEWED] 9225887

Description read

[DESCRIPTION-READ] 7ac7209ac47a39be7f5b49f5e5f129fab37e9e35e1c916165a0f391941fc04ad

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 18, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS

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

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 scrollIntoView.

[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 .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 18, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 9225887f3df5cd140173ece587d3f0b9266397c9 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 9225887

Verdict parsed from the review's SHA-scoped output markers for commit 9225887f3df5cd140173ece587d3f0b9266397c9.

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

@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 9225887f3df5cd140173ece587d3f0b9266397c9 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 9225887

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

@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 18, 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 18, 2026
@buluoray
buluoray marked this pull request as ready for review October 18, 2026 08:39
@buluoray
buluoray requested review from a team and KiroCrewCaptain as code owners October 18, 2026 08:39
@buluoray
buluoray requested a review from CrysisDeu October 18, 2026 08:39
@buluoray
buluoray enabled auto-merge (squash) October 18, 2026 08:39
@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 18, 2026

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

@buluoray
buluoray merged commit 6e834d3 into main Oct 18, 2026
107 checks passed
@buluoray
buluoray deleted the fix/embed-deeplink-tab-21449 branch October 18, 2026 09:28
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 18, 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.

Flaky: embed-popout.spec.ts embed chat renders the chat view for a session

2 participants