GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(server): make PDF attachments work with every model by reachjalil · Pull Request #4334 · different-ai/openwork

Conversation

@reachjalil

@reachjalil reachjalil commented Sep 2, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Why

Attaching a PDF only works today if the selected model happens to accept PDF input. The desktop sends application/pdf as a file:// part, the engine inlines the raw base64, and the provider receives it with no capability check (message-v2.ts, OpenCode 1.18.18). Any model without native PDF input — most local and open-source models, and many hosted ones — fails the whole request. The same happens when the agent uses Read on a PDF that is already in the workspace: Read returns the full PDF as a tool attachment and the engine forwards it the same way.

This PR makes PDFs work with every model the engine can run, in the best form that model can actually consume, without changing what OpenCode persists.

What the model receives

Model can take What the provider receives for a PDF
PDF natively, and the document is small enough that native is the better deal The PDF as-is — no change to the path that already works
PDF natively, but native would blow the request size, dominate the context window, or re-upload >10 MiB per step The derived form below, with a note saying which rule applied and the numbers
Images (most vision models, many open-source VLMs) Rendered page images (first 20, in order) plus page-marked extracted text
Text only, or a model the catalog does not list Page-marked extracted text, with an explicit note about pages that have no text layer
Any — oversized, encrypted, corrupt, or mislabelled A clear note; the bytes are never forwarded

Further pages are reachable through a new engine tool, openwork_pdf_pages, which renders up to eight requested pages of a workspace PDF and returns them as images for image-capable sessions or as text otherwise.

How

A new engine plugin, apps/server/src/opencode-plugins/openwork-pdf-attachments.ts, on experimental.chat.messages.transform — the same hook the shipped office-attachments plugin uses:

  • It rewrites only the provider-facing copy for the current step. The persisted transcript keeps the original PDF part or tool attachment, so the chat UI still shows the PDF chip and switching models mid-session re-decides from scratch.
  • Capability comes from the engine's own provider catalog (client.provider.list(), both capabilities.input and modalities.input shapes). An unlisted model is treated as text-only — text always works, an unsupported part fails the request.
  • Native is not automatically best even for PDF-capable models: the engine resends the transcript every step, so a native PDF rides inline as base64 each time and is tokenized per page. One per-step budget is shared by every PDF in transcript order and follows the providers' published rules (Anthropic, OpenAI, Gemini): request size counted at base64 size with 4 MiB headroom (32 MiB; Google 20 MiB inline), the per-request page cap (Anthropic 100, or 600 at ≥1M context; Google 1000), per-page token cost (Anthropic ≈2,300 from their own 7,000-tokens-for-3-pages figure; Gemini 258; 2,000 elsewhere) capped at 35 % of the model's context window, and a 10 MiB raw ceiling above which re-uploading per step stops being worth it. Documents and images are placed before the user's text, as Anthropic and OpenAI recommend. Small and medium documents stay native at full fidelity; large ones get text plus page images with a note stating the exact rule and numbers.
  • PDF attachments inside completed tool results (Read on a .pdf) are routed identically: the tool output gains the note and image-capable models get page images as attachments.
  • Rendering and text extraction use PDFium compiled to WebAssembly (@hyzyla/pdfium, MIT; PDFium is BSD-3) with fast-png and jpeg-js. Pure wasm: identical behaviour inside the Bun engine and the Node/Electron server, no native build, no allowBuilds or asar-unpack changes. Text pages encode as PNG; photo-like or scanned pages encode as full-resolution JPEG instead of being downscaled.
  • Every file read and write goes through a verified handle: open without following a final-component symlink, confirm the opened file is a regular single-link file the path still names at exactly the expected place beneath the real parent (device/inode), then use the handle. Writes open the file at its final name and let content flow only through that handle — there is no temporary file and no rename/link, because a path-based move resolves two paths and could be redirected between them. Once the identity check passes, a parent swapped underneath cannot change where the bytes land; a symlink, hardlink, or directory planted at the name is refused (never followed, never removed), so the derivation fails closed the way a symlinked bundle directory already does.
  • Nothing sent to the provider is read from the workspace. Page images and text are produced in-process from the attachment bytes and held in memory (bounded by entry count and a 96 MiB image budget, least-recently-used eviction); a cold start or eviction simply re-derives from the bytes. Workspace storage is treated as hostile and is write-only: every directory written must resolve to exactly the expected path beneath the real workspace root (no symlinked parents or bundles), files are written in place through verified handles, nothing is ever deleted (Node has no directory-relative delete, and a path-based one could be redirected), and the manifest is never read back.
  • A workspace copy is written under .opencode/openwork/inbox/pdf-pages/<sha16>-<name>/ (manifest.json, text.md, page-NNN.png|jpg) for the agent's own tools and for people, and the PDF is materialized under chat-attachments/ like office files. Later steps reuse in-memory results by content hash and by persisted part id, so a long tool loop never re-decodes the attachment. Bundles are not pruned automatically (see the deletion rule above); they accumulate under the inbox like chat attachments do until a person clears them.
  • Limits: 64 MiB processing ceiling; 300 pages of text with a 6 s budget; 20 eager pages with an 8 s budget; 1568 px long edge; ≤1.5 MiB per image; 12 MiB inline images per PDF; 60k characters of inline text with the full text on disk.

