Skip to content

refactor(agents): fold assistant string normalization into transcript ingest - #98908

Merged
obviyus merged 1 commit into
mainfrom
refactor/assistant-string-ingest
Jul 2, 2026
Merged

obviyus merged 1 commit into
mainfrom
refactor/assistant-string-ingest

Conversation

@obviyus

@obviyus obviyus commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Follow-up to #98891. src/llm/providers/transform-messages.ts carried a second, older copy of the "JSONL replay can hand us a raw string" normalization for assistant content — a special case at provider-conversion altitude, duplicating what the session-ingest boundary now owns. Worse, transport streams (anthropic-transport-stream, openai-transport-stream, google/xai extensions) never call transformMessages, so a replayed assistant message with string content was still mis-shaped on those paths — the same latent bug class #98891 fixed for tool results.

Why This Change Was Made

  • normalizeLoadedFileEntry (the fix(agents): normalize non-array tool-result content at transcript ingest #98891 ingest boundary in src/agents/sessions/session-manager.ts) now also normalizes assistant string content to [{ type: "text", text }] at JSONL parse time, covering providers and transport streams alike. User messages are untouched — UserMessage.content is legitimately string | blocks[] by type.
  • The transformMessages string branch is kept, not deleted: it is a shipped plugin-SDK surface (src/plugin-sdk/llm.ts exports transformMessages, published as ./plugin-sdk/llm), so external provider adapters may legally pass string assistant content. Its comment now names that contract instead of the stale JSONL-replay claim, and the old as unknown as string double-cast is gone in favor of real narrowing.
  • anthropic-payload-policy.ts string handling was inspected and deliberately left alone: it normalizes outbound Anthropic wire payloads (where string content is valid API shape) for the transport stream, cache-control wrappers, and plugin-sdk/provider-stream-shared — a wire-format contract, not replay defense.

Coverage map verified before deciding: all six transformMessages callers (anthropic, openai-completions, openai-responses-shared, google-shared, mistral, amazon-bedrock), live-runner assistant construction (always block arrays), the normalized JSONL replay path, and CLI/foreign transcript readers.

User Impact

  • Replayed sessions with legacy string assistant content now reach every provider and transport path in canonical block-array shape; no behavior change for well-formed sessions.
  • No API, config, or plugin-SDK surface changes; prod LOC net-neutral (8+/8−, 7+/7−).

Evidence

  • New ingest + replay regression coverage for assistant string content in src/agents/sessions/session-manager.tool-result-replay.test.ts; existing raw-entry assertions updated to the canonical normalized shape (disk bytes still asserted unchanged).
  • node scripts/run-vitest.mjs src/agents/sessions/session-manager.tool-result-replay.test.ts src/agents/sessions/session-manager.test.ts — 52 tests passing.
  • node scripts/run-tsgo.mjs -p tsconfig.core.json and -p test/tsconfig/tsconfig.core.test.json — both green.
  • node scripts/run-oxlint.mjs on touched files — clean.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Jul 2, 2026
@clawsweeper

clawsweeper Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 2, 2026, 1:39 AM ET / 05:39 UTC.

Summary
The PR normalizes legacy string assistant content at JSONL session ingest, keeps the public transformMessages fallback tolerant for SDK callers, and updates replay/session tests to expect canonical text blocks.

PR surface: Source 0, Tests +97. Total +97 across 9 files.

Reproducibility: yes. source-reproducible. Current main only normalizes loaded JSONL toolResult content, while AssistantMessage.content and transport replay consumers expect assistant content blocks.

Review metrics: 1 noteworthy metric.

  • Persisted Session Normalization Roles: 1 role added, 2 roles normalized total. Assistant entries would join toolResult entries at the JSONL ingest boundary, so reviewers should focus on replay role boundaries and legacy transcript behavior.

Stored data model
Persistent data-model change detected: serialized state: src/agents/cli-runner/session-history.test.ts, serialized state: src/agents/sessions/session-manager.tool-result-replay.test.ts, unknown-data-model-change: src/agents/sessions/session-manager.test.ts, unknown-data-model-change: src/agents/sessions/session-manager.tool-result-replay.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: canonical
Canonical: #98908
Summary: This PR is the active owner for the assistant-string replay follow-up; the merged related PR handled the same ingest-boundary pattern for tool-result replay.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🌊 off-meta tidepool
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P2] Let the remaining exact-head checks finish cleanly before merge.
  • Decide whether the focused provider payload regression is enough or whether a transport-stream payload proof should be added.

Risk before merge

  • [P1] The PR changes how persisted JSONL assistant entries are interpreted on load, so old transcript upgrade behavior is session-state sensitive even though existing files are not rewritten by default.
  • [P1] Assistant replay shape feeds provider and transport payloads; an incorrect role boundary here could drop or reshape prior assistant history in later model turns.
  • [P1] Several exact-head checks were still pending during the live review, so merge should wait for the required checks to finish cleanly.
  • [P1] The new payload regression uses the provider converter path; maintainers may still want an explicit transport-stream payload proof if they need confidence beyond source inspection.

Maintainer options:

  1. Finish Exact-Head Validation (recommended)
    If maintainers accept JSONL ingest as the owner boundary, wait for the pending exact-head checks to finish cleanly before merging.
  2. Request Transport Payload Proof
    Maintainers can ask for one focused transport-stream payload test or artifact if source inspection is not enough for the claimed transport coverage.
  3. Pause For Replay Contract Direction
    If malformed assistant content should remain tolerated only by replay sanitizers or provider helpers, pause this PR and decide that wider contract explicitly.

Next step before merge

  • [P1] Protected maintainer label plus compatibility-sensitive session/message replay behavior make this a maintainer review item, not an automated repair candidate.

Security
Cleared: The diff changes TypeScript session parsing, provider message normalization comments/narrowing, and tests only; it does not broaden dependency, workflow, credential, package, or secret-handling surfaces.

Review details

Best possible solution:

Land the ingest-boundary normalization after maintainer approval and clean exact-head checks, while keeping transformMessages tolerant for plugin-SDK callers.

Do we have a high-confidence way to reproduce the issue?

Yes, source-reproducible. Current main only normalizes loaded JSONL toolResult content, while AssistantMessage.content and transport replay consumers expect assistant content blocks.

Is this the best way to solve the issue?

Yes. Normalizing persisted legacy strings at JSONL ingest is the clean owner boundary, and keeping the transformMessages fallback protects external plugin-SDK callers without widening transport consumers.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against c8dba85b5d41.

Label changes

Label justifications:

  • P2: This is a bounded session/provider replay bugfix with limited blast radius and no emergency outage or security signal.
  • merge-risk: 🚨 session-state: The PR changes how persisted JSONL session entries are interpreted when sessions are reopened or cached appends are advanced.
  • merge-risk: 🚨 message-delivery: The normalized assistant replay shape determines whether prior assistant text reaches provider and transport payloads in later model turns.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The external contributor proof gate is not applied because the PR carries the protected maintainer label; PR-body test/type/lint evidence remains supplemental validation.
Evidence reviewed

PR surface:

Source 0, Tests +97. Total +97 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 2 15 15 0
Tests 7 109 12 +97
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 124 27 +97

What I checked:

Likely related people:

  • obviyus: Current-main blame shows Ayaan Zaidi introduced the session JSONL ingest normalizer in the merged tool-result replay predecessor that this PR extends. (role: recent session replay contributor; confidence: high; commits: e095dc840933; files: src/agents/sessions/session-manager.ts, src/agents/sessions/session-manager.tool-result-replay.test.ts)
  • joshavant: Current blame for the JSONL parser baseline and the older transformMessages assistant-string fallback points to this adjacent session/provider replay history. (role: adjacent baseline contributor; confidence: medium; commits: 3832b2be5f60; files: src/agents/sessions/session-manager.ts, src/llm/providers/transform-messages.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jul 2, 2026
@obviyus
obviyus force-pushed the refactor/assistant-string-ingest branch from 085f105 to 55f59ff Compare July 2, 2026 05:02
@obviyus
obviyus force-pushed the refactor/assistant-string-ingest branch from 55f59ff to f5b25d8 Compare July 2, 2026 05:34
@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Jul 2, 2026
@obviyus
obviyus merged commit a5bf55d into main Jul 2, 2026
103 of 105 checks passed
@obviyus
obviyus deleted the refactor/assistant-string-ingest branch July 2, 2026 05:44
@obviyus

obviyus commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

Landed via squash onto main.

  • Scoped validation: sweep of all 33 session-parsing test files with assistant-string fixtures via node scripts/run-vitest.mjs (727+ tests), plus node scripts/run-tsgo.mjs -p tsconfig.core.json, -p test/tsconfig/tsconfig.core.test.json, and node scripts/run-oxlint.mjs on touched files. Full CI green (64 checks) on f5b25d88a01.
  • Changelog: not edited — release-only in this repo; release-note context is in the PR body.
  • Land commit: f5b25d8
  • Merge commit: a5bf55d

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 3, 2026
steipete added a commit that referenced this pull request Jul 4, 2026
Session ingest has normalized legacy assistant string content into
[{ type: "text" }] blocks since #98908, which updated the core
cli-runner session-history analog but missed this extension file.
The suite only runs in full local runs and the dispatch-only
plugin-prerelease lane, so push/PR CI stayed green while local
scripts/pr prepare-gates failed on any OS.

refs #99857
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 5, 2026
Session ingest has normalized legacy assistant string content into
[{ type: "text" }] blocks since openclaw#98908, which updated the core
cli-runner session-history analog but missed this extension file.
The suite only runs in full local runs and the dispatch-only
plugin-prerelease lane, so push/PR CI stayed green while local
scripts/pr prepare-gates failed on any OS.

refs openclaw#99857
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant