Skip to content

fix(codex): refresh session meters after /codex compact - #123640

Merged
steipete merged 13 commits into
mainfrom
steipete/codex-compact-pipeline
Aug 14, 2026
Merged

steipete merged 13 commits into
mainfrom
steipete/codex-compact-pipeline

Conversation

@steipete

@steipete steipete commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor
Additional instructions

MUST: Keep Allow edits from maintainers enabled for this PR so maintainers
can help update the branch when needed.

What Problem This Solves

Fixes an issue where users running /codex compact received only a start acknowledgement while the session's compaction count and token meter stayed stale.

Why This Change Was Made

Plugin commands can now request compaction for their currently bound session through a gated host runtime callback. The host runs the canonical manual-compaction pipeline, including native completion watching and session-store accounting; /codex compact preserves Codex-thread binding admission, then delegates to that callback instead of exposing the redundant raw compact control method.

Maintainer decision (Peter Steinberger): compactCurrent is approved as a general public Plugin SDK capability for all plugin commands. Its documented structured result and lifecycle are supported external contracts; the host gates it to the current command invocation and exact bound session generation.

The dispatcher snapshots the complete admitted session entry and store target. Host-capability calls never fall back to a later live entry. Manual compaction revalidates that exact generation before aborting an active run, starting native work, and committing accounting. The SQLite commit edge rechecks invocation authority inside the synchronous transaction. Retained and detached callbacks fail closed after handler settlement. Unauthorized public commands receive a structured blocked result without compaction.

/codex compact additionally requires complete captured session identity, verifies Codex runtime ownership from the captured store path, and permits a conversation-selected target only when it is the same physical Codex owner (threadId and clientId) as the session binding. Incomplete, replaced, mixed-runtime, or distinct-owner states fail visibly before compaction.

User Impact

/codex compact now waits for the terminal compaction outcome, refreshes compactionCount and the fresh post-compaction token snapshot, and reports either the resulting token count or the skip/failure reason. Sessions without an attached Codex thread or exact Codex runtime ownership receive explicit non-compaction outcomes.

Evidence

  • Regression test applied to origin/main: failed because the host compaction callback was absent and no session metadata was recorded.
  • Invocation regressions prove retained and unawaited callbacks fail with command invocation closed after handler settlement, without later native compaction.
  • Session regressions cover durable and in-place generation replacement before invocation, replacement during admission, disappearance, queued-updater authority revocation, and commit-time CAS rejection; memory changes only after a matching authorized durable commit.
  • Context-engine successor regressions prove the final fence accepts only the successor committed by this invocation and rejects a harness-returned successor when accounting did not commit.
  • Codex coverage proves incomplete identity, non-Codex runtime ownership, missing binding, unauthorized public access, and distinct conversation/session physical owners all fail before host compaction.
  • node scripts/run-vitest.mjs src/auto-reply/reply/commands-plugin.test.ts src/auto-reply/reply/commands-compact.test.ts src/auto-reply/reply/session-updates.lifecycle.test.ts src/agents/subagents/registry/subagent-registry.steer-restart.test.ts — 87 tests passed.
  • node scripts/run-vitest.mjs extensions/codex/src/command-rpc.test.ts extensions/codex/src/commands.test.ts — 179 tests passed.
  • ClawSweeper acceptance set including src/config/sessions/session-accessor.sqlite-active-events.test.ts — 73 tests passed.
  • pnpm tsgo, pnpm tsgo:core:test, pnpm tsgo:extensions, and pnpm tsgo:extensions:test — passed.
  • pnpm lint:tmp:session-accessor-boundary, the exact hosted core lint stripe, focused core/extension oxlint, formatting, and diff checks — passed.
  • pnpm plugin-sdk:surface:check and pnpm docs:list — passed.
  • P1 autoreview — clean after the final commit-edge authority repair.
  • Pinned Codex contract: rust-v0.147.0 (be6e8eac029b) documents the immediate empty acknowledgement in codex-rs/app-server/README.md:194,786-799, submits Op::Compact in codex-rs/app-server/src/request_processors/thread_processor.rs:1876-1888, and emits token updates from codex-rs/app-server/src/bespoke_event_handling.rs:1576-1591 through the notification declared in codex-rs/app-server-protocol/src/protocol/common.rs:1703.
  • Exact-head CI run 31819137872 passed on 21afbd64548690fbf22215221b4ae54f4fb39210, including openclaw/ci-gate.
  • Exact-head ClawSweeper review: no actionable findings; Platinum Hermit, ready for maintainer review.

Production LOC: +308/-98 (net +210). Tests: +693/-27. Documentation: +34/-1. The production growth implements the approved public runtime capability and its closure-bound identity, runtime, binding, native-compaction, queued-update, and durable-commit authority; the former raw command-forward capability was removed.

@clawsweeper

clawsweeper Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review August 14, 2026 12:07
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: codex plugin: file-transfer size: M maintainer Maintainer-authored PR labels Aug 14, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 14, 2026
@clawsweeper

clawsweeper Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 14, 2026, 12:30 PM ET / 16:30 UTC.

ClawSweeper review

What this changes

This PR makes /codex compact wait for the shared manual-compaction result, persist refreshed token and compaction-meter state, and expose the host capability to bound plugin commands.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep open for maintainer review. The patch routes a stale-meter path through the canonical compaction owner and closes the previously reported authority race; its remaining blocker is independent verification of the upstream Codex app-server contract and exact-head validation after the branch refresh. Likely related people: steipete (high) and iridescentWen (medium).

Priority: P1
Reviewed head: 21afbd64548690fbf22215221b4ae54f4fb39210
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch follows the existing compaction owner and covers the prior session-authority finding; only independent upstream-contract verification remains unavailable to this review.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is not subject to the external-contributor real-behavior-proof gate; the body supplies focused test evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is not subject to the external-contributor real-behavior-proof gate; the body supplies focused test evidence.
Evidence reviewed 5 items Current-main gap: Current main sends /codex compact directly to the app-server and returns a start acknowledgement; it does not enter the manual-compaction accounting path that calls incrementCompactionCount.
Canonical native owner already fences binding changes: The current native compaction owner rechecks the physical thread binding immediately before requesting compaction and waits for completion before returning token state, so delegating to this pipeline is the right owner boundary.
Final authority repair: The final PR commit adds a transaction-edge authorization assertion before the session-row write; the current session accessor performs that assertion inside its synchronous SQLite write transaction.
Findings None None.
Security None None.

How this fits together

A Codex plugin command enters the plugin-command dispatcher, which supplies an invocation-bound host capability for the selected OpenClaw session. The host compaction pipeline drives the native Codex app-server operation, commits session accounting, and returns a visible terminal status to the chat.

flowchart LR
  A[User runs Codex compact command] --> B[Plugin command dispatcher]
  B --> C[Invocation-bound host capability]
  C --> D[Manual compaction pipeline]
  D --> E[Native Codex app-server compaction]
  E --> F[Session accounting commit]
  F --> G[Visible token and outcome reply]
Loading

Decision needed

Question Recommendation
Is the PR body's pinned Codex contract evidence sufficient for merge, or should this protocol-dependent change wait for an independent review in an environment containing the required ../codex checkout? Wait for independent Codex audit: Rebase as needed, inspect the cited upstream source in an environment with ../codex, then require exact-head CI before merge.

Why: Repository policy requires the acting reviewer to inspect the exact Codex source for a Codex-dependent verdict, but that checkout is unavailable here; only a maintainer can accept the supplied evidence as an exception or require the independent audit.

Before merge

  • Resolve merge risk (P1) - The PR adds a supported Plugin SDK command capability and session-write authority path (+210 production lines); its invocation lifetime and durable-generation guarantees are compatibility- and session-state-sensitive.
  • Resolve merge risk (P1) - Independent confirmation of the app-server completion/token contract remains unavailable in this review environment because the required sibling Codex source checkout is absent; refresh the branch and validate the exact merged head after that audit.
  • Complete next step (P2) - A maintainer must resolve the independent Codex-source proof gate and refresh exact-head validation; there is no narrow mechanical repair to dispatch.
Agent review details

Security

None.

PR surface

Source +210, Tests +666, Docs +33. Total +909 across 17 files.

View PR surface stats
Area Files Added Removed Net
Source 10 308 98 +210
Tests 5 693 27 +666
Docs 2 34 1 +33
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 17 1035 126 +909

Review metrics

Metric Value Why it matters
Production versus test delta production +308/-98 (net +210); tests +693/-27; docs +34/-1 The bug fix also establishes a general public plugin-command capability, so its production growth and lifecycle boundary warrant explicit merge review.

Stored data model

Persistent data-model change detected: serialized state: src/auto-reply/reply/session-updates.lifecycle.test.ts, serialized state: src/auto-reply/reply/session-updates.ts, unknown-data-model-change: src/auto-reply/reply/session-updates.lifecycle.test.ts, unknown-data-model-change: src/auto-reply/reply/session-updates.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Audit then merge (recommended)
    Verify the cited Codex app-server source, refresh the branch against current main, and merge only with green checks for the resulting exact head.
  2. Accept pinned protocol evidence
    A maintainer may accept the supplied upstream source references and own the residual protocol-verification risk after exact-head CI completes.

Technical review

Best possible solution:

Keep one host-owned compaction path and land only after an independent upstream Codex contract check plus exact-head validation confirms the documented lifecycle; no smaller net-neutral repair can both add the approved public capability and preserve its invocation and session fences.

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

Yes, from source: current main directly starts the Codex app-server operation and returns an acknowledgement, while the accounting call lives only in the separate manual-compaction pipeline. This review did not execute the reproduction because the checkout is read-only.

Is this the best way to solve the issue?

Unclear. Routing through the existing host compaction pipeline is the best architectural direction, but independent upstream Codex protocol verification is still required before this reviewer can make a complete dependency-backed verdict.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against e74671df05e8.

Labels

Label justifications:

  • P1: A normal Codex command currently leaves session meters stale, affecting an active user command workflow.
  • merge-risk: 🚨 compatibility: The PR adds a documented public Plugin SDK capability with invocation-lifetime behavior that external plugin commands may consume.
  • merge-risk: 🚨 session-state: The change writes compaction counts and token snapshots through generation- and invocation-fenced session persistence.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is not subject to the external-contributor real-behavior-proof gate; the body supplies focused test evidence.

Evidence

What I checked:

  • Current-main gap: Current main sends /codex compact directly to the app-server and returns a start acknowledgement; it does not enter the manual-compaction accounting path that calls incrementCompactionCount. (extensions/codex/src/command-handler-actions.ts:442, e74671df05e8)
  • Canonical native owner already fences binding changes: The current native compaction owner rechecks the physical thread binding immediately before requesting compaction and waits for completion before returning token state, so delegating to this pipeline is the right owner boundary. (extensions/codex/src/app-server/compact.ts:675, e74671df05e8)
  • Final authority repair: The final PR commit adds a transaction-edge authorization assertion before the session-row write; the current session accessor performs that assertion inside its synchronous SQLite write transaction. (src/auto-reply/reply/session-updates.ts:403, 21afbd645486)
  • History and current-main provenance: Blame attributes the current direct-command behavior to commit 94cdb6c, while Codex app-server supervision and the compact owner have sustained history led by steipete; the PR head is not contained in current main. (extensions/codex/src/command-handler-actions.ts:442, 94cdb6c46e12)
  • Upstream dependency audit unavailable: The PR explicitly depends on Codex app-server request/completion semantics, but the required sibling ../codex checkout is absent and DNS prevented the mandated source fetch; this is a reviewer-environment limitation, not missing contributor proof.

Likely related people:

  • steipete: Authored the prior native Codex supervision feature and the current PR; history shows repeated Codex compaction and ownership work. (role: Codex feature owner and recent area contributor; confidence: high; commits: f94a7dc183c6, 45dd558d923c, 21afbd645486; files: extensions/codex/src/app-server/compact.ts, extensions/codex/src/command-handler-actions.ts, src/auto-reply/reply/commands-compact.ts)
  • iridescentWen: Blame attributes the current direct /codex compact command path to this contributor's current-main commit. (role: current command-path contributor; confidence: medium; commits: 94cdb6c46e12; files: extensions/codex/src/command-handler-actions.ts, src/auto-reply/reply/session-updates.ts)
  • Qiong: History includes the native /compact token-accounting repair that this PR reuses as its canonical host path. (role: adjacent compaction contributor; confidence: medium; commits: 94746d713887; files: src/auto-reply/reply/commands-compact.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Inspect the cited Codex app-server source in an environment with the required sibling checkout, then validate the refreshed exact head.

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 (13 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-14T13:45:09.294Z sha f0495583a8c878b2d4964de58babc25bb9fdfc70 :: found issues before merge. :: [P1] Fence compaction that outlives its command | [P1] Fence accounting at the SQLite commit | [P1] Revalidate before aborting a stale run
  • reviewed 2026-08-14T14:14:51.953Z sha 06d83ff0f8a725f54d164049c1d4654bef144b32 :: needs changes before merge. :: [P1] Preserve the Codex binding admission check
  • reviewed 2026-08-14T14:23:09.082Z sha c0f9a55 :: found issues before merge. :: [P1] Restore the Codex binding admission check
  • reviewed 2026-08-14T14:33:14.080Z sha 3aa487c :: found issues before merge. :: [P1] Restore the Codex binding admission check | [P2] Return a typed result for public commands
  • reviewed 2026-08-14T15:02:25.752Z sha 12d040e :: found issues before merge. :: [P1] Confirm the public compaction capability
  • reviewed 2026-08-14T15:11:59.666Z sha 12d040e :: found issues before merge. :: [P1] Preserve the resolved Codex binding when compacting
  • reviewed 2026-08-14T15:29:12.369Z sha 8d4917b :: found issues before merge. :: [P1] Preserve the admitted session generation | [P1] Keep Codex compaction bound to the selected thread
  • reviewed 2026-08-14T16:11:52.835Z sha b82ff42 :: needs changes before merge. :: [P1] Recheck command authority at the SQLite commit edge

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Aug 14, 2026
Route /codex compact through host-owned manual compaction so native completion and token snapshots update session meters, and report the terminal outcome to the user.
Bind compactCurrent to one command invocation and captured session generation so retained or stale callbacks fail closed without running compaction.
Keep compaction session freshness checks at the auto-reply owner without pulling the session accessor into generic plugin command module initialization.
@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 Aug 14, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The coordinator-approved maintainer decision is now explicit in the PR body: compactCurrent is a supported general public Plugin SDK capability for all plugin commands, host-gated to the current invocation and exact bound session generation. The body also records the exact rust-v0.147.0 source paths inspected for the Codex protocol contract.

@clawsweeper

clawsweeper Bot commented Aug 14, 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.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 14, 2026
@clawsweeper clawsweeper Bot added 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: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 14, 2026
@steipete
steipete merged commit 8885be4 into main Aug 14, 2026
189 checks passed
@steipete
steipete deleted the steipete/codex-compact-pipeline branch August 14, 2026 16:47
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 15, 2026
)

* fix(codex): route compact through session pipeline

Route /codex compact through host-owned manual compaction so native completion and token snapshots update session meters, and report the terminal outcome to the user.

* test(codex): cover unavailable compact outcome

* fix(plugins): fence command compaction capability

Bind compactCurrent to one command invocation and captured session generation so retained or stale callbacks fail closed without running compaction.

* fix(plugins): lazy-load command session revalidation

Keep compaction session freshness checks at the auto-reply owner without pulling the session accessor into generic plugin command module initialization.

* fix(plugins): keep session revalidation lazy

Avoid loading the session accessor through generic plugin command initialization while preserving pre-compaction session-generation checks.

* fix(compaction): fence session lifecycle admission

Revalidate the exact session id and lifecycle revision immediately before native compaction and again before accounting so resets and rebinds fail closed across awaited work.

* fix(commands): fence plugin compaction authority

* fix(compaction): require accounting commit

* test(compaction): keep regression under lint cap

* fix(codex): preserve compact admission

* fix(codex): preserve compaction target identity

* fix(compaction): bind admitted target

* fix(compaction): fence accounting commit
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 maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. plugin: file-transfer rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL 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