Skip to content

fix(opencode): support encrypted_content and previous_response_id for OpenAI flows#23496

Open
Maaannnn wants to merge 3 commits intoanomalyco:devfrom
Maaannnn:feat/encrypted_content
Open

fix(opencode): support encrypted_content and previous_response_id for OpenAI flows#23496
Maaannnn wants to merge 3 commits intoanomalyco:devfrom
Maaannnn:feat/encrypted_content

Conversation

@Maaannnn
Copy link
Copy Markdown

@Maaannnn Maaannnn commented Apr 20, 2026

Issue for this PR

Closes #20847

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

This PR fixes two OpenAI replay gaps in packages/opencode.

  • On the OpenAI Responses path, it persists openai.responseId on step-finish parts and reuses it as previous_response_id on later matching turns.
  • On the OpenAI-compatible completions path, it captures streamed encrypted_content from raw chunks, stores it on reasoning metadata, and folds it back into replayed assistant messages.

It also adds regression tests for the two riskiest mock-only cases: automatic previous_response_id reuse in the prompt loop, and repeated raw chunks keeping the latest encrypted_content value.

How did you verify your code works?

  • bun test --timeout 30000 test/provider/transform.test.ts test/session/message-v2.test.ts test/session/processor-effect.test.ts test/session/llm.test.ts
  • bun test --timeout 30000 test/session/prompt-effect.test.ts -t "loop automatically reuses previous_response_id for matching OpenAI responses turns"
  • bun typecheck

Key coverage added in this PR:

  • test/session/processor-effect.test.ts
    Verifies multiple raw chunks keep the latest encrypted_content on reasoning metadata.
  • test/session/prompt-effect.test.ts
    Verifies the next matching OpenAI Responses turn automatically sends previous_response_id.

Screenshots / recordings

Not applicable.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions bot added needs:compliance This means the issue will auto-close after 2 hours. needs:title labels Apr 20, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Hey! Your PR title Support encrypted_content and previous_response_id for OpenAI flows doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@github-actions
Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

I found some related PRs that address similar OpenAI functionality:

  1. PR fix(opencode): wire OpenAI previous_response_id session caching #20848: "fix(opencode): wire OpenAI previous_response_id session caching"

  2. PR fix: reuse OpenAI Responses previous_response_id across turns #22149: "fix: reuse OpenAI Responses previous_response_id across turns"

These PRs appear to cover overlapping functionality with the current PR #23496 regarding previous_response_id handling. You may want to verify if PR #23496 is a continuation/enhancement of these earlier efforts or if there are unresolved gaps they didn't address (like the encrypted_content aspect).

@Maaannnn Maaannnn changed the title Support encrypted_content and previous_response_id for OpenAI flows fix(opencode): support encrypted_content and previous_response_id for OpenAI flows Apr 20, 2026
@github-actions github-actions bot removed needs:compliance This means the issue will auto-close after 2 hours. needs:title labels Apr 20, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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.

Bug: OpenAI responses API does not send previous_response_id in multi-turn sessions

1 participant