Skip to content

fix(chat): bound deep-link recovery to its restore window - #19296

Merged
iamwhatever merged 1 commit into
mainfrom
fix/12026-sid-recovery-window
Oct 12, 2026
Merged

iamwhatever merged 1 commit into
mainfrom
fix/12026-sid-recovery-window

Conversation

@iamwhatever

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Bound automatic denied deep-link recovery to the intended restore window.

A denied /chat?sid=<key> recovery record can remain armed indefinitely. A much later slots or reconnect frame can then navigate away from the session the user is reading or composing in.

Replaces #12026 by @leonlaiyc, carried to a main-repo branch so CI can run with full permissions. The original commit is cherry-picked unchanged with Leon's authorship preserved, plus a Co-authored-by: trailer. Thank you, @leonlaiyc.

Why it matters

A late slots frame can interrupt the session a user is reading or composing in.

Not a goal

  • No general routing redesign.
  • No new navigation UI.
  • No change to explicit session switching.

What changed (motivation → approach → change)

The denial is timestamped in the session controller (deniedAt). Automatic activation is allowed only within 30 seconds of that denial (SID_RECOVERY_WINDOW_MS). An expired matching frame still clears the false not-found banner, but leaves the active session alone. The away-and-back latch and explicit navigation stay intact. Reconnect does not renew the timestamp. The owning dashboard spec records the bound.

Backwards compatibility

Compatible: explicit switching and recovery inside the window still work. Automatic recovery after expiry is intentionally narrowed.

Reader: website/src/pages/chat/useChatPageSessionController.ts:deniedSidRef -- entry: chat -- expired frames clear the stale notice; explicit switchSlot is unaffected and fake-time tests cover both paths.

Tests

  • website/src/test/ChatPage.sid.test.tsx: fake-time tests cover recovery inside the window, notice-only clearing after expiry, reconnect without renewal, and explicit switching after expiry. The expired and reconnect regressions fail on main and pass on this head.
  • Code lanes were green on the fork head; this branch's CI supplies the full matrix.

Manual verification

N/A — fake-time component tests deterministically reproduce the delayed slots-frame behaviour.

Screenshots / video

Why no screenshot: This changes the timing of an existing navigation path without changing layout, components, styling or copy.

Related Issues

Fixes #16504

Replaces #12026

Provenance: Design review on #11870.

Pattern harvest

Rule candidate: review-prompt
Pattern: A retained recovery latch needs a bounded temporal predicate; test a matching frame after expiry and after reconnect.

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.

@iamwhatever
iamwhatever requested review from a team and KiroCrewCaptain as code owners October 12, 2026 06:20
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 12, 2026
@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of c357f54b709ece38a7a43e0ef8fef9d20dca0063 — 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

Check that 30s really covers a slow gateway restart. The only support is the comment's claim that restores "settle on the same seconds scale"; nothing measured it.

Not justified as shipped

  • Item 4 — undeclared: the diff adds a stray blank line before ### UI Pages in learn-cron-dashboard.md. It has nothing to do with the fix.

What this change ships

Inventory (4 items) — 3 justified

Intent: when a denied ?sid= link resolves much later, it should no longer pull the user out of the session they are in. FIX (Fixes #16504).

  1. If the session arrives more than 30s after the "not found" banner, the banner clears but the user stays where they are — justified
  2. A reconnect no longer restarts the 30s window, so a late re-delivered list cannot move the user — justified
  3. The dashboard spec now states the 30s bound and that reconnect does not renew it — justified
  4. A blank line is added to the dashboard spec — undeclared

[FIRST-PRINCIPLES-REVIEWED] c357f54

Description read

[DESCRIPTION-READ] 1f332154dfe4acaa03d6dac8e0ba81dacc9eb5d4e7775f509e536ccd8c29cd8b

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

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Check that 30s covers a slow gateway restart with a large restore; if not, a real deep link stops auto-activating and the user has to click it in the sidebar.

[DESIGN-REVIEWED] c357f54

Description read

[DESCRIPTION-READ] 2b761d92f1e2775440ffa39bccfd35c10238227a9615fdd3d4523af5b5ec91d7

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

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS

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

UX-Verdict: PASS

Check what the user sees after expiry: a deep link that resolves more than 35s after opening clears the "not found" banner and leaves them on another session, with no pointer to the one that arrived.

[UX-REVIEWED] c357f54

Description read

[DESCRIPTION-READ] 735d38ff5166ab61ff32469d7f512bb9d6a2b6dae2f70d4b7efee04077ef12f1

That sha256 names everything this verdict read: the PR description, plus the 3 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 12, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] c357f54

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

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

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] c357f54

False positive or not applicable? A repository writer can comment:
/ai-review override gpt c357f54b709ece38a7a43e0ef8fef9d20dca0063: <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 12, 2026
Expire automatic recovery after thirty seconds while still clearing a
disproved not-found notice. Reconnect does not renew the recovery latch.

Co-authored-by: Leon <276034861+leonlaiyc@users.noreply.github.com>
@iamwhatever
iamwhatever force-pushed the fix/12026-sid-recovery-window branch from 1f987bd to c357f54 Compare October 12, 2026 08:04
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 12, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Self-review (crew-pr-reviewer, read-only): RECOMMEND APPROVE

This PR stops a denied /chat?sid= recovery from staying armed forever. The record is stamped with deniedAt, and auto-activation happens only within 30 s (SID_RECOVERY_WINDOW_MS). After that, a matching slots frame only clears the false not-found banner. That fixes the root cause: a record with no expiry plus reconnects that re-deliver the full list. The explicit-switch path and the away-and-back latch are unchanged. The three fake-timer tests in website/src/test/ChatPage.sid.test.tsx cover expiry, the in-window control and no renewal on reconnect. The expiry and reconnect cases fail on base, since base has no expiry check. All lanes PASS on c357f54, checks are green, and there are no change requests. Nits: drop the stray blank line added before ### UI Pages in docs/system-specs/modules/learn-cron-dashboard.md, and answer the PASS punchlines asking whether 30 s covers a slow gateway restore. — crew-pr-reviewer

@iamwhatever
iamwhatever enabled auto-merge (squash) October 12, 2026 15:48

@buluoray buluoray 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.

LGTM. I checked this at head c357f54.

What it fixes: a /chat?sid=<key> link that was denied ("session not found") stayed armed forever, so a slots or reconnect frame minutes later could pull the person away from the session they were reading or typing in.

Checked:

  • The bound fails closed: useChatPageSessionController.ts:733 checks Date.now() - denied.deniedAt > SID_RECOVERY_WINDOW_MS (30s) before the "active slot unchanged" branch, clears only its own stale banner, and never calls switchSlot. The record is cleared first (:727), so it is used at most once.
  • A key that arrives inside the window still lands; that path is unchanged.
  • Reconnect does not renew the window: deniedAt is written only in the 5s deadline callback, which nulls initialSidRef and so cannot re-stamp.
  • No new timer; the check is a timestamp comparison. The tests fake timers, which fakes Date in vitest.
  • learn-cron-dashboard.md names the 30s bound and "reconnect does not renew".

Mutations: making the expiry check always false reddens "only clears the banner when the key arrives long after the restore window" and "does not renew recovery on reconnect and still permits an explicit switch"; a window of 0 reddens "still resolves the link when the key arrives inside the restore window"; re-stamping deniedAt on every effect re-run reddens the reconnect test. ChatPage.sid.test.tsx: 67/67. CI at this head: 0 failed.

Non-blocking: Date.now() is wall-clock, so a clock moved backwards stretches the window; performance.now() would remove that case. The spec diff adds a stray blank line before ### UI Pages.

@iamwhatever
iamwhatever merged commit cc78564 into main Oct 12, 2026
102 checks passed
@iamwhatever
iamwhatever deleted the fix/12026-sid-recovery-window branch October 12, 2026 16:14
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 12, 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.

chat: denied deep-link recovery remains armed after the restore window

3 participants