Skip to content

fix(web-shell): preserve authentication fragment on offline retry - #13176

Merged
wenshao merged 1 commit into
QwenLM:mainfrom
jabrailkhalil:fix/web-shell-offline-retry-fragment
Oct 2, 2026
Merged

wenshao merged 1 commit into
QwenLM:mainfrom
jabrailkhalil:fix/web-shell-offline-retry-fragment

Conversation

@jabrailkhalil

Copy link
Copy Markdown
Contributor

What this PR does

Retry on the offline Web Shell page reloads the current document and cancels the empty-link navigation. This preserves the complete address, including an existing authentication fragment, while keeping the fragment out of the worker response and network requests.

Why it's needed

After the worker displays its real 503 fallback, the previous Retry link drops the authentication fragment when the daemon becomes available again. This is the small Web Shell follow-up described in F3 on the merged Android profile PR.

Reviewer Test Plan

How to verify

Open a Web Shell address with query parameters and an authentication fragment, wait for worker control, stop the daemon and reload until the bilingual 503 page appears. Restore the daemon and click Try again. The recovered address should exactly match the original, including the fragment. Repeat with an encoded fragment on a nested path and with no fragment. The fallback HTML and server requests should contain no fragment token.

Evidence (Before & After)

I reproduced and verified the actual worker in Chromium 151 using a minimal loopback online-page fixture. Before the change, both ordinary and encoded fragments disappeared after Retry; after the change, all three recovered addresses exactly matched their originals. Path and query parameters remained intact, the real 503 fallback was used, and synthetic tokens appeared in neither server URLs nor fallback HTML.

All 21 service-worker tests pass. With the same permanent tests and the original worker, the 20 existing cases pass and the new regression fails; only replacing the worker with the fix makes all 21 pass. The new regression test parses the actual fallback HTML and executes its retry handler, requiring one reload and cancellation of link navigation. ESLint, Prettier, JavaScript syntax checking, focused TypeScript checking of the test, and whitespace checking pass.

Tested on

OS Status
macOS Not tested locally
Windows Node 22.21.1, Vitest 3.2.7 and Chromium 151: focused tests and browser scenarios passed
Linux Upstream CI required

Environment

Relevant dependencies in an isolated unit-test runtime. The browser harness used the exact product worker with synthetic fragments and a minimal local server. The global CLI is unavailable. Full daemon authentication, the React application and Android WebView were not exercised.

Risk & Scope

  • One retry-control change and one regression test; network/cache policies, the 503 status and both language labels remain unchanged.
  • The full workspace build could not start because the minimal runtime lacks cross-env; the Web Shell type check failed on missing workspace SDK and application dependencies. Complete build/type checking remains for upstream CI.
  • No dependency, configuration or migration changes.

Linked Issues

Follow-up to #12121; refs #11704. This addresses only the reported Retry fragment loss.

中文说明

本 PR 的改动

离线 Web Shell 页面的重试操作会重新加载当前文档,并取消空链接导航。这样保留完整地址及已有认证片段,同时不将片段写入 worker 响应或网络请求。

为什么需要

worker 显示真实的 503 回退页面后,守护进程恢复可用时,之前的重试链接会丢失认证片段。这是已合并 Android 配置 PR 的 F3 所描述的小范围 Web Shell 后续修复。

评审测试计划

如何验证

打开包含查询参数和认证片段的 Web Shell 地址,等待 worker 控制页面,停止守护进程并重新加载,直到双语 503 页面出现。恢复守护进程后点击重试。恢复后的地址应与原始地址完全一致,包括片段。对嵌套路径中的编码片段和无片段地址重复验证。回退 HTML 和服务器请求均不应包含片段 token。

证据(修改前后)

我在 Chromium 151 中使用最小回环在线页面夹具,对实际 worker 进行了复现和验证。修改前,普通片段和编码片段均在重试后丢失;修改后,三个恢复地址都与原始地址完全一致。路径和查询参数保持不变,测试使用真实的 503 回退页面,合成 token 未出现在服务器 URL 或回退 HTML 中。

全部 21 个 service-worker 测试通过。使用相同的永久测试和原始 worker 时,20 个现有用例通过,新增回归用例失败;仅替换为修复后的 worker,全部 21 个用例才通过。新增回归测试解析实际回退 HTML 并执行重试处理程序,要求重新加载一次并取消链接导航。ESLint、Prettier、JavaScript 语法检查、针对测试的 TypeScript 检查和空白检查通过。

测试平台

平台 状态
macOS 本地未测试
Windows Node 22.21.1、Vitest 3.2.7 和 Chromium 151:聚焦测试和浏览器场景通过
Linux 需要上游 CI

环境

使用安装相关依赖的独立单元测试环境。浏览器测试使用实际产品 worker、合成片段和最小本地服务器。本地无全局 CLI。未执行完整守护进程认证、React 应用或 Android WebView 流程。

风险与范围

  • 仅修改重试控件并增加一个回归测试;网络和缓存策略、503 状态及双语标签保持不变。
  • 精简环境缺少 cross-env,完整工作区构建无法启动;Web Shell 类型检查因缺少工作区 SDK 和应用依赖而失败。完整构建和类型检查仍需上游 CI。
  • 无依赖、配置或迁移改动。

关联 Issue

#12121 的后续修复;关联 #11704。本 PR 仅处理已报告的重试片段丢失。

@jabrailkhalil

Copy link
Copy Markdown
Contributor Author

I reproduced and verified this with the actual service worker and a real Retry click in Chromium 151 on Windows.

Scenario Original worker Fixed worker
Query + ordinary authentication fragment Fragment dropped Complete original URL retained
Nested path + query + encoded fragment Fragment dropped Complete original URL retained
Query without a fragment Recovered normally Recovered normally

Each scenario exercised the real HTTP 503 fallback before restoring the local server. Synthetic fragment tokens appeared in neither server request URLs nor fallback HTML.

The same permanent unit tests give 20 passed / 1 failed against the original worker and 21 passed against the fix; the sole failing baseline case is the new Retry regression. The normal package-config focused run also passes all 21 cases. Lint, formatting, JavaScript syntax, focused test TypeScript checking and whitespace checks pass.

Scope: a minimal loopback online-page fixture with the product worker, Node 22.21.1 and Playwright 1.52.0. This does not exercise a full daemon authentication handshake, the React application or Android WebView. The global CLI is unavailable, and the complete workspace build/type check remains for CI because the isolated runtime lacks the full workspace dependencies.

@wenshao

wenshao commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

Verdict: merge-ready — 110/110 scripted assertions passed, 0 failed. Verified head ae3ce95b52a134f41159c554bc927c7ad0f1147e against its exact parent base a7deb01bcbd5a5c795bfccbf2bd0b4e445286b92 (confirmed git rev-parse ae3ce95^ == base, so the A/B diff is exactly this PR's 2 files, +23/-1).

中文摘要

结论:merge-ready(可合并)——110/110 条脚本断言全部通过。

  • A/B 核心结论:在真实 Chrome 154 + 真实 service worker + 真实回环服务器下,base 臂点击 503 回退页的「Try again」后地址栏丢失认证片段(/session/123?workspace=review#auth-token-PLAIN → 无片段),head 臂三个场景(普通片段、嵌套路径+编码片段、无片段)恢复后的地址与原始地址逐字节一致。修复前后的行为差异与 PR 声称完全一致。
  • 回归测试承重证明:把 PR 新增的测试文件叠加到 base 树运行,20 个既有测试通过、新增回归测试按预期红在 expect(handler).not.toBeNull()(base 的 <a href=""> 没有 onclick);head 树 21/21 全绿。该测试确实是承重的。
  • 全套件归因:web-shell 全量套件(4602 测试)两臂顺序重跑,失败集合经 junit 逐项对比完全一致(headOnly=0, baseOnly=0)——PR 未引入任何新失败;273 个失败为 scratch 环境固有(jsdom localStorage 等),与 PR 无关。
  • 类型检查:两臂均通过(需先构建 sdk 的 dist,纯环境前提)。
  • 未发现任何新问题。 未覆盖范围见英文正文 "Not covered" 一节。

Central claim and A/B proof

Claim: on the offline Web Shell 503 fallback page, the <a href=""> Retry link drops the URL fragment (which carries Web Shell authentication) when the daemon recovers; replacing navigation with location.reload();return false preserves the exact address.

Harness: real Chrome 154.0.8037.97 (Playwright, system Chrome channel) + the arm's own packages/web-shell/client/sw.js registered as a real service worker + a real loopback HTTP server as the shell/daemon origin. Flow per scenario: navigate with query+fragment → wait for SW control → stop server (daemon down) → reload → assert the SW-served bilingual 503 → start server → click "Try again" → assert recovered address-bar URL and wire log.

Scenario base a7deb01b after Retry head ae3ce95b after Retry
/session/123?workspace=review#auth-token-PLAIN /session/123?workspace=review — fragment dropped byte-identical to original, fragment kept
/session/abc/def?x=1&y=2#token%20enc%2Foded%3D (nested + encoded) fragment dropped byte-identical to original
/session/789?plain=1 (no fragment) byte-identical byte-identical

All runs: SW controls the page, the real 503 fallback renders (not the browser error page), the recovered page is the real online page, and the auth token appears in no server request and no fallback HTML (fragments never reach the wire). 30/30 scripted checks per arm, repeated twice per arm with identical outcomes.

base browser run

head browser run

The fallback page rendered by the SW (base and head screenshots are byte-identical, sha256 4481b9d4…, as expected — the one-line onclick diff is invisible) and the recovered online page on head:

503 fallback served by the service worker

recovered page after retry on head

Load-bearing proof of the new regression test

The PR's new test (reloads the current document and cancels Retry link navigation) was copied test-only onto the base tree and run against the base sw.js:

  • base + PR test file: 20 passed, 1 failed — and the failure is the intended assertion, AssertionError: expected null not to be null at the onclick attribute read, not an import/compile break.
  • head (as committed): 21/21 passed.

So the test is red exactly against the un-fixed worker and green with it.

head focused suite green

base + PR test red

Gates

  • Full @qwen-code/web-shell vitest suite (4602 tests on head / 4601 on base), run sequentially in each arm: 273 failures on both arms, and the failing-test sets extracted from junit are identical in both directions (headOnly=0, baseOnly=0; 387 junit failure entries each). The PR introduces zero new failures; head passes exactly one more test than base — the new regression test. The 273 pre-existing failures are environmental to this scratch setup (jsdom localStorage shims etc.) and unrelated to the PR.
  • TypeScript (tsc -p tsconfig.json --noEmit in packages/web-shell): passes on both arms once the workspace SDK's dist exists (the earlier 937-error run was a missing-build artifact of the scratch install; identical on base, i.e. A/A environmental, and none of those errors touched the PR's files).

Findings

None. The change is one line, the mechanism does what the description says, and no sibling surface exists (the fallback page has a single link; the inline handler runs because the SW-served 503 sets no CSP — verified empirically by the reload actually executing). With scripting disabled the link degrades to the old href="" behavior, which is the correct graceful fallback.

One scope note, not a defect: the new unit test pins the handler's shape (parses the real fallback HTML, executes the real onclick, asserts one reload + cancelled navigation); fragment preservation itself is a browser navigation semantic that only a real browser can prove — that gap is exactly what the browser A/B above covers, so coverage is complete when both are read together.

Not covered

  • Full daemon authentication flow, the React application, and Android WebView (author also did not exercise these; the changed code path is the SW's offline fallback only).
  • Safari/Firefox behavior — measured on Chrome 154/macOS; the author measured Chromium 151/Windows with the same outcome.
  • Repo-wide gates outside @qwen-code/web-shell (PR touches only packages/web-shell/client/; upstream CI is green on ae3ce95).
  • The workspace SDK build script fails in this scratch worktree (its bundler spawn dies in this environment, on both arms identically); its dist/ was nevertheless present, which is what typecheck and the suites consumed. Not PR-related.

Methodology

Two detached worktrees at the resolved baseRefOid/headRefOid (never HEAD^1 of a branch checkout). Dependencies installed once at head with the repo-pinned pnpm (--frozen-lockfile, QWEN_SKIP_PREPARE=1), hardlinked into base with cp -al; the lockfile is untouched by this PR, so the control is clean, and workspace links were realpath-verified to resolve into each tree's own packages/* (packages/web-shell/node_modules/@qwen-code/sdk → <tree>/packages/sdk-typescript, node_modules/@qwen-code/qwen-code-core → <tree>/packages/core). The browser harness and full run logs are in tmp/pr13176-verify-20261002-224615/ (harness/browser-ab.mjs, harness/browser-{base,head}.log, harness/full-suite-{head,base}2.log, junit XMLs in each tree). An earlier concurrent full-suite run was discarded because an SDK build attempt materialized dist/ mid-run; the numbers above come from the clean sequential re-run.

Local verification by @wenshao (maintainer-driven, advisory evidence — not a review approval).

@jabrailkhalil

Copy link
Copy Markdown
Contributor Author

@wenshao Thank you for the independent browser A/B verification and for checking that the new regression test fails against the original worker. Your Chrome results complement my earlier Chromium verification without extending the claim to the full daemon authentication flow or Android WebView. I will keep head ae3ce95b unchanged for the required human review. I am ready to address any remaining feedback.

@wenshao
wenshao added this pull request to the merge queue Oct 2, 2026
Merged via the queue into QwenLM:main with commit 187a2d5 Oct 2, 2026
79 checks passed
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.

2 participants