Repository navigation
refactor(agents): deslop embedded agent runner fourth pass - #160906
Conversation
Reuse canonical helpers and owner types, consolidate equivalent result and prompt projections, and remove unused argument plumbing and narration. Preserve lifecycle, cancellation, authority, transcript, request, and usage contracts. Shrink only the assertion baseline entries affected by this cleanup.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed September 29, 2026, 2:18 AM ET / 06:18 UTC (Revision 3). ClawSweeper reviewWhat this changesThe branch removes duplicate helpers and unused plumbing from OpenClaw’s embedded agent runner and adjusts command-test fixtures while aiming to preserve runtime behavior. Merge readiness⛔ Blocked before merge - 3 items remain The cleanup remains distinct from the merged third pass and is absent from current main. One newly added broad partial mock conflicts with the scoped agent test policy and has a narrow repair. Priority: P3 Review scores
Verification
How this fits togetherThe embedded agent runner takes admitted requests through model selection, provider calls, tool execution, and transcript handling to produce a final reply. The changed command test exercises model selection at that boundary. flowchart LR
A[Inbound request] --> B[Run admission]
B --> C[Model selection]
T[Command test fixture] --> C
C --> D[Embedded agent attempt]
D --> E[Provider and tools]
E --> F[Transcript and reply]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource -641, Tests -19, Other -2. Total -662 across 76 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Keep the smaller runner while preserving explicit test isolation and the existing admission, provider, transcript, and reply contracts. Do we have a high-confidence way to reproduce the issue? Not applicable to a reported product defect. The newly introduced partial mock is directly visible in the pinned test diff; the PR body reports that the command suite passes after the fixture repair. Is this the best way to solve the issue? No, not quite: the production simplifications appear coherent, but the command fixture can supply the one real normalized lookup through an explicit mock without importing the full model-selection facade. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against d812797ec244. LabelsLabel changes:
Label justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
|
Use a partial mock so missing provider maps reach the real normalized lookup. Keep the collision fixture and assertions intact, moving its config into the existing helper to satisfy the line-cap ratchet.
…160906) Consolidate equivalent embedded-runner projections and owner helpers, remove unused plumbing, and simplify redundant branches while preserving run authority, cancellation, prompt/transcript bytes, tool policy, transport shaping, and usage accounting. Production change: 361 added / 1,002 removed, net -641 lines. Preserve real model-selection exports in the command test mock. Missing provider maps return undefined on both main and the refactor; the legacy automatic fallback still wins over the colliding alias. Keep the unchanged collision configuration in the existing fixture helper to satisfy the line-cap ratchet. Validation: main/PR comparison with model-selection fully unmocked; 138 command tests; all 20 facade-mocking siblings plus embedded runner tests (355 files / 5,827 tests); final check-changed; independent autoreview through P2. No production behavior change is claimed. Related: openclaw#159597 Exact-head CI exception: checks-node-compact-small-18 has the same two sparse-runner missing-prerequisite failures as unrelated PR openclaw#160075 run 36528303180. All other execution jobs passed or skipped. See PR Evidence.
What Problem This Solves
The embedded runner still contains duplicate result projections, unused argument plumbing, forwarding helpers, and repetitive commentary after the previous cleanup passes.
Related: #159597
User Impact
No user-visible behavior change. Run and attempt lifecycles, cancellation ordering, authority revalidation, prompt/transcript bytes, tool dispatch and schemas, provider request shaping, usage accounting, and persisted state remain unchanged.
Why This Change Was Made
This maintainer-requested fourth pass combines the remaining sound simplifications within
src/agents/embedded-agent-runner:Measured production change: 641 net lines removed (361 added / 1,002 removed). Tests/support: 19 net lines removed. The assertion-safety baseline contains only the four exact shrink updates required by the removed assertions. Production changes remain inside the embedded runner; the command-test repair is described below.
The full production census covered 274 files / 65,765 lines. This fourth pass is below the requested 1,000-line target after implementing the sound opportunities found; the required coverage log for every production file over 200 lines follows below.
Fixes Found Along the Way
No independently established product bug or flaky-test repair is claimed in this refactor.
Evidence
Exact-head CI: approved pre-existing-failure exception
CI run 36529548540 completed on repair head
f3483a23eba8c10c6edfc45a50765c60892c5e72: 127 jobs passed and 21 skipped. The only failed execution job waschecks-node-compact-small-18(job 109280246068); the aggregateopenclaw/ci-gatefailed because of that job. Security-fast and all CodeQL Security High checks passed; there are no pending checks or required reviews.The tooling shard
core-tooling-16-hosted-3failedtest/scripts/ci-node-worker-owner-boundary.test.ts, casesmodern-corruptandmodern-unshared, withERR_MODULE_NOT_FOUND: fixturescripts/lib/vitest-build-prerequisites.mtsis absent when imported by fixturescripts/ci-run-node-test-shard.mts.Pre-existence is proven by unrelated PR #160075 at its verified current head
4710cc9857949f295e3baf92b39d452de6874dde: its latest CI run 36528303180, same failed job failed the same two cases with the same missing prerequisite at 06:00:54 UTC, before this PR's 06:15:17 UTC failure. That PR changes Windows session/cron handling and Windows test selection; its package script edit changes no dependencies or the failing Linux path.Independence was checked against the actual tested merge
ed8fac598fd5d29b26f09517976bffbe983f2413and its main parent4735f663f61425b98fed9ae54550699a323e7db5: there are no PR changes underscripts/,test/,.github/, or inpackage.json/pnpm-lock.yaml. The sparse fixture omits the prerequisite; inherited prebuilt-mode configuration reaches its missing import before the intended worker owner or any changed agent code executes. None of this PR's changed files are in the failing test/import path. Main CI repair remains with the coordinator.The PR's own Testbox proof and fresh review passed as recorded above. Under the operator's explicit September 27/28 pre-existing-failure rule, submit the squash merge pinned to
f3483a23eba8c10c6edfc45a50765c60892c5e72; this exception does not claim green CI.Repair of the PR-owned command-test failure at
f3483a23eba8c10c6edfc45a50765c60892c5e72:863e377524a970787dfb2540b32722810c512cff, the missing provider map returned early; no TypeError was part of the behavior. The refactor delegates to the realfindNormalizedProviderValue, which also returnsundefinedbefore normalization. Prompt-alias preparation for the colliding Google alias reaches this lookup. The command fixture's complete module mock omitted that export.model-selection.jsfully unmocked in a temporary copy of the existing scenario, both main and the PR retaincloudflare-ai-gateway/gemini-2.5-flash-liteandrequestedRouteResolution: "resolved".importOriginalto preserve real exports before applying the existing scenario overrides. No production behavior or assertions changed; production remains 361 added / 1,002 removed, net -641 lines.pnpm test src/agents/agent-command.live-model-switch.test.ts --maxWorkers=1: 48.59s wall on the final repair. The existing 138-case command/lifecycle suite remains intact; no cases were added.node scripts/check-changed.mjs --base fd1467d466924a42f64cd00618e0f8e332b8e16f --timed: passed in 1,359.91s. Formatting, line-cap, core/test types, dead exports, lint, and all selected guards passed.Local attempts were blocked by host load (worker preparation reached the no-output deadline, then the command import exceeded the existing hook deadline); the exact reproduction and comparisons above ran on Testbox without changing deadlines. The initial comparison lease expired during slow local source staging before any comparison test ran; the replacement used a 90-minute idle window.
Final repair proof lease:
blacksmith-testbox,tbx_01m3ns27ctv8xqxgyr1zvsb0ed, controller run. The wrapper verifies source bytes; the controller status alone is not the proof result.Blacksmith Testbox validation (Linux, Node 24.19).
git range-diffconfirms the cleanup patch is identical after the clean pre-readiness rebase at225c629730c7e7df1cc14cba2b307892481cb9c1. On that pushed head,node scripts/check-changed.mjs --base fd1467d466924a42f64cd00618e0f8e332b8e16f --timedpassed in 1,637s, the four focused OpenRouter/CLI/compaction files passed 143 tests in 67s, andpnpm buildpassed in 349s. The wrapper verified the frozen source and reported exit 0. The patch-identical candidate also has this earlier proof:src/,extensions/, andpackages/: 606 files / 12,535 tests passed, 27 shards, 1,713s.node scripts/check-changed.mjs: passed, 1,428s. This includes core/test types, lint, dead exports, formatting, and ratchets.src/infra/fs-safe-import-boundary.test.tsand sibling boundaries: 20 files / 112 tests passed, 77s on the reviewed candidate before rebase.pnpm build: passed, 337s on the reviewed candidate before rebase.Pre-rebase final lease:
blacksmith-testbox,tbx_01m3ncs0hg8q4grpz44da3xpgv, controller run. Post-rebase lease:blacksmith-testbox,tbx_01m3ngcma7jxwmm87jk797p0tj, controller run. Both leases were stopped after proof. The repository wrapper verified the frozen source before running each command; the controller run alone is not the test-result claim. The post-rebase provider portal sync timed out after successful command completion; the reported test/build results and exit 0 were retained.Changed-test cost, measured with
pnpm test <file> --maxWorkers=1: stage timing 2s/6 tests; prompt helpers 39s/7 tests; attempt 29s/54 tests; transcript repair contract 42s/4 tests; session boundary 43s/30 tests. No new tests were added. Hosted CI cost will be available on the attached PR run.Existing E2E failure:
agent-runner.runreplyagent.e2e.test.tsthrewAgentDatabaseRegistryChangedErroratopenclaw-agent-db-registry-listing.ts:287in the adoption callback case. Replaying the identical 12-file selection on clean main27de2f87db284610f8deb3312318fa9934cb7182also passed 436/437, failing with the same exception/stack in the immediately preceding cancellation case. This establishes a pre-existing fixture-group failure, not exact-case reproduction or a claimed fix. The fixture mocks embedded execution; its mock never supplies context-engine attempt facts, so the changed run-entry discard path is not executed. The relevant fixture/storage sources are unchanged. Per campaign direction, existing main failures remain with the coordinator; no retry, timeout increase, skip, or assertion weakening was added.Initial candidate validation caught type inference, obsolete fixture fields, and lint issues; these were corrected before the final passing checks. A stopped Testbox/SSH connection interrupted one check attempt, so its partial output was not counted as a passing gate.
Fresh independent Codex review of the final candidate completed scoped-clean at P0-P2. Earlier findings were checked against complete source context; no accepted actionable finding remains.
Marked ready for review at the exact pushed head above. Hosted CI run 36517130819 attached to that head and was still running at readiness; pending hosted checks are not counted as passing proof.
Fourth-pass coverage: every production file over 200 lines, sorted by original size
Embedded agent runner fourth-pass coverage
Base:
ed5cddeae5269386b7b4469a02758994691eecc5. All 274 production files were read across non-overlapping worker slices. The lead inspected the combined diff. Sizes are before edits.runs.tscreateDeferredCorefor completion-claim registration. Keep synchronous abort, exact-handle claims, retained authority checks, pending-input eligibility, and forced-terminal persistence ordering intact.tool-result-truncation.tsreplay-history.tsextra-params.tsrun-orchestrator.tsrun/attempt-session-prepare.tsrun/terminal-resolution.tsrun/images.tscompaction-session-execution.tsmodel.static-catalog.tsrun-entry.tsrun/run-attempt-dispatch.tsmodel.configured-overrides.tsfindNormalizedProviderValuealready owns it. Exact-key-first behavior and configured/discovered route, pricing, media, and sizing precedence retained.run/auth-controller.tsrun-loop.tscompact.queued.tsrun/settled-turn-finalization.tscompact.queued-execution.tsrun/attempt-stream-settle.tsrun/attempt-stream-prepare.tsrun/attempt.tool-call-argument-repair.tsrun/attempt-llm-boundary.tsprepared-compaction-runtime.tsrun/attempt-finalize.tsrun/runtime-preparation.tsrun/attempt.tscompact.tsthinking.tssome; shortened comments retaining opaque-signature authority and latest-turn recovery constraints. Recovery/notification/stream-settlement ordering unchanged.google-prompt-cache.tsModelintersection, inlined one-use tool projection, removed null guard dominated by the earlier falsy guard, and removed module narration. Cache payloads, tool schemas, persisted entry shapes, expiry/backoff, and writer-claim propagation retained.run/compaction-runtime.tsrun/attempt-recovery.tsrun/attempt-prompt-helpers.tsrun/attempt-prompt-build.tsmodel.tsrun/assistant-failure.tsrun/llm-idle-timeout.tsdelivery-evidence.tsrun/attempt-prompt-phase.tstool-result-context-guard.tsrun/attempt-setup.tsrun/payloads.tsrun/session-bootstrap.tsrun/types.tsrun/attempt-tool-prepare.tsmodel.registry-resolution.tsrun/lane-controller.tsrun/attempt-stream.tsrun/overflow-context-recovery.tsrun/attempt-system-prompt-prepare.tsrun-state.tsrun/attempt.model-diagnostic-lifecycle.tsrun/attempt-tool-call-replay-sanitization.tsrun/attempt-result.tsrun/attempt-queue-message.tsrun/attempt-settle.tsdirect-compaction-preparation.tscontext-engine-maintenance.tsrun/attempt-history.tsrun/incomplete-turn-recovery.tsprompt-cache-observability.tspruneMapToMaxSize. Kept fingerprint bounds, unreadable/getter defenses, field order, diagnostic text, usage baseline, and cache-break thresholds.run/attempt.model-diagnostic-observation.tsrun/failover-retry-controller.tscompaction-runtime-context.tsrun/preemptive-compaction.tsrun/params.tscompaction-successor.tsrun/prompt-failure.tsrun/incomplete-turn-resolution.tstypes.tsrun/terminal-preparation.tsrun/attempt-prompt-support.tsrun/model-setup.tsrun/tool-media-payloads.tsrun/attempt-prompt-submit.tsrun/history-image-prune.tsstream-resolution.tsresult-fallback-classifier.tscompaction-hooks.tsrun/attempt-tool-call-stream-normalization.tsrun/attempt-session-runtime-prepare.tscli-backend-dispatch.tsrun/tool-error-warning.tsrun/attempt-normalization.tscompaction-runtime-preparation.tsrun/attempt-tool-construction-plan.tsrun-entry-terminal.tsrun/incomplete-turn-classification.tsopenrouter-model-capabilities.tstriggerFetchfor refresh deduplication; collapsed awaited-miss refresh branches. Cache persistence, schemas, parsing, timeout/body cleanup, and skip-next-miss semantics unchanged. SDK exports remain needed.run/attempt-prompt-preflight.tsrun/setup.tsrun/auth-profile-success.tsrun/attempt-bundle-tools.tsmodel.manifest-alias.tsrun/session-prompt-state.tsmodel.provider-hooks.tsnormalizeResolvedPricing: that would change tier metadata and object identity.run/attempt-history-prepare.tsrun/auth-plan.tsrun/attempt.model-diagnostic-events.tsrun/attempt-tool-catalog.tscli-backend-dispatch-transcript.tstranscript-rewrite.tsrun/failover-policy.tsrun/attempt-client-tools.tsrun/attempt-async-tasks.tsmodel.inline-provider.tspi-messagesvalue; no behavior change without entry-point evidence.model.configured-fallback.tsrun/provider-review-continuation.tsrun/attempt-transcript-lifecycle.tsmessage-visibility.tsrun/provider-review-run.tsrun/deferred-lifecycle-owner.tshistory.tssession-prompt-state.tssandbox-skills.tsprovider-prompt-state.tsrun/pre-persisted-user-turn.tsrun/attempt-execution-phase.tsrun/attempt-tool-call-name-resolution.tsrun/attempt-context-engine-helpers.ts