Skip to content

fix(pdf-server): detached-buffer on range re-request + stale e2e assertion#561

Merged
ochafik merged 2 commits intomainfrom
ochafik/pdf-detached-buffer-fix
Mar 23, 2026
Merged

fix(pdf-server): detached-buffer on range re-request + stale e2e assertion#561
ochafik merged 2 commits intomainfrom
ochafik/pdf-detached-buffer-fix

Conversation

@ochafik
Copy link
Contributor

@ochafik ochafik commented Mar 23, 2026

1. "Buffer is already detached" on iOS/Windows

PDFDataRangeTransport.onDataRange() transfers the ArrayBuffer to PDF.js's worker via postMessage, detaching it in the main thread. The rangeCache still holds a reference to that (now-detached) Uint8Array. When PDF.js re-requests the same range — common on iOS/WKWebView under memory pressure during scroll/zoom — we hand back the detached buffer and it throws.

Fix: pass result.bytes.slice() to onDataRange so the cache entry keeps a valid buffer.

2. Stale e2e assertion

The interact-enabled display_pdf result text changed from Displaying PDF (viewUUID: ...) to PDF opened. viewUUID: ... during the prompt rewrite, but pdf-annotations.spec.ts:110 still asserted the old string. This was failing on main post-#506.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 23, 2026

Open in StackBlitz

@modelcontextprotocol/ext-apps

npm i https://pkg.pr.new/@modelcontextprotocol/ext-apps@561

@modelcontextprotocol/server-basic-preact

npm i https://pkg.pr.new/@modelcontextprotocol/server-basic-preact@561

@modelcontextprotocol/server-basic-react

npm i https://pkg.pr.new/@modelcontextprotocol/server-basic-react@561

@modelcontextprotocol/server-basic-solid

npm i https://pkg.pr.new/@modelcontextprotocol/server-basic-solid@561

@modelcontextprotocol/server-basic-svelte

npm i https://pkg.pr.new/@modelcontextprotocol/server-basic-svelte@561

@modelcontextprotocol/server-basic-vanillajs

npm i https://pkg.pr.new/@modelcontextprotocol/server-basic-vanillajs@561

@modelcontextprotocol/server-basic-vue

npm i https://pkg.pr.new/@modelcontextprotocol/server-basic-vue@561

@modelcontextprotocol/server-budget-allocator

npm i https://pkg.pr.new/@modelcontextprotocol/server-budget-allocator@561

@modelcontextprotocol/server-cohort-heatmap

npm i https://pkg.pr.new/@modelcontextprotocol/server-cohort-heatmap@561

@modelcontextprotocol/server-customer-segmentation

npm i https://pkg.pr.new/@modelcontextprotocol/server-customer-segmentation@561

@modelcontextprotocol/server-debug

npm i https://pkg.pr.new/@modelcontextprotocol/server-debug@561

@modelcontextprotocol/server-map

npm i https://pkg.pr.new/@modelcontextprotocol/server-map@561

@modelcontextprotocol/server-pdf

npm i https://pkg.pr.new/@modelcontextprotocol/server-pdf@561

@modelcontextprotocol/server-scenario-modeler

npm i https://pkg.pr.new/@modelcontextprotocol/server-scenario-modeler@561

@modelcontextprotocol/server-shadertoy

npm i https://pkg.pr.new/@modelcontextprotocol/server-shadertoy@561

@modelcontextprotocol/server-sheet-music

npm i https://pkg.pr.new/@modelcontextprotocol/server-sheet-music@561

@modelcontextprotocol/server-system-monitor

npm i https://pkg.pr.new/@modelcontextprotocol/server-system-monitor@561

@modelcontextprotocol/server-threejs

npm i https://pkg.pr.new/@modelcontextprotocol/server-threejs@561

@modelcontextprotocol/server-transcript

npm i https://pkg.pr.new/@modelcontextprotocol/server-transcript@561

@modelcontextprotocol/server-video-resource

npm i https://pkg.pr.new/@modelcontextprotocol/server-video-resource@561

@modelcontextprotocol/server-wiki-explorer

npm i https://pkg.pr.new/@modelcontextprotocol/server-wiki-explorer@561

commit: efed982

ochafik added 2 commits March 23, 2026 20:12
PDF.js transfers the ArrayBuffer to its worker via postMessage, detaching
it in the main thread. When the same range is re-requested (common on
iOS/WKWebView under memory pressure during scroll/zoom/navigate), the
cached Uint8Array now wraps a detached buffer and onDataRange throws
'Buffer is already detached'.

Fix: pass result.bytes.slice() so the rangeCache entry stays valid.
…t text

The 91880a6 prompt rewrite changed the interact-enabled result text from
'Displaying PDF (viewUUID: ...)' to 'PDF opened. viewUUID: ...'. The e2e
test was still asserting the old string.
@ochafik ochafik force-pushed the ochafik/pdf-detached-buffer-fix branch from 76b42b8 to efed982 Compare March 23, 2026 20:12
@ochafik ochafik changed the title fix(pdf-server): slice bytes before onDataRange to avoid detached buffer fix(pdf-server): detached-buffer on range re-request + stale e2e assertion Mar 23, 2026
@ochafik ochafik merged commit e8a4ea5 into main Mar 23, 2026
20 checks passed
ochafik added a commit that referenced this pull request Mar 23, 2026
Changes since 1.3.0:
- fix(pdf-server): detached-buffer on range re-request + stale e2e assertion (#561)
ochafik added a commit that referenced this pull request Mar 23, 2026
Changes since 1.3.0:
- fix(pdf-server): detached-buffer on range re-request + stale e2e assertion (#561)
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.

1 participant