Repository navigation
Conversation
MoonOld
left a comment
There was a problem hiding this comment.
One focused blocker before this PR closes #3164:
P2 — durable replay drops PDF attachments from steering messages. The live steering path materializes attachments through appendAttachmentParts, but materializeRuntimeReplayItem returns item.content directly whenever item.steering is set, even though the replay plan preserves item.attachments. A later Turn or restart therefore replays the steering envelope text without the PDF file part.
Please route this branch through appendAttachmentParts using the stable steering:${item.steering.eventId} decision key, preserve steeringProviderOptions, and extend the existing prior-turn steering replay test with a PDF assertion.
I rechecked the scope and narrowed #3164: base-URL allowlisting, the removed Headless path, and encrypted/page-limit/provider-rejection-specific recovery are not blockers for this first slice.
Astro-Han
left a comment
There was a problem hiding this comment.
Thanks for taking this on — the provider evidence in #3164 and the wire-lowering tests here made the contract straightforward to check against the real adapters rather than against claims.
Reviewed exact head 303d20a3a295cfa54be20f7aaacaebe0a8707e87.
The provider/wire gate is the right minimal shape: resolveModelPdfInputContract fails closed for relays, subscriptions, and unknown models, an explicit provider inventory outranks generated modality metadata, and the three wire shapes are locked against the real SDK adapters rather than asserted. The turn budget is created once in TurnScope and the decision keys line up across current turn, RuntimeEvent replay, and steering. The implementation does not yet satisfy its bounded-work contract, so I recommend revising it before approval.
The concrete current-head findings are inline. At the architecture level the gap is that "bounded" is enforced on what reaches the provider payload, but not on the work done to produce and observe that payload: bytes are read again per step after a decision is already cached, and the always-on request telemetry expands them element-wise on every step. Both belong before materialization, not after.
@MoonOld's steering finding reproduces on this head, and it is pre-existing for images as well — materializeRuntimeReplayItem ignores item.attachments on the steering branch on current main too, while the replay plan does preserve them. A steered PDF replays as envelope text plus an <attachment> ref and zero file parts. Routing that branch through appendAttachmentParts with steering:${item.steering.eventId} fixes it and keeps dedupe aligned with the live drain and the stored-message sidecar.
Verification: I built this head in an isolated worktree and ran packages/runtime/dist/__tests__/ai-sdk-backend.test.js — 210/212 pass, the two failures being regressions I wrote for the steering gap and the per-step re-read. A 52-line change (cache-before-read, plus the steering branch) takes it to 212/212, including enforces the PDF subtype budget from bytes read, not attachment metadata, so the "charge actual bytes" semantics survive the fix.
Review disclosure: this review was prepared with Claude Code, which read the diff, traced the call paths, and executed the reproductions and measurements quoted inline against this head. The human contributor reviewed the findings and the measurements and chose to publish this COMMENT review. The P1 timings come from a single macOS machine and are order-of-magnitude evidence, not a benchmark. No CI checks are currently reported for this head.
| * 21.4 MiB, leaving headroom under Anthropic's 32 MiB whole-request limit for | ||
| * text, tool schemas, JSON framing, and other content. | ||
| */ | ||
| export const MAX_PROVIDER_PDF_REQUEST_BYTES = 16 * 1024 * 1024; |
There was a problem hiding this comment.
[P1] Bound the work the request telemetry does on these bytes before raising the cap that makes them routine. capturePreparedProviderRequest runs on every provider request — the tracker exists whenever model-call accounting does, so this is not gated on recordProviderRequestCapture — and canonicalize has no typed-array branch, so a Uint8Array is expanded element-wise through Object.keys().sort(). Measured against this repository's built packages/runtime/dist with capture persistence disabled: an 8 MiB attachment costs 3.5 s per step, 12 MiB (today's image cap) 7.5 s, and 16 MiB (this cap) 9.5 s per step with requestBytes reported as 222.4 MiB; across three steps that is 28.5 s during which a 10 ms timer scheduled beforehand never fires, and RSS grows 4.4 to 7.6 GiB. With capture persistence enabled the bytes are also verbatim in serializedRequest — I matched the %PDF- header inside it — which contradicts this PR's "without copying bytes into transcript text or diagnostics" and #3164's "PDF bytes must never enter transcript text, logs, RuntimeEvents, or diagnostics". This is not introduced here; images take the same path on main. But this slice raises the ceiling to 18 MiB combined and makes ten-plus-MiB attachments ordinary, because a 16 MiB PDF is a normal document and a 16 MiB PNG is not. Give request-shape.ts a binary branch that represents file data as { byteLength, sha256 } — substituting that summary drops the same call from 9.5 s to 0.4 ms and requestBytes from 222.4 MiB to 312 B — and add a regression asserting that a file part's bytes never appear in serializedRequest. Landing it as a separate prerequisite is fine; landing native PDF input without it is not.
| } | ||
| let read: Awaited<ReturnType<AttachmentByteReader>>; | ||
| try { | ||
| read = await this.input.readAttachmentBytes(attachment.ref); |
There was a problem hiding this comment.
[P2] Consult the decision cache before reading the bytes, not after. The cache is checked inside chargeAttachmentBudget, which runs once readAttachmentBytes has already returned, so an attachment whose omission was decided on the first step is read in full again on every later step; materializeToolResultOutput below already does this in the correct order. Reproduced on a durable turn with loadTurnRuntimeEvents wired, as Host composition does: reads equal steps + 1 for the omitted ref — 3 reads over 2 steps, 5 over 4. In production each read is a full readDurableAttachmentBinary with no maxBytes passed, so up to MAX_ATTACHMENT_BYTES (50 MiB), serialized on the ArtifactStore queue and blocking other artifact work in the session. Move the decisionKey computation and a non-keep early return above the read, and add a multi-step regression counting reads per ref.
| (attachment.kind === 'image' && this.input.supportsVision === true) || | ||
| (attachment.kind === 'pdf' && this.input.pdfInputContract !== undefined); | ||
| if (!isEligible) continue; | ||
| if (attachment.kind === 'pdf' && attachment.mimeType !== 'application/pdf') { |
There was a problem hiding this comment.
[P3] Degrade a mislabeled PDF locally instead of spending a provider round trip on it. This check compares declared metadata only, but readPreparedBinary already sniffs magic bytes and returns the true MIME — %PDF- is in the allowlist, so a file that is not any allowed binary type does fail closed with unsupported_mime. createAttachmentByteReader then discards result.mimeType, so a PNG named brief.pdf is uploaded as application/pdf and degrades through a provider 400 rather than the bounded local explanation #3164 asks for. Surface the sniffed MIME through the reader and compare it here; that is smaller than the preflight parsing deferred to #3284.
| * accept an AI SDK PDF file part. Provider identity is intentional: a relay | ||
| * using the same adapter or wire does not inherit first-party PDF support. | ||
| */ | ||
| export type ModelPdfInputContract = |
There was a problem hiding this comment.
[P3] Say provider identity, not endpoint, in this contract's wording, and give the union a consumer or drop it. The gate is providerType plus wire; the endpoint is not checked, and this PR's own test authorizes providerType: 'openai' with baseUrl: 'https://provider.invalid/v1'. Narrowing base-URL allowlisting out of this slice is reasonable and images are in the same position, but "verified first-party provider wire" reads as endpoint verification. Separately, nothing consumes providerType or wire — AiSdkBackend only tests the contract for presence — so either branch on the wire where it matters, such as per-wire caps, or let it be a boolean.
| const fallbackText = hasUnsupportedImages | ||
| ? appendNonVisionImageFallbackNotice(textContent) | ||
| : textContent; | ||
| const eligibleAttachments = binaryAttachments.filter( |
There was a problem hiding this comment.
[P3] Keep one copy of the eligibility rule. eligibleAttachments is computed only to decide the early return and the loop recomputes the same predicate per item, so the two must be kept in sync by hand. Iterating eligibleAttachments directly removes the duplicate; note the decision key indexes into binaryAttachments, so whichever array you iterate has to stay consistent with the key.
|
Hi — this PR conflicts with current I tested a rebase onto current
These are real source conflicts, so they need your judgement rather than a mechanical rebase — please rebase onto current Thanks for the contribution — happy to help if any conflict is unclear. AI-assisted maintenance note, not a review. It does not count as the required human review under |
303d20a to
16e99b5
Compare
|
Rebased onto the current Addressed the review points:
Local verification on this final rebased commit:
GitHub created the new CI run, but it is currently |
|
This pull request has had no new commits for 30 days and has been marked stale. It will be closed in 7 days unless a new commit is pushed. Comments do not reset this timer: only a new commit does. If the pull request is intentionally long-lived, a maintainer can apply the |
hqhq1025
left a comment
There was a problem hiding this comment.
Reviewed commit 16e99b5. The 12-file change adds a provider/model/wire gate for native PDF inputs, materializes durable PDFs across current turns, replay, steering, and compaction, and applies per-kind and combined byte budgets. I found one P2 in the byte/MIME gate (inline).
Node 24 npm ci and npm run build:test succeeded; 249 focused tests passed. The current-head CI test check fails because the newly added packages/runtime/src/__tests__/pdf-input-contract.test.ts lacks the required ASF header, reproduced with npm run check:asf-headers. The PR also conflicts with current main in runtime and runtime-host files. Resolve the finding, CI failure, and merge conflicts, then rerun validation on the resulting head. I did not verify actual provider PDF processing or end-to-end Desktop upload behavior.
Automated review notice: This comment was posted by an automated review agent operated by hqhq1025. It is not an independent human review and does not replace one.
| decisionKeyPrefix === undefined ? undefined : `${decisionKeyPrefix}:image:${index}`; | ||
| if (!this.chargeImageBudget(budget, read.bytes.length, decisionKey)) { | ||
| omittedByBudget += 1; | ||
| const mediaType = read.mimeType ?? attachment.mimeType; |
There was a problem hiding this comment.
[P2] Enforce the PDF gate on the loaded MIME, not only on the declared attachment kind. Upload ingestion derives kind from the client-supplied MIME (artifact-coordinator.ts:167), while the durable byte reader independently sniffs the bytes as application/pdf (artifact-store.ts:778). A PDF uploaded as image/png is therefore eligible here whenever supportsVision is true, even when supportsNativePdfInput is false. This line then replaces the declared image MIME with the sniffed PDF MIME, and the following check rejects mismatches only for kind === 'pdf'; the PDF file part reaches the provider under the image budget on a route that explicitly denied native PDF input. Reject a loaded PDF unless native PDF input is authorized (and account for it as PDF), or reject kind/MIME mismatches before appending the file part. Please cover the image-declared/PDF-bytes case alongside the existing PDF-declared/image-bytes test.
me2seeks
left a comment
There was a problem hiding this comment.
Automated review notice: This comment was posted by an automated review agent operated by me2seeks make. It is not an independent human review and does not replace one.
Summary
Materializes verified native PDF inputs with explicit byte economics: AttachmentByteReader now optionally reports the MIME sniffed from loaded bytes, PDF requests are capped at 16 MiB raw (Base64-expanding to ~21.4 MiB under Anthropic's 32 MiB whole-request limit, with the headroom arithmetic documented in the constant's comment), and a shared 18 MiB raw binary ceiling across image+PDF (24 MiB Base64, preserving 8 MiB of headroom on the strictest verified route). The caps are placed at the authority that loads the bytes, so every provider route inherits them.
Findings
- [P1]
testfails on this head — the required merge gate is red. For a change whose risk profile is entirely about request-size limits reaching the provider, the failing suite is very likely the new byte-ceiling assertions or an attachment-materialization expectation; pull the log, fix, and show green before merge.
Verdict
needs-changes — correct cap placement with documented arithmetic, but the red test gate must be fixed first.
1ddfd43 to
0959324
Compare
hqhq1025
left a comment
There was a problem hiding this comment.
Reviewed exact head 0959324125de5b76077bb23baba2a81884046480. The previous P2 MIME-spoofing path is closed: native PDF delivery requires the provider/model/wire gate (packages/runtime/src/model-runtime.ts:213-228, packages/runtime-host/src/server/execution-model-composition.ts:178,411), and the materializer re-sniffs loaded bytes before using the attachment kind and budget (packages/runtime/src/ai-sdk-message-projection.ts:664-726). An image-declared PDF is omitted rather than sent through the vision-only path; the reverse mismatch is also omitted. The new tests cover both. I found no substantiated P0–P3 issue in this head's PDF path. The prior missing ASF header is fixed, and the synthetic merge with current main is clean.
Validation: Node 24 clean npm ci, build:test, 25 focused PDF/wire/storage tests, two focused Host PDF/image integration tests, ASF-header check, and git diff --check passed. An unrelated Host managed-Bash test failed in a broader 49-test selection on this machine (execution-model-composition.test, expected true, got false); I have not established its baseline cause. Current-head GitHub CI and Release Windows runs are action_required and started no jobs, so hosted validation is unavailable; a maintainer needs to authorize them. I did not run protected live-provider calls or a packaged Desktop upload flow. No schema/migration change is in this PR. This is not a merge approval.
Automated review notice: This comment was posted by an automated review agent operated by hqhq1025. It is not an independent human review and does not replace one.
Astro-Han
left a comment
There was a problem hiding this comment.
Review at 09593241. The earlier gate bypass is fixed: the gate now re-sniffs the loaded bytes, so an attachment declared as an image can no longer carry PDF bytes. The new PDF, contract and request-shape tests pass locally (16/16). Two issues remain before this is safe to ship.
P2: a PDF the provider rejects breaks every later turn in the session. The only checks are byte size and the %PDF- marker. Replay re-sends every PDF from history on each turn (appendAttachmentParts from the replay path, called via buildPriorMessages). Nothing checks page count.
- If a user attaches a PDF of about 3 MiB with more than 100 pages, Anthropic and OpenAI reject it with a 400. That 400 is not classified as a context overflow, so no recovery runs, and every later message fails the same way until a compaction folds that event.
- Existing sessions are affected too. Sessions that already hold PDF attachments, which were previously sent only as text references, will start sending native PDF bytes on their first turn after upgrade, with no user action.
- Token estimation still counts only the reference text for attachments, so compaction does not trigger early to make room for PDF pages.
Possible fixes:
- On a provider rejection, drop the PDF on replay (or degrade it to a reference) and remember that decision.
- Only send native PDFs from history for attachments added after this change.
P2: older PDFs in history use up the budget before the PDF on the current message. History is materialized first (buildPriorMessages), then the current message (buildCurrentUserContent). The budget is first-come, first-served.
- If turn 1 sends a 10 MiB PDF A and turn 2 sends a 10 MiB PDF B, then from turn 2 on the model receives the old PDF A plus a note that B was omitted. That is the opposite of what the user expects.
- The combined cap works the same way: a 12 MiB image in history blocks any new PDF larger than 6 MiB.
- Every step of a turn also re-uploads up to 18 MiB of history.
The fix is to reserve the budget for the current message's attachments first, then fill it with history, newest first.
P3s are inline. The compatibility epoch is unchanged (198), which is fine because the host protocol is untouched.
Not covered by tests: priority between history and current attachments, a PDF read that throws, replay after a provider rejection, and the fallback when neither sniffing nor the reader yields a type.
Automated review (Claude lineage, posted from the Astro-Han account). No approval implied.
| decisionKeyPrefix === undefined ? undefined : `${decisionKeyPrefix}:image:${index}`; | ||
| if (!this.chargeImageBudget(budget, read.bytes.length, decisionKey)) { | ||
| omittedByBudget += 1; | ||
| const mediaType = sniffAttachmentMimeType(read.bytes) ?? read.mimeType ?? attachment.mimeType; |
There was a problem hiding this comment.
P3: when neither sniffAttachmentMimeType nor the reader returns a type, this uses the declared attachment.mimeType, so non-PDF bytes can go out as application/pdf. The durable storage reader fails closed, but the session_context reader and custom readers don't. Treating an undetectable type as a mismatch for pdf would keep the gate fail-closed.
Separately, when the bytes don't match the declared kind, the decision isn't cached under decisionKey, so each rebuild re-reads the file (up to 50 MiB) only to drop it again.
| if (keep) budget.used += bytes; | ||
| if (decisionKey !== undefined) budget.decisions.set(decisionKey, keep); | ||
| return keep; | ||
| const subtypeLimit = |
There was a problem hiding this comment.
P2 (see the review body): a first-come budget means PDFs replayed from history are charged before the current message's attachment.
| decision: 'image_limit' | 'pdf_limit' | 'combined_limit', | ||
| ): string { | ||
| return decision === 'combined_limit' | ||
| ? `Image was read, but the combined image/PDF request budget (${MAX_PROVIDER_BINARY_REQUEST_BYTES / 1024 / 1024}MB across all binary attachments this turn) was exceeded; earlier attachments were sent and this one was omitted. Read fewer or smaller attachments.` |
There was a problem hiding this comment.
P3: this message always prints the default MAX_PROVIDER_BINARY_REQUEST_BYTES, even when maxProviderBinaryRequestBytes is overridden.
| if (connection.providerType !== 'anthropic' && connection.providerType !== 'openai') { | ||
| return false; | ||
| } | ||
| if (!resolveModelPdfSupport(connection.providerType, connection.models, modelId)) return false; |
There was a problem hiding this comment.
P3: this gate ignores a custom baseUrl. An anthropic/openai connection pointed at a relay counts as first-party here, although the PR description says relay routes fail closed. The desktop UI can't create such connections, but the host protocol accepts them.
Also, the doc comment at line 210 (Native OpenAI lanes keep mutable continuation state…) now sits above this function, and modelUsesNativeOpenAiResponses has lost it.
Gate PDF byte materialization on explicit first-party provider and wire contracts, then share the durable attachment path across current turns, replay, steering, and compaction. Add PDF and combined binary budgets plus exact provider-wire and fail-closed regression coverage. Generated-by: OpenAI Codex
0959324 to
ec74589
Compare
hqhq1025
left a comment
There was a problem hiding this comment.
Reviewed exact head ec74589043b2239726013edb4b72a3e25153f065.
The new revision reserves binary budget for the current user message before history (ai-sdk-turn.ts:1166-1181), then admits newer historical user attachments before older ones while preserving prompt order (ai-sdk-message-projection.ts:471-496,559-579). It also omits a PDF whose loaded MIME cannot be verified and restricts native PDF delivery to the official first-party endpoint (ai-sdk-message-projection.ts:749-765, model-runtime.ts:211-248). These changes close the previous history-first omission path and narrow the trust boundary.
P2 remains from the earlier review (pullrequestreview-5343606508): native PDF admission still checks media type and byte budgets, not page count (ai-sdk-message-projection.ts:749-780). A PDF over the first-party providers' page limit can be sent and rejected despite fitting the byte cap. The same attachment is materialized into later replay (ai-sdk-message-projection.ts:471-496), while recovery is limited to context_overflow (ai-sdk-turn.ts:1991-1999), so the rejection can recur on subsequent turns. This revision does not add page-limit preflight or a bounded fallback. I am not duplicating the earlier inline finding.
Local Node 24 build:test, 266 focused runtime tests, ASF header check, diff-check, and merge-tree against current main passed. Hosted test and package checks were still running at publication. I did not exercise a live provider, Desktop upload flow, or a >100-page PDF against a provider. No schema or migration changes were found.
Automated review notice: This comment was posted by an automated review agent operated by hqhq1025. It is not an independent human review and does not replace one.
|
This pull request has had no new commits for 30 days and has been marked stale. It will be closed in 7 days unless a new commit is pushed. Comments do not reset this timer: only a new commit does. If the pull request is intentionally long-lived, a maintainer can apply the |
|
This pull request has been closed because it received no new commits during the 7-day grace period. This is not a judgement on the merit of the change; it only keeps the review queue aligned with work that is actively in flight. The branch and review history are preserved. Push a new commit and reopen the pull request whenever the work is ready to continue. |
Summary
mainuses RuntimeEvents as the model-history authority and no longer recovers provider history from StoredMessages.document, OpenAI Chatfile, and OpenAI Responsesinput_file, including a Host-to-provider streaming integration test.Fixes #3164
Verification
npm run build:test— all workspaces built successfully after applying the repository's dependency patches.npm run typecheck— all workspace typechecks passed.git diff --check— passed.Protected OpenAI/Anthropic live calls were not run because provider credentials were unavailable. The exact request bodies are covered against the locked SDK adapters, and the Host test exercises durable artifact storage, backend construction, streaming transport, and OpenAI Chat wire serialization without an external credential. A 16 MiB PDF request-observation measurement completed in 39 ms locally and produced only a short size summary; this is one-machine evidence, not a cross-platform benchmark. The full cross-platform test command was not run locally. The preceding head passed upstream CI and Release Windows checks. Runs for this updated head are
action_requiredwith no jobs started; an authorized maintainer must enable them. Independent human review is still required.Review focus
The provider/wire contract is narrower than SDK encoding support: a compatible relay does not receive raw PDF bytes merely because its adapter can serialize a file part. Budget accounting uses bytes actually read, does not charge failed reads, and applies one combined cap before Base64 expansion. Current request-composition telemetry exposes sizes without storing raw attachment content. The prior StoredMessage fallback claim was removed because current
mainexplicitly makes RuntimeEvents authoritative for model history. Deterministic PDF structure, encryption, and page-limit preflight remain in #3284; provider-rejection evidence and bounded fallback remain in #3285. Per #3164, these are follow-ups rather than first-slice merge gates.AI use
Select exactly one:
Tool(s) and scope: OpenAI Codex assisted with issue and review analysis, implementation, tests, local verification, and PR drafting. @tianrking requested the contribution and remains the human contributor of record.
Checklist
Does this PR entail a change in behavior?