Skip to content

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

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

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

Codex review: needs maintainer review before merge.

Summary
The PR adds synthetic compaction-boundary transcript rotation after successful harness compaction without a delegated successor, plus focused tests and harness-test mocks.

Reproducibility: yes. at source level: current main returns the harness compaction result before transcript rotation, and the rotation helper currently refuses transcripts without a compaction entry. The PR body also supplies terminal proof of the after-fix rotation behavior from a real local setup.

Real behavior proof
Sufficient (terminal): Sufficient terminal proof is in the PR body, showing a real macOS OpenClaw setup with an equivalent hot patch rotating a bloated Codex-native transcript into a smaller successor.

Next step before merge
No ClawSweeper repair job is needed because the updated PR already addresses the prior narrow review finding and should continue through normal PR validation.

Security
Cleared: The diff only changes TypeScript compaction logic and tests; it does not alter dependencies, CI, permissions, secrets handling, install scripts, or package resolution.

Review details

Best possible solution:

Land the PR after normal CI and maintainer gates, preserving synthetic rotation plus established post-compaction side effects for harness compaction without a delegated successor.

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

Yes, at source level: current main returns the harness compaction result before transcript rotation, and the rotation helper currently refuses transcripts without a compaction entry. The PR body also supplies terminal proof of the after-fix rotation behavior from a real local setup.

Is this the best way to solve the issue?

Yes. The updated approach keeps the fix in the compaction transcript utility and harness finalization path, and the second commit now emits the same post-compaction side effects expected by the existing rotation paths.

What I checked:

  • Current main returns harness compaction before rotation: On current main, compactEmbeddedPiSession returns any harnessResult before reaching the existing queued context-engine transcript rotation path, matching the reported failure mode for harness compaction without a delegated successor. (src/agents/pi-embedded-runner/compact.queued.ts:121, 45d9a0948571)
  • Current rotation requires a compaction boundary: Current main's rotation helper returns "no compaction entry" when no OpenClaw compaction entry exists, so external Codex app-server compaction can leave the bloated parent transcript active. (src/agents/pi-embedded-runner/compaction-successor-transcript.ts:46, 45d9a0948571)
  • PR head adds harness finalization and side effects: The latest PR diff finalizes harness compaction by rotating the transcript with synthesizeMissingBoundary and then calling runPostCompactionSideEffects with the rotated session file before returning the finalized result. (src/agents/pi-embedded-runner/compact.queued.ts, 897656b9d017)
  • PR head tests the previously reported side-effect gap: The updated test asserts the harness rotation path calls rotateTranscriptFileAfterCompaction, adopts the rotated session handles, emits a transcript update, and performs post-compaction memory sync. (src/agents/pi-embedded-runner/compact.hooks.test.ts:1326, 897656b9d017)
  • Prior review finding was followed by a repair commit: The only existing ClawSweeper comment requested post-compaction side effects; the PR commit list shows a later commit named "fix(codex): emit side effects after harness rotation". (897656b9d017)
  • Real behavior proof supplied: The PR body includes terminal output from a real macOS OpenClaw setup with an equivalent hot patch showing the active transcript shrinking from 958625 bytes to 106636 bytes, one synthetic compaction entry, a retained recent tail, and parent preservation. (897656b9d017)

Likely related people:

  • steipete: Recent GitHub commit history for the successor transcript and Codex app-server compaction paths includes multiple compaction, transcript maintenance, and Codex native compaction changes. (role: recent area contributor; confidence: high; commits: 934fc6ceeb10, f7fe6ad55eb0, 35335214b324; files: src/agents/pi-embedded-runner/compaction-successor-transcript.ts, src/agents/pi-embedded-runner/compaction-hooks.ts, extensions/codex/src/app-server/compact.ts)
  • jalehman: Recent merged work touched Codex context-engine projection and compact queued context-window behavior, which are adjacent to this harness compaction path. (role: adjacent owner; confidence: medium; commits: 80ca48418a21, 4004c9342d7d; files: src/agents/pi-embedded-runner/compact.queued.ts, extensions/codex/src/app-server/compact.ts)
  • pashpashpash: GitHub history for the successor transcript helper includes prior follow-up fixes for successor transcript ordering and state deduplication. (role: successor transcript follow-up contributor; confidence: medium; commits: 90de4bd85566, b99540964c05; files: src/agents/pi-embedded-runner/compaction-successor-transcript.ts)

Codex review notes: model gpt-5.5, reasoning high; reviewed against 45d9a0948571.

@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. 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. size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant