Skip to content

fix(agents): skip below-target CLI compaction failures#88319

Merged
obviyus merged 2 commits into
openclaw:mainfrom
frankekn:fix/codex-cli-compaction-under-target
May 31, 2026
Merged

fix(agents): skip below-target CLI compaction failures#88319
obviyus merged 2 commits into
openclaw:mainfrom
frankekn:fix/codex-cli-compaction-under-target

Conversation

@frankekn

@frankekn frankekn commented May 30, 2026

Copy link
Copy Markdown
Contributor

Summary

What problem does this PR solve?

  • Prevents retried CLI/Codex agent turns from failing when compaction reports the transcript is already below target.
  • Treats already under target / below-threshold compaction as a no-op instead of a fatal post-turn compaction error.
  • Clears stale Codex native CLI bindings when native compaction reports a missing thread and the context-engine fallback also has nothing to compact.

Why does this matter now?

  • Telegram and other webhook retries can re-enter the same agent path after a transient turn failure. A harmless compaction no-op should not become a visible repeated error.

What is the intended outcome?

  • CLI-backed Codex turns continue when compaction says there is nothing useful to reduce.
  • Real compaction failures, such as timeouts, still fail loudly.

What is intentionally out of scope?

  • Durable Telegram webhook dedupe behavior.
  • Notification dispatch policy changes.
  • Codex app-server compaction algorithm changes.

What does success look like?

  • already under target compaction results resolve as no-ops.
  • Stale Codex thread bindings are dropped after a recoverable missing-thread compaction response, so the next retry starts from a fresh binding instead of looping on the dead one.
  • Existing timeout/native harness failure coverage still proves non-benign failures throw.

What should reviewers focus on?

  • Whether below_threshold is the right existing classifier to reuse for CLI no-op behavior.
  • Whether the no-op branch avoids clearing CLI resume state or recording a compaction count.
  • Whether stale native binding cleanup should stay limited to recoverable Codex/native binding failures rather than all compaction no-ops.

Linked context

Which issue does this close?

Closes #

Which issues, PRs, or discussions are related?

Related #

Was this requested by a maintainer or owner?

  • Requested during investigation of repeated Telegram-visible progress errors caused by retried CLI/Codex turns hitting already under target compaction.
  • Builds on Ayaan Zaidi's (@obviyus) prior maintainer fix, c0a5f15dc8 fix(agents): clear unflushed cli bindings, which established the session-store path for clearing stale/unflushed CLI bindings. This PR extends that recovery to the compaction retry path.

Real behavior proof

  • Behavior or issue addressed: CLI/Codex compaction returning compacted:false with reason:"already under target" was treated as a fatal post-turn compaction failure.
  • Real environment tested: Local OpenClaw source checkout on macOS, Node 24.14.0, Codex CLI 0.135.0, Codex app-server 0.134.0.
  • Exact steps or command run after this patch: Ran a source-checkout Node/tsx smoke that creates an isolated production Codex app-server client, starts a real Codex thread, and calls thread/compact/start on that below-target thread.
  • Evidence after fix:
{
  "proof": "PR88319 Codex app-server below-target compact smoke",
  "source": "local OpenClaw source checkout",
  "codexCli": "0.135.0",
  "serverVersion": "0.134.0",
  "threadStarted": true,
  "compactReturned": true,
  "visibleTurnFailure": false,
  "redactions": [
    "thread id",
    "temp path"
  ]
}
  • Observed result after fix: The real Codex app-server compaction request returned successfully for the tiny below-target thread, and the OpenClaw regression tests prove both CLI transcript and Codex native already under target results now return as no-ops without recording a compaction or throwing.
  • What was not tested: Live Telegram webhook retry against production bot credentials.
  • Proof limitations or environment constraints: The local Codex/OpenAI auth path hit a Cloudflare 403 when trying to run a full OpenClaw agent turn with context-engine fallback, so the real runtime proof is scoped to the production Codex app-server compaction request plus focused OpenClaw regression tests for the exact already under target reason.
  • Before evidence (optional but encouraged): The pre-fix control flow threw for non-fallback compacted:false results; the old tests had no below-target coverage.

Tests and validation

Which commands did you run?

  • PNPM_CONFIG_FETCH_RETRIES=5 PNPM_CONFIG_FETCH_RETRY_MINTIMEOUT=60000 PNPM_CONFIG_FETCH_RETRY_MAXTIMEOUT=180000 pnpm install --frozen-lockfile
  • node scripts/test-projects.mjs src/agents/command/cli-compaction.test.ts
  • node_modules/.bin/tsgo -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo --declaration false --pretty false
  • node_modules/.bin/tsgo -p test/tsconfig/tsconfig.core.test.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core-test.tsbuildinfo --declaration false --pretty false
  • git diff --check
  • pnpm check:changed (blocked at unrelated lint tooling issue after core typechecks passed)

What regression coverage was added or updated?

  • Added context-engine CLI compaction coverage for { ok: true, compacted: false, reason: "already under target" }.
  • Added Codex native CLI compaction coverage for { ok: true, compacted: false, reason: "already under target" }.
  • Added stale Codex native binding coverage for missing-thread recovery where the context-engine fallback is also below target, proving the stale binding is cleared without recording a compaction.
  • Existing nonrecoverable native timeout failure coverage remains unchanged.

What failed before this fix, if known?

  • The CLI compaction lifecycle treated non-fallback compacted:false as fatal, even when the reason was below-target/no-op.

If no test was added, why not?

  • Tests were added.

Risk checklist

Did user-visible behavior change? (Yes/No)

Yes. Harmless below-target compaction no-ops no longer surface as failed CLI/Codex turns.

Did config, environment, or migration behavior change? (Yes/No)

No.

Did security, auth, secrets, network, or tool execution behavior change? (Yes/No)

No.

What is the highest-risk area?

  • Accidentally swallowing real compaction failures.

How is that risk mitigated?

  • The no-op handling is restricted to the existing below_threshold classifier.
  • Timeout and unsupported/stale-binding failure paths remain covered separately.

Current review state

What is the next action?

  • Maintainer review and CI.

What is still waiting on author, maintainer, CI, or external proof?

  • CI should confirm full repo gates in a clean environment.
  • Optional live webhook verification can be done by a maintainer with Telegram credentials.

Which bot or reviewer comments were addressed?

  • None yet.

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

clawsweeper Bot commented May 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed May 31, 2026, 1:14 AM ET / 05:14 UTC.

Summary
Review failed before ClawSweeper could summarize the requested change.

PR surface: Source +42, Tests +240. Total +282 across 2 files.

Reproducibility: unclear. The review failed before ClawSweeper could establish a reproduction path.

Review metrics: none identified.

Merge readiness
Overall: 🌊 off-meta tidepool
Proof: 🌊 off-meta tidepool
Patch quality: 🌊 off-meta tidepool
Result: rating does not apply to this item.

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

Risk before merge

  • [P1] No close action taken because the review did not complete.

Maintainer options:

  1. Decide the mitigation before merge
    Retry the Codex review after fixing the execution failure.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P1] Review did not complete, so no work-lane recommendation was made.
Review details

Best possible solution:

Retry the Codex review after fixing the execution failure.

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

Unclear. The review failed before ClawSweeper could establish a reproduction path.

Is this the best way to solve the issue?

Unclear. Retry the review first so ClawSweeper can evaluate the actual issue and fix direction.

AGENTS.md: unclear because the file could not be read completely.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 51dee73a5d3e.

Label changes

Label changes:

  • remove P2: Current review triage priority is none.
  • remove merge-risk: 🚨 session-state: Current PR review selected no merge-risk labels.

Label justifications:

  • rating: 🌊 off-meta tidepool: Overall readiness is 🌊 off-meta tidepool; proof is 🌊 off-meta tidepool and patch quality is 🌊 off-meta tidepool.
Evidence reviewed

PR surface:

Source +42, Tests +240. Total +282 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 50 8 +42
Tests 1 240 0 +240
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 290 8 +282

What I checked:

  • failure reason: codex execution failed.
  • codex failure detail: Codex review failed for this PR with exit 1.
  • codex stdout: Per-item Codex failure; continuing with the rest of the shard.

Likely related people:

  • unknown: Codex failed before it could trace repository history. (role: review did not complete; confidence: low)
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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a000d3a3ff

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread CHANGELOG.md Outdated
Comment thread src/agents/command/cli-compaction.ts
@clawsweeper clawsweeper Bot added 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. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels May 30, 2026
@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 30, 2026
@frankekn

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Addressed the proof/changelog feedback:

  • Removed the manual CHANGELOG.md entry in ece6b95d1c.
  • Updated the PR body with after-fix real runtime output from a local OpenClaw source checkout: isolated production Codex app-server client, real thread start, and thread/compact/start returning without visible turn failure.
  • The Real behavior proof gate is now green on latest head ece6b95d1c0a33a5f8c25345a3647a78c07eefcb: https://github.com/openclaw/openclaw/actions/runs/26683850188
  • Focused validation after cleanup:
    • node scripts/test-projects.mjs src/agents/command/cli-compaction.test.ts -> 15 passed
    • node_modules/.bin/tsgo -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo --declaration false --pretty false -> passed
    • node_modules/.bin/tsgo -p test/tsconfig/tsconfig.core.test.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core-test.tsbuildinfo --declaration false --pretty false -> passed
    • git diff --check -> passed

@clawsweeper

clawsweeper Bot commented May 30, 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 repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels May 30, 2026
@openclaw-barnacle openclaw-barnacle Bot added size: M and removed size: S proof: sufficient ClawSweeper judged the real behavior proof convincing. labels May 30, 2026
@frankekn

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Addressed the rank-up P2 stale-native-plus-below-target fallback gap in 71389790ec2a1f7d9088eea6724d1503f4d418bf.

What changed:

  • Added combined regression coverage for stale Codex native binding followed by context-engine fallback returning already under target.
  • Added clearCliSessionBindingInStore so recoverable native binding failures clear the stale CLI/native binding even when the fallback is a true below-target no-op.
  • Kept no-op semantics intact: the combined path does not call recordCliCompactionInStore, does not run maintenance, and does not increment compactionCount.
  • Scoped binding clearing to recoverable native binding failures only, not generic unsupported/native-auto fallback.

Validation:

  • node scripts/test-projects.mjs src/agents/command/cli-compaction.test.ts -> 16 passed
  • node_modules/.bin/tsgo -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo --declaration false --pretty false -> passed
  • node_modules/.bin/tsgo -p test/tsconfig/tsconfig.core.test.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core-test.tsbuildinfo --declaration false --pretty false -> passed
  • git diff --check -> passed

@clawsweeper

clawsweeper Bot commented May 30, 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 repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 30, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 31, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 31, 2026
@obviyus obviyus self-assigned this May 31, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 31, 2026
@obviyus

obviyus commented May 31, 2026

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

Addressed the current review feedback in 9320ab5145237dd9b5d29519b519b3e48f0633d2.

What changed:

  • Replaced the duplicate clearCliSessionBindingInStore helper with the existing clearCliSessionInStore path.
  • Removed the duplicate session-store helper entirely.
  • Dropped unrelated formatter-only changes from src/plugins/status-snapshot.ts, test/scripts/build-all.test.ts, and test/scripts/test-live.test.ts; the PR file list is now only src/agents/command/cli-compaction.ts and src/agents/command/cli-compaction.test.ts.
  • Resolved the addressed review threads.

Validation:

  • git diff --check -> passed
  • node scripts/run-vitest.mjs src/agents/command/cli-compaction.test.ts -> 16 passed
  • node_modules/.bin/tsgo -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo --declaration false --pretty false -> passed
  • node_modules/.bin/tsgo -p test/tsconfig/tsconfig.core.test.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core-test.tsbuildinfo --declaration false --pretty false -> passed

@clawsweeper

clawsweeper Bot commented May 31, 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 repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@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. rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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. labels May 31, 2026
@obviyus
obviyus force-pushed the fix/codex-cli-compaction-under-target branch from 9320ab5 to e3a63fa Compare May 31, 2026 05:10
@frankekn

Copy link
Copy Markdown
Contributor Author

@hxy91819 please review also

@obviyus
obviyus force-pushed the fix/codex-cli-compaction-under-target branch from e3a63fa to 4ca3773 Compare May 31, 2026 08:07
@obviyus
obviyus merged commit 15c1511 into openclaw:main May 31, 2026
136 of 140 checks passed
@obviyus

obviyus commented May 31, 2026

Copy link
Copy Markdown
Contributor

Landed via rebase onto main.

  • Scoped tests: git diff --check; node scripts/run-vitest.mjs src/agents/command/cli-compaction.test.ts; node_modules/.bin/tsgo -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo --declaration false --pretty false; node_modules/.bin/tsgo -p test/tsconfig/tsconfig.core.test.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core-test.tsbuildinfo --declaration false --pretty false
  • Changelog: skipped per repo release-owned changelog policy; behavior context is in the PR/commit history
  • Land commit: 4ca3773
  • Merge commit: 15c1511

Thanks @frankekn!

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

Labels

agents Agent runtime and tooling merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants