Skip to content

fix(codex): rotate transcript after harness compaction#82856

Closed
hansolo949 wants to merge 2 commits into
openclaw:mainfrom
hansolo949:fix/codex-native-compaction-transcript-rotation
Closed

fix(codex): rotate transcript after harness compaction#82856
hansolo949 wants to merge 2 commits into
openclaw:mainfrom
hansolo949:fix/codex-native-compaction-transcript-rotation

Conversation

@hansolo949

@hansolo949 hansolo949 commented May 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Rotate the active transcript after a successful agent-harness compaction when the harness did not already return a successor transcript.
  • Add an opt-in synthetic compaction boundary for external harness compaction that does not write an OpenClaw transcript boundary, preserving the recent unsummarized tail while keeping the original parent transcript archived.
  • Cover the transcript utility and queued harness compaction path with focused tests.

Verification

  • node scripts/run-vitest.mjs run --config test/vitest/vitest.agents-pi-embedded.config.ts src/agents/pi-embedded-runner/compaction-successor-transcript.test.ts
  • node scripts/run-vitest.mjs run --config test/vitest/vitest.agents-pi-embedded.config.ts src/agents/pi-embedded-runner/compact.hooks.test.ts
  • pnpm tsgo:core:test
  • pnpm exec oxfmt --check --threads=1 src/agents/pi-embedded-runner/compact.queued.ts src/agents/pi-embedded-runner/compaction-successor-transcript.ts src/agents/pi-embedded-runner/compact.hooks.harness.ts src/agents/pi-embedded-runner/compact.hooks.test.ts src/agents/pi-embedded-runner/compaction-successor-transcript.test.ts
  • git diff --check

Real behavior proof

Behavior addressed: Successful external agent-harness compaction, including Codex native app-server compaction, can compact the provider thread without writing an OpenClaw type: "compaction" transcript boundary. With agents.defaults.compaction.truncateAfterCompaction = true, OpenClaw should still rotate to a smaller active successor transcript instead of continuing to carry the bloated parent transcript.

Real environment tested: Han's local OpenClaw setup on macOS, running installed OpenClaw 2026.5.16-beta.3 with the equivalent local hot patch applied while investigating this regression. The source PR moves the same behavior into the core harness compaction wrapper.

Exact steps or command run after this patch: Ran openclaw --version, openclaw health --json, and a local Codex-native compaction smoke that copied the real main session transcript, simulated the Codex app-server compaction completion path, and inspected the rotated successor transcript written by OpenClaw.

Evidence after fix: Terminal output from the real local OpenClaw setup:

$ openclaw --version
OpenClaw 2026.5.16-beta.3 (d08cbf7)

$ openclaw health --json | node -e '...print ok...'
{
  "ok": true
}

$ node inspect-codex-native-compaction-smoke.js
{
  "smoke": "codex-native-compaction-installed-openclaw",
  "sourceBytes": 958625,
  "successorBytes": 106636,
  "successorLines": 42,
  "successorMessages": 40,
  "successorCompactions": 1,
  "parentSessionPreserved": true,
  "syntheticCompaction": true,
  "compactionBackend": "codex-app-server",
  "firstKeptEntryIdPresent": true
}

Observed result after fix: The active successor transcript shrank from 958625 bytes to 106636 bytes, retained the recent 40 message tail, wrote exactly one synthetic compaction entry for the Codex app-server backend, and preserved the original parent transcript path for rollback/history.

What was not tested: A full live WebChat browser run from this source branch was not run in the PR worktree; the live setup proof above was run against the installed local OpenClaw bundle with the equivalent hot patch.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI. labels May 17, 2026
@clawsweeper

clawsweeper Bot commented May 17, 2026

Copy link
Copy Markdown
Contributor

Thanks for the context here. I did a careful shell check against current main, and this is already implemented.

Current main, shipped in v2026.6.6, already solves the central Codex transcript-bloat problem by keeping context-engine compaction primary, rotating the OpenClaw successor transcript there, and only then starting Codex native compaction as a bounded secondary request. This PR's synthetic-boundary branch is now conflicting and no longer the best landing path.

So I’m closing this as already implemented rather than keeping a duplicate issue open.

Review details

Best possible solution:

Keep the shipped context-engine-first implementation from #91590 as the canonical fix and close this conflicting branch.

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

Not applicable as a current-main reproduction: the source path that mattered for Codex now compacts and rotates through the context engine before starting native Codex compaction. The older failure was source-proven by the prior review and the PR body, but current main no longer follows that path for Codex budget compaction.

Is this the best way to solve the issue?

No, this PR is no longer the best way to solve the issue. The current shipped implementation fixes the user-visible Codex transcript growth at the owner boundary without adding a synthetic compaction-boundary policy to the generic harness rotation helper.

Security review:

Security review cleared: The diff only changes TypeScript compaction logic and tests, with no dependency, workflow, credential, package-resolution, or external-code-execution changes.

AGENTS.md: found and applied where relevant.

What I checked:

  • Current main routes Codex/native harness compaction after context-engine rotation: Current main only invokes primary native harness compaction before the queue when the context engine does not own compaction; for owning context engines it rotates after context-engine compaction, runs side effects, then calls the native harness as a secondary request using the rotated session handles. (src/agents/embedded-agent-runner/compact.queued.ts:291, f1b8827d20c8)
  • Current main keeps the secondary Codex request private and bounded: The harness compaction router keeps after_context_engine as a private internal capability, so the current fix avoids broad plugin SDK/API expansion while still allowing the Codex follow-up path. (src/agents/harness/compaction.ts:31, f1b8827d20c8)
  • Current main Codex bridge sends the native compaction request only on the guarded path: The Codex app-server bridge still skips ordinary non-manual triggers, but the guarded secondary path clears the context-engine projection and sends thread/compact/start with request metadata after OpenClaw has compacted first. (extensions/codex/src/app-server/compact.ts:150, f1b8827d20c8)
  • Regression coverage pins the superseding behavior: The current test suite verifies owning context-engine compaction remains primary for Codex native sessions and that the Codex native follow-up is nested under the result instead of replacing the context-engine compaction result. (src/agents/embedded-agent-runner/compact.hooks.test.ts:2153, f1b8827d20c8)
  • Codex dependency contract checked: Upstream Codex app-server thread/compact/start loads the thread, submits Op::Compact, and returns an empty start response; core handles Op::Compact asynchronously via the compact task, matching OpenClaw's secondary pending-request model. (../codex/codex-rs/app-server/src/request_processors/thread_processor.rs:1737, dfd03ea01bbe)
  • Fix provenance from merged PR: The superseding implementation was merged as Fix context-engine compaction ownership for Codex sessions, with current-main merge commit a8d33f23a09d75d365434de25d7626891158ed09. (a8d33f23a09d)

Likely related people:

  • joshavant: Authored and merged the current-main context-engine-first Codex compaction implementation in the merged PR that supersedes this branch. (role: current fix owner and merger; confidence: high; commits: a8d33f23a09d, c7666c785d70, 2e24ceab886a; files: src/agents/embedded-agent-runner/compact.queued.ts, src/agents/harness/compaction.ts, extensions/codex/src/app-server/compact.ts)
  • steipete: Recent GitHub file history shows compaction runner, harness surface, and Codex compaction-path refactors and docs immediately before the superseding fix. (role: recent area contributor; confidence: medium; commits: b4dfa950b57d, 381a51b2d403, d07cce7bd166; files: src/agents/embedded-agent-runner/compact.queued.ts, src/agents/harness/compaction.ts, extensions/codex/src/app-server/compact.ts)
  • openperf: Recent merged successor-transcript work changed compaction replay and rotation behavior near the helper this PR originally edited. (role: successor transcript adjacent contributor; confidence: medium; commits: 6c259af759a5; files: src/agents/embedded-agent-runner/compaction-successor-transcript.ts)

Codex review notes: model internal, reasoning high; reviewed against f1b8827d20c8; fix evidence: release v2026.6.6, commit a8d33f23a09d.

@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI. labels May 17, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. P2 Normal backlog priority with limited blast radius. impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. labels May 17, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 17, 2026
@hansolo949

Copy link
Copy Markdown
Contributor Author

Addressed ClawSweeper feedback in 897656b9d0174080f62b3af363e4e42039018f82.

  • compactEmbeddedPiSession now runs runPostCompactionSideEffects with the rotated harness successor transcript before returning.
  • Expanded the harness rotation regression test to assert the transcript update event and post-compaction memory sync target the rotated session file.
  • Local validation passed:
    • node scripts/run-vitest.mjs run --config test/vitest/vitest.agents-pi-embedded.config.ts src/agents/pi-embedded-runner/compact.hooks.test.ts
    • node scripts/run-vitest.mjs run --config test/vitest/vitest.agents-pi-embedded.config.ts src/agents/pi-embedded-runner/compaction-successor-transcript.test.ts
    • pnpm exec oxfmt --check --threads=1 src/agents/pi-embedded-runner/compact.queued.ts src/agents/pi-embedded-runner/compact.hooks.test.ts src/agents/pi-embedded-runner/compact.hooks.harness.ts src/agents/pi-embedded-runner/compaction-successor-transcript.ts src/agents/pi-embedded-runner/compaction-successor-transcript.test.ts
    • git diff --check

Latest GitHub checks are green. @clawsweeper re-review

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 17, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. labels Jun 14, 2026
@clawsweeper

clawsweeper Bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

@clawsweeper clawsweeper Bot closed this Jun 14, 2026
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. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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.

1 participant