Repository navigation
fix(codex): refresh session meters after /codex compact - #123640
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 14, 2026, 12:30 PM ET / 16:30 UTC. ClawSweeper reviewWhat this changesThis PR makes Merge readinessKeep 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 Review scores
Verification
How this fits togetherA 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]
Decision needed
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
Agent review detailsSecurityNone. PR surfaceSource +210, Tests +666, Docs +33. Total +909 across 17 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest 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. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (13 earlier review cycles; latest 8 shown)
|
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 re-review The coordinator-approved maintainer decision is now explicit in the PR body: |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
Merged via squash.
|
) * 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
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 compactreceived 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 compactpreserves Codex-thread binding admission, then delegates to that callback instead of exposing the redundant raw compact control method.Maintainer decision (Peter Steinberger):
compactCurrentis 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 compactadditionally 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 (threadIdandclientId) as the session binding. Incomplete, replaced, mixed-runtime, or distinct-owner states fail visibly before compaction.User Impact
/codex compactnow waits for the terminal compaction outcome, refreshescompactionCountand 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
origin/main: failed because the host compaction callback was absent and no session metadata was recorded.command invocation closedafter handler settlement, without later native 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.src/config/sessions/session-accessor.sqlite-active-events.test.ts— 73 tests passed.pnpm tsgo,pnpm tsgo:core:test,pnpm tsgo:extensions, andpnpm 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:checkandpnpm docs:list— passed.rust-v0.147.0(be6e8eac029b) documents the immediate empty acknowledgement incodex-rs/app-server/README.md:194,786-799, submitsOp::Compactincodex-rs/app-server/src/request_processors/thread_processor.rs:1876-1888, and emits token updates fromcodex-rs/app-server/src/bespoke_event_handling.rs:1576-1591through the notification declared incodex-rs/app-server-protocol/src/protocol/common.rs:1703.31819137872passed on21afbd64548690fbf22215221b4ae54f4fb39210, includingopenclaw/ci-gate.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.