Skip to content

fix(replay): preserve synthetic tool repair aliases - #66447

Merged
vincentkoc merged 2 commits into
mainfrom
vk/pr-61556-main
Apr 24, 2026
Merged

vincentkoc merged 2 commits into
mainfrom
vk/pr-61556-main

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

Summary

Describe the problem and fix in 2–5 bullets:

  • Problem: replay repair logic for synthetic tool results only recognized older provider API names and could miss current alias transports.
  • Why it matters: replayed transcripts can lose tool-repair recovery on supported alias transports, which distorts follow-up agent behavior.
  • What changed: keep the current repair flow but explicitly recognize the supported Anthropic/Google alias transport names, add regression coverage, and carry the missing changelog entry.
  • What did NOT change (scope boundary): no broader transcript replay policy or pending-tool-call flow was rewritten.
  • Supersedes fix(transport): disable synthetic tool results for OpenAI #61556.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

Root Cause (if applicable)

  • Root cause: synthetic tool-result repair matched only a narrower providerApi set than the runtime now emits after transport aliasing.
  • Missing detection / guardrail: there was no focused regression coverage for replay repair across the alias transport names now used in practice.
  • Contributing context (if known): provider transport naming has grown compat aliases while the replay repair check stayed too literal.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: src/agents/transport-message-transform.test.ts
  • Scenario the test should lock in: replay repair still triggers for supported Anthropic/Google alias transport names.
  • Why this is the smallest reliable guardrail: the bug lives in transcript transform branching and is fully exercised with targeted unit coverage.
  • Existing test that already covers this (if any): src/agents/transcript-policy.test.ts covers adjacent replay policy, but not these aliases.
  • If no new test is added, why not: N/A.

User-visible / Behavior Changes

Replay repair once again works for the supported alias transports instead of silently skipping the synthetic tool-result fixup.

Diagram (if applicable)

N/A

Security Impact (required)

  • New permissions/capabilities? (Yes/No) No
  • Secrets/tokens handling changed? (Yes/No) No
  • New/changed network calls? (Yes/No) No
  • Command/tool execution surface changed? (Yes/No) No
  • Data access scope changed? (Yes/No) No
  • If any Yes, explain risk + mitigation: N/A

Repro + Verification

Environment

  • OS: macOS
  • Runtime/container: Node 22 / pnpm test:serial
  • Model/provider: Anthropic / Google transport replay
  • Integration/channel (if any): Agents replay pipeline
  • Relevant config (redacted): targeted fixture/test doubles only

Steps

  1. Replay a transcript containing synthetic tool results on a supported alias transport.
  2. Run pnpm test:serial src/agents/transport-message-transform.test.ts src/agents/transcript-policy.test.ts.
  3. Confirm the repair path still produces the expected synthetic tool result structure.

Expected

  • Supported alias transports trigger the same synthetic tool-result repair as their canonical provider API names.

Actual

  • Before the fix, alias transport names could bypass the repair branch entirely.

Evidence

Attach at least one:

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios: pnpm test:serial src/agents/transport-message-transform.test.ts src/agents/transcript-policy.test.ts.
  • Edge cases checked: Anthropic and Google alias transport names used in replay repair gating.
  • What you did not verify: full end-to-end replay against live providers.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? (Yes/No) Yes
  • Config/env changes? (Yes/No) No
  • Migration needed? (Yes/No) No
  • If yes, exact upgrade steps: N/A

Risks and Mitigations

  • Risk: narrow fix may miss adjacent provider-specific edge cases not covered by the focused regression.
    • Mitigation: keep the patch scoped and ship targeted regression coverage for the implicated path only.

@vincentkoc vincentkoc self-assigned this Apr 14, 2026
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Apr 14, 2026
@greptile-apps

greptile-apps Bot commented Apr 14, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Introduces SYNTHETIC_TOOL_RESULT_APIS to gate synthetic tool-result injection by model API, adds the openclaw-anthropic-messages-transport and openclaw-google-generative-ai-transport alias names to that set, and moves the pendingToolCalls/existingToolResultIds reset outside the conditional so state is always cleared. The fix is consistent with SIMPLE_TRANSPORT_API_ALIAS in provider-transport-stream.ts and is accompanied by targeted regression tests and the missing changelog entry from #61556.

Confidence Score: 5/5

  • Safe to merge — the fix is narrowly scoped, the alias names are consistent with the transport alias map, and the reset-state refactor is a no-op improvement.
  • All findings are P2: the only gap is a missing bedrock-converse-stream sub-case in the new test. No logic errors, data-loss risk, or contract breakage identified.
  • No files require special attention.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/agents/transport-message-transform.test.ts
Line: 58-75

Comment:
**Missing `bedrock-converse-stream` coverage**

`bedrock-converse-stream` is included in `SYNTHETIC_TOOL_RESULT_APIS` but has no case in this new test. The two alias entries are now locked in, but if `bedrock-converse-stream` is accidentally removed from the set in a future edit there will be no regression signal here. Consider adding a third sub-case alongside the Anthropic/Google aliases.

```suggestion
  it("still synthesizes missing tool results for transport alias apis that own replay repair", () => {
    const messages: Context["messages"] = [
      assistantToolCall("call_transport_1"),
      { role: "user", content: "continue", timestamp: Date.now() },
    ];

    const anthropicAlias = transformTransportMessages(
      messages,
      makeModel("openclaw-anthropic-messages-transport" as Api, "anthropic", "claude-opus-4-6"),
    );
    expect(anthropicAlias.map((msg) => msg.role)).toEqual(["assistant", "toolResult", "user"]);

    const googleAlias = transformTransportMessages(
      messages,
      makeModel("openclaw-google-generative-ai-transport" as Api, "google", "gemini-2.5-pro"),
    );
    expect(googleAlias.map((msg) => msg.role)).toEqual(["assistant", "toolResult", "user"]);

    const bedrockCanonical = transformTransportMessages(
      messages,
      makeModel("bedrock-converse-stream" as Api, "bedrock", "anthropic.claude-opus-4-6"),
    );
    expect(bedrockCanonical.map((msg) => msg.role)).toEqual(["assistant", "toolResult", "user"]);
  });
```

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

Reviews (1): Last reviewed commit: "fix(replay): preserve synthetic tool rep..." | Re-trigger Greptile

@vincentkoc
vincentkoc force-pushed the vk/pr-61556-main branch 4 times, most recently from be7a6df to 473ba8a Compare April 24, 2026 02:25
@vincentkoc
vincentkoc merged commit d42069b into main Apr 24, 2026
62 checks passed
@vincentkoc
vincentkoc deleted the vk/pr-61556-main branch April 24, 2026 02:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant