Skip to content

🪂 feat: Opt-In Text Fallback for Files No Tool Can Read - #15940

Merged
danny-avila merged 15 commits into
devfrom
danny-avila/code-routed-text-fallback
Sep 15, 2026
Merged

danny-avila merged 15 commits into
devfrom
danny-avila/code-routed-text-fallback

Conversation

@danny-avila

@danny-avila danny-avila commented Sep 14, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

I added opt-in text fallback for attachments routed to tools when the agent has no loaded tool that can read their type. Without this, a CSV or spreadsheet can be omitted from the prompt and remain unreadable after a handoff, permission change, or file-search loading failure.

  • Store best-effort extracted text for inferred none message uploads when textFallbackWithoutTools is enabled, including uploads initially assigned to a reading tool.
  • Settle the endpoint identity, custom dialect, and actual Responses API mode before attachment admission. Incorporate 🧭 refactor: Settle Turn Delivery Routing Once in Agent Initialization #15948 so initialization, BaseClient, steering, and child encoders consume one routing snapshot.
  • Materialize turn-local file copies before limits and content inspection. Reconcile file consumers with the final loaded tools and re-admit newly exposed fallback text after a soft failure or retry.
  • Retain authorized root file candidates for each top-level handoff, delivering missing text through its scoped-context checks while preserving isolated-subagent access boundaries and history resend controls.
  • Route live steer uploads using actual reachability: files arriving after resource priming use opt-in fallback, with the same consumer decision carried through admission and encoding.
  • Count referenced inferred fallback text conservatively when resuming a checkpoint, even if fallback was disabled while paused. Checkpoints replay encoded content; a current tool or routing change cannot remove that content. This recount can include stored fallback text whose original delivery is not independently recorded.
  • Preserve chosen destinations, legacy records, default-off behavior, ownership checks, and stored upload routes. Reuse loaded records; add no database queries.
  • Document configuration in librechat.example.yaml.
fileConfig:
  endpoints:
    default:
      defaultLLMDeliveryPath:
        overrides:
          text/csv: none
          application/vnd.openxmlformats-officedocument.spreadsheetml.sheet: none
      textFallbackWithoutTools: true

The setting is also accepted at the top level of fileConfig or under a provider/custom endpoint name. Existing uploads without extracted text are not backfilled. Extraction uses the built-in document/native-text readers, never RAG or OCR; failures, policy refusals, blank text, and the shared 15 MiB storage ceiling leave the primary tool upload intact.

How It Works

upload → infer route → optionally extract/store fallback text
turn   → resolve provider options → settle deliveryRouting
       → materialize files → filter / admit / inspect → prime resources
       → load tools → reconcile consumers → re-admit any new fallback
       → history / handoff / child delivery use each receiver’s routing and consumers
steer  → owner-hydrate late files → no provisioned consumer → fallback / admit / encode
resume → hydrate checkpoint references under owner scope
       → count potentially retained fallback text against current limits

Provider options now resolve before attachment admission. A missing provider key can therefore surface before an invalid attachment; provider resolution does not add another lookup.

Change Type

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Documentation update

Testing

  • Run data-provider resolver and file-config suites: 318 passing.
  • Run packages/api file-sharing, steering, initialization, HITL protection, upload, and file-context suites: 562 passing.
  • Run BaseClient, AgentClient, skill dependencies, and upload-processing suites: 514 passing.
  • Run npx tsc --noEmit in packages/data-provider and packages/api: passing.
  • Run import sorting, ESLint, and whitespace checks on changed files: passing.
  • Run Lighthouse against an isolated local server using a reused client build: the complete run passes, including teardown, with LCP 3.26 s / 4.5 s, CLS 0.039 / 0.1, and TBT 27 ms / 500 ms.
  • Exercise final Azure Responses modes, custom endpoint identity/dialect, successful and failed file search, post-failure text limits, history replay, live and restored steers, per-child routing, owner-scoped checkpoint hydration, changed limits after fallback is disabled, root-tool files handed to a receiver without tools, isolated subagents, disabled history resending, and late uploads with already-loaded tools.

The local API runtime bundle was emitted and used by the tests. Its declaration bundler reported an existing isolatedDeclarations error in unchanged stream/jobStoreCapabilities.ts; the independent workspace typecheck passes. Codex reported no major issues at c300dcc00480e796a708713b59aba211c3b2c5fa (review); all review threads are resolved. CI is tracked separately.

Test Configuration:

macOS, Node 24.16.0, the repository's agents SDK 3.8.7, Jest per workspace. Local focused test selection used graph-assisted source inspection; authenticated Codegraph selection credentials were unavailable.

Checklist

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • I have commented in any complex areas of my code
  • I have made pertinent documentation changes
  • I have written tests demonstrating that my changes are effective or that my feature works
  • Local unit tests pass with my changes

An upload routed to tools (`llmDeliveryPath: none`) reaches nothing when the
agent handling the turn runs neither Run Code nor File Search, or runs one that
cannot read the type. With `fileConfig.endpoints.<endpoint>.textFallbackWithoutTools`
(also accepted at the top level and inherited from `default`), such a turn
delivers the text extracted at upload instead. The setting is off by default,
which keeps today's behavior.

- Upload: when the setting is on and an inferred `none` route finds no reading
  tool, the built-in document parser or native text reader stores the text on
  the file, best effort, under the extracted-text size cap and content policy.
- Turn: `resolveTurnLLMDeliveryPath` re-resolves each inferred route against
  the tools the agent runs, and `applyTurnTextFallback` marks copies of the
  records a turn loads, so endpoint filtering, limits, inspection, history
  replay and steer media all see the text the turn delivers. The stored route
  is never rewritten.
- Explicit destinations, records predating routing, and turns whose tools are
  unknown are left as they are.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-15T00:55:23.641262Z c300dcc Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Head: 9412139

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 94121399b6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/api/src/agents/files/delivery.ts
Uploads route a custom endpoint agent by its saved provider, the endpoint name. initializeAgent marks turn copies before getProviderConfig swaps the provider for the backing client, and the endpoint keeps the name afterward, so the client and child encoders resolve the opt-in under the same endpoint. Cover both the initialization path and the post-initialization agent shape.
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Head: 7ade9f4

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7ade9f4205

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/api/src/files/upload/fallback.ts Outdated
The fallback defined its own copy of the 15 MiB cap context uploads already apply to extracted text. Export MAX_STORED_EXTRACTED_TEXT_BYTES from files/extract and use it in both places, documenting that it bounds what a MongoDB file document can hold rather than operator policy.
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Head: 7cc13c1

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7cc13c16c4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/api/src/files/upload/fallback.ts Outdated
Comment thread packages/api/src/agents/files/delivery.ts Outdated
Comment thread packages/api/src/agents/initialize.ts
Extraction skipped uploads filed under a reading tool, so a handoff agent
without that tool, or the same agent after its tools or grants changed, had
no text to fall back to. Store fallback text for every inferred route on a
message attachment; files kept on an agent's tool resources never reach a
prompt and still skip it.

Turn marking only ran while the fallback was enabled, so a stored tool-routed
record whose type the endpoint now routes to text stayed marked `none` and
`extractFileContext` skipped it. applyTurnTextDelivery (renamed from
applyTurnTextFallback) now marks any stored `none` record with text that the
turn resolves to text, and returns early when no such record is loaded.
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Head: fdac2a8

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fdac2a8eca

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/api/src/agents/files/delivery.ts Outdated
Comment thread api/server/services/Files/process.js Outdated
A record upload routed to tools that the current endpoint sends to the
provider stayed marked `none` on the turn copy, so admission skipped it while
BaseClient encoded its bytes, bypassing attachment count and size limits.
applyTurnDelivery (renamed from applyTurnTextDelivery) now gives every record
whose route upload inferred the route the turn resolves, before endpoint
filtering, limits and inspection, matching the run-file encoder.
hasInferredLLMDeliveryPath shares the inferred-route rule with the resolver.

Fallback extraction selected the document parser inside the CJS upload path.
resolveUploadFallbackText now takes the upload and picks parseDocument or
parseTextNative itself, with the extractors injectable, so process.js passes
request data only. Its tests run the real parser against the xlsx fixture and
the real native reader against temporary files.
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Head: ecbca89

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ecbca890a3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/api/src/files/upload/fallback.ts Outdated
Comment thread packages/api/src/agents/initialize.ts
initializeAgent materializes turn routes before getProviderConfig swaps the
saved custom endpoint name in agent.provider for its backing client, so
routing read that name as a non-OpenAI dialect. Media a custom endpoint opted
into could then be materialized off the provider path, skipping admission,
while the finalized client still sent the bytes. resolveAgentDeliveryRouting
now reads the dialect with getCustomEndpointProvider, as upload does, which
holds before and after the swap.

The upload fallback plan now keys on the chosen-destination marker the turn
resolver reads, so an upload recorded as chosen, including every legacy
chooser upload, never pays for text a turn cannot deliver.
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Head: 4b74b3a

Resolution while initializing and at delivery can disagree: delivery reads a
Responses API choice only the finished client config holds. Applying a route
that takes a record out of admission, off the model path or to text it never
stored, would then skip the limits for a file the client still sends.
applyTurnDelivery now applies a route only while the record stays model-bound;
admitting a record the turn leaves out cannot slip past a limit.
* feat: use declared attached project actions

* Complete named action definitions and approval previews

* Sort named environment imports

* Sort native environment fixture imports
* 🔓 fix: Keep Code Approval Mode Selectable Mid-Run

The composer's code approval mode selector was disabled while a run streamed, and a mode picked during a run was reverted when the final or abort event merged the server conversation back. The selector now stays usable in flight and both merges retain a mid-run selection, which the next send carries.

* 🔓 fix: Retain Mid-Run Approval Mode Across Cache and Recovery

Stamp the live approval mode onto the submission conversation at send so the retention baseline matches what was read, keep a retained mode in the conversation query cache on final and cancel, and rebuild failed or aborted conversations from a preset that carries the mid-run pick.

* 🔓 fix: Scope Retained Approval Mode to the Submitted Conversation

Retention now requires the live conversation to be the one the run submitted, or the id the server assigned to a new chat, so navigating elsewhere mid-run cannot write that conversation's mode back. A single recovery helper rebuilds failed or aborted conversations from the retained preset and patches the detail cache for every recovery site.

* 🔓 refactor: Keep the Local Approval Mode on Every Server Merge

Replace per-path retention with one rule: a locally picked code approval mode is newer than any server copy of the same conversation, so the final and abort merges and the error recovery preset keep it. The selector writes the pick into the conversation's detail cache, which navigation rebuilds from, so the pick is conversation-scoped without reading the index-global atom from the SSE handlers.

* 🔓 fix: Prefer the Live Conversation When Caching the Final Merge

The final handler's detail-cache merge now takes the local approval mode from the open conversation when it is the one that finished, falling back to the cached record only for a conversation that is no longer on screen.

* 🔓 fix: Keep the Local Approval Mode Through Settled-Start Reconciliation

The resumable transport's settled-start reconciliation and replacement handoff wrote a fetched conversation straight into conversation state and the detail cache. Both now apply the same local-mode rule as the event handlers, treating a new chat's pending id as the settled conversation's own.

* 🔓 fix: Seed the Detail Record When a Mode Is Picked

A conversation that has its id but no detail record yet now gets one from the live conversation when a mode is picked, the same key the resumable transport seeds optimistically, so recovery and navigation find the pick. A chat with no id yet still keeps the pick in conversation state alone.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4b74b3a218

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/data-provider/src/resolve-llm-delivery-path.ts
Comment thread packages/api/src/agents/files/delivery.ts
Comment thread packages/api/src/agents/files/delivery.ts
upman and others added 2 commits September 14, 2026 18:45
`initializeAgent` resolved the provider and its client options only after the
turn's files were loaded and admitted, and the two delivery readers each rebuilt
the attachment routing from the agent object at their own moment: `BaseClient`
took the custom-endpoint dialect from the already-swapped `agent.provider`, the
run-file encoder from whatever child config it was handed.

Move `getProviderConfig`/`getOptions` ahead of file discovery, where nothing in
between fed them, and settle one `deliveryRouting` value with every input final:
the file policy under the endpoint's own name, the dialect its config declares,
the Responses API decision the model call uses, and the transcription setting.
`InitializedAgent`, the child encoder and `BaseClient` consume that value;
`resolveTurnLLMDeliveryPath` is the one place a stored route is resolved again.
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Please review the current PR head d20978c. Confirm that this exact commit is the reviewed commit and ignore findings that apply only to earlier heads. This head integrates #15948 and audits the full attachment lifecycle: finalized routing before admission, actual loaded file consumers with post-load fallback admission, historical/steer/child copies, and conservative accounting of retained checkpoint fallback text even after configuration changes.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d20978c865

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread api/app/clients/BaseClient.js
Comment thread packages/api/src/agents/steering/media.ts
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Please review the current PR head b8ed9df. Confirm that this exact commit is the reviewed commit and ignore findings that apply only to earlier heads.

The attachment reachability audit now covers root-tool files delivered into handoff-scoped context, isolation of subagents, retained-history ownership and resend controls, and live steers arriving after tool provisioning. Admission and encoding use the same file-consumer decision; existing scoped topology, limits and inspection remain authoritative. Focused regression suites and the packages/api typecheck pass.

@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Please review the current PR head c300dcc. Confirm that this exact commit is the reviewed commit and ignore findings that apply only to earlier heads. This supersedes the previous request: the only intervening change types an untrusted-reference test fixture. The completed workspace typecheck and focused test pass; runtime fixes and the passing Lighthouse run are unchanged.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: c300dcc004

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danny-avila
danny-avila merged commit 2ffee7e into dev Sep 15, 2026
39 checks passed
@danny-avila
danny-avila deleted the danny-avila/code-routed-text-fallback branch September 15, 2026 01:02
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