Skip to content

fix(codex): preserve provenance through context-engine compaction - #150490

Merged
jalehman merged 4 commits into
openclaw:mainfrom
compoodment:codex/native-provenance-live
Sep 17, 2026
Merged

jalehman merged 4 commits into
openclaw:mainfrom
compoodment:codex/native-provenance-live

Conversation

@compoodment

@compoodment compoodment commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #150489.

What Problem This Solves

The generic compaction fix in #149869 does not own Codex-native sessions. Codex has two additional paths that can erase group-chat authorship before native compaction:

  1. a new Discord user turn is converted into a Codex app-server UserInput::Text; and
  2. an active context engine projects stored history into the native turn/start prompt.

Both paths previously reduced user turns to bare [user] text. After compaction, the model could retain the statement but not its speaker.

This patch carries a compact sender envelope only when OpenClaw provides a stable senderId. Display names are labels, never identity. Legacy and name-only records remain bare [user] rows.

Fix

  • Prefix new native user inputs with stable-ID provenance and preserve the same label in active context-engine history projection.
  • Treat generated metadata as inert: native skill-selection sigils are neutralized in sender metadata, while explicit mentions in the user's actual request remain unchanged.
  • Reserve the exact generated-prefix length before fitting the combined Codex text input to its 1,048,576-character cap.
  • Keep the existing app-server protocol shapes and public APIs unchanged.

Evidence

Focused regressions

  • native-provenance.test.ts: exercises the real active context-engine turn/start assembly with two attributed users plus one legacy user; it verifies distinct stable labels and an unchanged bare legacy row.
  • The same suite fills the native input to its real combined-text limit while provenance is enabled, proving the prefix is budgeted and the current request remains intact.
  • turn-params.test.ts: proves metadata $skill syntax is neutralized while an explicit $skill in the user request is preserved.
  • Focused local receipt: 12 native-input tests and 62 context-engine-projection tests passed; prompt snapshots and all three changed-file ratchets (line cap, max lines, assertion safety) pass.

Real Behavior Proof

Fresh two-speaker Codex-native session on Clanker, 2026-09-17 (UTC+2). Test messages:

  • “openclaw loves me and i love openclaw” — computment
  • “and i love you clanker” — softentity (alternativment)

After native compaction, the follow-up attribution query was issued without channel-history tooling. The model returned:

  • “openclaw loves me and i love openclaw” — computment
  • “and i love you clanker” — softentity (alternativment)

Redacted gateway/session receipt:

2026-09-17T09:38:09+02:00 started codex app-server compaction
2026-09-17T09:38:19+02:00 completed codex app-server compaction
2026-09-17T09:38:19+02:00 persisted context-compaction event
2026-09-17T09:39:40+02:00 post-compaction native turn accepted
2026-09-17T09:39:45+02:00 post-compaction assistant output started

No active-writer or secondary-compaction error occurred. The gateway remained healthy throughout.

Test-environment note: Clanker ran the #150490 provenance artifact plus a separate local Codex app-server owner-routing shim. That shim repairs an unrelated client-lifecycle bug which otherwise prevents native compaction from running; it is not part of this PR. The provenance behavior and sender mapping above exercise the #150490 code.

Session, thread, client, channel, host, and account identifiers are omitted. The synthetic test text and display names are intentionally retained.

Worked on by

  • computment

Native selection boundary proof

The pre-native turn/start assembly was exercised with sender metadata containing [@probe] (plugin://probe@market). Both a current sender envelope and projected-history sender labels emitted [@probe] (plugin://probe@market); the raw metadata sigil was absent. The explicit current request [@probe](plugin://probe@market) $intentional-skill remain selectable was preserved byte-for-byte. This keeps generated sender metadata out of Codex's explicit plugin/MCP selection path while retaining intentional current-request selection.

The focused receipt is 74/74 native Codex tests, including the current-input and active context-engine turn/start paths; production and extension-test typechecks pass.

@clawsweeper

clawsweeper Bot commented Sep 17, 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.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. 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 17, 2026
@clawsweeper

clawsweeper Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 17, 2026, 4:01 AM ET / 08:01 UTC (Revision 9).

ClawSweeper review

What this changes

Preserves stable speaker labels in Codex conversation history and context-engine projections while neutralizing metadata mentions and budgeting the added text.

Merge readiness

✅ Ready for maintainer review

This remains a useful fix: current main still loses sender labels in Codex history projection. The previous findings are addressed, and the supplied live compaction evidence supports the intended behavior.

Priority: P2
Reviewed head: 6a94d96813417f96ee398377006e522740857085

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with relevant live evidence, meaningful regression coverage, and no remaining actionable finding.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The supplied Clanker session receipt shows distinct speaker attribution surviving native compaction and a subsequent recall turn without channel-history tools. Assembly regressions supplement this with context-engine, metadata-selection, and budget coverage; the disclosed routing shim is outside this proof's provenance claim.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The supplied Clanker session receipt shows distinct speaker attribution surviving native compaction and a subsequent recall turn without channel-history tools. Assembly regressions supplement this with context-engine, metadata-selection, and budget coverage; the disclosed routing shim is outside this proof's provenance claim.
Evidence reviewed 10 items Current main still needs the fix: The fetched main revision renders projected messages with bare role labels; its current-sender context does not add provenance to native user input.
Latest release comparison: The v2026.9.4 turn builder supplies current-sender additional context but calls the user-input builder without a history provenance prefix.
Introduced behavior and prior findings: The reviewed head requires a stable sender ID, JSON-escapes metadata, neutralizes native mention syntax including whitespace-separated links, and reserves the generated prefix before fitting turn input. The previous mention and budget findings are resolved.
Findings None None.
Security None None.

How this fits together

The Codex plugin converts OpenClaw messages and assembled conversation history into native app-server inputs. These inputs become the history available to subsequent turns and native compaction.

flowchart LR
 A[Current user message] --> C[Codex input preparation]
 B[Assembled conversation history] --> D[History projection]
 C --> E[Bound and neutralize sender metadata]
 D --> E
 E --> F[Native Codex thread]
 F --> G[Compaction and later recall]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +103, Tests +270. Total +373 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 5 120 17 +103
Tests 6 305 35 +270
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 11 425 52 +373

Review metrics

Metric Value Why it matters
Production and regression balance Net production +103 lines; tests +264; prompt fixtures +6 Production growth supports two distinct Codex adapters and shared prefix budgeting, with focused regression coverage.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #150489
Summary: This PR is the candidate fix for the paired Codex provenance issue; generic compaction and native writer selection are separate boundaries.

Members:

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

Technical review

Best possible solution:

Keep speaker provenance in the Codex-owned input adapters, with legacy rows unattributed and generated metadata excluded from native selection.

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

Yes, from source: feed distinct sender-attributed user messages through current main's Codex projection and their labels become bare roles. No current-main runtime reproduction was executed in this review.

Is this the best way to solve the issue?

Yes. The patch repairs the two Codex-owned history boundaries without changing public protocol shapes, reconstructing legacy identities, or introducing another compaction owner.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: Repairs speaker attribution loss in Codex compaction with a bounded plugin-level change.
  • 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 supplied Clanker session receipt shows distinct speaker attribution surviving native compaction and a subsequent recall turn without channel-history tools. Assembly regressions supplement this with context-engine, metadata-selection, and budget coverage; the disclosed routing shim is outside this proof's provenance claim.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied Clanker session receipt shows distinct speaker attribution surviving native compaction and a subsequent recall turn without channel-history tools. Assembly regressions supplement this with context-engine, metadata-selection, and budget coverage; the disclosed routing shim is outside this proof's provenance claim.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • compoodment: 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 (8 earlier review cycles)
  • reviewed 2026-09-17T01:58:22.206Z sha edd0277 :: needs real behavior proof before merge. :: [P2] Neutralize native mentions in the sender prefix | [P2] Reserve input budget for the provenance prefix
  • reviewed 2026-09-17T03:06:56.606Z sha fa5ff11 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-17T03:14:33.188Z sha fa5ff11 :: needs real behavior proof before merge. :: [P2] [P2] Neutralize whitespace-bearing plugin links in sender metadata
  • reviewed 2026-09-17T03:24:32.518Z sha fa5ff11 :: needs real behavior proof before merge. :: [P2] [P2] Neutralize whitespace-bearing plugin links in sender metadata
  • reviewed 2026-09-17T06:30:34.732Z sha fa5ff11 :: needs real behavior proof before merge. :: [P2] Neutralize whitespace-bearing plugin links in sender metadata
  • reviewed 2026-09-17T06:52:06.332Z sha 6a94d96 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-17T07:04:24.739Z sha 6a94d96 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-17T07:54:48.014Z sha 6a94d96 :: needs maintainer review before merge. :: none

@compoodment

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. and removed merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Sep 17, 2026
@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. labels Sep 17, 2026
@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. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@jalehman

Copy link
Copy Markdown
Contributor

Land-ready verification for head 6a94d96813417f96ee398377006e522740857085:

  • Fresh independent autoreview (--mode branch --base origin/main --max-priority P1) exited 0, scoped-clean: no actionable P0/P1 findings. Manual inspection covered all changed production modules, caller assembly, generic compaction provenance, and the current main implementation.
  • Personally checked the pinned upstream Codex rust-v0.154.0 source: codex-rs/skills/src/mentions.rs:85-200, codex-rs/core/src/plugins/mentions.rs:86-111, codex-rs/app-server/src/request_processors/turn_processor.rs:505-559, and codex-rs/protocol/src/user_input.rs:8. These confirm native mention scanning (including whitespace-bearing links) and the combined text-input cap.
  • Exact-head CI run 35191100984 is green; the required openclaw/ci-gate passed. No approval requirement appears in the matching enforced branch rules.
  • Latest ClawSweeper review has no outstanding findings or before-merge moves.
  • git diff --check origin/main...origin/pr-150490, scripts/pr review-validate-artifacts 150490, and OPENCLAW_TESTBOX=1 scripts/pr prepare-run 150490 passed. Preparation retained the exact contributor head; no rebase, source change, or push was needed.

Root cause and fix: native current-user input and context-engine history projection discarded stable speaker metadata. The fix serializes bounded, inert provenance at those Codex-owned boundaries and reserves its prefix in the existing prompt budget. Generic-compaction-only changes cannot repair these native paths; no new compaction owner, protocol, or storage change is needed. Production +120/-17 (net +103); tests and fixtures +305/-35. Growth implements the two adapter boundaries and shared prefix budgeting.

Proof limits: I did not rerun authenticated live compaction or the runtime test suite locally. Hosted exact-head CI and the contributor's reported 74-test receipt supplement the live two-speaker compaction evidence already in this PR. That live environment included the separately disclosed owner-routing shim; it is not evidence of that unrelated lifecycle fix or a pristine-main live run. Autoreview did not execute project code. Same-turn steering is unchanged; this PR repairs new native turns and projected history.

@jalehman
jalehman merged commit d09b4bb into openclaw:main Sep 17, 2026
117 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 18, 2026
…enclaw#150490)

* fix(codex): preserve sender provenance in native history

* fix(codex): preserve provenance in context projections

* fix(codex): harden native provenance inputs

* fix(codex): neutralize whitespace-separated plugin links

---------

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

extensions: codex 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: M 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.

Bug: Codex context-engine compaction drops stable sender provenance

2 participants