Packaging

The three libraries are devDependencies of apps/server: they are inlined into the plugin bundle at build time and the server runtime never imports them, so the desktop's runtime-dependency mirror is unchanged. pdfium.wasm is copied next to the bundled plugin by scripts/copy-pdfium-wasm.mjs (part of build), and the desktop electron-builder.base.yml plugin filter now includes *.wasm. In development the plugin resolves the wasm from node_modules.

Model-facing note

Each derived PDF carries a structured note: filename, pages, sha256, pdf_path, full_text_path, text-layer coverage, which pages are attached as images, how to get more pages, why this representation was chosen for this model, and a line marking the extracted text as document content rather than instructions. Text-only models are told not to open image files.

Not in this PR

  • Running PDFium in a worker thread for hard isolation against pathological PDFs. Current guard: per-document time budgets checked between pages.
  • A workspace .gitignore for .opencode/openwork/inbox/ (pre-existing for chat attachments too).
  • Automatic clean-up of old derived bundles; it needs a directory-relative delete Node does not offer, so it is left to people (or a future safe primitive).
  • Any change to the composer or to what OpenCode persists.

Verification

Local lane (no Daytona credentials in this session). Exact head e1d1326f2, on dev@59cb5a3be (2026-09-04); the previous head 60a05e007 passed the same server checks and full CI except the items explained below.

Check Command Result
Server typecheck pnpm --filter openwork-server typecheck 0 errors
Full server unit suite (CI step) pnpm --filter openwork-server test 932 pass, 8 skip; the only local red is workspace-kv-store.node.test.ts importing node:sqlite under local Bun 1.3.4 (CI pins 1.3.14 and passes it)
derive.test.ts on Linux docker run … oven/bun:1.3 bun --conditions=development test src/pdf-attachments/derive.test.ts 17 pass, 0 fail (the inode-reuse fix below: pre-fix tree failed 1/18 in the same container)
New modules + plugin bun --conditions=development test src/pdf-attachments src/opencode-plugins/openwork-pdf-attachments.test.ts 48 pass, 0 fail
Plugin bundle + wasm copy pnpm --filter openwork-server build openwork-pdf-attachments.js 0.86 MB next to openwork-chrome-devtools.js from #4423, pdfium.wasm copied
Desktop dependency mirror / outbound manifest node --test electron/server-dependency-mirror.test.mjs, pnpm check:outbound-access 2 pass; no stale entries
Evals gate: layers, channel + boundary ratchets, runner tests pnpm --dir evals run test 233 pass, 0 fail; spec-boundary-ratchet: 78 specs checked
Lockfile pnpm install --frozen-lockfile after rebase up to date; diff vs dev is additive only (@hyzyla/pdfium, fast-png + fflate/iobuffer, jpeg-js)
evals/specs/pdf-attachments-model-routing.test.ts (pr lane) pnpm --dir evals exec vitest run --config vitest.config.ts --project pr specs/pdf-attachments-model-routing.test.ts 1 passed, 0 skipped (7–9 s, cold engine profile; 8 consecutive local runs green)

What changed on the 2026-09-04 rebase

dev moved under this branch in three ways that touched the proof, not the feature:

  • evals: spec boundary ratchet; coverage default is zero new test files #4398 added the spec boundary ratchet: a new evals/specs file may not import product source and must observe the product through a boundary (app(), chrome(), server(), spec.world(), or a world). The old spec imported the plugin directly and spawned a bare engine with a hand-written plugin list, so it would have failed the gate.
  • test(evals): remove e2e quarantine and spec-impact bookkeeping #4378 removed the spec-impact/quarantine bookkeeping, including evals/specs/contracts.snapshot.json; this branch's addition to that file is dropped with it.
  • test: repair cross-server handoff registration and isolate the app SDK smoke #4375 repaired the cross-server-handoff-atomic-commit registration that was red on dev and was the cause of the spec-impact / spec-quarantine failures in this PR's last CI run.

The spec is now a thin spec.world() spec over a new world, evals/worlds/pdf-attachments.ts. The world boots the real openwork-server CLI with a managed engine, so the engine loads the plugin list the server writes itself (openwork-runtime-config.ts) rather than a list the test hand-wrote, and points the workspace's only provider at a loopback mock that records what each model received. The spec drives sessions through the server's /workspace/:id/opencode/* proxy and asserts: the vision model got three image_url PNG pages plus the note; the text model got the note only; the native model got file(report.pdf) unchanged; a text model that used Read on a PDF on disk got the note in the tool result and no file part; every request advertised openwork_pdf_pages; every persisted user message and tool part kept its application/pdf attachment; two derived bundles were written to the workspace inbox. The fake-catalog scenarios the old spec duplicated live in the plugin's colocated bun tests (48 tests above).

The Linux-runner timeout at the first POST /session in the last CI run was the fresh-profile npm install waiting on npm's advisories endpoint; the server's managed engine spawn now sets npm_config_audit=false (#4408), and this spec inherits it by going through the server. The world removes its scratch profile (≈226 MB of engine runtime) on dispose.

Warden clearance: why it was withheld, and what changed

Warden clearance requires zero blocking findings. On every head since c0a909518, diff-security-review re-flagged the write-side TOCTOU on the path-based publish (rename/link after a realpath check) as High, deduplicated it against the resolved GBG-P9Z thread (so nothing new was posted), and the clearance verdict stayed flagged. The finding has a real kernel: a rename resolves its two paths separately, so a parent swapped inside that window could move the bytes written here — text derived from the attacker's own PDF — over a file the user can write, and the after-the-fact check could only detect it. Two commits close the class: the write-in-place commit removes the path-based publish entirely (files are opened at their final name and written only through a handle verified against the confined directory, see How), and the follow-up removes every delete from the module after Warden flagged the prune's own unlink for the same reason (LL7-W6E): no automatic pruning, no cleanup of a refused create, and a planted entry at a target name is refused instead of removed — Node has no directory-relative delete, so none of those could be made race-free. Tests: a parent swapped before the write for both modes leaves at most an empty file outside and never truncates an existing outside file; a planted symlink or hardlink is refused without touching its target and the derivation fails closed; a handle stays bound to its inode across a parent swap.

With the deletes gone, Warden's next pass raised one medium (U3U-C85): the derivation cache was keyed by content digest alone and the plugin's part memo (part id + payload length → digest) was process-wide and skipped the bytes on a hit, so another session or workspace presenting a known part id with a same-length URL could have been served an earlier document's text. e1d1326f2 keys the derivation cache by workspace root + digest (DerivedPdf.scope) and scopes the part memo by workspace and session, for inline data: URLs only (a workspace file can change between steps and is always re-read); tests cover both halves. Warden then reported no findings on e1d1326f2 and granted clearance (diff-warden approval); every Warden thread on this PR is resolved.

The first rebased run also surfaced a real Linux-only unit failure in this branch: verifyPublished trusted a published file by (dev, ino) and only compared bytes when the identity differed. ext4 hands a freed inode number to the very next file, so a file with someone else's bytes could carry the identity of the one written here; APFS allocates inode numbers monotonically and hid it. verifyPublished now compares the bytes every time (the identity parameter is gone), and the regression test frees the original inode before the other writer's file is created. Reproduced and fixed in an oven/bun:1.3 Linux container against this worktree. On the 2026-09-04 rebase the branch also merged #4423's openwork-chrome-devtools bundled plugin into the same build script, plugin list, and devDependencies.

Test evidence for this head is published in the sticky comment below.

Reviewer notes

  • The engine still persists the original base64 PDF in its own transcript store; that is upstream OpenCode behaviour (Memory leak: PDF attachments are base64-encoded without size limit and re-encoded every turn, causing OOM anomalyco/opencode#42263) and untouched here. This PR only changes what reaches the provider.
  • Why the derived path even for PDF-capable models past a size: a 60-page report is ~120k native tokens per step on Claude — more than half of a 200k window — while its text is ~40k. Below the thresholds nothing changes.
  • openwork_pdf_pages is advertised in every session (~100 tokens of tool schema). It is the only way a vision model can reach a page beyond the inline set, and the only way a scanned long PDF is usable at all.
  • The lockfile diff is additive only (@hyzyla/pdfium, fast-png + fflate/iobuffer, jpeg-js).
  • Manifest version is bumped when the derivation changes, so stale bundles are simply re-derived.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vercel

vercel Bot commented Sep 2, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

4 Skipped Deployments
Project Deployment Actions Updated
openwork-app Skipped Skipped Sep 4, 2026 7:09pm UTC
openwork-den Skipped Skipped Sep 4, 2026 7:09pm UTC
openwork-diagnostics Skipped Skipped Sep 4, 2026 7:09pm UTC
openwork-landing Skipped Skipped Sep 4, 2026 7:09pm UTC
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vercel
vercel Bot deployed to Preview – openwork-den September 2, 2026 20:49
View deployment
@vercel
vercel Bot deployed to Preview – openwork-app September 2, 2026 20:49
View deployment
@vercel
vercel Bot deployed to Preview – openwork-landing September 2, 2026 20:49
View deployment
github-actions[bot]
github-actions Bot reviewed Sep 2, 2026
View reviewed changes
Comment thread apps/server/src/opencode-plugins/openwork-pdf-attachments.test.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@vercel
vercel Bot temporarily deployed to Preview – openwork-diagnostics September 2, 2026 21:06 Inactive
@vercel
vercel Bot temporarily deployed to Preview – openwork-landing September 2, 2026 21:06 Inactive
@vercel
vercel Bot temporarily deployed to Preview – openwork-den September 2, 2026 21:06 Inactive
@vercel
vercel Bot temporarily deployed to Preview – openwork-app September 2, 2026 21:06 Inactive
github-actions[bot]
github-actions Bot reviewed Sep 2, 2026
View reviewed changes
Comment thread apps/server/src/opencode-plugins/openwork-pdf-attachments.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@vercel
vercel Bot temporarily deployed to Preview – openwork-diagnostics September 2, 2026 21:16 Inactive
@vercel
vercel Bot temporarily deployed to Preview – openwork-den September 2, 2026 21:16 Inactive
@vercel
vercel Bot temporarily deployed to Preview – openwork-app September 2, 2026 21:16 Inactive
@vercel
vercel Bot temporarily deployed to Preview – openwork-landing September 2, 2026 21:16 Inactive
@vercel
vercel Bot temporarily deployed to Preview – openwork-den September 3, 2026 00:40 Inactive
@vercel
vercel Bot temporarily deployed to Preview – openwork-landing September 3, 2026 00:40 Inactive
@vercel
vercel Bot temporarily deployed to Preview – openwork-diagnostics September 3, 2026 00:40 Inactive
@vercel
vercel Bot temporarily deployed to Preview – openwork-app September 3, 2026 00:40 Inactive
@reachjalil

reachjalil commented Sep 3, 2026

Copy link
Copy Markdown
Member Author

Addressed the two Warden security findings (9QY-SUC, SGW-NVQ) in b5c97f2: the stored manifest is now untrusted workspace content. It carries no paths; the bundle directory, text path, and PDF path are recomputed from the workspace root, the content digest, and the sanitized filename of the current attachment. Rendered-page entries must use the exact generated page-NNN.png|jpg name and lie within the page count, and any manifest failing validation is ignored and re-derived. readPageImage builds its path from page number and mime only.

Regression tests plant a manifest pointing outside the bundle, tamper with an in-memory descriptor, and corrupt page metadata; the real-engine spec was re-run on this head and its evidence republished above.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

github-actions[bot]
github-actions Bot reviewed Sep 3, 2026
View reviewed changes
Comment thread apps/server/src/pdf-attachments/derive.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread apps/server/src/pdf-attachments/derive.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@vercel
vercel Bot temporarily deployed to Preview – openwork-diagnostics September 3, 2026 00:50 Inactive
@vercel
vercel Bot temporarily deployed to Preview – openwork-app September 3, 2026 00:50 Inactive
@vercel
vercel Bot temporarily deployed to Preview – openwork-landing September 3, 2026 00:50 Inactive
@vercel
vercel Bot temporarily deployed to Preview – openwork-den September 3, 2026 00:50 Inactive
@reachjalil

reachjalil commented Sep 3, 2026

Copy link
Copy Markdown
Member Author

Addressed Warden findings 4FX-JHS and 6NA-G2F in 70479ef: every directory the PDF module reads or writes must resolve to exactly the expected path beneath the real workspace root, so a symlinked .opencode/openwork/inbox/... or bundle directory fails the derivation closed instead of redirecting writes. Bundle files (manifest.json, text.md, page images) are read only when they are regular files; prune skips non-directories; the bundle directory is created only once there is content to store.

Regression tests plant a symlinked attachments directory, a symlinked bundle directory, and a symlinked text.md. Real-engine spec re-run on this head; evidence republished above.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

github-actions[bot]
github-actions Bot reviewed Sep 3, 2026
View reviewed changes
Comment thread apps/server/src/pdf-attachments/derive.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@vercel
vercel Bot temporarily deployed to Preview – openwork-diagnostics September 3, 2026 01:03 Inactive
@vercel
vercel Bot temporarily deployed to Preview – openwork-app September 3, 2026 01:03 Inactive
@vercel
vercel Bot temporarily deployed to Preview – openwork-den September 3, 2026 01:03 Inactive
@vercel
vercel Bot temporarily deployed to Preview – openwork-landing September 3, 2026 01:03 Inactive
github-actions[bot]
github-actions Bot reviewed Sep 4, 2026
View reviewed changes
Comment thread apps/server/src/pdf-attachments/derive.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

reachjalil added 18 commits September 4, 2026 11:55
@reachjalil
feat(server): route PDF attachments by what the model can take as input
2a15e7b
A PDF attached in chat reached the provider as raw base64 with no check of
the model's input capabilities, so any model without native PDF input
(most open-source and many hosted models) failed the whole request.

Add an engine plugin, openwork-pdf-attachments, on
experimental.chat.messages.transform. It rewrites only the provider-facing
copy per step and leaves the persisted transcript untouched, so switching
models mid-session re-decides from scratch:

- Models that accept PDF input within provider limits receive the PDF as-is.
- Image-capable models receive rendered page images (PNG, 1568 px long
  edge, byte-budgeted, first 20 pages inline) plus page-marked text.
- Text-only or unlisted models receive page-marked text and an honest note
  about pages without a text layer.
- Oversized, encrypted, corrupt, or mislabelled PDFs become a clear note
  instead of a provider error; workspace file: URLs stay confined to the
  workspace.

Rendering and text extraction use PDFium compiled to WebAssembly, so the
same code runs inside the Bun engine and the Node/Electron server with no
native build. The wasm ships next to the bundled plugin; the desktop
packaging picks it up alongside the plugin scripts. Derived text and page
images are cached under .opencode/openwork/inbox/pdf-pages/<sha>-<name>/
so later steps, other models, and the agent's Read/Grep tools reuse them.

Proof: bun unit suites for the PDFium runtime, derivation cache, capability
resolver, and plugin; evals/specs/pdf-attachments-model-routing.test.ts
drives the real OpenCode engine against a mock provider and asserts what
each model actually received.
@reachjalil
feat(server): cover PDFs read by tools, share the native page budget,…
3f3be1a
… and render pages on demand

Closes the gaps found while reviewing the PDF attachment plugin against the
engine's actual behavior:

- The Read tool returns a PDF as a full attachment that the engine forwards
  with no capability check, so an agent reading a PDF from disk failed on the
  same models as attachments did. Tool-result attachments are now routed the
  same way: the provider-facing tool output gains the page-marked note, and
  image-capable models get page images as attachments, while the persisted
  tool part keeps its original attachment.
- Providers cap PDF pages and bytes per request, not per file. One native
  budget is now shared by every PDF in the step in transcript order; a PDF
  that does not fit takes the derived path with a "limits" note.
- Pages beyond the eager set are reachable through a new engine tool,
  openwork_pdf_pages, which renders up to eight requested pages of a
  workspace PDF and returns them as images when the session's model can
  view images, or as text otherwise. Eager rendering drops to the inline set.
- Photo-like or scanned pages encode as full-resolution JPEG instead of a
  downscaled PNG, so scans stay legible; text pages remain crisp PNGs.
- The note no longer invites text-only models to open image files, flags the
  extracted text as document content rather than instructions, and text
  extraction has a time budget like rendering. Derived bundles are pruned
  past 64 per workspace.

The real-engine spec now also drives a Read-tool turn and asserts the tool
is advertised to the provider.
@reachjalil
refactor(server): keep PDF page images on disk only
28beabc
The engine always provides a workspace directory, so the in-memory page
image path never ran. Without a root the model still gets the text.
@reachjalil
feat(server): send a PDF natively only while it is cheaper than break…
55693f8
…ing it down

A PDF-capable model is not always best served by the PDF itself. The engine
resends the whole transcript on every step, so a native PDF rides inline as
base64 each time and is tokenized page by page (roughly 1.5k-3k tokens per
page). Past a point it exceeds the provider's request size, dominates the
context window, or re-uploads tens of megabytes per tool call while adding
nothing the derived form lacks.

Replace the two flat limits with a per-provider policy applied to the shared
per-step budget:

- request size is counted at base64 size with headroom for the rest of the
  prompt (the previous 30 MiB raw cap encoded to ~40 MB, over the 32 MB limit);
- raw size above 10 MiB takes the derived path;
- pages above the provider cap take the derived path;
- native pages may occupy at most 35% of the model's context window per step,
  using the context size from the engine catalog when it is known.

The model-facing note now states which rule applied and the numbers behind
it, so the model can explain the trade-off if asked.
@reachjalil
feat(server): follow the providers' published PDF rules on the native…
63c08d5
… path

Align the native-input policy with what Anthropic, OpenAI, and Google
document rather than generic guesses:

- Anthropic: 100 pages per request, or 600 when the model's context window is
  at least 1M tokens; about 2,300 tokens per page (their own figure of ~7,000
  tokens for a 3-page PDF with text and page images).
- Gemini: 1,000 pages, 20 MB inline, 258 tokens per page.
- Documents and images go before the user's text in the provider-facing copy,
  as both Anthropic and OpenAI recommend; the derived note is marked synthetic
  and moves with them. Tool results are never reordered.
- The note says page markers are physical 1-based positions, since providers
  suggest quoting logical page numbers and printed labels can differ.
@reachjalil
fix(server): never let a stored PDF manifest steer a filesystem read
84e25ef
The derived-PDF manifest lives inside the workspace, so a hostile workspace
can plant one next to a matching PDF. Its `directory`, `fileName`, and path
fields were joined into filesystem reads, which could have made the plugin
read an arbitrary readable file and send it to the provider as a page image.

Paths are now recomputed from trusted inputs only: the workspace root, the
content digest, and the sanitized filename of the current attachment. The
manifest carries no paths at all; rendered-page entries must use the exact
generated `page-NNN.png|jpg` name and stay within the page count, and any
manifest that fails validation is ignored and re-derived. Page images are
read from the recomputed bundle directory by page number and mime, never by
a stored name.

Regression tests plant a manifest that points outside the bundle, tamper with
an in-memory descriptor, and corrupt page metadata.
@reachjalil
fix(server): refuse PDF storage paths that resolve through workspace …
43d28bb
…symlinks

A hostile workspace can pre-create `.opencode/openwork/inbox/...` or the
predictable derived-bundle directory as a symlink, redirecting the plugin's
temporary files, materialized PDFs, and bundle writes outside the workspace,
or feeding it a symlinked `text.md`.

Every directory the module reads or writes must now resolve to exactly the
expected path beneath the real workspace root; anything routed through a
symlink fails the derivation closed. Bundle files are only read when they are
regular files, prune skips non-directories and non-file manifests, and the
bundle directory is created only once there is content to store, so
unreadable input still leaves nothing behind.

Regression tests plant a symlinked attachments directory, a symlinked bundle,
and a symlinked text file.
@reachjalil
fix(server): keep provider-facing PDF content out of workspace reads …
28dcbce
…entirely

Path-based file APIs cannot close a check-then-open race against a concurrent
writer in the workspace, and Node offers no openat. Rather than narrow the
window, remove its target: nothing sent to the provider is read from the
workspace any more.

Page images and page-marked text are produced in this process from the
attachment bytes and kept in memory, bounded by an entry count and an image
byte budget with least-recently-used eviction; an evicted or cold-started
document is simply re-derived from its bytes (about two seconds for the
eager pages). The workspace copy under `.opencode/openwork/inbox/` is now
write-only: materialized PDF, `text.md`, page images, and `manifest.json`
exist for the agent's own tools and for people, are written atomically
through symlink-refusing directory checks, and are never read back. The
manifest parser is gone with the trust it implied.

Tests now poison the workspace copy between steps and plant symlinked
`text.md` and page files to show the model still receives only bytes
produced here.
@reachjalil
fix(server): move every PDF file read and write onto verified handles
1bc7bee
Path-based checks leave a window between the check and the open. Close it
the way a platform without openat allows: open first, never following a
symlink at the final component, then confirm the opened file is a regular
file that the path still names beneath the expected real parent, and only
then let content flow through that handle.

Writes create the temporary file the same way and verify where it landed
before any bytes are written; rename or link then completes the atomic
publish. The model-requested `file:` URL and `openwork_pdf_pages` reads use
the same verified open, so a workspace path swapped mid-read is refused
rather than forwarded.
@reachjalil
fix(server): create PDF storage directories without ever crossing a s…
d6f702c
…ymlink

`mkdir -p` follows symlinks in parent components, so a hostile workspace
could make the module create directories elsewhere before the confinement
check ran. Directories are now created one component at a time, refusing
any symlink or non-directory along the way, before the real-path check. A
temporary file that fails verification is removed only through its verified
real path, never through a path that may have been swapped.
@reachjalil
fix(server): refuse PDF reads through files with more than one hard link
3d3ec7b
A hardlink inside the workspace gives an outside inode an in-workspace
name, so the realpath and device/inode identity checks in
openVerifiedForRead both pass while the handle reads external content.
Require a single link count on the opened handle before any bytes flow
to the provider, and cover it in the verified-read test.
@reachjalil
fix(server): verify PDF storage writes on both sides of the publishin…
ad90c98
…g step

Content was already written through a verified handle, but the step that
publishes it (rename or link) and the temporary-file cleanup resolved the
path again, so a directory swapped for a symlink between the confinement
check and the rename could redirect the publish. Node has no
directory-relative rename or link, so confirm the verified directory is
still reached without a symlink immediately before the publishing call,
then open the published path without following symlinks and require a
regular file with a single link that is either the inode written here or
another writer's copy of the same bytes. Temporary files are removed only
while the path still names the file this module created, and bundle
pruning removes only bundle-named directories while the pdf-pages parent
is still symlink-free.

Tests swap the directory for a symlink after the temporary file was
written, for both rename and link publishing, and cover the published-file
verification: same inode, another writer's identical copy, different
bytes, a symlink at the final component, and the written inode reached
through a directory that is now a symlink.
@reachjalil
test(evals): keep the parent's OPENCODE_* variables out of the PDF ro…
c095d66
…uting engine

When the spec runs inside an opencode session, the spawned engine inherited
OPENCODE_CONFIG and loaded that session's live runtime config, plugins and
providers instead of the isolated fixture. Filter those variables out of the
child environment, as the MCP OAuth spec already does.
@reachjalil
test(evals): prove PDF routing through openwork-server and its shippe…
2657bb6
…d plugins

The PDF routing spec bundled the plugin by hand, spawned a bare engine with a
hand-written plugin list, and drove the plugin directly with a fake catalog.
evals/specs now requires a spec to observe the product through a boundary and
keeps unit tests next to their module, so:

- a new world, evals/worlds/pdf-attachments.ts, boots the real openwork-server
  CLI with a managed engine and the plugin list the server writes itself,
  against a loopback mock provider that records what each model received;
- the spec drives sessions through the server's engine proxy and asserts the
  provider-facing parts, the persisted transcript, the Read-tool path, the
  advertised page tool, and the derived bundles in the workspace inbox;
- the fake-catalog routing scenarios were already covered by the plugin's
  colocated bun tests and are dropped from the spec.

Going through the server also inherits its npm_config_audit=false engine
spawn, so a fresh engine profile no longer waits on npm's advisories endpoint
before the first session, which is the stall behind the previous spec's
Linux-runner timeout. The world removes its scratch profile on dispose.
@reachjalil
fix(server): prove a published PDF file by its bytes, not its inode n…
f47e4af
…umber

verifyPublished trusted a published file when it carried the (dev, ino) of
the file written here and only compared bytes when it did not. That identity
is not proof once the write handle is closed: if the path is swapped and the
inode freed, the filesystem may hand the same number to the next file. ext4
does exactly that, so on Linux a file holding someone else's bytes passed as
ours, while APFS, which allocates inode numbers monotonically, hid it. Compare
the content every time and drop the identity parameter.

The regression test now frees the original inode before the other writer's
file is created, so it exercises the reuse on filesystems that do it; it
failed on the Linux runner and passes there with this change.
@reachjalil
fix(server): write derived PDF files in place through a verified hand…
da8a616
…le, never by rename or link

Publishing a derived file by writing a temporary file and then renaming or
linking it into place resolves two paths in one call. A parent directory
swapped for a symlink between those resolutions could move the bytes written
here — text extracted from the attacker's own PDF — over any file the user can
write, and the check after the fact could only detect it. Node has no
directory-relative rename or link, so the move itself cannot be made safe.

Open the file at its final name instead and let content flow only through
that handle: create with O_EXCL|O_NOFOLLOW, or for a replace open the existing
entry only when lstat shows a regular single-link file, confirm through the
handle that the inode is the one the path names at exactly that place beneath
the confined directory, and truncate and write only after that. A later swap
of a parent cannot change where bytes bound to a verified inode land. A
symlink, hardlink, or directory planted at the name has its entry removed and
is never written through. The temporary files, rename, link, and the
after-the-fact verification are gone.

Bundle pruning no longer removes a directory recursively: it unlinks only the
fixed names this module writes, re-checks the parent before each deletion, and
removes the directory only once it is empty, so a swapped parent can reach at
most those names inside a same-named directory. Anything else inside a bundle
is left for a person.

Tests cover a parent swapped before the write for both modes (nothing lands
outside, an existing outside file is neither truncated nor overwritten), a
planted symlink and hardlink being replaced without touching their target, a
handle staying bound to its inode across a parent swap, in-place replacement,
and pruning that leaves a foreign subdirectory untouched.
@reachjalil
test(evals): let the PDF routing world retry one early server exit
1d55d72
openwork-server gives its managed engine a fixed 15 s start budget. On a
fresh profile a slow moment (plugin runtime install, cold transpile) can
exceed it once, and the server then exits before it reports a port, which
failed the world build in one run out of many. Boot at most twice on that
exact failure and keep the first attempt's output in the world diagnostics;
every other failure still surfaces immediately.
@reachjalil
fix(server): never delete from the PDF attachment storage; refuse pla…
088da03
…nted entries

Every delete in this module resolved a path on its own: pruning old derived
bundles, removing a file the module had just created but refused, and
clearing a symlink, hardlink, or directory planted at a name it writes.
Node has no directory-relative delete, so each of those could be redirected
by a parent swapped in the moment between the check and the call and remove
someone else's file of that name.

Remove them all. Derived bundles now accumulate under the inbox until a person
clears them; a created file that fails verification is left where the swap
sent it, empty and never written; and a planted entry at a target name is
refused with a clear message instead of replaced, consistent with how a
symlinked bundle directory already fails the derivation closed.

Tests: a planted symlink at text.md or a page image fails the derivation and
leaves both the entry and its target untouched, while the same PDF derives
normally once the entries are gone; a planted symlink or hardlink at a write
target is refused; a redirected create leaves only an empty file behind and
never truncates an existing file at the redirected place.
@reachjalil
reachjalil force-pushed the feature/pdf-attachments-model-ready branch from 9f5e11b to 088da03 Compare September 4, 2026 18:55
@vercel
vercel Bot deployed to Preview – openwork-diagnostics September 4, 2026 18:56
View deployment
@vercel
vercel Bot deployed to Preview – openwork-app September 4, 2026 18:56
View deployment
@vercel
vercel Bot deployed to Preview – openwork-landing September 4, 2026 18:56
View deployment
@vercel
vercel Bot deployed to Preview – openwork-den September 4, 2026 18:57
View deployment
github-actions[bot]
github-actions Bot reviewed Sep 4, 2026
View reviewed changes
Comment thread apps/server/src/pdf-attachments/derive.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@reachjalil
fix(server): scope PDF derivation caches to the workspace and session
e1d1326
Two caches could hand one context's result to another. The derivation cache
was keyed by content digest alone, so a second workspace attaching the same
bytes received the first workspace's entry, whose text.md and page image paths
exist only in that first workspace. The plugin's part memo mapped a part id
and payload length to a digest process-wide and served the cached derivation
without reading the bytes, so a part in another session carrying a known id
and a same-length URL would have received the earlier document's text.

Key the derivation cache by workspace root and digest (DerivedPdf carries its
scope), and scope the part memo by workspace and session, only for inline
data URLs: a workspace file can change between steps and is always re-read.

Tests: the same part id and payload length in another session is not served
from the memo, and a second workspace attaching the same bytes gets its own
copy with paths that exist there.
@reachjalil

reachjalil commented Sep 4, 2026

Copy link
Copy Markdown
Member Author

Test evidence — each-model-receives-an-attached-pdf-in-the-form-it-can-take-and-the-transcript-k — ✅ passed

✅ passed · 3 expectations passed · 0 failed · 0 pending

screenshots not attached (gh < 2.99; run brew upgrade gh)

steps 1 ✅ attach report.pdf for the vision model (1.2s) · 2 ✅ attach report.pdf for the text model (0.0s) · 3 ✅ attach report.pdf for the native model (0.0s) · 4 ✅ a text-only model reads on-disk.pdf from disk through the Read tool (0.1s)
verdict passed · 0 user observations · 0 probes · steps 4/4

ℹ️ ASSERTION — 1. Inside the real engine, an image-capable model received page images plus text, a text-only model received text, and a PDF-capable model received the PDF itself

OpenCode 1.18.18 behind openwork-server with its shipped plugins; the provider saw vision=image_url:data:image/png,image_url:data:image/png,image_url:data:image/png,text:note,text:Summarize this. text=text:note,text:Summarize this. native=file:report.pdf,text:Summarize this.; every reply completed and every persisted user message kept its application/pdf part.

  • ✅ PASS Inside the real engine, an image-capable model received page images plus text, a text-only model received text, and a PDF-capable model received the PDF itself — OpenCode 1.18.18 behind openwork-server with its shipped plugins; the provider saw vision=image_url:data:image/png,image_url:data:image/png,image_url:data:image/png,text:note,text:Summarize this. text=text:note,text:Summarize this. native=file:report.pdf,text:Summarize this.; every reply completed and every persisted user message kept its application/pdf part.

ℹ️ ASSERTION — 2. A text-only model that reads a PDF from disk through the Read tool receives its text instead of a PDF it cannot take, and the persisted tool result keeps the original attachment

The mock model asked the engine to read on-disk.pdf; the follow-up request carried one tool result containing the OpenWork PDF note and no file or image parts, the turn completed, and the transcript's tool part still holds an application/pdf attachment. Every request advertised the openwork_pdf_pages tool.

  • ✅ PASS A text-only model that reads a PDF from disk through the Read tool receives its text instead of a PDF it cannot take, and the persisted tool result keeps the original attachment — The mock model asked the engine to read on-disk.pdf; the follow-up request carried one tool result containing the OpenWork PDF note and no file or image parts, the turn completed, and the transcript's tool part still holds an application/pdf attachment. Every request advertised the openwork_pdf_pages tool.

ℹ️ ASSERTION — 3. Derived text and page images are kept in the workspace inbox for the agent's tools and later steps

.opencode/openwork/inbox/pdf-pages holds b2fc86b31300ea96-on-disk and f80d003ffc4116df-report.

  • ✅ PASS Derived text and page images are kept in the workspace inbox for the agent's tools and later steps — .opencode/openwork/inbox/pdf-pages holds b2fc86b31300ea96-on-disk and f80d003ffc4116df-report.

Test run created 2026-09-04T19:08:30.032Z · Source: evals/results/test-runs/2026-09-04T19-08-30-031Z-each-model-receives-an-attached-pdf-in-the-form-it-can-take-and-the-transcript-k/test-run.json · Repro: pnpm --dir evals artifacts:publish -- --pr 4334 --test-run 2026-09-04T19-08-30-031Z-each-model-receives-an-attached-pdf-in-the-form-it-can-take-and-the-transcript-k

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vercel
vercel Bot temporarily deployed to Preview – openwork-landing September 4, 2026 19:09 Inactive
diff-warden[bot]
diff-warden Bot approved these changes Sep 4, 2026
View reviewed changes

@diff-warden diff-warden Bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Warden security clearance: clear. No blocking findings (security or desktop↔den sync) in this diff (e1d1326f2d9cd1204d8dcce579de1c97e692f785). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@benjaminshafii benjaminshafii mentioned this pull request Oct 7, 2026
[Feature]: Session-owned local attachment storage and cleanup on chat deletion #5355
Open
3 tasks done

This branch was previously deployed

4 inactive deployments
Preview – openwork-app — e1d1326f Deployed Sep 4, 2026 by vercel[bot]
View deployment
Preview – openwork-den — e1d1326f Deployed Sep 4, 2026 by vercel[bot]
View deployment
Preview – openwork-diagnostics — e1d1326f Deployed Sep 4, 2026 by vercel[bot]
View deployment
Preview – openwork-landing — e1d1326f Deployed Sep 4, 2026 by vercel[bot]
View deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@github-actions github-actions[bot] github-actions[bot] left review comments
@diff-warden diff-warden[bot] diff-warden[bot] approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@reachjalil
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.