refactor: consolidate core stream cleanup, watchdog locality, and approval text duplication#99901
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed July 4, 2026, 5:00 AM ET / 09:00 UTC. Summary PR surface: Source -9, Docs 0, Other 0. Total -9 across 16 files. Reproducibility: Do we have a high-confidence way to reproduce the issue? Not as a runtime bug, but yes as source-level cleanup: current main has duplicated stream cleanup and target/hint helper patterns that the PR centralizes. Review metrics: 1 noteworthy metric.
Stored data model Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Land the consolidation only after maintainer confirmation that the new SDK exports and migration target Do we have a high-confidence way to reproduce the issue? Do we have a high-confidence way to reproduce the issue? Not as a runtime bug, but yes as source-level cleanup: current main has duplicated stream cleanup and target/hint helper patterns that the PR centralizes. Is this the best way to solve the issue? Is this the best way to solve the issue? Mostly yes: the shared helper locations match the observed owner boundaries, but the best merge state needs explicit maintainer acceptance/proof for the public SDK exports and migration target path alignment. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against eafe2a8d0bb6. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source -9, Docs 0, Other 0. Total -9 across 16 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
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. How this review workflow works
|
|
Merged via squash.
|
…roval text duplication (openclaw#99901) * refactor(infra): share guarded body-stream cleanup across fetch consumers * refactor(agents): extract shared runtime model locality for llm watchdogs * refactor(auto-reply): share exec approval route resolution between command handlers * refactor(plugin-sdk): share approval reaction hint text helpers * refactor(plugin-sdk): share planned migration target resolution * refactor(infra): use canonical sleep helper in backup retry * docs(plugins): mention shared migration targets and reaction hint helpers * chore(plugin-sdk): pin surface budgets for reaction hint and migration target helpers
Related: #99841
What Problem This Solves
Second consolidation pass over the duplication clusters catalogued in #99841, this time centered on core
src/:src/agents/mcp-http-fetch.tsandsrc/agents/provider-transport-fetch.tseach hand-rolled the same delicate guarded-response stream wrapper (reader lifecycle, exactly-once finalize, FinalizationRegistry backstop for abandoned bodies) - a 29-line verbatim clone of leak-prevention code that must not drift.src/agents/embedded-agent-runner/run/llm-idle-timeout.tsduplicated its 16-line model-endpoint locality classification between the idle and first-event watchdogs.src/auto-reply/reply/commands-diagnostics.tsandcommands-export-trajectory.tsduplicated the private-vs-origin exec-approval routing ternaries (the exact fallback cluster that must stay in sync across command handlers).insert...HintNearHeader+ add-with-guard), a 30-line clone of theID:header text surgery.targets.tsfiles.src/infra/backup-create.tshad a localsleepcopy ofsrc/utils/sleep.ts.Why This Change Was Made
Same policy as #99850: one canonical owner per behavior.
wrapGuardedBodyStreaminsrc/infra/net/guarded-body-stream.ts(next to thefetchWithSsrFGuardcontract both callers consume); the MCP and provider transports keep their caller-specific pieces (MCP global-fetch Response rewrap, provider local-service lease release) as small closures. A dedicated module keeps the transport test's explicitfetch-guardmock factory narrow while the real stream-cleanup behavior stays under test.resolveRuntimeModelLocalitynow feeds both LLM watchdog resolvers;resolveCommandExecApprovalRoutelives incommands-private-route.ts(the existing owner of route reading helpers) and both command handlers spread it.hasApprovalReactionHintText/insertApprovalReactionHintNearIdHeader/addApprovalReactionHintToTextjoin the other reaction helpers inplugin-sdk/approval-reaction-runtime; imessage and signal shrink to wrappers/callers.resolvePlannedMigrationTargetsjoinsplugin-sdk/migration-runtime; both migration plugins re-export it. One deliberate alignment: a configuredagentDirwith a~prefix now resolves through the product's effective-home resolution (resolveHomeRelativePath) instead of a rawos.homedir()string replace, matching how the primary runtime resolver treats paths.User Impact
No user-visible behavior change. Internal hardening: stream-cleanup semantics are now provably identical across MCP and provider transports, and the watchdog locality rules cannot drift between the idle and first-event paths. Net negative production LOC.
Evidence
git diff origin/main --stat -- src/infra/net/fetch-guard.tsis empty: the guard contract file is untouched; the helper is a sibling module.