Skip to content

Filter out reasoning items from previous turns - #5857

Merged
pakrym-oai merged 7 commits into
mainfrom
pakrym/filter-out-reasoning-item-from-previous-turns
Oct 28, 2025
Merged

pakrym-oai merged 7 commits into
mainfrom
pakrym/filter-out-reasoning-item-from-previous-turns

Conversation

@pakrym-oai

Copy link
Copy Markdown
Contributor

Reduces request size and prevents 400 errors when switching between API orgs.

Based on Responses API behavior described in https://cookbook.openai.com/examples/responses_api/reasoning_items#caching

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

Copy link
Copy Markdown
Contributor

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.

ℹ️ 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".

…visible_history

- Move filtering logic for prompt input from filter_model_visible_history to ConversationHistory::get_history_for_prompt.
- Update all relevant call sites to use get_history_for_prompt instead of get_history and filtering.
- Remove now-unused filter_model_visible_history.
…access

Eliminate SessionState::history_snapshot and Session::history_snapshot; refactor call sites to use clone_history().get_history*() as appropriate. Update tests and compact task logic for consistency.
- Added get_history_for_prompt_drops_ghost_commits test to verify ghost commits are filtered out
- Fixed test usage to call get_history_for_prompt instead of get_history
sess.record_conversation_items(&turn_context, &pending_input)
.await;
sess.history_snapshot().await
sess.clone_history().await.get_history_for_prompt()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

history_snapshot was doing the same effective clonning but clone_history give us more flexibility

@jif-oai jif-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you add an integration test?

else {
return;
};
let mut index = 0usize;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This pattern is pretty strange but I guess retain_mut is not stable yet so good for now

}

let history = sess.history_snapshot().await;
let history = sess.clone_history().await.get_history();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

NIT: The verbosity here is pretty strange. clone_history should conceptually return an "history"
Out of scope for this PR but there is something strange

…ring

- Add inputs_of_type(&self, ty: &str) -> Vec<Value> to ResponsesRequest for type-based filtering of input items
- Add cached_prompt_filters_reasoning_items_from_previous_turns test to prompt_caching.rs to verify prior reasoning items are filtered from cached prompts
@pakrym-oai

Copy link
Copy Markdown
Contributor Author

Can you add an integration test?

Done.

@pakrym-oai
pakrym-oai merged commit 1b8f254 into main Oct 28, 2025
@pakrym-oai
pakrym-oai deleted the pakrym/filter-out-reasoning-item-from-previous-turns branch October 28, 2025 18:39

@aibrahim-oai aibrahim-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AWESOME

@github-actions github-actions Bot locked and limited conversation to collaborators Oct 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants