Skip to content

[codex] fix Codex budget native compaction trigger#87158

Closed
Steady-ai wants to merge 1 commit into
openclaw:mainfrom
Steady-ai:codex/codex-budget-compaction-trigger
Closed

[codex] fix Codex budget native compaction trigger#87158
Steady-ai wants to merge 1 commit into
openclaw:mainfrom
Steady-ai:codex/codex-budget-compaction-trigger

Conversation

@Steady-ai

@Steady-ai Steady-ai commented May 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Start Codex native app-server compaction for the budget preflight trigger instead of treating it like an unrelated automatic trigger.
  • Keep omitted and overflow triggers on the existing Codex-owned skip path.
  • Document that agents.defaults.compaction.maxActiveTranscriptBytes starts native Codex compaction for Codex harness sessions.

Duplicate check

I checked current origin/main plus open PRs/issues before opening this PR. Current main still skipped trigger: "budget" in extensions/codex/src/app-server/compact.ts and had a test pinning that skip in compact.test.ts. I did not find an open PR from this fork for this compaction trigger; the only open Steady-ai PR was #86716 for Discord delivery accounting. I also inspected nearby compaction/Codex PRs including #81916, #63636, #54585, #86160, #83229, #82856, #86094, and #73092; none made budget start native Codex compaction.

Real behavior proof

Behavior addressed: Codex harness sessions with agents.defaults.compaction.maxActiveTranscriptBytes call compaction with trigger: "budget". Current source skipped that trigger before sending thread/compact/start, so the local transcript-byte guard could leave long-lived channel mirrors above the configured cleanup threshold.

Real environment tested: OpenClaw source worktree rebased on origin/main at d88681662b, PR head 47f33748d4, on WSL Ubuntu 24.04 / Node 22.22.0. The source-runtime probe used the real maybeCompactCodexAppServerSession entry point and real Codex session-binding file I/O, with the app-server client boundary instrumented only to capture the outgoing app-server request.

Exact steps or command run after this patch: Ran a node --import tsx - source-runtime probe from the PR worktree. The probe wrote a temporary Codex app-server binding, invoked maybeCompactCodexAppServerSession once with trigger: "budget" and once with trigger: "overflow", then printed the request/result shape. I then ran the focused checks listed in Verification.

Evidence after fix: Copied terminal output from the source-runtime probe:

[agent/embedded] started codex app-server compaction
[agent/embedded] skipping codex app-server compaction for non-manual trigger
{
  "head": "47f33748d4",
  "behavior": "codex budget compaction trigger starts native app-server compaction",
  "budget": {
    "request": {
      "method": "thread/compact/start",
      "params": {
        "threadId": "thread-proof-budget"
      }
    },
    "ok": true,
    "compacted": false,
    "reason": null,
    "signal": "thread/compact/start",
    "pending": true,
    "tokensBefore": 456
  },
  "overflow": {
    "additionalRequests": 0,
    "ok": true,
    "compacted": false,
    "reason": "codex app-server owns automatic compaction",
    "skippedReason": "non_manual_trigger",
    "trigger": "overflow"
  }
}

Observed result after fix: Budget preflight compaction now sends thread/compact/start and returns the existing pending native-compaction result shape. The overflow trigger sends no additional app-server request and still returns the existing non_manual_trigger skip result.

What was not tested: I did not run a live Discord or Telegram gateway replay from this source branch. The live failure was observed in an installed runtime; this PR ports the source-level behavior and locks it with focused Codex extension tests.

Risk

Low. The change is limited to the Codex app-server compaction trigger gate. It does not wait for native compaction completion, add credentials, change network targets, or replace Codex compaction with OpenClaw summarization.

Verification

  • OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs run --config test/vitest/vitest.extension-codex.config.ts extensions/codex/src/app-server/compact.test.ts -> 1 file / 19 tests passed
  • node_modules/.bin/oxfmt --check extensions/codex/src/app-server/compact.ts extensions/codex/src/app-server/compact.test.ts docs/plugins/codex-harness-runtime.md docs/reference/session-management-compaction.md -> passed
  • git diff --check -> passed
  • pnpm docs:list -> passed
  • node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.extensions.json extensions/codex/src/app-server/compact.ts extensions/codex/src/app-server/compact.test.ts -> passed
  • node scripts/check-docs-mdx.mjs docs/plugins/codex-harness-runtime.md docs/reference/session-management-compaction.md -> passed

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: codex size: XS labels May 27, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI. label May 27, 2026
@Steady-ai
Steady-ai force-pushed the codex/codex-budget-compaction-trigger branch from 4a4bb8f to 47f3374 Compare May 27, 2026 04:35
@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 27, 2026
@clawsweeper

clawsweeper Bot commented May 27, 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 already handles the useful Codex budget/native-compaction behavior through the merged context-engine-first implementation from #91590, so this older helper-only branch is no longer a useful landing candidate.

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

Review details

Best possible solution:

Keep the merged current-main implementation from #91590 as the canonical Codex budget compaction path and close this stale branch.

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

Not applicable as a current-main reproduction: the relevant behavior is already fixed on main by #91590. The pre-fix failure mode is documented by that merged PR's before/after proof and by the older ClawSweeper review on this PR.

Is this the best way to solve the issue?

No, this PR is no longer the best way to solve the issue. Current main uses the safer owner-boundary shape: context-engine compaction remains primary and Codex native thread/compact/start is only a bounded secondary follow-up.

Security review:

Security review cleared: The PR diff does not add dependencies, workflows, package-resolution changes, credentials handling, or new external code execution paths.

AGENTS.md: found and applied where relevant.

What I checked:

  • Current main source: context-engine first, then secondary native Codex request: Current main compacts with the owning context engine first, then conditionally calls maybeCompactAgentHarnessSession(..., { nativeCompactionRequest: "after_context_engine" }) as a secondary native harness follow-up. (src/agents/embedded-agent-runner/compact.queued.ts:526, 9408380ae729)
  • Current main source: private after-context-engine harness capability: The harness compaction router keeps the secondary native compaction request behind the private after_context_engine option instead of exposing the PR's broad direct budget behavior as the default compact hook. (src/agents/harness/compaction.ts:31, 9408380ae729)
  • Current main source: Codex bridge allows guarded non-manual native requests only by option: The Codex app-server bridge still skips normal non-manual triggers, but allowNonManualNativeRequest takes the guarded lock path and sends thread/compact/start with request: "after_context_engine" details. (extensions/codex/src/app-server/compact.ts:150, 9408380ae729)
  • Current main source: Codex harness wires the guarded secondary hook: The Codex harness exposes compactAfterContextEngine internally and passes allowNonManualNativeRequest: true, which is the safer current implementation of the budget/native compaction handoff. (extensions/codex/harness.ts:91, 9408380ae729)
  • Codex dependency contract checked: Upstream Codex app-server protocol defines thread/compact/start, and the app-server loads the thread, submits Op::Compact, then returns an empty start response while compaction notifications follow asynchronously. (../codex/codex-rs/app-server/src/request_processors/thread_processor.rs:1698, a7b6baecc635)
  • Fix provenance from git blame: git blame ties the guarded non-manual Codex compaction option, secondary request details, and context-engine handoff plumbing to commit a8d33f23a09d75d365434de25d7626891158ed09. (extensions/codex/src/app-server/compact.ts:212, a8d33f23a09d)

Likely related people:

  • joshavant: Merged Fix context-engine compaction ownership for Codex sessions #91590, which introduced the current context-engine-first plus secondary Codex native compaction behavior that supersedes this branch. (role: current fix owner; confidence: high; commits: a8d33f23a09d; files: src/agents/embedded-agent-runner/compact.queued.ts, src/agents/harness/compaction.ts, extensions/codex/src/app-server/compact.ts)
  • Steady-ai: Authored the earlier merged fix(codex): avoid native compaction on budget triggers work and this PR edits the same Codex app-server trigger gate. (role: introduced current skip behavior and current PR proposer; confidence: high; commits: 307a1409c3ee, 47f33748d4b6; files: extensions/codex/src/app-server/compact.ts, extensions/codex/src/app-server/compact.test.ts)
  • Shakker: Recent blame on the compact bridge and queued compaction files shows adjacent baseline work immediately before the current main fix, so this is a secondary routing signal rather than ownership of the superseding behavior. (role: recent adjacent contributor; confidence: low; commits: ef2ca9e50eaf; files: extensions/codex/src/app-server/compact.ts, src/agents/embedded-agent-runner/compact.queued.ts)

Codex review notes: model gpt-5.5, reasoning high; reviewed against 7f1d82ab2518; fix evidence: commit a8d33f23a09d, main fix timestamp 2026-06-09T21:33:00-05:00.

@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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels May 27, 2026
@clawsweeper

clawsweeper Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

✨ Hatched: 🥚 common Cosmic Shellbean

Hatch command

Comment @clawsweeper hatch when this PR is hatchable.

Hatchability rules:

  • Merged PRs are hatchable.
  • Open PRs are hatchable when they are status: 👀 ready for maintainer look, status: 🚀 automerge armed, or labeled clawsweeper:automerge.
  • Closed unmerged PRs are hatchable only when one of those hatchable labels is still present in the durable record.

Rarity: 🥚 common.
Trait: stacks clean commits.
Image traits: location status garden; accessory CI status badge; palette moonlit blue and soft silver; mood mischievous; pose waving from a small platform; shell soft speckled shell; lighting subtle sparkle highlights; background subtle branch markers.
Share on X: post this hatch
Copy: My PR egg hatched a 🥚 common Cosmic Shellbean in ClawSweeper.

What is this egg doing here?
  • Eggs appear after the PR passes real-behavior proof. It is here for vibes, not verdicts: it does not change labels, ratings, merge decisions, or automation.
  • The shell reacts to review momentum: open follow-up work warms it up, re-review makes it wobble, and a clean final review lets it hatch.
  • Hatchability usually comes from sufficient real-behavior proof, no blocking P0/P1/P2 findings, no security attention needed, and clean correctness. A merged PR is already final, so merge makes the egg hatchable independently.
  • The hatch is seeded from this repository and PR number, so the same PR keeps the same creature; the reviewed head SHA can only change safe visual details.
  • Rarity is just collectible sparkle: 🥚 common, 🌱 uncommon, 💎 rare, ✨ glimmer, and 🌈 legendary.

@clawsweeper clawsweeper Bot added rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. and removed 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 29, 2026
@clawsweeper clawsweeper Bot added 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. and removed rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. labels May 29, 2026
@clawsweeper

clawsweeper Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

@clawsweeper clawsweeper Bot closed this Jun 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: codex 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: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants