Skip to content

fix(sessions): reconcile pending input appends - #4776

Open
FU-max-boop wants to merge 6 commits into
openai:mainfrom
FU-max-boop:fix/pending-input-session-reconciliation
Open

fix(sessions): reconcile pending input appends#4776
FU-max-boop wants to merge 6 commits into
openai:mainfrom
FU-max-boop:fix/pending-input-session-reconciliation

Conversation

@FU-max-boop

Copy link
Copy Markdown
Contributor

Summary

  • checkpoint client-managed Session admission before appending resumed RunState.pending_input
  • reconcile atomic failures and lost acknowledgements exactly once, then consume only the checkpoint-owned pending prefix without advancing the current-turn persisted count
  • preserve staged admission items through streaming to_state() and normalize assistant-role ownership across JSON round trips
  • keep pending input fail-closed while its Session write is unresolved

Test plan

Passed locally:

  • pytest -q tests/test_run_state_pending_input.py tests/test_run_impl_resume_paths.py tests/test_runner_guardrail_resume.py — 122 passed
  • serial suite — 77 passed, 4 skipped
  • changed-file Ruff format/check and optional-truthiness check
  • changed-source mypy — clean
  • changed-file Pyright — 0 errors
  • git diff --check

Full locked verification could not complete locally because make sync stalled twice while downloading optional litellm, botocore, and temporalio packages. The fallback reused environment is openai-agents==0.17.0 while this tree is 0.22.0 and lacks multiple optional extras. In that same environment, exact base 89c02c82 reports 8743 passed / 26 failed / 24 collection errors; this branch reports 8753 passed / 27 failed / 24 collection errors. The failure groups are unchanged version-skew or missing-extra surfaces plus one nondeterministic Runloop import failure; none touch the changed files or focused suites. Upstream CI can exercise the frozen lock environment.

Issue number

Fixes #4775

Checks

  • Added regression tests
  • Ran .agents/skills/code-change-verification/scripts/run.sh in the frozen all-extras environment
  • Confirmed every full-repository verification step passes locally
  • Completed an independent Codex review and fixed both findings before submission

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 30, 2026

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review Completed 2026-08-30T05:45:46.742955Z 97c9a62 Manual request
🔒 Security Review Completed 2026-08-30T05:47:10.054246Z 97c9a62 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 chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

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.

Reviewed commit: b2e3048e02

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

Comment thread src/agents/run_state.py Outdated
@FU-max-boop

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: ebacb6c356

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

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

Copy link
Copy Markdown

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.

Reviewed commit: ebacb6c356

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

Comment thread src/agents/run_state.py Outdated
@FU-max-boop

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: b35f30006d

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

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

Copy link
Copy Markdown

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.

Reviewed commit: b35f30006d

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

Comment thread src/agents/run_internal/session_persistence.py Outdated
@FU-max-boop

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: ee0ddafed2

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review


P2 Badge Prefer the exact committed tail before overlap checks

When the pre-append tail overlaps the pending batch—for example, a one-item Session containing "same" receives another identical message—and add_items() commits before raising, the observed [same, same] tail equals expected while its last len(before) items also equal before. This makes both committed and unchanged true, so the next line reports an ambiguous history on every retry even though the exact expected tail proves the append committed. Handle committed first and only test the unchanged suffix otherwise.

AGENTS.md reference: AGENTS.md:L202-L202

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

Comment thread src/agents/run_internal/session_persistence.py Outdated
@FU-max-boop

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: cb9fcdb750

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

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

Copy link
Copy Markdown

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.

Reviewed commit: cb9fcdb750

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

Comment thread src/agents/run_internal/session_persistence.py
@FU-max-boop

Copy link
Copy Markdown
Contributor Author

Follow-up to the duplicate-tail concern in review 5059982645: 97c9a62 adds the safe committed-tail preference, but only when the initial m+1 read proves that the complete pre-append history was observed. In that complete-history case, a lost acknowledgment after appending an item identical to the old tail is recognized exactly once. If the bounded pre-append window was saturated, committed and unchanged can both match after a pre-commit failure, so the retry remains fail-closed instead of blindly accepting committed. Regression tests cover both the one-old-identical lost-ack success and the three-old-identical ambiguous atomic-failure case; the checkpoint and history remain intact in the latter.

@FU-max-boop

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 97c9a62bf4

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

@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: 97c9a62bf4

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@linhongyu510 linhongyu510 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

One remaining ownership issue in the latest reconciliation path: item_reference.id is payload identity, not a response-only envelope ID. The existing sanitizer test explicitly includes item_reference among item types whose required IDs must be preserved, but reconciliation removes that ID unconditionally.

dict[str, Any],
_sanitize_openai_conversation_item(normalized),
)
clean.pop("id", None)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1: Preserve semantic IDs for item_reference during reconciliation

This unconditional removal makes distinct references canonicalize identically:

{"type": "item_reference", "id": "item_A"}
{"type": "item_reference", "id": "item_B"}

Both become {"type": "item_reference"}. After a lost ACK, a checkpoint for item_A can therefore treat a Session tail containing item_B as the committed batch, clear the pending write, and consume the owned pending input even though the referenced item differs.

This conflicts with test_sanitize_preserves_ids_required_by_openai_conversation_items, which correctly lists item_reference as requiring its ID. Please preserve id for item_reference (and ideally remove IDs only for item types confirmed to receive output-only server IDs), with a resume regression asserting item_A vs item_B fails closed before checkpoint/pending-input cleanup.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Confirmed against current head 97c9a62b in an isolated worktree. The existing sanitizer suite passes (38 passed), but the direct reconciliation regression fails exactly as described:

{"a": {"type": "item_reference"},
 "b": {"type": "item_reference"},
 "equal": true}
AssertionError: distinct item_reference IDs canonicalized equally

So the existing required-ID sanitizer test does not cover the later reconciliation canonicalizer. This is reproducible without a remote Session and should be fixable with a focused unit test before the full lost-ACK resume case.

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.

RunState pending input can be duplicated when a Session append loses acknowledgement

2 participants