Skip to content

fix: preserve sender provenance through compaction - #149869

Merged
jalehman merged 19 commits into
openclaw:mainfrom
compoodment:codex/transcript-provenance
Sep 16, 2026
Merged

jalehman merged 19 commits into
openclaw:mainfrom
compoodment:codex/transcript-provenance

Conversation

@compoodment

@compoodment compoodment commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #149868.

What Problem This Solves

OpenClaw already persists stable channel sender metadata and exposes it during ordinary replay. Compaction was the projection boundary that discarded it, serializing every historic participant as anonymous [User]. That can cause a later summary to merge different speakers' decisions or preferences.

What changed

  • Serialize sender provenance for compaction only when a nonblank stable senderId exists; display name and username are labels, not identity.
  • Charge the exact rendered sender={...} suffix to ordinary and branch-history token budgets.
  • Make preservation of speaker attribution a shared summarization system invariant for ordinary, custom, split-turn, and branch summaries.
  • Leave legacy or partial metadata without a stable ID explicitly unattributed.
  • Keep sender JSON safely escaped so a hostile display label cannot create a synthetic prompt line.

Evidence

Automated coverage

  • Ordinary, custom, split-turn, and branch summarization prompt assembly.
  • Token budgeting with rendered sender suffixes.
  • Same-name/no-ID legacy records remain unattributed.
  • Stable-ID collisions and renamed display labels remain distinct.
  • Generated compaction persisted through the real session tree, then reloaded and navigated through a branch.
  • Local gates on the current branch: focused compaction tests, durable session-tree test, core TypeScript, and root test TypeScript.

Real Behavior Proof

Two provider-backed synthetic runs exercised the patched ordinary and branch summary helpers. In each result, distinct stable-ID speakers remained distinct and an unlabeled legacy note remained unattributed. The inputs contained synthetic names and content only; no live conversation or delivery target was used. This verifies semantic behavior in addition to the request-assembly regressions above.

Serializer compatibility

The exported serializeConversation(messages) signature is unchanged. Legacy user records without a stable sender ID preserve their existing [User]: … output. Only user records carrying a nonblank persisted senderId gain an escaped sender={...} suffix inside that existing user label; this is the intentional attributed-row extension. No public API or normal-replay behavior changes.

Scope

This preserves provenance that the transcript already stored. It does not reconstruct authors for historic sessions that never had stable sender metadata, change normal replay, or add a public API.

Worked on by

@clawsweeper

clawsweeper Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. size: M labels Sep 16, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 16, 2026
@clawsweeper

clawsweeper Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 16, 2026, 4:15 PM ET / 20:15 UTC (Revision 16).

ClawSweeper review

What this changes

Preserves stored sender identities in conversation summaries, accounts for their token cost, and adds attribution and persisted-replay coverage.

Merge readiness

✅ Ready for maintainer review

The fix remains necessary: current main and the latest release still discard sender attribution during summary serialization. No blocking introduced defect was found, and the latest commit preserves the behavior covered by the existing proof.

Priority: P2
Reviewed head: d9d8612984d25421029320cb998dfda375c86d4d

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with relevant provider-backed observations and regression coverage; no blocking patch defect was identified.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured body records provider-backed synthetic runs through the changed ordinary and branch summarizers, preserving distinct speakers and leaving legacy content unattributed; prompt and persistence tests supplement those observations. The latest export-only change does not invalidate that proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured body records provider-backed synthetic runs through the changed ordinary and branch summarizers, preserving distinct speakers and leaving legacy content unattributed; prompt and persistence tests supplement those observations. The latest export-only change does not invalidate that proof.
Evidence reviewed 10 items Current main still loses attribution: The pinned current-main serializer emits the same User label for every user message without reading persisted sender metadata.
Latest release has the same serializer: GitHub reports serializer blob f08790b1719f1984d8cb1cd24cd33b18c3ee3c07 for both v2026.9.4 and pinned current main; the released serializer therefore also lacks sender attribution.
Introduced serialization and budgeting: The reviewed implementation requires a nonblank stable sender ID, JSON-escapes labels, and leaves legacy rows anonymous. Ordinary token estimates charge the same rendered suffix; branch preparation already budgets serialized text.
Findings None None.
Security None None.

How this fits together

OpenClaw compaction turns older conversation messages into summaries used by later model requests. The serializer supplies conversation text to ordinary and branch summarizers while the original transcript remains intact.

flowchart TD
  A[Stored conversation turns] --> B{Stable sender ID present}
  B -->|Yes| C[Escaped sender label]
  B -->|No| D[Unattributed user label]
  C --> E[Budgeted summary input]
  D --> E
  E --> F[Model with attribution instructions]
  F --> G[Summary for later turns]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +72, Tests +583. Total +655 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 5 195 123 +72
Tests 4 583 0 +583
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 778 123 +655

Review metrics

None.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #149868
Summary: This PR is the candidate fix for the companion attribution issue; the merged compaction audit addresses adjacent behavior.

Members:

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

Technical review

Best possible solution:

Keep attribution preservation in the shared summarization path, anchored to stable IDs while leaving legacy history explicitly unattributed.

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

Yes, from source: current-main serialization turns user messages carrying distinct persisted sender IDs into anonymous User rows. This review did not execute that path.

Is this the best way to solve the issue?

Yes. Extending the existing serializer and shared summary instructions repairs the projection boundary without adding configuration, rewriting transcripts, or creating another metadata store.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against fa5d32f78264.

Labels

Label justifications:

  • P2: Repairs attribution loss in compacted multi-person conversations without evidence of an urgent outage or authorization bypass.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured body records provider-backed synthetic runs through the changed ordinary and branch summarizers, preserving distinct speakers and leaving legacy content unattributed; prompt and persistence tests supplement those observations. The latest export-only change does not invalidate that proof.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured body records provider-backed synthetic runs through the changed ordinary and branch summarizers, preserving distinct speakers and leaving legacy content unattributed; prompt and persistence tests supplement those observations. The latest export-only change does not invalidate that proof.

Evidence

What I checked:

  • Current main still loses attribution: The pinned current-main serializer emits the same User label for every user message without reading persisted sender metadata. (packages/agent-core/src/harness/compaction/utils.ts:273, fa5d32f78264)
  • Latest release has the same serializer: GitHub reports serializer blob f08790b1719f1984d8cb1cd24cd33b18c3ee3c07 for both v2026.9.4 and pinned current main; the released serializer therefore also lacks sender attribution. (packages/agent-core/src/harness/compaction/utils.ts, 3a9d69db306c)
  • Introduced serialization and budgeting: The reviewed implementation requires a nonblank stable sender ID, JSON-escapes labels, and leaves legacy rows anonymous. Ordinary token estimates charge the same rendered suffix; branch preparation already budgets serialized text. (packages/agent-core/src/harness/compaction/utils.ts:261, d9d8612984d2)
  • Shared prompt and implementation boundary: Ordinary, custom, and split-turn summaries use the extracted completion runner; branch summaries consume the same attribution system prompt. These are OpenClaw agent-core operations, with no introduced dependency on the Codex harness or protocol. (packages/agent-core/src/harness/compaction/summarization-completion.ts:57, d9d8612984d2)
  • Existing metadata and authority boundary: The transcript producer already persists sender ID, name, and username, and separately distinguishes observed channel identity from authenticated profiles. The patch projects those existing facts into summary text without changing grants, owner bits, or side-effect authorization. (src/sessions/user-turn-transcript.metadata.ts:24, d9d8612984d2)
  • Proof and review continuity: Captured body sourceRevision 65d427d20b07d5aa11cec9ac72c0202c40ab7496bdc42dc7d2b80b1930725da6 reports two provider-backed synthetic runs through ordinary and branch summarization: distinct stable-ID speakers remained distinct and legacy content remained unattributed. The prior completed review accepted these observations and recorded no findings. GitHub's exact-head commit patch changes only the provenance constant from exported to private, leaving prompt bytes unchanged. (packages/agent-core/src/harness/compaction/summarization-prompts.ts:2, d9d8612984d2)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Alix-007: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

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

History

Review history (15 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-16T18:25:26.107Z sha ebc7e19 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-16T18:36:25.610Z sha 80f6936 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-16T18:48:46.654Z sha d476314 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-16T19:02:16.359Z sha 674e86f :: needs maintainer review before merge. :: none
  • reviewed 2026-09-16T19:12:18.185Z sha bc7104f :: needs maintainer review before merge. :: none
  • reviewed 2026-09-16T19:28:24.218Z sha bc7104f :: blocked before merge. :: none
  • reviewed 2026-09-16T19:47:19.491Z sha 500ca90 :: blocked before merge. :: none
  • reviewed 2026-09-16T19:57:16.063Z sha 500ca90 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Sep 16, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Sep 16, 2026
@compoodment
compoodment force-pushed the codex/transcript-provenance branch from 9db7189 to 1a7aa52 Compare September 16, 2026 08:56
@compoodment
compoodment marked this pull request as draft September 16, 2026 08:57
@compoodment
compoodment marked this pull request as ready for review September 16, 2026 08:57
@compoodment
compoodment force-pushed the codex/transcript-provenance branch from 8108fb7 to 88126d3 Compare September 16, 2026 09:38
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 16, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Sep 16, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Sep 16, 2026
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Sep 16, 2026
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Sep 16, 2026
@jalehman jalehman self-assigned this Sep 16, 2026
@jalehman

Copy link
Copy Markdown
Contributor

Maintainer verification of d9d8612: no blocking findings.

The root cause is the shared compaction serializer, which discarded existing persisted sender metadata. I executed the main serializer at afc27e7 against two distinct IDs sharing a display name and an unattributed legacy turn: main anonymized both known speakers; this head preserved both IDs and left the legacy turn unattributed. The stable v2026.9.4 serializer has the same lossy behavior. Original introduction provenance remains unknown.

Best-fix verdict: repair the existing summary projection and matching token accounting. Storage changes would duplicate existing metadata, and instructions alone cannot recover discarded IDs. Ordinary/custom/split-turn and branch requests share the attribution system invariant. No authentication, schema, or public signature changes.

Verification commands:

pnpm install --frozen-lockfile
node scripts/run-vitest.mjs packages/agent-core/src/harness/compaction src/agents/sessions/session-manager-provenance-compaction.test.ts src/agents/compaction.token-sanitize.test.ts src/agents/compaction-planning-worker.test.ts
# Passed all 3 selected Vitest shards in 39.17s.
# Main-versus-head serializer assertions also passed through node --import tsx.
autoreview --mode branch --base fc52265f8406ccc1efd69aa7e752b6c5ee5e1552 --max-priority P2
# Fresh independent review: scoped-clean, no P0–P2 findings.
git diff --check fc52265f8406ccc1efd69aa7e752b6c5ee5e1552 HEAD

Exact-head hosted CI: https://github.com/openclaw/openclaw/actions/runs/35144784780 — completed successfully. No unresolved review threads. Latest ClawSweeper review covers this exact head and lists no remaining pre-merge requests/rank-up moves.

Production LOC +195/-123 (net +72); tests +583/-0. Most completion code is relocated unchanged; added logic provides stable-ID projection, safely escaped optional labels, shared attribution policy, and matching accounting. No contributor code or ancestry was rewritten during this landing review.

Proof limit: provider-backed ordinary/branch semantic runs are reported in the PR body and accepted by ClawSweeper; I did not rerun a provider call. The local tests prove prompt assembly, budgeting, session-tree persistence/reload/navigation, and deterministic serialization, not model semantics.

@jalehman
jalehman merged commit 8446968 into openclaw:main Sep 16, 2026
215 checks passed
@jalehman

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 17, 2026
* fix(compaction): retain user sender provenance

* fix: preserve provenance instructions in branch summaries

* fix(compaction): cover sender provenance budgets and prompts

* test(compaction): satisfy strict provenance checks

* test(compaction): pin sender token estimate

* fix(compaction): resolve branch summary rebase

* fix(compaction): keep branch provenance policy shared

* test(compaction): align branch budget with serializer

* fix(compaction): share sender suffix across message carriers

* fix(compaction): keep sender policy after custom focus

* test(compaction): cover stable sender identities

* test(compaction): exercise provenance through session compaction

* refactor(compaction): extract summary completion runner

* fix(compaction): remove stale completion imports

* fix(compaction): use type-only llm imports

* fix(compaction): require stable sender ids

* fix(compaction): make sender policy a system invariant

* test(compaction): cover persisted provenance reload

* fix(compaction): keep provenance instruction private

---------

Co-authored-by: compoodment <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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.

Compaction loses persisted group sender provenance, allowing summaries to misattribute history

2 participants