Skip to content

fix(transcript): disable OpenAI tool-use pairing repair - #61337

Closed
VictorJeon wants to merge 1 commit into
openclaw:mainfrom
VictorJeon:fix/openai-replay-pairing
Closed

VictorJeon wants to merge 1 commit into
openclaw:mainfrom
VictorJeon:fix/openai-replay-pairing

Conversation

@VictorJeon

Copy link
Copy Markdown

Summary

  • disable repairToolUseResultPairing for OpenAI-compatible replay policy
  • keep allowSyntheticToolResults false for OpenAI-compatible models
  • add transcript-policy coverage for openai-responses and openai-codex-responses

Why

For OpenAI/Codex response sessions, replay-time tool-use/result pairing repair can synthesize missing tool results into the transcript. In the harness flow this poisoned resumed sessions after gateway restart/turn interruption and broke checkpoint recovery with synthetic error tool results.

Observed live symptom locally before the fix:

  • harness_execute resumed flows were getting replay-poisoned by synthetic missing tool results
  • current-session recovery only became stable after disabling OpenAI pairing repair locally

Verification

  • targeted source test passed:
    • pnpm exec vitest run --config vitest.config.ts --project agents src/agents/transcript-policy.test.ts
  • live local validation after equivalent runtime patch:
    • harness_execute returned Run: resumed from checkpoint for a recoverable checkpoint smoke in an OpenAI session

Scope

This change is intentionally narrow:

  • Anthropic/Google pairing repair behavior remains unchanged
  • OpenAI-compatible replay still keeps its existing sanitization and tool-call-id handling

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Apr 5, 2026

@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.

Reviewed commit: 7c8c258c50

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

return {
sanitizeToolCallIds: true,
toolCallIdMode: "strict",
repairToolUseResultPairing: false,

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.

P1 Badge Disable repair in OpenAI-owned replay policy

Setting repairToolUseResultPairing: false here does not affect the OpenAI/OpenAI-Codex providers that the change is targeting, because those providers build replay policy via buildOpenAIReplayPolicy in extensions/openai/replay-policy.ts (which still omits this field), and resolveTranscriptPolicy then falls back to DEFAULT_TRANSCRIPT_POLICY.repairToolUseResultPairing === true. In practice, OpenAI response sessions will still run pairing repair and can still synthesize the problematic tool results after resume/replay, so the fix is not applied where intended.

Useful? React with 👍 / 👎.

@greptile-apps

greptile-apps Bot commented Apr 5, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR disables repairToolUseResultPairing for OpenAI-compatible replay sessions to prevent synthetic error tool results from poisoning checkpoint recovery in resumed harness flows.

The change correctly updates buildOpenAICompatibleReplayPolicy in src/plugins/provider-replay-helpers.ts, which benefits all providers using the openai-compatible replay family (xai, ollama, moonshot, fireworks, zai). However, the openai and openai-codex providers — the stated targets of the fix — use a separate buildOpenAIReplayPolicy function in extensions/openai/replay-policy.ts that was not updated. This means the production bug the PR intends to fix remains live for openai and openai-codex sessions. The new test in transcript-policy.test.ts passes because its mock hardcodes the desired behavior, masking the divergence from the actual plugin code.

  • src/plugins/provider-replay-helpers.ts: repairToolUseResultPairing: false correctly added to buildOpenAICompatibleReplayPolicy — fixes the openai-compatible family providers
  • extensions/openai/replay-policy.ts: Not updated — buildOpenAIReplayPolicy still does not set repairToolUseResultPairing: false, leaving the regression active for openai and openai-codex providers
  • src/agents/transcript-policy.test.ts: New test mocks the provider runtime with the desired behavior, but the mock does not reflect the real buildOpenAIReplayPolicy output and therefore does not catch the gap

Confidence Score: 1/5

Do not merge — the stated regression for openai and openai-codex providers is not fixed by this PR; the production replay policy for those providers was not updated.

The fix lands in the wrong function. buildOpenAICompatibleReplayPolicy is not used by the openai/openai-codex providers; their actual buildOpenAIReplayPolicy still omits repairToolUseResultPairing: false, so mergeTranscriptPolicy defaults to repairToolUseResultPairing: true in production. The new test's mock hides this divergence.

extensions/openai/replay-policy.ts must add repairToolUseResultPairing: false to buildOpenAIReplayPolicy; extensions/openai/openai-provider.test.ts (lines 306-312) must be updated to assert the new field in the expected policy object.

Comments Outside Diff (1)

  1. extensions/openai/replay-policy.ts, line 9-24 (link)

    P0 Fix not applied to the actual OpenAI/Codex replay policy

    The PR disables repairToolUseResultPairing in buildOpenAICompatibleReplayPolicy (src/plugins/provider-replay-helpers.ts), but the openai and openai-codex providers register buildOpenAIReplayPolicy from this file as their buildReplayPolicy hook (see extensions/openai/openai-provider.ts:244 and extensions/openai/openai-codex-provider.ts:309). buildOpenAIReplayPolicy is not the same as buildOpenAICompatibleReplayPolicy and was not updated in this PR.

    As a result, mergeTranscriptPolicy still falls back to the default repairToolUseResultPairing: true (from DEFAULT_TRANSCRIPT_POLICY) for all openai and openai-codex sessions — exactly the behavior the PR intends to fix. The harness checkpoint recovery regression described in the PR description remains active in production for these providers.

    This is confirmed by the existing contract test in extensions/openai/openai-provider.test.ts (lines 300-312), which shows the expected policy for openai-codex-responses has no repairToolUseResultPairing field and was not updated by this PR.

    The contract test at extensions/openai/openai-provider.test.ts:306-312 should also be updated to assert repairToolUseResultPairing: false in the expected policy object.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: extensions/openai/replay-policy.ts
    Line: 9-24
    
    Comment:
    **Fix not applied to the actual OpenAI/Codex replay policy**
    
    The PR disables `repairToolUseResultPairing` in `buildOpenAICompatibleReplayPolicy` (`src/plugins/provider-replay-helpers.ts`), but the `openai` and `openai-codex` providers register `buildOpenAIReplayPolicy` from **this file** as their `buildReplayPolicy` hook (see `extensions/openai/openai-provider.ts:244` and `extensions/openai/openai-codex-provider.ts:309`). `buildOpenAIReplayPolicy` is **not** the same as `buildOpenAICompatibleReplayPolicy` and was not updated in this PR.
    
    As a result, `mergeTranscriptPolicy` still falls back to the default `repairToolUseResultPairing: true` (from `DEFAULT_TRANSCRIPT_POLICY`) for all `openai` and `openai-codex` sessions — exactly the behavior the PR intends to fix. The harness checkpoint recovery regression described in the PR description remains active in production for these providers.
    
    This is confirmed by the existing contract test in `extensions/openai/openai-provider.test.ts` (lines 300-312), which shows the expected policy for `openai-codex-responses` has no `repairToolUseResultPairing` field and was not updated by this PR.
    
    
    
    The contract test at `extensions/openai/openai-provider.test.ts:306-312` should also be updated to assert `repairToolUseResultPairing: false` in the expected policy object.
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: extensions/openai/replay-policy.ts
Line: 9-24

Comment:
**Fix not applied to the actual OpenAI/Codex replay policy**

The PR disables `repairToolUseResultPairing` in `buildOpenAICompatibleReplayPolicy` (`src/plugins/provider-replay-helpers.ts`), but the `openai` and `openai-codex` providers register `buildOpenAIReplayPolicy` from **this file** as their `buildReplayPolicy` hook (see `extensions/openai/openai-provider.ts:244` and `extensions/openai/openai-codex-provider.ts:309`). `buildOpenAIReplayPolicy` is **not** the same as `buildOpenAICompatibleReplayPolicy` and was not updated in this PR.

As a result, `mergeTranscriptPolicy` still falls back to the default `repairToolUseResultPairing: true` (from `DEFAULT_TRANSCRIPT_POLICY`) for all `openai` and `openai-codex` sessions — exactly the behavior the PR intends to fix. The harness checkpoint recovery regression described in the PR description remains active in production for these providers.

This is confirmed by the existing contract test in `extensions/openai/openai-provider.test.ts` (lines 300-312), which shows the expected policy for `openai-codex-responses` has no `repairToolUseResultPairing` field and was not updated by this PR.

```suggestion
export function buildOpenAIReplayPolicy(ctx: ProviderReplayPolicyContext): ProviderReplayPolicy {
  return {
    sanitizeMode: "images-only",
    applyAssistantFirstOrderingFix: false,
    validateGeminiTurns: false,
    validateAnthropicTurns: false,
    repairToolUseResultPairing: false,
    ...(ctx.modelApi === "openai-completions"
      ? {
          sanitizeToolCallIds: true,
          toolCallIdMode: "strict" as const,
        }
      : {
          sanitizeToolCallIds: false,
        }),
  };
}
```

The contract test at `extensions/openai/openai-provider.test.ts:306-312` should also be updated to assert `repairToolUseResultPairing: false` in the expected policy object.

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: src/agents/transcript-policy.test.ts
Line: 231-247

Comment:
**Test mock diverges from the real production `buildOpenAIReplayPolicy`**

This test passes because the mock at the top of the file hardcodes `repairToolUseResultPairing: false` for the `openai`/`openai-codex` cases. However, the actual production `buildOpenAIReplayPolicy` in `extensions/openai/replay-policy.ts` does **not** set this field — confirmed by the unmodified contract test in `extensions/openai/openai-provider.test.ts` (lines 300-312) which asserts the returned policy contains no `repairToolUseResultPairing` key.

This test validates `resolveTranscriptPolicy`'s merge behavior correctly given the right plugin input, but it masks the fact that the real plugin does not produce `repairToolUseResultPairing: false`. The production regression therefore goes undetected.

A more robust approach would be to add an assertion directly to the existing replay-policy contract test in `extensions/openai/openai-provider.test.ts` so it locks the real `buildOpenAIReplayPolicy` output and catches this gap.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "fix(transcript): disable OpenAI tool-use..." | Re-trigger Greptile

Comment on lines +231 to +247
it("disables tool-use/result pairing repair for OpenAI-compatible replay", () => {
const openAiResponsesPolicy = resolveTranscriptPolicy({
provider: "openai",
modelId: "gpt-5.4",
modelApi: "openai-responses",
});
const codexResponsesPolicy = resolveTranscriptPolicy({
provider: "openai-codex",
modelId: "gpt-5.4",
modelApi: "openai-codex-responses",
});

expect(openAiResponsesPolicy.repairToolUseResultPairing).toBe(false);
expect(openAiResponsesPolicy.allowSyntheticToolResults).toBe(false);
expect(codexResponsesPolicy.repairToolUseResultPairing).toBe(false);
expect(codexResponsesPolicy.allowSyntheticToolResults).toBe(false);
});

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.

P1 Test mock diverges from the real production buildOpenAIReplayPolicy

This test passes because the mock at the top of the file hardcodes repairToolUseResultPairing: false for the openai/openai-codex cases. However, the actual production buildOpenAIReplayPolicy in extensions/openai/replay-policy.ts does not set this field — confirmed by the unmodified contract test in extensions/openai/openai-provider.test.ts (lines 300-312) which asserts the returned policy contains no repairToolUseResultPairing key.

This test validates resolveTranscriptPolicy's merge behavior correctly given the right plugin input, but it masks the fact that the real plugin does not produce repairToolUseResultPairing: false. The production regression therefore goes undetected.

A more robust approach would be to add an assertion directly to the existing replay-policy contract test in extensions/openai/openai-provider.test.ts so it locks the real buildOpenAIReplayPolicy output and catches this gap.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/transcript-policy.test.ts
Line: 231-247

Comment:
**Test mock diverges from the real production `buildOpenAIReplayPolicy`**

This test passes because the mock at the top of the file hardcodes `repairToolUseResultPairing: false` for the `openai`/`openai-codex` cases. However, the actual production `buildOpenAIReplayPolicy` in `extensions/openai/replay-policy.ts` does **not** set this field — confirmed by the unmodified contract test in `extensions/openai/openai-provider.test.ts` (lines 300-312) which asserts the returned policy contains no `repairToolUseResultPairing` key.

This test validates `resolveTranscriptPolicy`'s merge behavior correctly given the right plugin input, but it masks the fact that the real plugin does not produce `repairToolUseResultPairing: false`. The production regression therefore goes undetected.

A more robust approach would be to add an assertion directly to the existing replay-policy contract test in `extensions/openai/openai-provider.test.ts` so it locks the real `buildOpenAIReplayPolicy` output and catches this gap.

How can I resolve this? If you propose a fix, please make it concise.

@vincentkoc

Copy link
Copy Markdown
Member

Closing this as superseded by #61556.

The review on this branch is correct: it disables pairing repair on the wrong replay helper and does not actually touch the production OpenAI / OpenAI Codex replay policy. The canonical path is #61556, which fixes the real transport/replay ownership seam instead of partially changing the shared compat helper.

Thanks for chasing the transcript issue here.

@vincentkoc vincentkoc closed this Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants