Repository navigation
refactor(agents): deslop tools, auth profiles, sandbox and failover - #161122
Conversation
Keep abort checks at the final public return boundaries, including legacy fallback. Complete the cleanup with canonical literal task kinds, bound response reads, unshadowed projections, and a shrinking assertion baseline.
|
🦞👀 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, 9:14 AM ET / 13:14 UTC (Revision 4). ClawSweeper reviewWhat this changesThe branch consolidates agent tool, credential, sandbox, replay, compaction, and media helpers and adds final cancellation checks to OAuth credential resolution. Merge readiness⛔ Blocked before merge - 2 items remain Keep this PR open. Current main retains code that this branch consolidates, so the earlier merged cleanups do not supersede it. No discrete introduced defect is established, but one exact-head child-followup CI failure remains unqualified. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw's agent runtime receives user requests and model tool calls, selects credentials, and executes tools through Gateway and sandbox boundaries. Replay and compaction then shape the context available to later model turns. flowchart LR
A[User request] --> B[Agent runtime]
C[Stored credentials] --> D[Auth selection]
D --> B
B --> E[Tool and sandbox execution]
B --> F[Replay and compaction]
E --> G[Gateway actions and artifacts]
F --> B
Before merge
Agent review detailsSecurityNone. PR surfaceSource -919, Tests +53, Other -3. Total -869 across 79 files. View PR surface stats
Review metricsNone. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep one owner for each agent contract while preserving credential scope, sandbox containment, replay pairing, and tool output; credential lookup should reject cancellation at its final public return. Do we have a high-confidence way to reproduce the issue? Yes for the incidental OAuth defect: pinned main can return a legacy fallback after cancellation, and the new public-resolver test stages that continuation. I did not execute the test. Is this the best way to solve the issue? Yes for the identified cancellation gap: checking the signal after the final awaited fallback is a narrow repair, and the surrounding consolidation reuses existing owners. The heartbeat CI failure still needs attribution. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against aa56d37f1c81. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat 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 |
…o break import cycle
Restore the existing callback lookup boundary for prepared runtimes and keep the visible-spawn dependency type private. Preserve the remaining cleanup and existing test assertions.
Coordinator landing note: pre-existing main failuresExact-head CI on
The PR-owned defect (eager bootstrap-reader access at |
…penclaw#161122) * refactor(agents): deslop tools, auth profiles, sandbox and failover * fix(agents): preserve cancellation across profile resolution Keep abort checks at the final public return boundaries, including legacy fallback. Complete the cleanup with canonical literal task kinds, bound response reads, unshadowed projections, and a shrinking assertion baseline. * fix(agents): define spawn tool options with the visible spawn owner to break import cycle * fix(agents): preserve lazy OAuth bootstrap initialization Restore the existing callback lookup boundary for prepared runtimes and keep the visible-spawn dependency type private. Preserve the remaining cleanup and existing test assertions.
What Problem This Solves
The fourth tools pass and accompanying agent-subsystem sweep remove duplicate projection, parsing, and forwarding code left after the previous cleanups.
User Impact
The cleanup preserves tool names, registered descriptors, schemas and prompts, credential selection and cooldowns, OAuth fencing, sandbox path/isolation policy, failover ordering, and persisted state. Canceled OAuth lookups now honor cancellation at their final return boundary, including legacy-profile fallback.
Why This Change Was Made
The combined sweep removes 919 net production lines (722 added, 1,641 removed). The coverage log below records all 158 production files over 200 lines after the complete file-by-file pass, with retained authority and compatibility boundaries called out. The prior third tools pass (#159639) and subsequent merged fixes were inspected before editing. The integration preserves main's canonical replay-ID owner (#134425) and worker-owned subagent Stop persistence (#160203); the reduction is measured against
d3008b2d5ee.Fixes found along the way
An OAuth lookup could return credentials when cancellation arrived between an inner lookup finishing and its public continuation resuming. The selected-profile and legacy-fallback paths now recheck the caller signal after their final awaits. Started refresh settlement remains independent. A timer-free public-resolver regression permits earlier successful completion and rejects credential returns when cancellation wins; the legacy case uses a concurrent peer lookup to expose the outer boundary.
The refactor also exposed an incomplete no-external-credentials fixture. Its mock now supplies the missing null bootstrap result; existing assertions are unchanged.
Evidence
CI failure repair (
500deef514d)The repair restores main's lazy
readBootstrapCredentialcallback insrc/agents/auth-profiles/oauth.ts. Replacing it with an eager imported function read caused prepared-model and Gateway suites to throw during module initialization, before their test cases ran.VisibleSessionsSpawnDepsis now file-private, removing the sole Knip unused-export finding. No test assertions, ignores, or changelog entries changed; the rest of the reduction remains intact.Fresh isolated Codex review is clean through P2. Repair validation runs on Blacksmith Testbox
tbx_01m3pcf7n8gcq90jfpaq9km8st(lease workflow). The wrapper allocated the lease; after local source-capsule preparation stalled on the overloaded host, the installed Crabbox CLI used the same provider and lease. Both baselines were fetched into separate clean remote worktrees at full pinned SHAs. The candidate patch and file hashes were verified, and its index tree is41f2e00bd103f2dbbfc859ccd487943ef35de3ec.The repaired candidate passes the five requested files (62 tests, 94s), owning suites (127 files, 1,419 tests, 266s), and import boundaries (18 selected files, 87 cases, 78s). All dependency, unused-file, and unused-export checks pass with zero entries (93s, 54s, 61s); Madge reports zero cycles (40s). The complete staged
check-changedgate passes in 37m52s, including core and all 27 test-type shards, lint, formatting, and storage/import guards. The final source hashes and index tree remain unchanged.f8f3bd546844208c175496src/boards/board-store.parity.test.tssrc/gateway/server-chat-metadata-lifecycle.integration.test.tssrc/agents/prepared-model-runtime.auth-recovery.test.tssrc/agents/prepared-model-runtime.reload-auth.test.tsextensions/discord/src/monitor/listeners.thread-delete.session-store.integration.test.tsThe original failed CI run tested merge
c0bccdad90b8985be053225a8d800dbdddd80e6c, incorporating newer main code than the raw PR head. Main commit26dffe7468cdf23b5d99b183d025e49198e39ceaintroduced execution capture into session deletion. The board fixture opens under a custom state environment and deletes without that environment, so the existing ownership guard rejects the mismatched shared database. The same commit adds an incognito post-deletion identity check that can observe the row it just deleted and roll the transaction back. Main repair remains with its coordinator. Discord's separate worker-pool routing issue was already repaired on main by5d6f464a1cb3345a112707b53ce0ee2818bb0c9d.Scheduled main CI 36556391603, at
3baf08ac9b1af2bb180c771104a8d2d0764e4848, repeats all 19 inherited non-Discord cases with the same test names and errors as the original PR CI run. The preceding scheduled run36550256341also reproduces them. These causal test/implementation paths are unchanged by this PR:checks-node-compact-small-26/109367122379src/boards/board-store.parity.test.tschecks-node-compact-large-24/109367122486src/gateway/server.incognito-lifetime.test.tsok:false; rows remain (7 cases)checks-node-compact-large-13/109367121965src/config/sessions/session-history-budget-owner-parity.test.tschecks-node-compact-small-4/109367121998src/agents/subagents/registry/subagent-control.publication.test.tschecks-node-compact-small-8/109367122002src/config/sessions/cleanup-service.applied-summary.test.ts;src/config/sessions/session-accessor.sqlite-prepared-admission.test.tschecks-node-compact-large-18/109367121857src/config/sessions/cleanup-service.fix-missing.test.ts;src/config/sessions/session-accessor.sqlite-cleanup-race.test.tschecks-node-compact-large-8/109367122022src/infra/session-cost-usage.archive-identity.test.tsRepair head:
500deef514d77cdd4b8887086a2a3ca1c8ea4251; its committed tree is the tested candidate tree above. Exact-head CI 36567887239 completed with four failing test shards;check-dependenciesand the original eager-bootstrap suites pass. Three failures have exact case/error matches in scheduled main CI 36562252809 ata15f3f72a6aabe4d51ce53426d717b4c65a4589e:checks-node-changed-compact-large-27/109404811225109385864663subagent-registry-queued-registration.test.ts: missingcaptureOpenClawStateReadContextmock export and its 58-case cascadechecks-node-changed-compact-large-20/109404811326109385864569chat.reset-visible-yield.test.ts: both cases fail to emit a real yield event; preceding registry persistence reports an ended turnchecks-node-changed-compact-large-15/109404811458109385864571session-accessor.sqlite-prepared-admission.test.ts: five child/worker admission expectations failThe first two trace to main
437572e2e90be2f0bead9835814fbb06c0c758e5. Their causal source/test files are unchanged by this PR. The remainingchecks-node-changed-compact-small-18/109404811337failure is not qualified for an exception:server.heartbeat-store-lifecycle.product-proof.test.tsreceivesagent.waitstatuserrorinstead ofokon a child followup, before the store switch. Main CI passes that case. The exact eight-file shard selection passes all 30 cases on both CI main base149a41c5a91f1dd27e69f2b12011d7a9ccfab63fand CI merge230e9177e56ac1d1ffd9c9c81345c8974abd3056, with one worker and again with CI's eight-worker setting. Those passing replays do not prove a fix. The bounded diagnostic reproduced the first different-store case on main:agent.waitreturnedreplacement subagent source changed before commit, before provider dispatch (four provider requests, no provider errors). Main's ten-case diagnostic finished with one failure and nine passes; the CI merge passed all ten. The failing CAS owner issrc/agents/subagents/registry/subagent-registry-replacement-store.ts:37, reached through Gateway child reactivation. Direct main-parent/CI-merge comparison verifies identical Gateway agent-turn, reactivation, heartbeat-test, and subagent-registry blobs. This is a main-owned stale-source replacement race; the exact regression-introducing commit is not established, and no main fix was made.This evidence used Blacksmith Testbox
tbx_01m3pk95c6y5rtjs4vzs4nkj6d; both task leases were stopped after their commands completed. Temporary diagnostic changes kept the original assertions and were restored; the PR contains no diagnostic/test changes. Scheduled main36562252809passes the heartbeat case, and newer scheduled main36570405582has no matching completed failed Node-job annotation. The requested exception requires a matching main/unrelated-PR CI failure, so the Testbox reproduction alone does not authorize an admin merge. Landing remains blocked on this heartbeat CI witness or the coordinator's repair. The pushed repair and all its passing proof remain valid; no CI rerun was requested. An additional attempt to expose the Incognito error payload was blocked by Testbox sync/command support; its pre-existence is established by the matching scheduled-main cases, and the post-deletion guard cause is source-attributed.Fresh isolated Codex review is clean through P2, including the cancellation regression and final lint corrections. The patch retains sandbox checks across awaited work, auth settlement ownership, loss ordering, and replay early-exit guards. The assertion baseline only shrinks for removed lane-owned assertions.
The original implementation validation ran remotely through
node scripts/crabbox-wrapper.mjson Blacksmith Testbox. Fullnode scripts/run-vitest.mjsselections passed for tools, auth profiles, sandbox (including the real local-shell backend E2E), embedded-agent helpers, agent hooks, runtime plans, utilities, and failover. The 17 import-boundary files, includingsrc/infra/fs-safe-import-boundary.test.tsand its siblings, and 17 caller files passed. Existing conditional skips remain unchanged. Tools and auth profiles were run again after the final fixes; unchanged suites retain their integrated-base proof.The registered tool descriptor/schema/prompt capture is byte-identical to the pinned base: 1,058 cases covering 53 tool names and 76 system-prompt cases, 10,591,556 bytes, SHA-256
321367faa4a97a56655ca95eb50af0bc6436d38b24233fec55a36bce51332fe3.Cancellation controls exercise the public resolver with synthetic credentials and the real legacy fallback chooser. On the original base, the primary case passes and the legacy fallback returns credentials after cancellation. Both repaired cases pass. Removing only the public fallback check makes the fallback case fail again; the intermediate refactor without final-boundary checks fails both cases. The test permits success that completes before cancellation and uses explicit promise settlement, with no timers, sleeps, polling, or retries. No live provider calls or production credentials were used.
Final committed validation passed on Blacksmith Testbox
tbx_01m3p53yk5m18zdw26x8rpxy1w(lease workflow): fullnode scripts/check-changed.mjs(34m23s),pnpm build(5m43s), descriptor/prompt comparison, full tools and auth-profile suites, and all 17 import-boundary files. The wrapper verified source commit63650d68ff877e0f65acb6cf5c461056e4847c62and treeea5de25de13134e0b56589682a5a08ffc09c683c; source hashes remained unchanged before and after every phase.The cancellation negative controls passed on
tbx_01m3nstgff8933z4kadrph0mzd(lease workflow). The unchanged integrated-base suites usedtbx_01m3nh1w6fgb58640xpe6yt978(lease workflow). Earlier validation caught two refactor lint errors (a shadowed projection name and an extracted response method), which are corrected and reviewed. An earlier lease expired during a gate; that interrupted run is not counted as passing. These workflow links identify the leases; stopping a completed lease can cancel its waiting Actions job without changing the recorded command results.Measured Linux wall time for
pnpm test <file> --maxWorkers=1: OAuth cancellation 27s (two cases), media retention 36s, media shared lifecycle 27s, model-config helpers 28s, and restart-sentinel media binding 47s. These include cold source loading. The new cancellation regression must reach the public async return boundary: testing only the manager/helper misses the extra continuation that caused the defect. Hosted per-file CI timing is not yet available.Coverage: every production file over 200 lines
All listed files were read in full, largest first; all smaller production files in the assigned subtrees were also read. Sizes are from the pinned starting main revision. No top-level
src/agents/*.tsfiles or reserved lane directories were changed.src/agents/auth-profiles/store.tssrc/agents/agent-hooks/compaction-safeguard.tstruncatedLoss; removed a repeated missing-model condition inside the same established branch. Prompt strings, boundaries, loss ordering, cancellation reasons, error retention, model/auth ownership, and finalization remain unchanged.src/agents/auth-profiles/oauth-manager.tssrc/agents/tools/sessions-send-tool.tssrc/agents/auth-profiles/usage.tssrc/agents/tools/web-fetch.tssrc/agents/tools/session-status-tool.tssrc/agents/auth-profiles/persisted.tssrc/agents/tools/gateway.tssrc/agents/auth-profiles/runtime-snapshots.tssrc/agents/tools/message-tool-execution.tssrc/agents/tools/sessions-list-tool.tssrc/agents/tools/ask-user-tool.tssrc/agents/sandbox/docker.tssrc/agents/sandbox/remote-fs-bridge.tssrc/agents/tools/computer-tool-node.tssrc/agents/runtime-plan/prepare-auth.tssrc/agents/auth-profiles/session-override.tssrc/agents/tools/media-generate-background-shared.tssrc/agents/tools/pdf-tool.tssrc/agents/tools/cron-tool.tssrc/agents/tools/sessions-spawn-tool.tssrc/agents/tools/sessions-spawn-visible.tssrc/agents/tools/sessions-tool.tssrc/agents/tools/image-tool.tssrc/agents/tools/web-fetch-visibility.tssrc/agents/tools/media-tool-shared.tssrc/agents/failover/user-copy.tssrc/agents/tools/system-agent-tool.tssrc/agents/auth-profiles/profiles.tssrc/agents/modes/interactive/theme/theme.tssrc/agents/tools/sessions-search-tool.tssrc/agents/auth-profiles/oauth.tssrc/agents/tools/video-generate-tool.tssrc/agents/sandbox/browser.tssrc/agents/runtime/proxy.tssrc/agents/auth-profiles/runtime-read.tssrc/agents/tools/skill-workshop-tool.tssrc/agents/tools/sessions-history-tool.tssrc/agents/tools/mobile-ui-tool.tssrc/agents/auth-profiles/oauth-refresh-failure.tssrc/agents/tools/image-generate-tool.tssrc/agents/agent-hooks/compaction-safeguard-quality.tssrc/agents/tools/message-tool-schema.tssrc/agents/tools/common.tssrc/agents/sandbox/context.tssrc/agents/sandbox/remote-shell-backend.tssrc/agents/tools/in-process-gateway.tssrc/agents/tools/sessions-resolution.tssrc/agents/tools/model-config.helpers.tssrc/agents/tools/gateway-caller-context.tssrc/agents/sandbox/remote-shell-command.tssrc/agents/tools/computer-tool-request.tssrc/agents/sandbox/fs-bridge-path-safety.tssrc/agents/auth-profiles/sqlite.tssrc/agents/auth-profiles/oauth-refresh-peers.tssrc/agents/embedded-agent-helpers/openai.tssrc/agents/embedded-agent-helpers/bootstrap.tssrc/agents/tools/cron-tool-schema.tssrc/agents/sandbox/fs-bridge.tssrc/agents/failover/classify-core.tssrc/agents/tools/cron-tool-creator-cap.tssrc/agents/embedded-agent-helpers/turns.tssrc/agents/auth-profiles/upsert-with-lock.tssrc/agents/auth-profiles/order.tssrc/agents/tools/nodes-tool-media.tssrc/agents/sandbox/podman-runtime.tssrc/agents/failover/classification-rules.tssrc/agents/utils/tools-manager.tssrc/agents/tools/message-tool-discovery.tssrc/agents/tools/transcripts-tool.tssrc/agents/tools/web-search-provider-common.tssrc/agents/auth-profiles/runtime-snapshot-owner.tssrc/agents/sandbox/docker-backend.tssrc/agents/tools/secrets-tool.tssrc/agents/sandbox/runtime-status.tssrc/agents/sandbox/validate-sandbox-security.tssrc/agents/auth-profiles/external-cli-sync.tssrc/agents/auth-profiles/oauth-refresh-fence.tssrc/agents/tools/web-fetch-utils.tssrc/agents/tools/dashboard-tool.tssrc/agents/tools/media-generate-background.tssrc/agents/auth-profiles/usage-state.tssrc/agents/tools/sessions-access.tssrc/agents/auth-profiles/legacy-source-diagnostic.tssrc/agents/tools/sessions-send-tool.a2a.tssrc/agents/tools/subagents-tool.tssrc/agents/tools/pdf-tool.model-config.tssrc/agents/tools/video-generate-tool.execution.tssrc/agents/sandbox/registry.tssrc/agents/sandbox/fs-paths.tssrc/agents/runtime-plan/resolve-auth.tssrc/agents/tools/web-search-output.tssrc/agents/tools/cron-tool-canonicalize.tssrc/agents/failover/message-patterns.tssrc/agents/sandbox/remote-shell-transport.tssrc/agents/tools/agents-wait-tool.tssrc/agents/tools/image-tool.model-execution.tssrc/agents/runtime-plan/types.tstypes.test.tsexplicitly enforces independence from concrete config/provider/transcript/prompt policy modules. Removing these copies would violate the established import boundary.src/agents/tools/computer-tool.tssrc/agents/embedded-agent-helpers/error-text.tssrc/agents/sandbox/container-lifecycle.tssrc/agents/sandbox/registry.kernel.tssrc/agents/tools/music-generate-tool.tssrc/agents/tools/embedded-gateway-stub.tssrc/agents/tools/nodes-tool.tssrc/agents/runtime-plan/build.tsresolvedReffields instead of reconstructing them. Kept lazy policy/extra-param getters and exact override semantics.src/agents/auth-profiles/external-auth.tssrc/agents/embedded-agent-helpers/sanitize-user-facing-text.tssrc/agents/sandbox/backend.tssrc/agents/sandbox/mount-plan.tssrc/agents/tools/media-generate-background-completion.tssrc/agents/tools/message-tool-visible-content.tssrc/agents/session-maintenance/run.tssrc/agents/tools/web-shared.tssrc/agents/tools/sessions-send-followup.tssrc/agents/tools/sessions-send-tool.delivery.tssrc/agents/runtime-plan/credential-scoped-model.tssrc/agents/sandbox/config.tssrc/agents/embedded-agent-helpers/provider-runtime-failure.tssrc/agents/sandbox/docker-mount-source.tssrc/agents/tools/computer-tool-result.tssrc/agents/auth-profiles/sqlite-json.tssrc/agents/tools/image-tool.helpers.tssrc/agents/tools/manifest-capability-availability.tssrc/agents/tools/terminal-tool.tssrc/agents/sandbox/ssh.tssrc/agents/auth-profiles/mutation-lineage.tssrc/agents/sandbox/workspace-mounts.tssrc/agents/tools/pdf-native-providers.tssrc/agents/tools/computer-tool-bindings.tssrc/agents/auth-profiles/inline-usage.tssrc/agents/auth-profiles/shared-store-bootstrap.tssrc/agents/tools/music-generate-tool.execution.tssrc/agents/auth-profiles/sqlite-read.tssrc/agents/sandbox/workspace-authority.tssrc/agents/tools/image-generate-tool.execution.tssrc/agents/tools/plugins-tool.tssrc/agents/tools/nodes-tool-commands.tssrc/agents/tools/gateway-tool.tssrc/agents/sandbox/manage.tssrc/agents/sandbox/tool-policy.tssrc/agents/failover/assistant-request-failure-copy.tssrc/agents/session-maintenance/coordinator.tssrc/agents/failover/retry-evidence.tssrc/agents/tools/computer-tool-schema.tssrc/agents/tools/message-tool-source-policy.tssrc/agents/tools/session-status-model.tssrc/agents/sandbox/local-workspace-quiescence.tssrc/agents/utils/syntax-highlight.tssrc/agents/tools/media-generate-tool-actions-shared.tssrc/agents/auth-profiles/external-cli-auth-selection.tssrc/agents/auth-profiles/types.tssrc/agents/tools/message-tool-schema-scoping.tssrc/agents/tools/sessions-control-authority.tssrc/agents/auth-profiles/usage-failure-state.tssrc/agents/tools/cron-tool-write.tssrc/agents/auth-profiles/path-resolve.ts