Skip to content

refactor(agents): use fixed tool-loop defaults directly - #130681

Merged
steipete merged 1 commit into
mainfrom
codex/cleanup20k-tool-loop-defaults-20260827
Aug 27, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/cleanup20k-tool-loop-defaults-20260827

Conversation

@steipete

@steipete steipete commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Related: #111382

Additional instructions

Maintainer-owned branch; maintainer edits remain allowed.

What Problem This Solves

The tool-loop detector still rebuilt a private configuration object for thresholds and detector switches that are now fixed built-in defaults. That obsolete indirection duplicates the real policy constants and makes the current behavior harder to audit. This is a maintainer-requested cleanup, not a change to loop-detection policy.

Why This Change Was Made

Use the existing constants directly and remove the duplicate private config object, resolved type, resolver, and always-true detector conditions. Keep the exported argument positions/types, opt-in setting, thresholds, detector precedence, outcome matching, run scoping, warning text, and history trimming unchanged.

The public numeric/detector options retired in #111382 stay retired. Their doctor migration remains intact for upgrades; this PR only removes the runtime's constant projection. No dependency, schema, storage, API, import, or lazy-loading changes.

User Impact

No user-visible behavior change. Loop detection remains opt-in and uses exactly the same warning, critical, circuit-breaker, and history limits.

Evidence

  • Production +16/-80 (net -64); tests unchanged.
  • Original owner baseline: 83 tests passed. Final Node 24.19.0 owner/admission/runner-bridge proof: 90 tests across 3 files passed, including run isolation, outcome reconciliation, vetoes, detector escalation, and batch admission.
  • Formatting, typed lint, dead-export scans, runtime and static import-cycle checks, plugin boundaries, doctor/dependency/line/assertion guards, and native-state/database/media/sidecar/webhook/pairing guards passed.
  • Independent Codex precommit review of the complete patch and 20 whole owner/caller/test/config contexts: no actionable findings.
  • Local full changed gate and core-test typecheck stopped on unrelated stale installed dependency declarations (Google SDK, Pi TUI, and Markdown-it); no diagnostics in the changed owner. The local install also has Vitest 4.1.10 instead of pinned 4.1.11. No dependency overrides or shared-install changes were made. This proof gap is closed by successful exact-head hosted CI below.
  • A broader E2E attempt stopped before test collection during its implicit build because @lit/context was unavailable in the local worktree. No E2E, standalone build, or live-provider result is claimed; this internal constant cleanup changes no build, package, import, or external API surface.

Focused command:

node scripts/run-vitest.mjs src/agents/tool-loop-detection.test.ts src/agents/tool-loop-admission.test.ts src/agents/embedded-agent-runner/run/tool-loop-recovery.test.ts

AI-assisted with Codex; the owner, callers, retained upgrade contract, and proof limitations were manually inspected.

Exact-head hosted completion

Ordinary PR CI completed successfully on d822f7a2f52c2aa368bbc4963de261730518fa84. Completed logs confirm Linux Node 24.19.0, the frozen lockfile, and Vitest 4.1.11: the owner passed 83 tests, admission passed 6, and runner recovery passed 1. Full production types, test types (all core shards, plugins, root tests and scripts), typed lint, build artifacts, and the required CI gate passed.

A distinct independent published-head Codex review of the full patch and 24 complete context files also completed with no P0–P3 findings. The latest ClawSweeper review found no actionable defect; its remaining next step was exact-head CI and normal landing checks. CI is now successful and native preparation passed without changing the commit. Its focused replay also passed all 90 tests; the harness did not find a single Test Files 3 passed line because the runner reports separate 2-file and 1-file shards, not because tests failed.

The pre-existing volatile-delivery-ID documentation wording identified during review was independently corrected by #130261 while this PR was in flight. Post-merge inspection confirms that correction and the complete upstream nonce-hashing fix are preserved; no follow-up remains for that wording, and this cleanup takes no credit for the upstream repair.

Landing

Merged as b5ed58c2bc67504a0009e3b7e46826ff59949ca5 after native hosted-proof preparation and merge both completed successfully. The actual squash removes 64 net production lines and matches the reviewed cleanup after accounting only for shifted hunk coordinates and blob IDs. The temporary native review workspace was removed. Native cleanup reported a remote-branch deletion warning, so the source branch was retained; no force cleanup was attempted.

@steipete steipete self-assigned this Aug 27, 2026
@clawsweeper

clawsweeper Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Aug 27, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 27, 2026
@clawsweeper

clawsweeper Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 27, 2026, 12:12 AM ET / 04:12 UTC.

ClawSweeper review

What this changes

The branch removes the obsolete private tool-loop configuration projection and uses the existing fixed thresholds and detector policy constants directly.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep open for normal maintainer landing: the one-file refactor is behavior-preserving and has no actionable review finding, while exact-head CI is still in progress.

Priority: P3
Reviewed head: d822f7a2f52c2aa368bbc4963de261730518fa84

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused net-negative refactor whose direct source, caller, configuration, migration, and test-surface review found no regression.
Proof confidence 🌊 off-meta tidepool Not applicable: Not applicable: this is a maintainer-authored internal refactor with no user-visible change; focused test evidence is documented in the PR body.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Not applicable: this is a maintainer-authored internal refactor with no user-visible change; focused test evidence is documented in the PR body.
Evidence reviewed 5 items Head diff preserves policy: The only behavioral gate remains the enabled setting; the diff replaces resolver reads with the same fixed 10/20/30 constants and removes literal-true detector conditions.
Current configuration contract: The strict runtime schema and exported type expose only tools.loopDetection.enabled; no legal current configuration can vary a removed threshold or detector field.
Caller and owner boundary: Single and batch admission still require enabled === true and pass the same run scope; the retained positional config argument is intentionally unused by history recording because history size is fixed.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/agents/tool-loop-detection.test.ts src/agents/tool-loop-admission.test.ts src/agents/embedded-agent-runner/run/tool-loop-recovery.test.ts

Result: PASS (completed)

[test] starting test/vitest/vitest.agents-core.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130681-bcLcJK/target

 ✓  agents-core  src/agents/tool-loop-detection.test.ts (83 tests) 163ms
 ✓  agents-core  src/agents/tool-loop-admission.test.ts (6 tests) 190ms

 Test Files  2 passed (2)
      Tests  89 passed (89)
   Start at  04:13:11
   Duration  11.55s (transform 9.09s, setup 960ms, import 9.88s, tests 354ms, environment 0ms)

[test] starting test/vitest/vitest.agents-embedded-agent-run.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130681-bcLcJK/target

 ✓  agents-embedded-agent-run  src/agents/embedded-agent-runner/run/tool-loop-recovery.test.ts (1 test) 99ms

 Test Files  1 passed (1)
      Tests  1 passed (1)
   Start at  04:13:23
   Duration  3.53s (transform 2.57s, setup 965ms, import 2.10s, tests 99ms, environment 0ms)

[test] passed 2 Vitest shards in 22.19s
[test] starting test/vitest/vitest.agents-core.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130681-bcLcJK/target

 ✓  agents-core  src/agents/tool-loop-admission.test.ts (6 tests) 89ms
 ✓  agents-core  src/agents/tool-loop-detection.test.ts (83 tests) 72ms

 Test Files  2 passed (2)
      Tests  89 passed (89)
   Start at  04:13:34
   Duration  5.39s (transform 2.93s, setup 442ms, import 4.54s, tests 161ms, environment 0ms)

[test] starting test/vitest/vitest.agents-embedded-agent-run.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130681-bcLcJK/target

 ✓  agents-embedded-agent-run  src/agents/embedded-agent-runner/run/tool-loop-recovery.test.ts (1 test) 46ms

 Test Files  1 passed (1)
      Tests  1 passed (1)
   Start at  04:13:40
   Duration  1.80s (transform 813ms, setup 442ms, import 1.08s, tests 46ms, environment 0ms)

[test] passed 2 Vitest shards in 14.20s

Assertions:

  • NOT OBSERVED expect_output: Test Files 3 passed — command exited successfully; expected output was not observed in the captured pane

How this fits together

Tool-loop detection examines run-scoped agent tool-call history and returns warnings or blocking outcomes to the agent runner. This cleanup preserves the opt-in configuration boundary while simplifying the fixed internal policy used by admission and recovery.

flowchart LR
A[Agent tool calls] --> B[Run-scoped history]
B --> C[Tool-loop detector]
D[Enabled setting] --> C
C --> E[Fixed warning and block thresholds]
E --> F[Admission or recovery outcome]
Loading

Before merge

  • Complete next step (P2) - No repair lane is needed because the review found no actionable defect; this maintainer-labeled PR only awaits normal exact-head CI and landing checks.
Agent review details

Security

None.

PR surface

Source -64. Total -64 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 1 16 80 -64
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 16 80 -64

Review metrics

Metric Value Why it matters
Production versus test LOC production +16/-80 (net -64); tests 0 The cleanup reduces production indirection without adding test-support or configuration surface.

Technical review

Best possible solution:

Retain the direct-constant implementation and land it after exact-head CI completes successfully.

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

Not applicable: this PR is a behavior-preserving refactor, and source inspection establishes that current configuration only controls enablement.

Is this the best way to solve the issue?

Yes. Direct use of the canonical fixed constants is the narrowest maintainable implementation now that the public tuning fields are retired and Doctor owns their cleanup.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P3: This is a behavior-preserving internal cleanup with no claimed user-visible impact.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Not applicable: this is a maintainer-authored internal refactor with no user-visible change; focused test evidence is documented in the PR body.

Label justifications:

  • P3: This is a behavior-preserving internal cleanup with no claimed user-visible impact.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Not applicable: this is a maintainer-authored internal refactor with no user-visible change; focused test evidence is documented in the PR body.

Evidence

What I checked:

Likely related people:

  • steipete: Authored this cleanup and the merged fixed-default config reduction that established the remaining enabled-only contract. (role: recent area contributor and cleanup author; confidence: high; commits: d822f7a2f52c, 783a5d21cfc1; files: src/agents/tool-loop-detection.ts, src/config/types.tools.ts)
  • cxbAsDev: Recent merged history records this contributor on the tool-loop detection file’s preceding owner change. (role: recent feature contributor; confidence: medium; commits: e3c78c348738; files: src/agents/tool-loop-detection.ts)

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.

@steipete
steipete merged commit b5ed58c into main Aug 27, 2026
222 checks passed
@steipete
steipete deleted the codex/cleanup20k-tool-loop-defaults-20260827 branch August 27, 2026 04:36
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Aug 27, 2026
…-retirement-v13

* origin/main: (243 commits)
  fix: preserve Gateway error reasons in text logs (#130645)
  refactor(video): deduplicate generation contracts (#130635)
  fix(agents): preserve direct-message sender identity (#124548)
  fix(agents): preserve silent reply after settled tools (#130675)
  fix(talk): preserve replacement speech when an old utterance is canceled (#130687)
  fix(browser): preserve literal names and formatter-owned snapshot refs (#130599)
  fix(auth): reset only the profile replaced by a successful login (#124014)
  fix: bind session creation to admitted Gateway (#130686)
  refactor(qa-lab): reuse model reference splitter (#130317)
  docs(gateway): clarify independent HTTP endpoint switches (#130690)
  fix(ui): Control UI smooth scrolling ignores the reduced-motion preference (#130428)
  refactor(lmstudio): remove unreachable catalog merge (#130689)
  fix(crabbox): restore cloud machine CPU and RAM (#130684)
  fix(secrets): compare proxy bearer tokens directly (#127054)
  fix(matrix): show recovery key availability in text status (#128051)
  fix(ios): restore approval settings navigation and remove duplicate shell state (#130651)
  refactor(agents): use fixed tool-loop defaults directly (#130681)
  refactor(qa-lab): share process tree metric reader (#130419)
  refactor(models): simplify prepared owner access (#130683)
  fix(parallels): main install and update smoke cannot complete (#130658)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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