Skip to content

feat: preserve host model invocation context through output protection - #704

Merged
danny-avila merged 1 commit into
mainfrom
danny-avila/sdk-model-context
Nov 17, 2026
Merged

danny-avila merged 1 commit into
mainfrom
danny-avila/sdk-model-context

Conversation

@danny-avila

Copy link
Copy Markdown
Collaborator

Summary

Provider-text protection intentionally withholds the raw callback manager from the underlying model. That also removed the model run ID needed by remote host-model services to correlate input admission with the SDK graph. Preserve a small, read-only invocation context independently of callbacks so both protections can compose.

HostModelService.invoke and stream accept an optional third argument, { version: 1, runId }. HostChatModel.invocationContextVersion = 1 advertises support. An internal WeakMap associates context with the exact protected options object; it adds no provider parameters and uses no ambient async context. Raw output callbacks remain suppressed. Two-argument services keep working, and direct low-level calls without a native invocation have no inferred identity.

Related to LibreChat-AI/LibreChat#18271. This is SDK source only: no version bump, tag, or publication. Release work remains separate.

Validation

  • 388 tests across host models, output boundaries, Langfuse and deterministic trace identity.
  • New real-model tests cover concurrent invoke/stream calls, nested protection, immutable context, no context inherited by later direct calls, and output rejection without raw callback disclosure.
  • npx tsc --noEmit, scoped ESLint/import sorting, production CJS/ESM/declaration build and circular-dependency check passed.

Contract and limits

The run ID is correlation only, never authorization. Transports still authenticate execution identity, verify root callback lineage, negotiate support and own cancellation/recovery. This does not automatically wire product policy, billing or tracing. The corresponding LibreChat adapter is stacked on #18271 and will negotiate the additive capability during rollout.

Copy link
Copy Markdown
Collaborator Author

@codex review

Please review the current PR head c14bfb8. Confirm that this exact commit is the reviewed commit and ignore findings that apply only to earlier heads. Please check callback confidentiality, per-invocation context isolation and backward compatibility of the optional host service argument.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-17T18:51:49.342972Z c14bfb8 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: c14bfb8b68

ℹ️ 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 abfed1b into main Nov 17, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant