Skip to content

chore(ci): ratchet mid-request authority re-checks - #201072

Merged
obviyus merged 3 commits into
mainfrom
chore/lifetime-check-ratchet
Nov 18, 2026
Merged

obviyus merged 3 commits into
mainfrom
chore/lifetime-check-ratchet

Conversation

@obviyus

@obviyus obviyus commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

OpenClaw checks authority once, when a request starts (AGENTS.md: Choose good compromises). The code has hundreds of checks that run again while a request is running, and they abort started work when a role, policy, device or connection changes. Follow-up PRs delete them subsystem by subsystem. Nothing stops new ones from being added meanwhile.

Change

  • check:lifetime-check-ratchet: per production file, count calls to the reviewed mid-request re-check constructors plus string literals that use authority refusal wording. A changed file whose count grows fails CI with the rule and the file's delta. No baseline file, no bypass; the merge base is the baseline.
  • Uses the TypeScript AST (calls and literals, not comments, declarations or references), the dialect ratchet's production-file filter, and shrink-ratchet's rename handling.
  • Only authority wording counts. <owner|lock|generation> is no longer current is a data or ownership fence and is not counted.
  • Registered in ci-baseline-ratchets.mts. --full-tree prints totals per subsystem, to report the count falling.
  • No production code change.

Evidence

  • check-lifetime-check-ratchet.test.ts: counts calls and refusal literals but not comments, declarations, references or data-fence wording; rejects a per-file gain even when another file loses one; accepts reductions, verified renames, --staged, and ignores test files.
  • ci-baseline-ratchets.test.ts: the runner includes the new check.
  • tsgo:core, tsgo:core:test, tsgo:scripts, oxfmt/oxlint on changed files; every baseline sub-ratchet passes.
  • Tier full: ocx build --dts and the packed tarball installed into a clean prefix (CLI, doctor).

Full tree today: 446. hasCurrentPluginInstanceAuthority is not counted: it gates prepared plugin credential reads, a kept secret boundary.

Subsystem Count
src/gateway 249
src/agents 126
src/infra 11
src/auto-reply 9
src/sessions 8
src/plugins 5
src/cron 5
src/state 4
src/channels, src/skills, extensions/discord 3 each
other (17 subsystems) 1–2 each

- Count reviewed lifetime calls and refusal literals with the TypeScript AST.
- Reject per-file growth, preserve verified renames, and print full-tree subsystem totals.
- Owner, lock and generation "no longer current" checks are data fences; stop counting them.
- Point the reviewed list at AGENTS.md and the trust model.
@clawsweeper

clawsweeper Bot commented Nov 18, 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 scripts Repository scripts size: M labels Nov 18, 2026
- hasCurrentPluginInstanceAuthority gates prepared plugin credential reads; that is a kept secret boundary.
@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. 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. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 18, 2026
@clawsweeper

clawsweeper Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR adds a CI ratchet that rejects per-file growth in selected authority-related calls and string literals.

Example: A changed production file adds captureHttpRequestAuthority(reqOptions).

  • Before: Baseline ratchets do not count that call.
  • After: The new check reports a 0 → 1 increase and fails CI.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Focused Git fixtures support the implementation, but two source-verifiable false positives need repair before this becomes mandatory CI.
Proof confidence 🦐 gold shrimp (3/6) This tooling-only change requires no Gateway or channel demonstration; supplied evidence describes Git-fixture coverage of the scanner and runner integration.
Patch quality 🦪 silver shellfish (2/6) 2 actionable review findings remain.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: New mid-request authority checks can reintroduce interruptions of work that was already admitted.
Reason: The maintainer-authored direction implements the repository's explicit authority-lifetime policy without expanding the product runtime.

Merge readiness

⛔ Needs changes before merge - 2 items remain

Keep open: the maintainer-authored ratchet supports an established policy, but its matcher also rejects legitimate lifecycle machinery and refusal handling.

Priority: P2
Reviewed head: f357e7e42fe8844bb0fa323697af79c96bb47177

Before merge

  • Exclude approval reads and cleanup leases from forbidden growth (P2) - These entries do not exclusively create mid-request policy re-checks. On current main, retainExecApprovalsCurrentRead prepares the node-local execution-policy view before launch, and createPluginRuntimeCapabilityLease owns scheduler cleanup on disposal. Adding another legitimate launch-policy preparer or independently disposed plugin resource therefore increases this counter and fails mandatory CI, despite adding no prohibited role/reload veto. Remove these mixed-purpose constructors from enforcement and retain their runtime owners; the scanner's own comment expressly excludes admission and cancellation.
  • Stop treating refusal-message consumers as new checks (P2) - Every matching literal increments debt regardless of its use. Current main already demonstrates the failing input in extensions/telegram/src/telegram-ingress-non-retryable.ts:34: comparing candidate.message with "Gateway requester authority changed" classifies an existing error and introduces no authority decision. Adding equivalent error handling in another production file produces a 0 → 1 increase and fails CI. Remove the unrestricted literal heuristic or restrict it to independently reviewed refusal-producing constructs; error consumers and diagnostics must remain admissible.

Findings

  • [P2] Exclude approval reads and cleanup leases from forbidden growth — scripts/check-lifetime-check-ratchet.mts:30-31
  • [P2] Stop treating refusal-message consumers as new checks — scripts/check-lifetime-check-ratchet.mts:73-77
Agent review details

How this fits together

The baseline CI runner invokes the new scanner, which reads production source and Git baseline blobs, counts selected AST constructs, and returns a pass or per-file growth failure.

flowchart TD
  A[Baseline CI runner] --> B[Lifetime ratchet]
  C[Current production source] --> B
  D[Git baseline and renames] --> B
  B --> E[AST construct counts]
  E --> F[Per-file comparison]
  F --> G[CI result]
Loading

Technical review

Best possible solution:

Keep the shared baseline machinery and narrow enforcement to reviewed constructs that exclusively represent prohibited mid-request checks.

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

The matcher deterministically counts the identified lifecycle calls and error-comparison literals; these false positives are established from source without executing target code.

Is this the best way to solve the issue?

The baseline integration is focused and reuses existing owners, but syntax matching must exclude constructs whose current purpose is admission, cleanup, or handling an existing refusal.

Full review comments:

  • [P2] Exclude approval reads and cleanup leases from forbidden growth — scripts/check-lifetime-check-ratchet.mts:30-31
    These entries do not exclusively create mid-request policy re-checks. On current main, retainExecApprovalsCurrentRead prepares the node-local execution-policy view before launch, and createPluginRuntimeCapabilityLease owns scheduler cleanup on disposal. Adding another legitimate launch-policy preparer or independently disposed plugin resource therefore increases this counter and fails mandatory CI, despite adding no prohibited role/reload veto. Remove these mixed-purpose constructors from enforcement and retain their runtime owners; the scanner's own comment expressly excludes admission and cancellation.
    Confidence: 0.95
  • [P2] Stop treating refusal-message consumers as new checks — scripts/check-lifetime-check-ratchet.mts:73-77
    Every matching literal increments debt regardless of its use. Current main already demonstrates the failing input in extensions/telegram/src/telegram-ingress-non-retryable.ts:34: comparing candidate.message with "Gateway requester authority changed" classifies an existing error and introduces no authority decision. Adding equivalent error handling in another production file produces a 0 → 1 increase and fails CI. Remove the unrestricted literal heuristic or restrict it to independently reviewed refusal-producing constructs; error consumers and diagnostics must remain admissible.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.95

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 74e5127c0c3d.

Provenance checked

  • CI baseline runner keeps the original intent (cc14a17: Run existing ratchets in two managed slots while preserving aggregate failures and cancellation cleanup.)
  • Package tooling bootstrap keeps the original intent (ce0fafe: Avoid shared tsx-cache startup stalls through the maintained bootstrap.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test test/scripts/check-lifetime-check-ratchet.test.ts test/scripts/ci-baseline-ratchets.test.ts --maxWorkers=1
  • pnpm tsgo:scripts
  • pnpm check:lifetime-check-ratchet --base 1f03e27 --no-merge-base
  • git diff --check

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit cc14a17 adds scripts/ci-baseline-ratchets.mts:14 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: cc14a17e5f1e; files: scripts/ci-baseline-ratchets.mts)
  • Ayaan Zaidi: Raw commit edbc5bc adds scripts/ci-baseline-ratchets.mts:21 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: edbc5bcea9b6; files: scripts/ci-baseline-ratchets.mts)

PR surface

Tests +80, Config +1, Other +187. Total +268 across 5 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 2 80 0 +80
Docs 0 0 0 0
Config 1 1 0 +1
Generated 0 0 0 0
Other 2 187 0 +187
Total 5 268 0 +268

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P2: The defects affect developer CI enforcement without changing current Gateway runtime behavior.
  • add merge-risk: 🚨 automation: The added mandatory ratchet can fail future CI for legitimate cleanup, execution-admission, and error-handling changes.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: The defects affect developer CI enforcement without changing current Gateway runtime behavior.
  • merge-risk: 🚨 automation: The added mandatory ratchet can fail future CI for legitimate cleanup, execution-admission, and error-handling changes.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

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 execution lanes are retired.

Reviewed November 18, 2026, 2:57 AM ET / 07:57 UTC.

@obviyus

obviyus commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

Maintainer override: the two red jobs are not caused by this PR.

Job Failing test Failure
checks-node-changed-7 test/e2e/qa-lab/runtime/telegram-recovered-artifact.e2e.test.ts Matcher did not succeed in time (expected 1 delivery, got 0); failed on the first run and on the rerun
checks-node-changed-4 test/e2e/qa-lab/runtime/channel-progress-presentation.e2e.test.ts timed out waiting for ambiguous announcement settlement; passed on the first run, failed on the rerun

Why they are unrelated:

  • This PR changes no runtime code: it adds scripts/check-lifetime-check-ratchet.mts and its test, one package.json script entry, and one entry in scripts/ci-baseline-ratchets.mts.
  • Nothing under src/, extensions/qa* or test/e2e/qa-lab imports or runs those scripts (rg for the script names finds no reference).
  • These e2e lanes ran only because the package.json change selects every changed lane; both failures are delivery timeouts in the qa-lab Gateway harness.

The local ClawSweeper review on this exact head (ed6c6dea31d2) is clean, and every other check passes.

@obviyus
obviyus merged commit 1a6fa58 into main Nov 18, 2026
386 of 394 checks passed
@obviyus
obviyus deleted the chore/lifetime-check-ratchet branch November 18, 2026 10:03
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 19, 2026
Problem: OpenClaw checks authority once, when a request starts. Hundreds of checks run again while a request is running and abort started work. Follow-up PRs delete them; nothing stopped new ones from being added.

Fix: `check:lifetime-check-ratchet` counts, per production file, calls to the reviewed mid-request re-check constructors and string literals with authority refusal wording, using the TypeScript AST. A changed file whose count grows fails CI with the rule. The merge base is the baseline; data, ownership and secret checks are not counted. `--full-tree` prints totals per subsystem (446 today).

User impact: none at runtime; CI blocks new mid-request authority re-checks.

Proof: counter and ratchet tests (growth rejected, reductions and renames accepted, data-fence wording not counted); every baseline sub-ratchet passes.

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. scripts Repository scripts size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant