Skip to content

fix(feishu): honor abortSignal in drive comment reply retry loop - #108408

Merged
steipete merged 2 commits into
openclaw:mainfrom
wangmiao0668000666:fix/feishu-monitor-comment-abort
Jul 16, 2026
Merged

steipete merged 2 commits into
openclaw:mainfrom
wangmiao0668000666:fix/feishu-monitor-comment-abort

Conversation

@wangmiao0668000666

@wangmiao0668000666 wangmiao0668000666 commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Feishu's drive-comment reply lookup retries FEISHU_COMMENT_REPLY_MISS_RETRY_LIMIT = 6 times with FEISHU_COMMENT_REPLY_MISS_RETRY_DELAY_MS = 1_000 between attempts when the requested reply is not immediately visible in the embedded batch payload. The inter-attempt delay in monitor.comment.ts:367 used setTimeout(resolve, ms) and never received the owning monitor account's AbortSignal. When monitorSingleAccount (line 469) tears down the websocket or webhook for an account restart, the in-flight comment retry loop runs through the full ~6 s poll-miss window instead of stopping with the rest of the account lifecycle.

monitor.bot-identity.ts:40 in the same plugin already uses the shared waitForAbortableDelay(ms, abortSignal) helper for the bot-identity recovery retry; only the comment reply retry path was unwired. The retry is exported through fetchDriveCommentContext → resolveDriveCommentEventTurn → handleFeishuCommentEvent → createFeishuDriveCommentNoticeHandler; none of those signatures accepted an AbortSignal, so the handler had no way to forward the account-level stop.

Why This Change Was Made

  • delayMs is now a thin wrapper over waitForAbortableDelay from ./async.js and returns Promise<boolean> (true = full delay elapsed, false = aborted). The retry loop checks the boolean and exits instead of starting another 1 s delay.
  • fetchDriveCommentContext, ResolveDriveCommentEventParams, HandleFeishuCommentEventParams, and createFeishuDriveCommentNoticeHandler each gain an optional abortSignal?: AbortSignal; monitorSingleAccount (which already held the signal at line 469) is the source, threaded via registerEventHandlers.
  • No new config, no new env, no SDK change, no shared helper change. abortSignal stays optional everywhere — callers that never pass it get the old bare-setTimeout behavior via waitForAbortableDelay(ms, undefined).

#104431 (merged) explicitly kept this result-predicate poll off retryAsync; this PR targets the delay-abort contract, orthogonal to that error-retry refactor.

User Impact

Stopping or restarting a Feishu account no longer leaves a drive-comment reply retry loop running for up to ~6 s after the rest of the account has settled. The loop now exits on the abort event, the same cadence the sibling bot-identity recovery loop already follows. Happy-path behavior is unchanged — when the requested reply appears within the retry budget, the loop still breaks at the matching attempt.

Evidence

Fix before (base 1f9a9281d9; abort fires 374 ms into attempt 3's 1 s delay — the loop keeps polling for 3.6 s and 4 more fetches):

[2118ms] log: retrying comment reply lookup attempt=3/6 delay_ms=1000
[2501ms] >>> owner abortSignal fires (monitor stop)
[3138ms] >>> replies fetch #4
[4149ms] >>> replies fetch #5
[5157ms] >>> replies fetch #6
[6164ms] >>> replies fetch #7
{"elapsedMs":6167,"replyFetchCount":7,"replyFetchesAfterAbort":4,"turnResolved":true}

Fix after (this head 4f1c0e99cf; same harness — the abort interrupts the delay, no post-stop fetch):

[2127ms] log: retrying comment reply lookup attempt=3/6 delay_ms=1000
[2501ms] >>> owner abortSignal fires (monitor stop)
[2502ms] log: comment reply resolution match_source=miss
{"elapsedMs":2505,"replyFetchCount":3,"replyFetchesAfterAbort":0,"turnResolved":true}

Blind rerun of the fixed head: elapsedMs:2507, replyFetchCount:3, replyFetchesAfterAbort:0.

How the proof was produced

Uncommitted scratchpad/feishu-comment-abort-proof.ts drives the production resolveDriveCommentEventTurn entry with no createClient/waitMs injection: the client comes from the real createFeishuClient factory with the account domain pointed at a loopback node:http stub of the Feishu OpenAPI (the same custom-domain seam private deployments use), the abort is a real AbortController standing in for the owning account signal, and all timers are real wall-clock. The stub serves tenant-token, doc-meta, and comment batch_query with replies that never contain the requested reply_id, then counts GET …/replies hits server-side. The before run is the same harness against base 1f9a9281d9.

Mutation proof

Prod source stashed to 1f9a9281d9 with only the test change applied → the new regression test fails: expected "vi.fn()" to be called 1 times, but got 6 times.

Tests & checks

  • monitor.comment.test.ts 17/17; focused feishu sweep (7 files) 82/82. Full-plugin sweep shows 17 pre-existing i18n failures on stock 1f9a9281d9 (LANG=zh_CN.UTF-8 vs English string expectations), unrelated to this change.
  • run-tsgo -p tsconfig.extensions.json exit=0; run-oxlint on 5 changed files exit=0; oxfmt --check exit=0; git diff --check clean.

Prod-only non-test LOC: +28 / -9 across four files.

Not tested: a live Feishu tenant with real bot credentials. The loopback run exercises the real production client factory, Lark SDK request path, and retry loop over real HTTP — only the upstream server is stubbed, and requestFeishuOpenApi timeout behavior is intentionally untouched (bounded by timeoutMs, a separate concern from the poll-delay abort).

@openclaw-barnacle openclaw-barnacle Bot added channel: feishu Channel integration: feishu size: S labels Jul 15, 2026
@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 16, 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: 🦪 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 16, 2026
@clawsweeper

clawsweeper Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 16, 2026, 3:01 AM ET / 07:01 UTC.

Summary
Threads the Feishu monitor account’s optional abort signal into drive-comment reply polling, stops retries after cancellation, and adds focused regression coverage.

PR surface: Source +27, Tests +49. Total +76 across 5 files.

Reproducibility: yes. with high confidence from the existing bare-delay source path and the supplied before-run harness showing four reply fetches after account cancellation; it was not independently rerun against the exact current-main SHA during this read-only review.

Review metrics: none identified.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • none.

Risk before merge

  • [P1] The PR head is behind current main; if updating the branch changes any touched Feishu monitor files, the focused comment-monitor tests and proof path should be rerun against the refreshed head.

Maintainer options:

  1. Decide the mitigation before merge
    Refresh the branch onto current main if needed, preserve the single account-owned cancellation signal and shared abortable-delay helper, then merge with the focused regression test and supplied runtime proof intact.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • No automated repair is indicated; the patch has no actionable finding and should proceed through normal maintainer review, branch refresh if needed, and merge.

Security
Cleared: The patch adds internal cancellation plumbing and tests without changing dependencies, workflow permissions, secrets, package resolution, downloaded code, or other security-sensitive surfaces.

Review details

Best possible solution:

Refresh the branch onto current main if needed, preserve the single account-owned cancellation signal and shared abortable-delay helper, then merge with the focused regression test and supplied runtime proof intact.

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

Yes, with high confidence from the existing bare-delay source path and the supplied before-run harness showing four reply fetches after account cancellation; it was not independently rerun against the exact current-main SHA during this read-only review.

Is this the best way to solve the issue?

Yes. Reusing the plugin’s shared abortable-delay helper and forwarding the existing lifecycle signal through the owning handler chain is narrower and more maintainable than adding config, another retry engine, or a separate cancellation source.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 863443fac8c3.

Label changes

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The detailed before-and-after live output exercises the production resolver and client factory with real timers and HTTP, directly showing that cancellation reduces post-abort reply fetches from four to zero; although the upstream Feishu API is loopback-stubbed, that is sufficient for this internal delay-cancellation behavior.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The detailed before-and-after live output exercises the production resolver and client factory with real timers and HTTP, directly showing that cancellation reduces post-abort reply fetches from four to zero; although the upstream Feishu API is loopback-stubbed, that is sufficient for this internal delay-cancellation behavior.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This fixes a bounded Feishu account-teardown defect that can leave unnecessary polling active for several seconds but does not break normal message delivery or core availability.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The detailed before-and-after live output exercises the production resolver and client factory with real timers and HTTP, directly showing that cancellation reduces post-abort reply fetches from four to zero; although the upstream Feishu API is loopback-stubbed, that is sufficient for this internal delay-cancellation behavior.
  • proof: sufficient: Contributor real behavior proof is sufficient. The detailed before-and-after live output exercises the production resolver and client factory with real timers and HTTP, directly showing that cancellation reduces post-abort reply fetches from four to zero; although the upstream Feishu API is loopback-stubbed, that is sufficient for this internal delay-cancellation behavior.
Evidence reviewed

PR surface:

Source +27, Tests +49. Total +76 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 4 37 10 +27
Tests 1 52 3 +49
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 89 13 +76

What I checked:

Likely related people:

  • steipete: Authored the merged retry-loop classification work that explicitly documented why Feishu comment polling remains a result-predicate loop. (role: recent adjacent retry-area contributor; confidence: high; commits: 3902adf9f673; files: extensions/feishu/src/monitor.comment.ts)
  • xiwuqi: Recent merged Feishu document-comment session work is closely connected to the handler and context-resolution surface changed here. (role: document-comment feature contributor; confidence: medium; files: extensions/feishu/src/monitor.comment.ts, extensions/feishu/src/comment-handler.ts, extensions/feishu/src/monitor.comment-notice-handler.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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
  • 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.
Review history (3 earlier review cycles)
  • reviewed 2026-07-16T00:57:50.910Z sha 4f1c0e99cfda988085e047e94a6550f29b90505e :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-16T03:57:03.866Z sha 4f1c0e99cfda988085e047e94a6550f29b90505e :: needs real behavior proof before merge. :: [P2] Terminate the comment event when the account aborts
  • reviewed 2026-07-16T06:20:58.502Z sha 4f1c0e99cfda988085e047e94a6550f29b90505e :: needs real behavior proof before merge. :: none

@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 16, 2026
@steipete steipete self-assigned this Jul 16, 2026
wangmiao0668000666 and others added 2 commits July 16, 2026 16:56
The inter-attempt delay in monitor.comment.ts used a bare setTimeout and
never received the owning monitor account's AbortSignal, so an account
teardown (ws disconnect, webhook stop, config reload) left the in-flight
comment reply retry running for up to ~6s after the rest of the lifecycle
settled. delayMs now wraps waitForAbortableDelay from async.ts and the
abortSignal is threaded through fetchDriveCommentContext →
resolveDriveCommentEventTurn → handleFeishuCommentEvent →
createFeishuDriveCommentNoticeHandler, sourced from
monitorSingleAccount.

The retry loop checks the waitMs return value and the abortSignal flag,
breaking out of the next 1s tick instead of running the full 6×1s poll
budget. Sibling surface monitor.bot-identity.ts already uses the same
pattern; openclaw#104431 explicitly skipped the comment-monitor retry because
it is a result-predicate poll, not an error retry, and this fix is
orthogonal to that decision.

Not tested: live Feishu tenant, real bot identity, real drive comment,
and account restart. requestFeishuOpenApi itself does not accept
AbortSignal — that is a separate, larger refactor and is out of scope.
@steipete
steipete force-pushed the fix/feishu-monitor-comment-abort branch from 4f1c0e9 to 8b751d1 Compare July 16, 2026 15:58
@steipete

Copy link
Copy Markdown
Contributor

Maintainer review complete. Improved the patch to use the existing abortable-delay helper directly, replaced the injected-delay test with a real fake-timer regression against a mocked Feishu OpenAPI client, and pinned signal propagation through the notice and comment-handler boundaries.

Proof:

No actionable findings remain. Preparing to merge.

@steipete
steipete merged commit 813021f into openclaw:main Jul 16, 2026
85 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 17, 2026
…nclaw#108408)

* fix(feishu): honor abortSignal in drive comment reply retry loop

The inter-attempt delay in monitor.comment.ts used a bare setTimeout and
never received the owning monitor account's AbortSignal, so an account
teardown (ws disconnect, webhook stop, config reload) left the in-flight
comment reply retry running for up to ~6s after the rest of the lifecycle
settled. delayMs now wraps waitForAbortableDelay from async.ts and the
abortSignal is threaded through fetchDriveCommentContext →
resolveDriveCommentEventTurn → handleFeishuCommentEvent →
createFeishuDriveCommentNoticeHandler, sourced from
monitorSingleAccount.

The retry loop checks the waitMs return value and the abortSignal flag,
breaking out of the next 1s tick instead of running the full 6×1s poll
budget. Sibling surface monitor.bot-identity.ts already uses the same
pattern; openclaw#104431 explicitly skipped the comment-monitor retry because
it is a result-predicate poll, not an error retry, and this fix is
orthogonal to that decision.

Not tested: live Feishu tenant, real bot identity, real drive comment,
and account restart. requestFeishuOpenApi itself does not accept
AbortSignal — that is a separate, larger refactor and is out of scope.

* test(feishu): prove comment retry abort

---------

Co-authored-by: Peter Steinberger <[email protected]>
SunnyShu0925 added a commit to SunnyShu0925/openclaw that referenced this pull request Jul 26, 2026
The bare setTimeout in ensureBrowserRunning prevents abort during the
250ms retry window. Replace with sleepWithAbort + .catch + throwIfAborted
so the caller's abort signal cancels promptly while preserving the
original abort reason in the error response.

Add a real-timer production-route proof test exercising the actual
registerBrowserTabRoutes handler with real performance.now() timers.

Related: openclaw#108561, openclaw#108408
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
…nclaw#108408)

* fix(feishu): honor abortSignal in drive comment reply retry loop

The inter-attempt delay in monitor.comment.ts used a bare setTimeout and
never received the owning monitor account's AbortSignal, so an account
teardown (ws disconnect, webhook stop, config reload) left the in-flight
comment reply retry running for up to ~6s after the rest of the lifecycle
settled. delayMs now wraps waitForAbortableDelay from async.ts and the
abortSignal is threaded through fetchDriveCommentContext →
resolveDriveCommentEventTurn → handleFeishuCommentEvent →
createFeishuDriveCommentNoticeHandler, sourced from
monitorSingleAccount.

The retry loop checks the waitMs return value and the abortSignal flag,
breaking out of the next 1s tick instead of running the full 6×1s poll
budget. Sibling surface monitor.bot-identity.ts already uses the same
pattern; openclaw#104431 explicitly skipped the comment-monitor retry because
it is a result-predicate poll, not an error retry, and this fix is
orthogonal to that decision.

Not tested: live Feishu tenant, real bot identity, real drive comment,
and account restart. requestFeishuOpenApi itself does not accept
AbortSignal — that is a separate, larger refactor and is out of scope.

* test(feishu): prove comment retry abort

---------

Co-authored-by: Peter Steinberger <[email protected]>
@wangmiao0668000666
wangmiao0668000666 deleted the fix/feishu-monitor-comment-abort branch October 28, 2026 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: feishu Channel integration: feishu P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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