Repository navigation
refactor(cli): deslop CLI, ACP, and logging - #157748
Conversation
|
🦞👀 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 25, 2026, 10:15 AM ET / 14:15 UTC (Revision 11). ClawSweeper reviewWhat this changesThe branch consolidates CLI commands and service handling, Agent Client Protocol session flows, and diagnostic logging and redaction, with focused test updates. Merge readiness⛔ Blocked before merge - 2 items remain Keep open. Current main retains the pre-refactor implementations, and this remains a coherent contribution with production-path upgrade proof. This review found no supported blocking defect at the pinned head. Priority: P2 Review scores
Verification
How this fits togetherThe CLI turns operator commands into Gateway requests and service actions, while Agent Client Protocol translates client sessions and events into Gateway operations. Diagnostic logging turns runtime events into bounded, redacted support output. flowchart LR
A[CLI commands] --> B[Command routing]
C[ACP client] --> D[Session translation]
B --> E[Gateway]
D --> E
E --> F[Diagnostic events]
F --> G[Redaction]
G --> H[Support output]
Before merge
Agent review detailsSecurityNone. PR surfacePR surface statistics unavailable: the file list is incomplete. Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Keep one owner for each CLI, ACP, and diagnostic decision while preserving observable command, session, upgrade, and redacted-support behavior. Do we have a high-confidence way to reproduce the issue? Not applicable: this is an internal refactor rather than a reported failure. The recorded production-path runs provide behavior-parity evidence. Is this the best way to solve the issue? Yes: the branch reuses existing owners and removes repeated paths while retaining the checked routing, service-admission, and redaction decisions. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 86ac7739b1a5. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (10 earlier review cycles; latest 8 shown)
|
36efd25 to
72294f8
Compare
bbb7ef5 to
9561698
Compare
Consolidate command registration, result projection, strict service reads, ACP session mapping, and bounded diagnostic traversal under existing owners. Remove redundant wrappers, declarations, and repeated normalization while preserving command, protocol, lifecycle, output, and redaction contracts. Configure the ACP abort-cause fixture for the direct tool surface it implements. Production code shrinks by 1,410 net lines; no operator migration is required.
Keep the synthetic manager fixture independent of updater reader placement. Exercise real updater wrappers and delegate to the actual native policy for runtime-only cases. Preserve all maintenance and refusal assertions.
9561698 to
2ea37d3
Compare
|
Merged via squash.
|
* refactor(cli): deslop CLI, ACP, and logging Consolidate command registration, result projection, strict service reads, ACP session mapping, and bounded diagnostic traversal under existing owners. Remove redundant wrappers, declarations, and repeated normalization while preserving command, protocol, lifecycle, output, and redaction contracts. Configure the ACP abort-cause fixture for the direct tool surface it implements. Production code shrinks by 1,410 net lines; no operator migration is required. * test(doctor): mock the native service policy boundary Keep the synthetic manager fixture independent of updater reader placement. Exercise real updater wrappers and delegate to the actual native policy for runtime-only cases. Preserve all maintenance and refusal assertions.
Related: #156622
The prerequisite #157900 merged as
24827cd1a9e7a6dca19027ca121ba90fc03108c3. This PR is rebased onto main; the scanner changes are no longer part of its diff.What Problem This Solves
This maintainer-requested second CLI pass and first ACP/logging pass remove repeated internal decisions, result construction, and forwarding layers that make the existing command and session flows harder to maintain.
User Impact
No intended user-visible change: command names, aliases, options, defaults, help, exit status and JSON shapes remain fixed, as do ACP messages/session behavior and logging fields, redaction, and file/rotation behavior. This refactor introduces no configuration or data migration.
Why This Change Was Made
The changes reuse existing owners and combine identical paths while preserving their boundary checks and explicit output projections. Production code shrinks by 1,404 net lines (CLI 921, ACP 257, logging 225, and one companion barrel line); tests/support grow by 50 lines. The assertion-safety baseline only shrinks to match removed assertions.
Simplifications and rationale
The audit read the complete production subtrees, including all 217 files originally over 200 lines. No source file changed by the first CLI pass is edited again. Changed-export importers were searched across src, extensions, packages, test, scripts, ui, and apps; meaningful lifecycle/authority guards and output allowlists remain intact.
Evidence
Fresh independent Codex review is clean through P2. The stacked candidate preserves main's filesystem-helper redirects and Windows Task Scheduler diagnostics. Remote proof verified all 115 changed-file hashes before execution.
OPENCLAW_BUILD_PRIVATE_QA=1 pnpm buildnode scripts/check-changed.mjs -- <115 changed paths>node scripts/run-vitest.mjspnpm openclawCLI/ACP smokeThe importer census covered all 431 named exports in the old/new changed-production-file union, searching src, extensions, packages, ui, apps, scripts, and test. Anthropic and memory-core consumer tests also passed in the initial candidate run (54.574 s); those inputs are unchanged.
The real CLI smoke covers help, config, JSON/error routes, a task-owned loopback Gateway, ACP initialize/new/mode/list/resume/close, cron creation/edit/scratch/toggle/removal, and support export. Additional checks cover maintenance, audit, private QA, Discord thread dry-run, unknown-command JSON, and dashboard JSON. All state, tokens, messages, and workspaces are synthetic and isolated.
Changed-test wall costs with
pnpm test <file> --maxWorkers=1: session mapper 2.520 s / 8 cases; Gateway probe 19.100 s / 9 cases; supervised CLI probe 22.647 s / 16 cases; ACP abort-cause fixture 24.332 s / 1 case. The original Gateway-probe baseline was 21.051 s. Hosted CI reported 0.019 s across the eight mapper cases, 1.065 s across the nine Gateway-probe cases, 0.093 s across the 16 supervised-lock cases, and 8.362 s across the ten legacy Doctor cases. These sums of per-case timings exclude collection and shard overhead; the ACP abort fixture also has a reported whole-file duration of 9.661 s.The build reports startup JavaScript at 371,511 compressed bytes, 179 B above the numeric warning limit. PR #157942 already owns this UI budget condition and documents clean main at 371,516 B; it defers MCP text without raising budgets. This lane does not change UI budgets. The shared duration parser participates in the UI startup closure, so the exact byte difference is not attributed without paired measurement. Structural build checks passed.
Fixes found along the way
The ACP abort-cause end-to-end fixture still expected a directly advertised
session_statustool after Tool Search became the default. It now explicitly selects the direct-tool surface its synthetic provider implements; its validation-error and cancelled-settlement assertions remain unchanged. A control confirmed the original fixture lacked the direct tool, produced five requests, and failed its unchanged assertion (53.465 s); the repaired fixture passed (22.448 s). No timeout, retry, or assertion was weakened.The strict service-reader consolidation exposed an implementation-coupled Doctor fixture: it mocked exported updater policy wrappers, so validation inside their owner reached the real host-account policy and rejected synthetic state. The shared fixture now emulates only the native-manager policy boundary; updater readers and error mapping remain real, and runtime-only cases delegate to the real assertion. No production check or existing test assertion was weakened. The captured 36-file CI shard reproduced exactly eight Doctor failures plus 522 passes in 208.587 s; removing the cleanup yielded 530 passes in 199.351 s; the corrected fixture passed all 530 in 172.558 s. All 12 other fixture consumers passed 150 cases in 146.614 s, and the independent native-policy suite passed all 16 cases in 2.271 s. The legacy file's measured
pnpm test ... --maxWorkers=1cost is 24.654 s for 10 cases. Fresh independent review of this fixture-only correction is clean through P2.The original PR's hosted CI hit the manifest planner's 20-minute budget. The separate prerequisite fixes repeated literal scanning and an unterminated-Unicode cursor loop. A captured large request measured 102.687 / 5.276 / 5.574 / 105.510 seconds in A-B-B-A order with identical JSON hashes. The original failed merge's complete planner replay then passed in 258.288 seconds. The prerequisite's narrower exact-head CI is green; its 29-second manifest step is not a comparable measurement of the original workload.
The canonical public package and installed published
[email protected]updater passed in 514.651 seconds. The first update invocation installed candidate2026.9.6, preserving npm ownership, launcher identity, installed manifest/build-info, operator configuration, and the workspace sentinel. Candidate tarball SHA-256:318af29fc97ff1a376ddf51609e678e65bee5e29e0cacb215d24e42840f9fe70. This isolated--no-restartcell did not exercise native service restart or session-history migration.Remote provider: Blacksmith Testbox (run), lease
tbx_01m3bg0w800rm4jphmr17n67p4. Commands ran sequentially throughnode scripts/crabbox-wrapper.mjs run --provider blacksmith-testbox --id … --timing-json -- OPENCLAW_TESTBOX=1 OPENCLAW_TESTBOX_REMOTE_RUN=1 …, starting withpnpm install --frozen-lockfile. The complete proof passed and reverified all 115 source hashes. The lease is stopped.The fixture-only follow-up also passed
node scripts/check-changed.mjs -- src/flows/doctor-health.test-support.tsin 359.658 seconds, including both selected test-type graphs, all three dead-export scans, lint, and repository guards. Its Blacksmith Testbox run used leasetbx_01m3bn9mndpebk4bfxh7kysxth, now stopped. All 116 final source hashes were verified, and the committed treec40ac37ce3cd97b6ec4f6d279d16c86da232fac6exactly matches that completed proof. Production files are unchanged from the full build, CLI/ACP smoke, and published-driver update proof above.Real managed-service upgrade
The authentic published
[email protected]updater completed its first actual update invocation with restart enabled against this candidate. The isolated native scenario passed in 108.224 seconds, after a fresh canonical public package build/validation passed in 656.834 seconds. It used a newly created Linux OS account, its canonical HOME/state paths, real user-systemd and D-Bus, and the published CLI'sgateway install,gateway start, andupdate --tag file:<candidate> --yes --jsoncommands. No service-manager shim or production-code patch was used.Before update, the real Gateway reported
2026.9.4; afterward it reported2026.9.6and the candidate's exact packaged build ID. Both HTTP health/readiness and authenticated RPC health passed. The native PID changed from 11237 to 13052, systemd's invocation ID changed, the same unit ID and unit-file location were retained, and UID/cgroup ownership was verified. The updater reportedok/npm; install root, launcher, operator configuration, and the workspace sentinel were preserved.Verified source:
bbb7ef56c7d230296d7d9bc93040ab5e79d9a39c, treec40ac37ce3cd97b6ec4f6d279d16c86da232fac6. Crabbox materialized build commitbe6e8c653d77b4b3cee06386b01c067256332ec4; the serving Gateway reported2026.9.6-be6e8c653d77-2026-09-25T08-28-10.325Z, matching the installed artifact. Candidate SHA-256:a7c24acf564b27dfce6635bac8c16052456ea4d8f3450a3345a17975a642ca42. All 116 source hashes remained unchanged.Blacksmith Testbox hosting run, lease
tbx_01m3bsr6vnx0378y6g3bez18fk. The owned service, user manager, account, and processes were removed successfully; all six cleanup checks returned success, then the lease was stopped. An initial bootstrap-only attempt stopped at an unnecessarybusctl statuscredentials-introspection probe before OpenClaw was installed. Replacing that extra probe with the repository's canonicalsystemctl --user show-environmentreadiness check, with output discarded, left all real product assertions intact; the same integrity-verified tarball was reused.The review's managed-restart observation is now complete. Its automated schema warning does not describe this diff:
claws-cli.runtime.tsconsolidates planning inputs, and the assertion-safety file is a shrink-only ratchet, not a stored-data schema. This refactor introduces no configuration, default, schema, or retention change.Approved rebase resolution
Main commit
d57aa0cc18f(#157892) added explicit restart-health failure reasons. Insrc/cli/daemon-cli/restart-health-diagnostics.ts, the resolution retains main's complete six-entryrestartFailureReasonsmap andGatewayRestartWaitOutcometype import. The entireformatGatewayRestartFailurefunction is byte-identical to main: the existing still-starting and service-stayed-stopped branches retain precedence, followed byGateway restart failed: <reason>.for bothstatusLineandfailMessage, then the timeout branch.Kept from this PR: the direct
ports-format.jsimport of the same formatter, exporting the existing renderer implementation asrenderGatewayPortHealthDiagnostics, calling it directly fromrenderRestartDiagnostics, and deleting the redundant forwarding function. Dropped: none; each retained simplification remains equivalent. Main'slifecycle-readiness.test.tsandrestart-health-progress.test.tsare unmodified.After the first rebase, the post-prerequisite measurement was 109 production files, 1,104 insertions / 2,514 deletions, 1,410 net lines removed. Every added and deleted line of the previously approved patch was unchanged; range-diff differed only in context around main's new import and map. The Doctor fixture commit was patch-identical.
Final update-verification rebase
Main commit
c926e83c8e9(#157329) independently inlined the previous-Gateway verification receipt helper while adding readiness progress at its owner. The conflict insrc/cli/update-cli/update-command-verification.tsis resolved by keeping main's complete previous-Gateway verification implementation byte-for-byte, including its positive run guard, receipt text, authority check, callback ordering, and timestamp.Dropped from this PR: the now-redundant
recordPreviousGatewayVerificationhelper-inlining hunk, because it is already owned by main. Kept: the two equivalent loops that project version/build mismatches and plugin/channel errors into existing failure facts, preserving order, fields, messages, and codes. Every other added/deleted line in the previously approved patch remains unchanged. The earlier restart-health resolution remains intact, with no additional dropped hunks there.The final production measurement is 109 files, 1,103 insertions / 2,507 deletions, 1,404 net lines removed. The six-line difference from the post-prerequisite measurement is entirely the helper simplification already incorporated by main. Tests/support remain +50 lines and the assertion baseline remains -7.
Final status
The coordinator has removed the archive-worker dependency hold because exact-head CI for
956169817f6e958d71174165004cc0d9a6475d6ccompleted green. The current rebase at2ea37d37ff204a96cd972a00f46925e019633bd9passed 15 unmodified main test files / 607 cases in 304.184 seconds throughnode scripts/run-vitest.mjs, including all nine new Windows readiness-progress cases, original-service coverage, restart probes, verification/recovery callers and triage. All 131 source/test hashes matched before and after; the frozen dependency install passed. Blacksmith Testbox run, leasetbx_01m3c96efrjzy7wx48c8s6ezre, now stopped. The command and wrapper exited successfully; an external runner-portal sync warning occurred only after proof completed. Exact-head CI and the subsequent failure investigation are recorded below. No archive repair is included in this PR.CI timeout investigation and authorized retry
Initial CI failure (attempt 1). Exact-head CI 36138658157 failed in
checks-node-changed-config-compact-small-1(plus the aggregate CI gate); fail-fast cancelled the run. This is not the archive-worker failure. After six passing cases,src/gateway/server.config-patch.test.tshit a 180-second hook timeout foropenclaw.changes.list preserves an approved include-only operation without a duplicate write, then a 300-second no-output termination (exit 143). Its failed job log was captured once; no hosted rerun was used during the diagnostic comparison.A bounded Blacksmith comparison replayed the original full-file shard and order at the exact CI merge
ceefc05b8d178ae5157ce8fa97bf320c9d4dd87eand its clean first parentd5d4952c5bcabcf1470846c02d88bf04c66051d2. Both used Node 24.19.0, two workers, two-CPU affinity, frozen dependencies, unchanged test/hook/no-output deadlines, and separate clean worktrees. Candidate: 81/81 passed in 213.262 seconds; clean base: 81/81 passed in 279.285 seconds. The named case passed in 2.629 and 5.416 seconds respectively. These replays did not reproduce the CI timeout and do not establish a repair.Blacksmith Testbox run, lease
tbx_01m3cc6xxq5b5t0hysk9mq439a, stopped after the comparison. Source remained unchanged. Open #157886 independently documents the same case, hook timeout, no-output termination and exit 143 in CI 36099648083; it explicitly says no cause or repair is established. No owning repair is merged on inspected main. The initial landing stopped under the standing rule. The coordinator then explicitly authorized exactly one failed-job rerun on the unchanged head. Attempt 2 completed successfully for head 2ea37d3. No second rerun was used. The passing rerun does not establish a repair for the timeout; its ownership and any further investigation remain a separate follow-up.