Skip to content

Add native OpenAI compaction to LanguageModel - #8893

Closed
danieljvdm wants to merge 1 commit into
Effect-TS:mainfrom
danieljvdm:feat/native-openai-compaction-01a11798
Closed

danieljvdm wants to merge 1 commit into
Effect-TS:mainfrom
danieljvdm:feat/native-openai-compaction-01a11798

Conversation

@danieljvdm

Copy link
Copy Markdown
Collaborator

Summary

Add LanguageModel.compact and atomic opaque-context parts to the shared AI model. The OpenAI adapter sends JSON to the stateless /responses/compact endpoint and returns the complete replacement prompt, effective provider/model affinity, and usage. Use result.prompt as the next input window rather than appending it to the old history.

Retained text messages, reasoning, ordinary function calls/string results, and compaction items round-trip without reordering or rewriting wire strings. Ordinary results belong in tool messages. Unsupported items and extensions fail instead of being dropped, with independently readable usage preserved even when returned context or usage detail is invalid. Providers without a compaction hook reject opaque-context inference before transport.

Replay requires the same effective provider/model and the complete returned window. Compaction does not execute historical tools, change Chat history, or update response-ID tracking. Conversation, previous-response, and explicit item-reference shortcuts are incompatible with native context; the original input must still fit the model's context window.

Validation

The transport/complete/streaming decoder regressions, affected runtime and type checks, and a local HTTP workflow pass. The workflow checks the entire ordered replacement window through Prompt serialization, repeated compaction, and text/structured/streamed replay, including affinity rejection and usage-preserving failures.

Bounded live OpenAI workflows with gpt-5.4-mini verified standalone compaction, exact Prompt serialization, and next-inference replay for provider-generated and portable history. The final usage validator received an additional compact-only check: six paid requests in total. These checks establish availability and replay for those inputs, not compaction quality, speed, or token savings.

Limits and release notes

The configured Stainless spec URL returns 404. The generation source now pins a public OpenAI snapshot, and only the compact transport delta was regenerated. Full provider regeneration remains blocked by the existing JSON-Schema importer's CreateAssistantRequest.tool_resources.file_search intersection handling. The compact transport change overlaps one hunk of #6678; this does not import its broad refresh.

The changesets request a minor release for effect and @effect/ai-openai. These APIs are unreleased; downstream publication requires a release containing them and matching dependency requirements. Custom services must supply the new compact or compactResponse member, and exhaustive matches must handle the compaction part and UnsupportedOperationError reason.

Add provider-neutral compaction and opaque Prompt/Response parts with typed unsupported-operation failures. Preserve the complete OpenAI replacement window, exact model affinity, and available usage on rejection.

Send compact requests as JSON and reject stateful replay shortcuts. Include the narrow generated transport fix and failure-first transport and decoder regressions.
@changeset-bot

changeset-bot Bot commented Oct 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9caf126

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 32 packages
Name Type
effect Minor
@effect/ai-openai Minor
@effect/opentelemetry Minor
@effect/vitest Minor
@effect/ai-anthropic Minor
@effect/ai-cloudflare Minor
@effect/ai-openai-compat Minor
@effect/ai-openrouter Minor
@effect/ai-typesafe Minor
@effect/atom-react Minor
@effect/atom-solid Minor
@effect/atom-vue Minor
@effect/platform-browser Minor
@effect/platform-bun Minor
@effect/platform-deno Minor
@effect/platform-node-shared Minor
@effect/platform-node Minor
@effect/sql-clickhouse Minor
@effect/sql-d1 Minor
@effect/sql-libsql Minor
@effect/sql-mssql Minor
@effect/sql-mysql2 Minor
@effect/sql-pg Minor
@effect/sql-pglite Minor
@effect/sql-sqlite-bun Minor
@effect/sql-sqlite-do Minor
@effect/sql-sqlite-node Minor
@effect/sql-sqlite-react-native Minor
@effect/sql-sqlite-wasm Minor
@effect/docgen Minor
@effect/doctest Minor
@effect/openapi-generator Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@effect-janitor effect-janitor Bot added the 4.0 label Oct 7, 2026
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
arbitrary-combinators.ts 38.79 KB 38.79 KB 0.00 KB (0.00%)
basic.ts 7.06 KB 7.06 KB 0.00 KB (0.00%)
batching.ts 10.14 KB 10.14 KB 0.00 KB (0.00%)
brand.ts 6.73 KB 6.73 KB 0.00 KB (0.00%)
cache.ts 10.89 KB 10.89 KB 0.00 KB (0.00%)
config.ts 22.25 KB 22.25 KB 0.00 KB (0.00%)
differ.ts 21.34 KB 21.34 KB 0.00 KB (0.00%)
http-client.ts 22.67 KB 22.67 KB 0.00 KB (0.00%)
http-router.ts 34.05 KB 34.05 KB 0.00 KB (0.00%)
logger.ts 11.22 KB 11.22 KB 0.00 KB (0.00%)
metric.ts 9.03 KB 9.03 KB 0.00 KB (0.00%)
optic.ts 6.96 KB 6.96 KB 0.00 KB (0.00%)
pubsub.ts 15.18 KB 15.18 KB 0.00 KB (0.00%)
queue.ts 12.13 KB 12.13 KB 0.00 KB (0.00%)
schedule.ts 11.22 KB 11.22 KB 0.00 KB (0.00%)
schema-bigdecimal.ts 13.74 KB 13.74 KB 0.00 KB (0.00%)
schema-binary.ts 40.00 KB 40.00 KB 0.00 KB (0.00%)
schema-class.ts 21.07 KB 21.07 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 32.10 KB 32.10 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 27.28 KB 27.28 KB 0.00 KB (0.00%)
schema-string-transformation.ts 14.48 KB 14.48 KB 0.00 KB (0.00%)
schema-string.ts 12.00 KB 12.00 KB 0.00 KB (0.00%)
schema-template-literal.ts 16.07 KB 16.07 KB 0.00 KB (0.00%)
schema-toArbitrary.ts 38.32 KB 38.32 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 25.30 KB 25.30 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 20.26 KB 20.26 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 20.45 KB 20.45 KB 0.00 KB (0.00%)
schema-toFormatter.ts 20.57 KB 20.57 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 25.03 KB 25.03 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 20.55 KB 20.55 KB 0.00 KB (0.00%)
schema.ts 20.29 KB 20.29 KB 0.00 KB (0.00%)
stm.ts 13.24 KB 13.24 KB 0.00 KB (0.00%)
stream.ts 9.99 KB 9.99 KB 0.00 KB (0.00%)

@tim-smart

Copy link
Copy Markdown
Contributor

As discussed, we will add this at a later point when we get to adding agent primitives.

@tim-smart tim-smart closed this Oct 8, 2026

This branch had an error being deployed

1 failed deployment
fork — 9caf1260 Deployed Oct 7, 2026 by danieljvdm via approval-gate #18146
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants