Skip to content

feat(ai): support server-side response compaction - #43708

Closed
rekram1-node wants to merge 1 commit into
v2from
openresponses-audit
Closed

rekram1-node wants to merge 1 commit into
v2from
openresponses-audit

Conversation

@rekram1-node

Copy link
Copy Markdown
Collaborator

Summary

  • expose OpenAI Responses contextManagement and lower it to context_management
  • retain completed encrypted compaction items in durable provider state
  • replay compaction items for same-model stateless continuation without response-only fields
  • preserve compaction-only assistant outputs through Session history projection

Scope

  • supports in-stream server-side compaction on normal Responses calls
  • does not add the standalone /responses/compact operation

Testing

  • bun typecheck in packages/ai
  • bun run build in packages/ai
  • bun test test/provider/openai-responses.test.ts test/provider/openai-compatible-responses.test.ts in packages/ai (101 pass)
  • bun typecheck in packages/core
  • bun test test/session-runner-message.test.ts in packages/core (22 pass)

@Enough1122

Copy link
Copy Markdown

AI code review — automated review for reference; please use your judgment.

  • packages/ai/src/protocols/open-responses.ts:434 — compactionItems() silently filters out any persisted entry that fails Schema.is, so corrupted or future-schema compaction state disappears without a trace and later requests can fail upstream with confusing "missing item" errors — log (or collect into providerMetadata as a diagnostics field) whenever stored items are discarded during lowering.
  • packages/ai/src/protocols/utils/openai-options.ts:38 — resolve() swallows providerOptions decode failures via Option.getOrElse(() => ({})), meaning a typo like compactThreshold: "100k" disables server-side compaction with zero feedback on a feature whose whole point is invisible context management — either propagate the decode error or emit a one-time warning naming the offending option.
  • packages/core/src/session/runner/to-llm-message.ts:209 — An assistant message that carries ONLY compaction state (meaningful.length === 0, native defined) now survives as an empty-content message; the replay test covers non-empty content, so add a case asserting how lowering handles the truly-empty-content-plus-compaction shape end-to-end — if lowerMessages emits a message item with an empty content array the Responses API may reject the whole request.
  • packages/ai/test/provider/openai-responses.test.ts:1553 — Good happy-path coverage for retaining and replaying compaction items, but the malformed-item guard in onOutputItemDone (missing id or non-string encrypted_content must surface eventError) has no test — one negative case would lock in the validation branch against accidental loosening.
  • packages/ai/src/protocols/openai-responses.ts:139 — context_management entries always materialize a compact_threshold key even when undefined, relying on the serializer to strip undefined values before transport; using conditional spread (...(item.compactThreshold !== undefined ? { compact_threshold: item.compactThreshold } : {})) makes the intent explicit regardless of serialization behavior.

— AI code review (automated)

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants