Skip to content

fix(agents): drop partialJson streaming artifacts from session history repair#93469

Merged
vincentkoc merged 3 commits into
openclaw:mainfrom
drvoss:fix/repair-partial-tool-call-streaming-artifacts-v2
Jun 16, 2026
Merged

fix(agents): drop partialJson streaming artifacts from session history repair#93469
vincentkoc merged 3 commits into
openclaw:mainfrom
drvoss:fix/repair-partial-tool-call-streaming-artifacts-v2

Conversation

@drvoss

@drvoss drvoss commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Summary

What problem does this PR solve?

  • Transcript repair was treating any tool call with non-null arguments as complete, then stripping partialJson without checking whether the remaining block was a finalized OpenAI Responses call or an interrupted Anthropic artifact.

Why does this matter now?

  • That leaves interrupted Anthropic artifacts replayable in repaired history, which can corrupt later tool-result repair and preserve bad session state.

What is the intended outcome?

  • Drop interrupted Anthropic partialJson artifacts, keep finalized OpenAI Responses tool calls, and preserve retained sessions_spawn attachment content on kept blocks.

What is intentionally out of scope?

  • This PR does not claim to fix the upstream Kimi transport ordering problem itself, and it does not change provider transport handling outside transcript repair.

What does success look like?

  • Interrupted Anthropic artifacts are removed during transcript repair, finalized OpenAI Responses calls remain usable after partialJson stripping, and existing sessions_spawn attachment preservation still works.

What should reviewers focus on?

  • The keep/drop split in repairToolCallInputs() and the matching regression coverage in src/agents/session-transcript-repair.test.ts.

Linked context

Which issue does this close?

  • None claimed.

Which issues, PRs, or discussions are related?

Was this requested by a maintainer or owner?

  • No.

Real behavior proof (required for external PRs)

  • Behavior or issue addressed: interrupted Anthropic tool-call artifacts that still have id, name, arguments: {}, and partialJson should be dropped, while finalized OpenAI Responses tool calls should keep valid arguments, lose partialJson, and preserve retained sessions_spawn attachment content.
  • Real environment tested: local OpenClaw checkout on Windows 11 with Node 22.
  • Exact steps or command run after this patch:
    1. Ran a temporary TypeScript proof script through pnpm exec tsx that imports sanitizeToolCallInputs() from src/agents/session-transcript-repair.ts.
    2. Fed that script one finalized OpenAI-style sessions_spawn block (call_spawn|fc_456) plus one interrupted Anthropic-style block (toolu_123 with arguments: {} and partialJson).
    3. Printed the repaired assistant content from the current PR head.
  • Evidence after fix (screenshot, recording, terminal capture, console output, redacted runtime log, linked artifact, or copied live output):
{
  "droppedAnthropicArtifact": true,
  "assistantContent": [
    {
      "type": "toolCall",
      "id": "call_spawn|fc_456",
      "name": "sessions_spawn",
      "arguments": {
        "attachments": [
          {
            "content": "secret data",
            "name": "a.txt"
          }
        ]
      }
    }
  ],
  "sessionsSpawnAttachmentContent": "secret data"
}
  • Observed result after fix: the interrupted Anthropic artifact was removed, the finalized OpenAI-style sessions_spawn block stayed, partialJson was removed from the retained block, and attachment content was preserved.
  • What was not tested: a live remote-provider replay round-trip against Anthropic or OpenAI Responses in this environment.
  • Proof limitations or environment constraints: no live provider credentials or remote replay harness were available in this environment, so proof is limited to direct transcript-repair execution plus focused regression tests.
  • Before evidence (optional but encouraged): the previous branch behavior kept the initialized Anthropic shape after deleting partialJson, which is the blocker called out in prior review.

Tests and validation

Which commands did you run?

  • node scripts/run-vitest.mjs src/agents/session-transcript-repair.test.ts --run
  • node scripts/run-vitest.mjs src/agents/session-transcript-repair.attachments.test.ts --run
  • pnpm check:changed

What regression coverage was added or updated?

  • src/agents/session-transcript-repair.test.ts now locks in the keep/drop split between finalized OpenAI Responses tool calls and interrupted Anthropic partialJson artifacts.

What failed before this fix, if known?

  • The initialized Anthropic id + name + arguments: {} + partialJson shape survived cleanup as a replayable tool call after partialJson removal.

If no test was added, why not?

  • N/A

Risk checklist

Did user-visible behavior change? (Yes/No)

  • Yes. Transcript repair now drops interrupted Anthropic partialJson artifacts instead of replaying them as valid tool calls.

Did config, environment, or migration behavior change? (Yes/No)

  • No.

Did security, auth, secrets, network, or tool execution behavior change? (Yes/No)

  • No.

What is the highest-risk area?

  • Misclassifying a valid non-OpenAI tool call that still carries partialJson.

How is that risk mitigated?

  • Current source only persists partialJson on Anthropic streaming artifacts and finalized OpenAI Responses blocks, and the updated regression tests pin the intended split and preserved sessions_spawn payload path.

Current review state

What is the next action?

  • Wait for CI and maintainer review on the fresh replacement PR.

What is still waiting on author, maintainer, CI, or external proof?

  • Waiting on GitHub CI and maintainer review. No additional author-side code change is planned unless CI or maintainer feedback finds a concrete regression.

Which bot or reviewer comments were addressed?

  • Reworded the PR body to remove the over-claiming fully tested footer.
  • Narrowed #57523 from a closing claim to related context only, because this PR repairs transcript fallout rather than claiming to fix the upstream Kimi transport ordering bug itself.

AI-assisted: drafted with Copilot.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M proof: supplied External PR includes structured after-fix real behavior proof. labels Jun 16, 2026
@vincentkoc vincentkoc self-assigned this Jun 16, 2026
@vincentkoc vincentkoc force-pushed the fix/repair-partial-tool-call-streaming-artifacts-v2 branch 2 times, most recently from a193340 to 3a694e1 Compare June 16, 2026 07:59
drvoss and others added 3 commits June 16, 2026 16:01
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@vincentkoc vincentkoc force-pushed the fix/repair-partial-tool-call-streaming-artifacts-v2 branch from 3a694e1 to 86fe9d5 Compare June 16, 2026 08:02
@vincentkoc

Copy link
Copy Markdown
Member

reverified after relevant mainline drift:

  • synced prepared head: 86fe9d5a43bddd6b9536aad962d5171f439c6f74
  • focused proof: node scripts/run-vitest.mjs src/agents/session-transcript-repair.test.ts (55 passed)
  • fresh autoreview after the relevant sync: clean
  • final non-overlapping CLI-only rebase was conflict-free and the focused proof passed again
  • local broad gate gap remains the unrelated database-first legacy-store guard heap OOM / wedged local pnpm install; Testbox CLI unavailable
  • exact-head repo merge verification: passed; no required checks configured

@vincentkoc vincentkoc merged commit ff5e735 into openclaw:main Jun 16, 2026
38 of 39 checks passed
@vincentkoc

Copy link
Copy Markdown
Member

Merged via squash.

Thanks @drvoss!

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jun 17, 2026
…y repair (openclaw#93469)

Merged via squash.

Prepared head SHA: 86fe9d5
Co-authored-by: drvoss <3031622+drvoss@users.noreply.github.com>
Co-authored-by: vincentkoc <25068+vincentkoc@users.noreply.github.com>
Reviewed-by: @vincentkoc
crh-code pushed a commit to crh-code/openclaw that referenced this pull request Jun 18, 2026
…y repair (openclaw#93469)

Merged via squash.

Prepared head SHA: 86fe9d5
Co-authored-by: drvoss <3031622+drvoss@users.noreply.github.com>
Co-authored-by: vincentkoc <25068+vincentkoc@users.noreply.github.com>
Reviewed-by: @vincentkoc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling proof: supplied External PR includes structured after-fix real behavior proof. size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants