Skip to content

refactor(agents): simplify failed-turn settlement and Codex fixtures - #135833

Merged
steipete merged 1 commit into
mainfrom
steipete/codex-policy-simplify-20260902
Sep 2, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/codex-policy-simplify-20260902

Conversation

@steipete

@steipete steipete commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Related: the stale Codex instruction repair.

What Problem This Solves

Maintainer-requested cleanup following the Codex instruction repair. Failed-turn maintenance required keeping three equivalent settlement paths aligned, while the native lifecycle fixture retained history state and an accessor that no test consumed.

Why This Change Was Made

One local, typed helper now owns the shared final-settlement sequence. The fixture drops only unused bookkeeping; its real-client wire, request recording, loaded/subscribed validation, and lifecycle transitions remain intact.

Production +25/−29 (net −4); test support +1/−7 (net −6). No regression tests were removed. A proposed direct throw inside finally was discarded rather than suppressing or circumventing no-unsafe-finally.

User Impact

No intended user-visible behavior change. Preflight refusals remain ahead of provider-text classification, visible delivery settles before terminal failure, model-patch failure remains awaited, post-compaction attribution is preserved, and only the existing final fallback branch emits fallback-exhaustion metadata. Policy text, ownership checks, incognito refusal/recovery, persistence, and native protocols are unchanged.

This is not a fix for the separate empty-policy model-adherence limitation described below.

Evidence

  • The same ordered 1,258 tests across 47 files passed on both unmodified main (c4b8d42bd42cdf4ef447bd48dc96abc1fa33c27f) and the cleanup candidate in Blacksmith Testbox run 33580471050. The two retained files are byte-identical to that tested candidate; the discarded finally change was restored exactly to HEAD. The separately gated native-MCP live suite was explicitly excluded from the hermetic run. Counts overlap and must not be summed.
  • The final two-file changed gate passed locally: four typecheck lanes, formatting, lint, dead-export checks, doctor contracts, boundary/schema guards, and import-cycle checks. An abandoned artifact owner and its child claim were inspected and removed only after verifying the associated processes/groups were gone.
  • Fresh isolated Codex autoreview of the final two-file diff was scoped-clean at P0/P1, with no findings. This review is separate from test execution.
  • The branch was rebased onto 82bcef85ffef1010e53cac09b4ea0bcea7b68f72; both changed files remained byte-identical. Exact-head PR CI 33585118125 completed successfully at 2b817962e6c75356ea32d1124f6b15b47427f3af.
  • Refreshed-head hook-context/projector/attempt smoke passed 192 tests in three files. Its first attempt stopped before collection because a local Vitest file was missing; one frozen dependency repair followed by the same command passed.

The final local static command was:

node scripts/check-changed.mjs --base c4b8d42bd42cdf4ef447bd48dc96abc1fa33c27f -- extensions/codex/src/app-server/thread-lifecycle.test-fixtures.ts src/auto-reply/reply/agent-runner-error-handler.ts

The refreshed-head smoke command was:

node scripts/run-vitest.mjs extensions/codex/src/app-server/run-attempt.auth-context.test.ts extensions/codex/src/app-server/event-projector.verbose-hooks.test.ts extensions/codex/src/app-server/run-attempt.test.ts

The first broad Mac test attempt hit CLI-test timeouts and subsequent preflight call-count failures after multi-minute imports. The clean Linux baseline/candidate comparison retained ordering, assertions, and timeouts; no assertions were weakened and no timeout was increased. No unsupported OS or package-manager root-cause claim is made.

Live verification qualification

Real OpenClaw hook/admitted-host/lifecycle composition, stock Codex 0.151.0, and actual gpt-5.6-luna inference exercised 12 scenarios and 28 HTTP requests. The corrected recording relay retained native OpenAI provider semantics and protocol headers, and asserted generic-policy provenance metadata. All native handoff/ownership assertions passed, and all 15 clients and both servers closed.

The live model-output result was 11/12, not fully green: one warm empty-policy turn returned the old policy marker even though the request contained empty native configuration and the later explicit withdrawal notice. Replacement, cold withdrawal, incognito refusal/recovery, contention recovery, and compaction checks passed. Earlier custom-provider captures are not treated as default OpenAI proof: stock Codex strips internal metadata for non-OpenAI provider identities.

That finding is recorded for a separate behavioral investigation; this cleanup neither changes the policy producer/carrier nor claims to fix model adherence. The failing canary completed as a successful native attempt, so it did not exercise the changed error-settlement path; the changed fixture bookkeeping is not used by the real native probe. No policy-format change, forced compaction, replay, or history rewrite is introduced here. The task credential stayed in the recording relay and was never passed to the native environment or persisted; the credential window and Testbox lease were closed.

Pinned dependency source personally checked at 78c290807ce710180111df227df3b7a4fe845452: generic context versus later-turn differences, history injection, loaded-resume ownership, and provider-specific metadata stripping.

Consolidate preflight, provider-facet, and fallback settlement without changing ordering, presentation, or post-compaction attribution. Remove unused synthetic lifecycle history and waiter state.

Maintainer-requested follow-up to #135577; no policy-text or incognito-contract changes.
@steipete steipete self-assigned this Sep 2, 2026
@clawsweeper

clawsweeper Bot commented Sep 2, 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 September 2, 2026 02:56
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 Sep 2, 2026
@clawsweeper

clawsweeper Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 1, 2026, 11:16 PM ET / September 2, 2026, 03:16 UTC.

ClawSweeper review

What this changes

The PR centralizes shared failed-turn settlement in one typed helper and removes unused bookkeeping from the Codex lifecycle test harness.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open for normal maintainer review: this fresh, maintainer-labelled cleanup has no introduced correctness or security defect in the reviewed diff, and current main has not changed either touched path since the PR’s merge base.

Priority: P3
Reviewed head: 2b817962e6c75356ea32d1124f6b15b47427f3af
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, net-negative cleanup with preserved ordering, existing boundary coverage, and no actionable review finding.
Proof confidence 🌊 off-meta tidepool Not applicable: The changed production owner is the failed-turn settlement handler, but this is a maintainer-authored behavior-preserving consolidation; the external-contributor real-behavior proof gate does not apply.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The changed production owner is the failed-turn settlement handler, but this is a maintainer-authored behavior-preserving consolidation; the external-contributor real-behavior proof gate does not apply.
Evidence reviewed 5 items Introduced settlement refactor: The extracted helper retains the prior ordered sequence—emit terminal error, fail the reply operation, await model-patch failure, then return the marked final payload—and the three replaced branches supply the same differing payload/metadata inputs.
Caller and sibling failure boundaries: The execution loop awaits this handler and preserves its final/aborted/retry distinction; restart, compaction, and live-model-switch branches remain outside the new helper because their settlement contracts differ. Existing provider-failure tests assert fallback-exhaustion metadata is present only for the fallback path and absent for direct provider errors.
Fixture state is unused: The fixture still rejects injection unless the thread is loaded and subscribed, while consumers assert recorded outbound inject requests rather than synthetic item retention. Repository search found no consumer of the removed fixture item state or accessor.
Findings None None.
Security None None.

How this fits together

Agent-turn errors are classified and settled into a lifecycle terminal event, reply-operation outcome, and model-patch result. The Codex fixture simulates native thread lifecycle requests so integration tests can exercise OpenClaw’s real client-side protocol handling.

flowchart LR
A[Agent turn error] --> B[Failure classification]
B --> C[Failure settlement]
C --> D[Lifecycle terminal event]
C --> E[Reply operation]
C --> F[Model patch]
G[Codex lifecycle fixture] --> H[Native thread protocol]
H --> I[Integration tests]
Loading

Decision needed

Question Recommendation
Should this maintainer-labelled, behavior-preserving cleanup proceed through normal maintainer approval? Approve the cleanup: Accept the exact-sequence consolidation and fixture-state deletion after normal maintainer review.

Why: Repository policy keeps maintainer-authored and protected-label PRs open for explicit maintainer handling even when the review finds no defect.

Before merge

  • Complete next step (P2) - The maintainer label and member authorship require normal human review; no narrow automated repair is needed.
Agent review details

Security

None.

PR surface

Source -4, Tests -6. Total -10 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 25 29 -4
Tests 1 1 7 -6
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 26 36 -10

Review metrics

Metric Value Why it matters
Production versus test-support LOC production −4 net; test support −6 net The refactor removes duplicated settlement code and unused fixture bookkeeping without adding production behavior.

Technical review

Best possible solution:

Retain one local settlement path for the three equivalent final-failure branches while preserving the intentionally distinct abort, restart, compaction, and retry flows.

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

Not applicable: this is a behavior-preserving refactor, not a report of a separately reproducible user defect.

Is this the best way to solve the issue?

Yes: the helper absorbs three byte-for-byte-equivalent settlement sequences at their owner boundary, while distinct failure paths remain explicit.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P3: This is a small internal cleanup with no intended user-visible behavior change.
  • 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: The changed production owner is the failed-turn settlement handler, but this is a maintainer-authored behavior-preserving consolidation; the external-contributor real-behavior proof gate does not apply.

Evidence

What I checked:

  • Introduced settlement refactor: The extracted helper retains the prior ordered sequence—emit terminal error, fail the reply operation, await model-patch failure, then return the marked final payload—and the three replaced branches supply the same differing payload/metadata inputs. (src/auto-reply/reply/agent-runner-error-handler.ts:92, 2b817962e6c7)
  • Caller and sibling failure boundaries: The execution loop awaits this handler and preserves its final/aborted/retry distinction; restart, compaction, and live-model-switch branches remain outside the new helper because their settlement contracts differ. Existing provider-failure tests assert fallback-exhaustion metadata is present only for the fallback path and absent for direct provider errors. (src/auto-reply/reply/agent-runner-execution.ts:381, 2b817962e6c7)
  • Fixture state is unused: The fixture still rejects injection unless the thread is loaded and subscribed, while consumers assert recorded outbound inject requests rather than synthetic item retention. Repository search found no consumer of the removed fixture item state or accessor. (extensions/codex/src/app-server/thread-lifecycle.test-fixtures.ts:125, 2b817962e6c7)
  • Direct Codex contract inspection: The directly inspected Codex source shows response-item injection records items and flushes rollout, and loaded thread resumes preserve existing-thread semantics when overrides cannot safely replace the thread. This PR does not alter either wire request or lifecycle guard; it removes only local unused fixture retention. (codex-rs/core/src/codex_thread.rs:626, 78c290807ce710180111df227df3b7a4fe845452)
  • Current-main and area-history check: The verified merge base is an ancestor of fetched main, and no changes to either touched path occurred between that merge base and fetched main; this PR’s refactor is therefore not already present on current main. Recent merged history identifies the prior Codex repair and failover-retry consolidation as the relevant maintained area. (src/auto-reply/reply/agent-runner-error-handler.ts:55, 77a24659740f)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Ayaan Zaidi: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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-09-02T03:02:51.557Z sha 2b81796 :: needs maintainer review before merge. :: none

@steipete

steipete commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Land-ready review for 2b817962e6c75356ea32d1124f6b15b47427f3af.

The final diff changes two files: production −4 lines, test support −6 lines. Settlement ordering, failure metadata, presentation, fixture wire/guards, policy text, and incognito behavior are preserved. Both files remained byte-identical through rebase. Fresh final-diff Codex autoreview found no P0/P1 issues; the latest ClawSweeper review found no correctness/security defects or separate Rank-up moves. Its remaining CI step is now complete.

Exact-head CI 33585118125 passed. The ordered baseline/candidate comparison passed 1,258 tests in 47 files on each side; the final retained files match that tested candidate, and the discarded finally experiment was restored to HEAD. Refreshed-head smoke passed 192 tests in three files after one frozen dependency repair; the initial missing-Vitest attempt never reached collection and is not counted as passing.

Exact local static command:

node scripts/check-changed.mjs --base c4b8d42bd42cdf4ef447bd48dc96abc1fa33c27f -- extensions/codex/src/app-server/thread-lifecycle.test-fixtures.ts src/auto-reply/reply/agent-runner-error-handler.ts

Exact refreshed-head smoke command:

node scripts/run-vitest.mjs extensions/codex/src/app-server/run-attempt.auth-context.test.ts extensions/codex/src/app-server/event-projector.verbose-hooks.test.ts extensions/codex/src/app-server/run-attempt.test.ts

The PR's live qualification remains explicit: stock Codex plus actual OpenAI inference passed all native handoff/ownership assertions in 12 scenarios/28 requests, but one warm-empty model-output canary retained the old marker. That successful native attempt did not invoke the changed failure handler, and the real probe did not use the synthetic fixture. This behavior-neutral cleanup neither introduces nor claims to repair that separate limitation. No policy-format change, forced compaction, unsafe replay, or history rewrite is included.

Proceeding through the required native review/prepare/merge gates; no bypass or release action.

@steipete
steipete merged commit 0535146 into main Sep 2, 2026
347 checks passed
@steipete
steipete deleted the steipete/codex-policy-simplify-20260902 branch September 2, 2026 03:20
@steipete

steipete commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 2, 2026
openclaw#135833)

Consolidate preflight, provider-facet, and fallback settlement without changing ordering, presentation, or post-compaction attribution. Remove unused synthetic lifecycle history and waiter state.

Maintainer-requested follow-up to openclaw#135577; no policy-text or incognito-contract changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: codex maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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