Skip to content

fix(codex): reduce stale instructions after policy withdrawal - #140630

Closed
steipete wants to merge 1 commit into
mainfrom
worktree-codex-policy-withdrawal-frame
Closed

steipete wants to merge 1 commit into
mainfrom
worktree-codex-policy-withdrawal-frame

Conversation

@steipete

@steipete steipete commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Related: #135338. Follow-up to #135577; the native configuration/ownership repair remains intact.

What Problem This Solves

Resolves a reliability problem where ongoing Codex conversations can keep following an earlier OpenClaw generic policy after a prompt hook replaces or withdraws it. The native configuration can already be correctly empty and the withdrawal recorded, yet the model can still return the old policy's requested output because that policy remains in append-only history.

This is an explicitly approved model-visible policy-format change, not a behavior-neutral cleanup or a new authorization boundary.

Why This Change Was Made

Frame the final nonempty OpenClaw generic policy once, identifying its origin and stating that it applies only until a later OpenClaw policy replaces or withdraws it. Preserve the policy body byte-for-byte. Exactly empty configuration remains "", and its existing separate withdrawal notice is unchanged.

The entire nonempty injected refresh equals the native configured string, with the supersession notice inside the frame. Stock Codex V2 child overrides replace the current parent's configured literal string; leaving a notice outside it would leave text surrounding the child override. The common configuration producer covers start/resume/canonical forks; direct supervision probes and side conversations use the same framing. Prompt reports count the frame and MCP diagnostics once, with collaboration instructions kept separate.

No native patch, dependency/config/schema change, history rewriting, new runtime store, or weakening of ownership, incognito refusal/recovery, or unknown-write handling. Independent native managed/project/guardian/security/collaboration/child-role instructions retain their own authority.

User Impact

New OpenClaw policies carry explicit replacement/withdrawal semantics, reducing ambiguity when older policy text remains in a conversation. This does not retroactively label legacy history, erase historical policies, guarantee model obedience, or replace enforced tool/approval boundaries. The fixed added overhead is 631 UTF-8 bytes, below the frozen 768-byte budget; empty policy adds no frame.

Production LOC: +36/−17 (net +19). Tests: +475/−261 (net +214). Docs: +9. Production growth implements one encoder and consistent final-policy/report composition, without a parallel lifecycle path.

Evidence

Fixed-count live comparison

Both cohorts used the same OpenClaw base 8c7e36560d11d3ed211e2aca254efd33e34cdcb0, stock Codex 0.153.4, public model gpt-5.6-luna, provider name exactly OpenAI, recorder hashes, and predefined scenario order. Each contained 22 scenarios and 52 HTTP-200 requests.

Scenario Unchanged control Framed candidate
Warm withdrawal, five distinct histories 1 stale-marker failure 0 failures
Cold withdrawal, five distinct histories 1 stale-marker failure 0 failures
Warm withdrawal → compaction → empty policy Passed Passed
Cold withdrawal → compaction → empty policy Passed Passed

The candidate had zero behavioral failures across all 22 scenarios. Native delivery/configuration, metadata, ownership, incognito refusal/restoration, and execution checks passed in both cohorts. Every cohort closed/exited all 31 native clients, closed both relay servers, and joined its composition process with no outstanding native PIDs.

This is finite, sequential evidence—not statistically established improvement or deterministic obedience. The candidate text was frozen before comparison; no prompt tuning or extra cohort was used to obtain green model results. An earlier 53-request control is retained separately with three marker failures; it exposed recorder response-tail handling and an obsolete contention-fixture assumption and is not pooled with the corrected comparison. Seven local recorder regressions verified the correction before the paired run. Synthetic ordered captures and source identities are retained locally; no operator conversation or credential is included in this PR.

Stock native binary SHA-256: b973d440acac501fd2594a43e7ca9ce41e0a65b9dfb28d0d7a7837c99e1261e3. Exact native source inspected at 3d2ee51ca2d5db578f328aa75e20aa22c0197c9a, including generic fragment serialization and current-parent replacement in native child forks. Content-kind metadata is enabled by default; non-OpenAI provider-name filtering is a separate behavior, not the explanation claimed here.

Native child and local validation

  • Stock-native, credential-free scripted-provider baseline and candidate each passed two cases / seven requests: current-parent inheritance and A→B refresh followed by a V2 child override. Independent project/permissions/collaboration fragments and native child identity were verified. These are payload tests, not child model-obedience tests; compacted-history child variants were not exercised.
  • New framing regressions demonstrably failed before production edits for missing framing/configuration-injection mismatch. Coverage preserves exact empty policy, Unicode/CRLF/whitespace and long bodies, incognito same-thread restoration, and uncertain-write no-replay behavior.
  • 810 tests passed across nine full Codex files: lifecycle binding, lifecycle, side questions, upstream fork, upstream-fork continuation, run attempt, hooks, configured MCP, and compaction.
  • After test-only cleanup, 71 canonical integration + 28 configured-MCP tests passed. The 28 MCP cases overlap the 810 and must not be added again. The old canonical raw-text expectation was reproduced failing before migration; full configured/injected equality now replaces its weaker substring check.
  • Final node scripts/check-changed.mjs passed, including extension/root-test types and lint, import cycles, and runtime guards. pnpm build passed, including declarations, SDK exports, plugin runtime/assets, and Control UI output. Only nonblocking upstream eval, browser-externalization, and timing advisories were emitted.
  • Fresh isolated Codex autoreview of the final candidate completed scoped-clean at P0–P2, with no findings.

Static/build proof used an independently installed, byte-identical checkout outside the parent repository's dependency tree. The nested worktree's compiler consulted outer package manifests despite its own frozen install; no containment guard, dependency, or baseline was weakened. That tooling issue is separate from this PR.

The final validated tracked diff SHA-256 is 475d4c4f71d403894a9c6868d3218136cde038b93a85779f92f182804c2edb74. The six-file production diff remained unchanged after live proof: 188d03447029dfabb6cf0aaf9b0290a4d646e9261829cf919b2f3cde0a0261ca.

Documentation: https://docs.openclaw.ai/plugins/codex-harness-runtime#hook-boundaries

Frame final nonempty OpenClaw generic policy with explicit replacement and
withdrawal lifetime, preserving body bytes and exactly empty configuration.
Keep configured and injected policy identical for native child overrides,
and include framing and MCP diagnostics once in prompt reports.

Preserve incognito refusal/restoration, native ownership, independent
instructions, and unknown-write no-replay behavior. Finite stock-native
live comparison observed zero candidate failures across 22 scenarios;
this does not guarantee model obedience or rewrite legacy history.

Related: #135338. Follow-up to #135577.
@clawsweeper

clawsweeper Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: codex size: L maintainer Maintainer-authored PR labels Sep 7, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 Sep 7, 2026
@clawsweeper

clawsweeper Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed October 7, 2026, 10:31 PM ET / October 8, 2026, 02:31 UTC (Revision 2).

ClawSweeper review

What this changes

This PR frames nonempty OpenClaw instructions with explicit replacement and withdrawal semantics while keeping native configuration, injected refreshes, and prompt reports consistent.

Example: A hook supplies "replacement policy" before resuming a Codex conversation.

  • Before: Native configuration contains the plain policy, while its injected refresh adds a separate supersession notice.
  • After: Native configuration and the injected refresh contain the same policy inside an <openclaw_generic_policy> frame.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The pinned implementation has meaningful native and live-model proof, but later replacement evidence leaves limited confidence in adopting it on the current runtime.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The pinned production policy producers were exercised through stock Codex app-server and real provider inference, with observed after-fix withdrawal improvements across the recorded 22-scenario comparison. Later mixed evidence belongs to an unpushed adoption and limits current-runtime readiness without erasing the pinned-head proof. No stored-data migration is required: existing history and binding contracts remain intact.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes
User problem: An ongoing Codex conversation can still follow an earlier OpenClaw instruction after that instruction is replaced or withdrawn.
Reason: The residual reliability problem is concrete, and the area owner's recorded approval covers this bounded model-visible format change. The PR correctly limits its claims rather than promising deterministic obedience.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep open: this PR contains distinct, owner-approved work that current main does not implement. No definite defect was found in the pinned patch, but later runtime results leave its replacement reliability unsettled.

Priority: P2
Reviewed head: 48e13e84ca982008d934eb0569eda61d37fde82f

Before merge

  • Resolve merge risk (P1) - The later adoption's warm replacement failure leaves uncertainty about whether framing improves withdrawal without impairing replacement on the current native runtime; the available sample does not establish causality.
  • Complete next step (P2) - Resolve the conflicts against current main while preserving its separate parent-local and refreshable instruction owners.

Findings

None.

Tests

  • Missing end-to-end proof: The conflicting branch has no published current-main adoption with reconciled warm replacement and post-repair compaction results on the current Codex runtime. Reported base-failing regressions were not rerun during this read-only review.
Agent review details

How this fits together

The Codex plugin carries OpenClaw instructions into native Codex conversations. It prepares configuration and policy refresh messages before the native runtime sends conversation context to the model.

flowchart TD
  A[Prompt hook and OpenClaw instructions] --> B[Complete generic policy]
  B --> C{Policy empty?}
  C -->|No| D[Policy lifetime frame]
  C -->|Yes| E[Empty configuration and withdrawal notice]
  D --> F[Native configuration and history refresh]
  E --> F
  F --> G[Codex model request]
Loading

Technical review

Best possible solution:

Carry the bounded frame through current policy owners while preserving separate parent-local and refreshable instructions, exact empty withdrawal, native-child replacement, and enforced tool authority.

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

No deterministic current-main reproduction is established. Recorded live comparisons expose stale-policy behavior, but model compliance is variable and current main uses a newer Codex runtime.

Is this the best way to solve the issue?

Unclear: one bounded encoder with configured/injected equality is a coherent solution, but the later warm replacement result must be reconciled against current instruction ownership.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 1f891df2c45f.

Merge-risk options

Maintainer options:

  1. Resolve the replacement uncertainty (recommended)
    Reconcile the observed warm replacement failure on the refreshed production path before accepting the framing change.
  2. Accept bounded model reliability
    The area owner may explicitly accept the mixed finite results while retaining the documented absence of guaranteed model obedience.

Provenance checked

Testing

Proof path: shipped entry point. Added test files: 6.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 759e127 adds extensions/codex/src/app-server/thread-policy.ts:18 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 759e127777b5; files: extensions/codex/src/app-server/thread-policy.ts)
  • Kimi Yu: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

PR surface

Source +19, Tests +214, Docs +9. Total +242 across 13 files.

View PR surface stats
Area Files Added Removed Net
Source 6 36 17 +19
Tests 6 475 261 +214
Docs 1 9 0 +9
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 13 520 278 +242

Review metrics

Metric Value Why it matters
Policy overhead 631 UTF-8 bytes per nonempty policy; 0 for empty policy The fixed frame remains below the recorded 768-byte budget without truncating the policy body.

Labels

Label changes:

  • add merge-risk: 🚨 session-state: The frame changes how retained conversation policy is interpreted, and a later adoption observed a warm turn ignoring the replacement policy.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.

Label justifications:

  • P2: This is a bounded improvement to changed-policy reliability in ongoing Codex conversations.
  • merge-risk: 🚨 session-state: The frame changes how retained conversation policy is interpreted, and a later adoption observed a warm turn ignoring the replacement policy.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rank-up moves

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

  • Publish a current-main refresh preserving the newer parent-local and refreshable instruction boundaries.
  • Reconcile the later warm replacement failure and document the resulting reliability limits.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-07T02:12:12.306Z sha 48e13e8 :: needs maintainer review before merge. :: none

@steipete steipete self-assigned this Sep 24, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Current-runtime revalidation found mixed results, so I am leaving this PR open for discussion rather than landing the current-main adoption yet. The published head remains unchanged; the adoption described below has not been pushed.

The stock 0.155.1 synthetic native tests pass for warm/cold policy refresh, inherited child policy, and explicit child replacement. In the fixed authenticated comparison, stale policy appeared in 8 of 10 control withdrawal cases and 0 of 10 candidate cases. However, the candidate's warm replacement case returned the user-requested marker instead of the current policy marker. Its cold replacement passed, and both replacement controls passed. This finite sample does not establish statistical improvement or prove that the candidate introduced a replacement regression. No ordinary cases were replayed to obtain a cleaner result.

Both compaction cases in each arm failed before a compaction request reached the provider. A separate credential-free native diagnostic reproduced the boundary: the normal turn obtains a live model source, but the new standalone compaction turn does not. The native error reports missing owner authority, and the turn fails before forwarding. This executed on the adoption candidate; the implicated owner code matches the separately inspected current-main snapshot. It is a broader host-to-harness authority handoff issue, so it should be repaired separately while preserving the existing denial, cancellation, and cleanup rules.

The authenticated recorder also aborted when native stopped reading at response.completed, losing transport-tail capture and usage. The retained native answers above remain available, including the candidate failure; incomplete historical captures were not backfilled. Two credential-free controls reproduced the old recorder's missing-body defect, and all nine repaired-recorder tests passed. Those recorder tests do not add model-behavior evidence.

The diagnostic intentionally ended with a failing compaction assertion and its owned Testbox was stopped. These are unresolved findings, not a passing current-runtime compaction result. The PR body's earlier results remain evidence for its older head/runtime, not for this unpushed adoption.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Oct 8, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Closing this older policy-format experiment. Main already sends explicit replacement and withdrawal notices, and the recorded follow-up results do not establish a reliable benefit for the current instruction lifecycle.

Closed in a sweep of stale maintainer PRs (no activity for 7+ days). Reopen with a current reproduction if this still matters.

@steipete steipete closed this Oct 21, 2026
@RomneyDa
RomneyDa deleted the worktree-codex-policy-withdrawal-frame branch October 22, 2026 05:54
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: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L 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