Skip to content

fix(moonshot): forward abort signal through Kimi web search provider - #105125

Merged
steipete merged 1 commit into
openclaw:mainfrom
wangmiao0668000666:fix/moonshot-abort-signal
Aug 1, 2026
Merged

steipete merged 1 commit into
openclaw:mainfrom
wangmiao0668000666:fix/moonshot-abort-signal

Conversation

@wangmiao0668000666

@wangmiao0668000666 wangmiao0668000666 commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Cancelling an agent run does not cancel its Kimi (Moonshot) web-search HTTP request. The Kimi provider drops the execution context at its owner boundary, so both an already-aborted run and an in-flight cancellation can still complete a network request after the caller has stopped.

Why This Change Was Made

Forward the existing optional execution AbortSignal through the original Kimi provider owner modules: createTool.execute(args, context) -> executeKimiWebSearchProviderTool -> runKimiSearch -> the existing trusted, SSRF-guarded web-search endpoint. This matches sibling Google and SearXNG providers; no new config, fallback, cache behavior, timeout policy, auth behavior, or SDK surface is introduced.

User Impact

An already-cancelled Kimi search makes no upstream request. Cancelling a search already in flight promptly rejects the real HTTP request with the caller's original abort reason. Normal and cached search behavior are unchanged.

Evidence

Maintainer independently ran the identical actual production Kimi provider and SSRF-guarded HTTP path against a real localhost HTTP CONNECT proxy, both on current main and this refreshed contributor head:

{"version":"before","mode":"preaborted","callerAborted":true,"upstreamRequests":1,"tunnels":1,"status":"completed","provider":"kimi"}
{"version":"before","mode":"inflight","callerAborted":true,"upstreamRequests":1,"tunnels":2,"status":"completed","provider":"kimi"}
{"version":"after","mode":"preaborted","callerAborted":true,"upstreamRequests":0,"tunnels":0,"status":"rejected","error":"caller-cancelled-before-request"}
{"version":"after","mode":"inflight","callerAborted":true,"upstreamRequests":1,"tunnels":1,"status":"rejected","error":"caller-cancelled-during-request"}

Real proxy tunnels, production provider execution, production SSRF guard, and production HTTP dispatcher were used; no mocked gateway, external API credentials, or paid API traffic.

Focused owner + sibling provider regression command:

OPENCLAW_VITEST_FS_MODULE_CACHE_PATH=/private/tmp/openclaw-vitest-s02-105125-moonshot node scripts/run-vitest.mjs extensions/moonshot/src/kimi-web-search-provider.test.ts extensions/google/web-search-provider.test.ts extensions/searxng/src/searxng-search-provider.test.ts

Result: 60 passing tests across 3 files and 2 Vitest shards. Targeted existing repository oxlint also passes for the colocated regression.

Fresh independent structured review: .agents/skills/autoreview/scripts/autoreview --mode commit --commit HEAD --engine codex --thinking xhigh — gpt-5.6-sol, clean, confidence 0.99.

The refreshed patch intentionally retains only the two original production owner modules and one existing colocated regression test (+8/-2 production lines, +37/-20 test lines). The redundant 212-line standalone proof file was removed; the pre-existing unsafe local environment-mutation helper was replaced by the canonical existing SDK withEnv helper because the hosted security scanner correctly rejects that old helper when the file changes. Original human contributor and July 12 authored date are preserved.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. labels Jul 12, 2026
@clawsweeper

clawsweeper Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 1, 2026, 3:43 PM ET / 19:43 UTC.

ClawSweeper review

What this changes

The PR forwards an agent run’s existing abort signal through Moonshot’s Kimi web-search plugin to the guarded outgoing HTTP request, with an in-flight cancellation regression test.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

This PR remains necessary: current main drops the web-search execution context before Moonshot’s Kimi request. The patch follows the existing plugin and guarded-HTTP contracts, has focused regression coverage, and includes credible before/after real proxy proof; wait for the remaining exact-head CI lanes before maintainer merge review.

Priority: P2
Reviewed head: 76841d2d03f8baa90fdf2b4a314e8650367a9f5e

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused, contract-aligned provider repair with strong before/after behavior proof and a regression that exercises the plugin call chain.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body and maintainer comment show before/after production Kimi-provider runs through the guarded HTTP path and a real localhost CONNECT proxy, including observed in-flight cancellation without exposing credentials.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body and maintainer comment show before/after production Kimi-provider runs through the guarded HTTP path and a real localhost CONNECT proxy, including observed in-flight cancellation without exposing credentials.
Evidence reviewed 6 items Current-main defect: The Kimi tool accepts only arguments and calls the runtime without its public execution context, so the optional cancellation signal cannot reach the request.
Plugin contract: The public web-search tool contract explicitly provides an optional execution context carrying an AbortSignal, which makes forwarding the existing signal the contract-aligned repair.
Shared transport contract: The existing trusted web-search endpoint accepts an optional AbortSignal and forwards it to the trusted HTTP endpoint, so the patch uses the established SSRF-guarded transport path rather than adding a parallel request mechanism.
Findings None None.
Security None None.

How this fits together

Moonshot’s Kimi plugin converts a web-search tool call into a Kimi chat-completions request through OpenClaw’s SSRF-guarded web-search HTTP helper. The agent runtime supplies an optional cancellation signal to the tool, which the shared helper already knows how to carry to the request.

flowchart LR
  A[Agent run cancellation] --> B[Web-search tool context]
  B --> C[Moonshot Kimi plugin]
  C --> D[Kimi search runtime]
  D --> E[Guarded HTTP endpoint]
  E --> F[Kimi chat completions]
  F --> G[Search result or cancellation]
Loading

Before merge

  • Resolve merge risk (P1) - The supplied exact-head check snapshot still has build, dependency, lint, and architecture lanes in progress; merge only after those required gates complete green on the current head.
  • Complete next step (P2) - No repair job is needed: the patch is correct and the remaining action is completion of normal exact-head CI followed by maintainer merge review.
Agent review details

Security

None.

PR surface

Source +6, Tests +17. Total +23 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 8 2 +6
Tests 1 37 20 +17
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 45 22 +23

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land this focused owner-boundary repair after exact-head CI completes, retaining the existing guarded transport seam and the colocated cancellation regression.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Land this focused owner-boundary repair after exact-head CI completes, retaining the existing guarded transport seam and the colocated cancellation regression.

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

Yes. Current source shows the execution signal is discarded at the Kimi facade before the shared HTTP helper, and the PR body includes before/after real proxy evidence for pre-aborted and in-flight requests.

Is this the best way to solve the issue?

Yes. The patch follows the existing public execution context and guarded HTTP transport contract, matching sibling provider behavior without adding configuration, fallback policy, or a parallel transport abstraction.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 2f92c17db6e3.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: This is a Kimi-specific web-search cancellation defect with a bounded provider-level blast radius.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body and maintainer comment show before/after production Kimi-provider runs through the guarded HTTP path and a real localhost CONNECT proxy, including observed in-flight cancellation without exposing credentials.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body and maintainer comment show before/after production Kimi-provider runs through the guarded HTTP path and a real localhost CONNECT proxy, including observed in-flight cancellation without exposing credentials.

Evidence

What I checked:

Likely related people:

  • steipete: Current-main blame attributes the central Kimi tool and request-owner lines to a commit authored by Peter Steinberger. (role: recent source contributor; confidence: medium; commits: 3edbe19fbd84; files: extensions/moonshot/src/kimi-web-search-provider.ts, extensions/moonshot/src/kimi-web-search-provider.runtime.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.

History

Review history (7 earlier review cycles)
  • reviewed 2026-07-12T08:13:40.207Z sha 2ac44a57eb2269f6d59ef0b4523f106d1097889b :: needs real behavior proof before merge. :: [P2] Remove the unused proof-test initializers
  • reviewed 2026-07-12T09:09:53.365Z sha ddead3ba55b8c710bb80e782418fba8673146aef :: needs real behavior proof before merge. :: [P2] Make the provider abort proof fail on unexpected resolution | [P2] Assert that the execution signal reaches fetch
  • reviewed 2026-07-12T10:25:20.260Z sha 3e66edefcc19828402d5ffef9da7264d5a9d068f :: needs changes before merge. :: [P2] Require the live proof to observe cancellation
  • reviewed 2026-07-13T01:06:29.575Z sha fe3848517e16b7307332faadf83c1c824ac77eea :: needs maintainer review before merge. :: none
  • reviewed 2026-07-13T01:13:34.667Z sha fe3848517e16b7307332faadf83c1c824ac77eea :: needs maintainer review before merge. :: none
  • reviewed 2026-07-31T17:01:13.381Z sha fe3848517e16b7307332faadf83c1c824ac77eea :: needs maintainer review before merge. :: none
  • reviewed 2026-08-01T19:14:16.874Z sha f36b8123bd4fa8fc336a7f062e469c766243a2a3 :: needs maintainer review before merge. :: none

@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

All R2 findings fixed (R3):

P1 — Real in-flight cancel proof. Added live in-flight abort test: dispatches real Kimi web search, aborts mid-flight at ~500ms via withTrustedWebSearchEndpoint → fetch(). Terminal JSON output proves signal reaches fetch() before API responds. (Requires KIMI_API_KEY env var.)

P1 — Regression test protects the fix (control-red). Rewrote the signal-forwarding test: the mock captures the signal passed to fetch() and rejects when the signal fires. Reverting signal: context?.signal → fetchSignal stays undefined → test fails. Previous R2 test only checked fetchMock.toHaveBeenCalled() which passes even with reverted fix.

P2 — Fixed false-positive sentinel. Removed the throw new Error(...) inside the try block. Now uses a resolved flag checked after the catch — if execute() resolves unexpectedly, expect(resolved).toBe(false) fails. Reverting signal forwarding causes a genuine test failure instead of a false-positive pass.

P2 — Assert signal reaches fetch. Unit test now captures init?.signal from the mock and asserts it is defined and aborted after cancellation. Reverting signal forwarding → undefined signal → test fails.

Verification:

  • node scripts/run-vitest.mjs run extensions/moonshot/... — 19/19 passed
  • node scripts/run-oxlint.mjs (4 files) — clean
  • pnpm tsgo:extensions:test — clean

@clawsweeper

clawsweeper Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 12, 2026
@wangmiao0668000666
wangmiao0668000666 force-pushed the fix/moonshot-abort-signal branch from 3e66ede to 5995f2a Compare July 12, 2026 15:09
@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

P2 fixed — live proof now requires cancellation observation:

  1. completed_before_abort now fails: if Kimi responds before the 500ms abort timer, expect.fail() ensures the test does not silently pass when no cancellation was observed.

  2. Catch block verifies abort origin: asserts controller.signal.aborted === true and errorMessage.toContain("proof: in-flight cancellation"), so authentication/DNS/HTTP/parse failures can no longer masquerade as proof.

Verification:

  • node scripts/run-vitest.mjs run extensions/moonshot/... — 19/19 passed
  • node scripts/run-oxlint.mjs (4 files) — clean
  • pnpm tsgo:extensions:test — clean
  • git diff --check origin/main — clean

@clawsweeper

clawsweeper Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

P2 fixed — opengrep Scan changed paths (precise) was the actual blocker (rule ghsa-82g8-464f-2mv7.openclaw-skill-env-host-injection, severity ERROR). The R3 commit introduced a local withEnv helper at extensions/moonshot/src/kimi-web-search-provider.test.ts:10-27 that assigned process.env[key] = value directly inside Object.entries iteration, which matches the rule's for…of Object.entries($ENV) { … process.env[$KEY] = $VALUE; } pattern and is NOT inside sanitizeSkillEnvOverrides / sanitizeEnvVars.

This was likely why the R3 verdict never wrote back — the opengrep check failed, blocking the durable review comment edit.

R4 commit fe3848517e drops the local helper (20 lines) and uses the SDK-exported withEnv from openclaw/plugin-sdk/test-env (which delegates to setTestEnvValue → Reflect.set(process.env, …), bypassing the rule's direct-assignment pattern). The only call site (it("falls back to env apiKey")) keeps its existing sync withEnv(overrides, run) signature, so no test logic changes.

Verification:

  • node scripts/run-vitest.mjs run extensions/moonshot/src/kimi-web-search-provider.test.ts — 16/16 passed
  • node scripts/run-oxlint.mjs extensions/moonshot/src/kimi-web-search-provider.test.ts — clean
  • Proof test (live in-flight abort) verified separately in isolation: 3/3 passed
  • Diff: 1 file changed, 1 insertion(+), 20 deletions(-)

@clawsweeper

clawsweeper Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 13, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Jul 28, 2026
@steipete
steipete force-pushed the fix/moonshot-abort-signal branch from fe38485 to 5c4b4b9 Compare August 1, 2026 19:03
@steipete

steipete commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Maintainer verification through the same actual production Kimi provider -> SSRF-guarded HTTP -> real localhost HTTP CONNECT proxy, before/current main and after the refreshed original contributor head 76841d2d03f8baa90fdf2b4a314e8650367a9f5e:

BEFORE pre-aborted: 1 real CONNECT + 1 upstream request; search wrongly completes
BEFORE in-flight abort: 1 real upstream request; search wrongly completes after caller cancellation
AFTER pre-aborted: 0 CONNECTs, 0 upstream requests; rejects caller-cancelled-before-request
AFTER in-flight abort: 1 real CONNECT/request; rejects caller-cancelled-during-request

The original human author and July 12 authored date are preserved. Scope remains exactly two original Kimi production owner modules (+8/-2 production lines) plus one existing colocated regression (+37/-20 test lines). The redundant 212-line standalone proof file was removed; the existing unsafe local environment-mutation helper was replaced with canonical SDK withEnv. The focused cancellation test now rejects an explicit Error, and targeted repository oxlint passes.

Moonshot, Google, and SearXNG focused owner/sibling regressions: 60 tests passed. Fresh final full-commit gpt-5.6-sol xhigh structured review: clean (0.99).

@steipete
steipete force-pushed the fix/moonshot-abort-signal branch from 5c4b4b9 to f36b812 Compare August 1, 2026 19:08
@steipete
steipete force-pushed the fix/moonshot-abort-signal branch from f36b812 to 76841d2 Compare August 1, 2026 19:37
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 1, 2026
@steipete
steipete merged commit ebb301c into openclaw:main Aug 1, 2026
95 of 97 checks passed
@steipete

steipete commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: moonshot P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S stale Marked as stale due to inactivity 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.

2 participants