Skip to content

refactor(acpx): reuse operation session snapshot - #120924

Merged
steipete merged 1 commit into
mainfrom
worktree-agent-a31711a9d704b4730
Aug 9, 2026
Merged

steipete merged 1 commit into
mainfrom
worktree-agent-a31711a9d704b4730

Conversation

@steipete

@steipete steipete commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Modern ACPX handle operations could reload the wrapper session record while separately resolving the agent command and managed-tools delegate. That split ownership made one logical operation observe more than one record snapshot and allowed a foreign-gateway lease rejection to occur only after a per-session delegate had already been cached.

Why This Change Was Made

The OpenClaw ACPX wrapper now loads one record-and-command snapshot per modern handle operation. Lease-owning startTurn, mode, config, and close operations validate and retain the process lease before resolving the managed-tools delegate; status and cancel keep their intentionally non-lease semantics. Upstream [email protected] remains the mutation owner and continues its mutation-time requireRecord reloads.

The production diff is +83/-75 (net +8). That small growth establishes the explicit operation-snapshot ownership boundary and removes the older repeated command/delegate resolution paths. The legacy runTurn compatibility adapter remains excluded from the one-snapshot contract pending its separate removal path.

User Impact

Operators get consistent ACPX wrapper routing for each modern handle operation, and a record leased by another Gateway is rejected without leaking a managed-tools delegate into the session cache. There is no new configuration or user-facing command surface.

Evidence

  • Diff: 2 files; production +83/-75 (net +8), tests +107/-36 (net +71).
  • Focused ACPX runtime proof: 103 tests passed with strict unhandled-rejection handling clean.
  • Full ACPX proof: 244 tests passed with strict unhandled-rejection handling clean.
  • Retained Testbox command proof: run 31295179602, lease tbx_01kzjdax5jm34genfs3htvvx68.
  • ACPX-relevant type, lint, boundary, and import lanes passed.
  • Formatting and diff checks passed.
  • Final commit-mode structured review was clean, followed by an independent exact-head review with a READY verdict.
  • An earlier aggregate check reported three doctor-closure violations in unrelated Discord/Telegram base files. Exact tested-base 192885c4e811 and head a085994b70c27a6724892faa79eb6da74cea213b comparison shows this PR changes only extensions/acpx/src/runtime.ts and extensions/acpx/src/runtime.test.ts; later path-scoped checks passed.
  • Direct dependency inspection covered the published [email protected] runtime and type contract, including mutation-time record reloads.
  • The separate upstream ACPX result-before-finalization lifecycle issue remains tracked outside this patch; this PR deliberately adds no OpenClaw compatibility shim for it.

Direct dependency and sibling runtime inspection

The required source contracts were inspected directly rather than inferred from OpenClaw wrappers:

  • [email protected] resolves the authoritative record again when a turn actually starts (prepareRuntimeTurn), and independently reloads for status, mode, config, and close mutation boundaries. Its cancel path intentionally targets only the active controller. See manager.ts:938-951, manager.ts:1303-1345, and manager.ts:1348-1402. The wrapper snapshot therefore prepares routing and lease facts without replacing dependency-owned mutation validation.
  • Current Codex app-server turn/start is keyed by threadId and loads that thread before submitting input; turn/interrupt validates the requested active turnId against per-thread state. See turn.rs:71-99, turn_processor.rs:474-503, turn_processor.rs:1409-1450, and thread_state.rs:92-104. This patch does not alter Codex thread/turn identity or cancellation semantics; it only makes OpenClaw's wrapper-local delegate and lease selection consume one consistent snapshot.

@steipete
steipete marked this pull request as ready for review August 9, 2026 05:37
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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 Aug 9, 2026
@clawsweeper

clawsweeper Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 9, 2026, 2:46 AM ET / 06:46 UTC.

ClawSweeper review

What this changes

The PR makes each modern ACPX handle operation reuse one loaded session record and command snapshot so lease checks occur before managed-tools delegate caching.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

No concrete defect was found in the wrapper refactor, but the required direct ACPX and sibling Codex contract checks cannot be completed in this checkout; this protected maintainer PR needs a human merge decision after that evidence is available.

Priority: P2
Reviewed head: a085994b70c27a6724892faa79eb6da74cea213b
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The internal refactor and focused tests are coherent, but contract verification required for merge confidence is unavailable in this environment.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-associated PR is outside the external-contributor proof gate; the supplied focused ACPX tests and CI remain supplemental validation.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-associated PR is outside the external-contributor proof gate; the supplied focused ACPX tests and CI remain supplemental validation.
Evidence reviewed 5 items Wrapper ordering: Modern start, mode, config, and close operations reuse one snapshot and resolve the delegate only after lease validation; status and cancel retain non-lease behavior.
Focused regression coverage: Tests cover foreign-gateway rejection without managed-tools delegate caching and single-load behavior for lease-owning operations.
Current-main comparison: Current main is ahead of the PR base but has no later ACPX-path rewrite that supersedes this refactor.
Findings None None.
Security None None.

How this fits together

ACPX is OpenClaw’s wrapper around the ACP runtime for persisted agent sessions. A handle operation reads its session record, applies gateway lease rules where needed, and then sends the operation to the selected runtime delegate.

flowchart LR
  A[ACPX handle request] --> B[Load session record]
  B --> C[Build operation snapshot]
  C --> D{Lease-sensitive operation?}
  D -->|Yes| E[Validate gateway lease]
  D -->|No| F[Use non-lease path]
  E --> G[Resolve runtime delegate]
  F --> G
  G --> H[ACPX runtime operation]
Loading

Decision needed

Question Recommendation
Should this ACPX session-state refactor wait for direct inspection of the pinned ACPX and sibling Codex contracts before merge? Complete the contract check first: Make the pinned ACPX and sibling Codex sources available, verify the cited mutation and cancellation behavior, then refresh the exact-head review.

Why: Repository policy expressly requires those direct sources for a Codex-related merge or proof verdict, and this read-only environment cannot retrieve them.

Before merge

  • Resolve merge risk (P1) - The source-level ordering is coherent, but merging would rely on unverified claims about ACPX mutation reloads and Codex thread/turn semantics because the required direct dependency and sibling-Codex inspection was unavailable.
Agent review details

Security

None.

PR surface

Source +8, Tests +71. Total +79 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 83 75 +8
Tests 1 107 36 +71
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 190 111 +79

Review metrics

Metric Value Why it matters
Production versus test delta production net +8, tests net +71 The small production increase establishes a single session-snapshot ownership boundary, with focused regression coverage for lease and delegate-cache behavior.

Merge-risk options

Maintainer options:

  1. Verify contracts before merge (recommended)
    Inspect the pinned ACPX and sibling Codex sources directly, then confirm the snapshot does not replace dependency-owned mutation validation.
  2. Accept the evidence gap
    Merge with the supplied focused tests and CI evidence while explicitly accepting that direct upstream contract verification was unavailable.

Technical review

Best possible solution:

Retain the single wrapper-local snapshot boundary, then complete direct ACPX and Codex source inspection and exact-head validation before merging.

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

Yes, at source level: the added focused tests exercise foreign-lease rejection and snapshot reuse, but no independent current-head runtime execution was possible here.

Is this the best way to solve the issue?

Unclear: the wrapper-local snapshot is the cleanest owner boundary found, but its fit with ACPX mutation reloads and Codex semantics needs the required direct contract review.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded ACPX runtime consistency change without evidence of an active user-facing outage.
  • merge-risk: 🚨 session-state: The patch changes the ordering and reuse of persisted ACPX session-record and process-lease facts.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-associated PR is outside the external-contributor proof gate; the supplied focused ACPX tests and CI remain supplemental validation.

Evidence

What I checked:

  • Wrapper ordering: Modern start, mode, config, and close operations reuse one snapshot and resolve the delegate only after lease validation; status and cancel retain non-lease behavior. (extensions/acpx/src/runtime.ts:1569, a085994b70c2)
  • Focused regression coverage: Tests cover foreign-gateway rejection without managed-tools delegate caching and single-load behavior for lease-owning operations. (extensions/acpx/src/runtime.test.ts:2035, a085994b70c2)
  • Current-main comparison: Current main is ahead of the PR base but has no later ACPX-path rewrite that supersedes this refactor. (extensions/acpx/src/runtime.ts:920, dba99b355b4e)
  • Lease-history provenance: Recent ACPX lease lifecycle work dates to the merged lease-ownership change, making its author an appropriate reviewer for the preserved invariant. (extensions/acpx/src/runtime.ts:1214, b6adb8e25db4)
  • Contract-review blocker: The pinned ACPX source and sibling ../codex checkout are absent, and DNS prevented read-only upstream retrieval; repository policy requires direct Codex inspection before a Codex-related merge or proof verdict. (AGENTS.md:13, dba99b355b4e)

Likely related people:

  • steipete: Authored this refactor and the earlier ACPX wrapper/delegate plumbing. (role: current ACPX wrapper contributor; confidence: high; commits: a085994b70c2; files: extensions/acpx/src/runtime.ts, extensions/acpx/src/runtime-turn.ts)
  • shakkerdroid: Recent merged ACPX work established the process-lease lifecycle that this refactor preserves. (role: recent lease-invariant contributor; confidence: medium; commits: b6adb8e25db4, a22a3ac8; files: extensions/acpx/src/runtime.ts)

Rank-up moves

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

  • Directly inspect the pinned ACPX and sibling Codex sources, then refresh exact-head validation.

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 (1 earlier review cycle)
  • reviewed 2026-08-09T05:44:47.326Z sha a085994 :: needs maintainer review before merge. :: none

@steipete

steipete commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@steipete

steipete commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

Maintainer contract review completed for the unchanged head a085994b70c27a6724892faa79eb6da74cea213b.

I directly inspected the pinned [email protected] source at aeb45a0ba1e91c2cfa2a317d026a7423e81a4d19 and current Codex app-server source at 646f7c0a91b8e327d263335da68ae8ef212895ce; the exact public file/line citations are in the PR body.

The contracts agree with this patch:

  • ACPX retains authoritative requireRecord reloads at turn, status, mode, config, and close mutation boundaries. The OpenClaw snapshot only prepares wrapper-local command/delegate/lease facts.
  • Codex keeps thread/turn identity and interrupt validation in app-server thread state. This patch does not change that protocol or cancellation ownership.

Therefore I accept the session-state merge risk and consider the ClawSweeper dependency-inspection blocker resolved. The optional rank-up move is satisfied by the cited maintainer inspection; no code change or new head is required.

@steipete steipete self-assigned this Aug 9, 2026
@steipete

steipete commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

Exact-head landing proof for a085994b70c27a6724892faa79eb6da74cea213b:

  • Native scripts/pr review artifacts validate as READY FOR /prepare-pr with no findings; a fresh structured Codex autoreview also returned no accepted/actionable findings.
  • OPENCLAW_TESTBOX=1 scripts/pr prepare-run 120924 completed in hosted exact-head mode. It reused the successful required CI gate, verified Workflow Sanity, pushed the unchanged source head, and confirmed the remote PR head tree matches the local prep head.
  • Focused ACPX runtime proof passed 103 tests and the full ACPX proof passed 244 tests, both with strict unhandled-rejection handling clean. Retained Testbox evidence is run 31295179602, lease tbx_01kzjdax5jm34genfs3htvvx68.
  • Production LOC is +83/-75 (net +8); tests are +107/-36 (net +71). The production growth establishes the single wrapper-operation snapshot boundary and removes repeated command/delegate resolution paths.
  • Direct [email protected] inspection confirms authoritative record reloads at turn and control/close mutation boundaries, while cancel remains controller-only: manager.ts:938-951, manager.ts:1303-1402, and manager.ts:1449-1455.
  • Direct sibling Codex inspection confirms turn/start loads the requested thread before submission and turn/interrupt validates thread-local active-turn state: turn.rs:71-99, turn.rs:209-217, turn_processor.rs:474-607, turn_processor.rs:1409-1471, and thread_state.rs:91-104.

The latest ClawSweeper review found no concrete code defect. Peter's owner decision completed the requested direct contract inspection, accepted the session-state merge risk, and resolved the only remaining review item on this unchanged head.

@steipete
steipete merged commit 4e9e735 into main Aug 9, 2026
169 of 171 checks passed
@steipete
steipete deleted the worktree-agent-a31711a9d704b4730 branch August 9, 2026 10:52
@steipete

steipete commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

extensions: acpx maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M 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