Skip to content

fix(feishu): keep probe and streaming-backoff windows on elapsed time - #192308

Closed
wangmiao0668000666 wants to merge 3 commits into
openclaw:mainfrom
wangmiao0668000666:fix/feishu-clock-elapsed
Closed

wangmiao0668000666 wants to merge 3 commits into
openclaw:mainfrom
wangmiao0668000666:fix/feishu-clock-elapsed

Conversation

@wangmiao0668000666

@wangmiao0668000666 wangmiao0668000666 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor
Maintainer edits

Maintainer edits to this branch are welcome and will not be overwritten; the author will not force-push over them.

Maintainer options

What Problem This Solves

A host wall-clock correction while the Gateway runs makes two Feishu process-local cache/backoff windows jump with it: the health-probe result cache (probe.ts) and the streaming-start failure backoff (reply-dispatcher.ts). A forward step expires a fresh 10-minute probe entry and reissues the bot/v3/info API call (burning Feishu's free-tier quota on duplicate health checks), and clears the 60-second streaming backoff early; a backward step keeps entries and backoff alive far past their intended elapsed windows.

Precedent: #190894 (same shape — wall-clock cache/backoff windows → performance.now() in extensions; this PR covers the Feishu sites that sweep left behind). Sibling: #191911, #191916 (same Feishu extension, bot-name/sender-name caches), #191210, #192122, #192144, #192293, #192296.

Why This Change Was Made

extensions/feishu/src/probe.ts keeps probeCache as a process-local map whose timestamps never leave the module; extensions/feishu/src/reply-dispatcher.ts's streamingStartBackoffUntilByAccount (in reply-dispatcher-state.ts) is the same. The read and write sites now share the elapsed-time domain (performance.now()), the only domain a wall-clock step cannot shift; switching one side alone would mix clock domains, so each window's sites move together. Known trade-off, identical to the core stale-while-revalidate cache owner: monotonic windows measure awake time, so system suspend pauses them. Fix classification: behavior-preserving (clock domain only; no TTL, owner, config, or API change).

User Impact

On a long-running Gateway whose clock is corrected (NTP step, manual change, VM resume), Feishu health checks either lose the cached probe result and spend free-tier API quota on duplicate bot/v3/info calls (or a failed probe is retried immediately instead of after its 60-second error window), or keep serving stale probe verdicts and suppressing streaming beyond their windows. TTL values and backoff durations are unchanged.

Evidence

Base be881a7f8b1ff5af7ff7783340c98ed9047ea450 → candidate 8773efbdc3a6f00d95fa4fbb40fb258db6c3c651, same commands. The wall step is a process-local Date.now offset under fake timers (the #190894/#188293 preload method), never an OS clock jump.

Deterministic regression in the existing suite (remote Node 24.22.1 container, vitest.extension-feishu.config.ts):

extensions/feishu/src/probe.test.ts Result
Base 1 failed / 13 passed — exactly the new wall-clock case fails (expected "vi.fn()" to be called 1 times, but got 2 times: the forward step expires the 10-minute window and reissues the bot-info request)
Candidate 14 passed
node scripts/run-vitest.mjs run extensions/feishu/src/probe.test.ts --maxWorkers=1

The new test seeds a successful probe through the real probeFeishu (real client factory, request mocked), then steps Date.now() forward 20 minutes — past the 10-minute PROBE_SUCCESS_TTL_MS window — and asserts the cached result is still returned without a second bot-info request. On base (wall-clock window) the step expires it; on candidate (monotonic window) it stays fresh.

Real-transport proof (shipped Lark SDK over HTTPS proxy)

The discriminant also runs through the extension's real transport — the shipped createFeishuClient (Lark SDK on the extension's own HTTP transport) making a real HTTPS request through an ambient HTTPS_PROXY to a local CONNECT stub that counts tunnel connections, then forwarding to a TLS origin stub (remote Node 24.22.1 container, proof.test.ts):

extensions/feishu/src/proof.test.ts CONNECT tunnels
Base (Date.now) 3 — after the +11 min wall step the 10-min success window looks expired and re-probes (tenant token + bot info)
Candidate (performance.now) 2 — the cached probe is served; no re-probe
[stub-proxy] CONNECT #1  [tenant_access_token]
[stub-proxy] CONNECT #2  [bot/v3/info]
[result] connects before step=2 after step=2   # candidate

The wall step is again a process-local Date.now offset (the #190894 preload method). No mocks on the transport: probeFeishu → real createFeishuClient → real TLS handshake through the proxy to the stub.

Scope and risk

  • Production LOC: +4/−4 (4 sites, 2 files)
  • Test LOC: +22
  • Existing-solutions preflight: reuses the established extension clock-domain shape (performance.now()) from fix: keep probe timings and cache windows stable across clock corrections #190894/fix(codex): keep plugin metadata cache on elapsed time #191533; no new helper or abstraction.
  • Config/default, protocol/schema, authorization, storage, migration, upgrade impact: none.
  • Not tested: the streaming-start failure backoff change (reply-dispatcher.ts) has no remote-runnable suite here — its test pulls mdast-util-from-markdown (via markdown.ts) which the remote dependency closure lacks. The change is the same two-site clock-domain substitution as the proven probe.ts change (same read/write symmetry), and streamingStartBackoffUntilByAccount is a plain in-memory Map<string, number> (grep-verified, reply-dispatcher-state.ts). The existing reply-dispatcher.test.ts covers the backoff path under fake timers.

@clawsweeper

clawsweeper Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added channel: feishu Channel integration: feishu size: XS labels Nov 3, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 3, 2026
@clawsweeper

clawsweeper Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR measures Feishu probe-cache expiration and streaming-start backoff with monotonic time.

Example: The host clock moves forward 20 minutes immediately after a successful Feishu health probe.

  • Before: The 10-minute cache expires prematurely and another bot-info request is sent.
  • After: The cached result remains fresh until 10 minutes actually elapse.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The focused patch addresses both previous findings, but runtime evidence covers only the probe window and the remaining CI failure is unattributed.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Host clock corrections can refresh Feishu health probes prematurely or retain stale results and streaming suppression too long.
Reason: The change restores the existing duration contracts without new configuration, public APIs, persisted state, or production machinery.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep open: this PR narrowly fixes clock-sensitive Feishu windows that remain on current main, and both earlier findings are addressed.

Priority: P2
Reviewed head: 513fc9b6e0a415bd28405cd07690ce2040b55094

Before merge

  • Add real behavior proof - The supplied Node 24.22.1 trace exercises probeFeishu through the real Lark HTTPS transport and shows the cached probe surviving a forward wall-clock step; the production probe code is unchanged since that candidate. Streaming-start failure, fallback, and elapsed-time recovery remain explicitly unexercised. Provide redacted terminal output or logs for that path, removing IPs, API keys, phone numbers, and non-public endpoints. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.

Findings

None.

Tests

  • Missing end-to-end proof: Supply production-path transport evidence that an HTTP 400 streaming-start failure falls back, remains backed off across a wall-clock correction, and retries after the normal 60-second elapsed window.
Agent review details

How this fits together

The Feishu plugin caches health-probe responses and temporarily suppresses streaming-card starts after failures; these windows control subsequent Lark API requests.

flowchart TD
  A[Gateway health checks] --> B[Feishu probe cache]
  B --> C[Lark HTTP client]
  D[Agent reply] --> E[Streaming backoff]
  E --> F[Streaming card or fallback]
  F --> C
Loading

Technical review

Best possible solution:

Keep the paired monotonic deadline substitutions in the existing Feishu owners, preserving durations, credential scoping, and epoch-based message checks.

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

Current main derives both process-local deadlines from Date.now(), so forward and backward wall-clock corrections directly alter their effective lifetime; the contributor also reports a discriminating base/candidate probe transport run.

Is this the best way to solve the issue?

The patch is the smallest complete clock-domain repair: each existing deadline writer and reader moves together, with one distinct probe regression and an updated streaming fixture.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 40b3be0b302d.

Provenance checked

  • Probe-cache expiration keeps the original intent (6614cf2: The owner-consolidation cleanup replaced private timestamp helpers with direct arithmetic while preserving the existing quota-saving cache.)
  • Streaming-backoff expiration and deadline creation keeps the original intent (4df0e10: The backoff prevents repeated failed streaming-card starts; later refactors removed forwarding helpers and unused private clock arguments without changing that purpose.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Pinned introduction and smallest complete fix: The introduced production change replaces four clock readings in the existing owners, moving each deadline writer and reader together without adding an abstraction or changing durations. (extensions/feishu/src/probe.ts:53, 513fc9b6e0a4)
  • Current-main defect remains: Fetched main still writes and compares probe deadlines using Date.now(); streaming-start backoff likewise uses wall-clock deadlines. (extensions/feishu/src/probe.ts:53, 40b3be0b302d)
  • Earlier findings addressed: The existing streaming regression now advances performance.now(), retaining suppression and eventual-retry assertions; the new allocation provides exactly 22 lines for the added probe regression. (extensions/feishu/src/reply-dispatcher.test.ts:1841, 513fc9b6e0a4)
  • Supplied transport evidence: The full PR body reports probeFeishu using the shipped Lark client over a real HTTPS CONNECT transport: a forward clock step produces three tunnels on base versus two on candidate. It explicitly leaves streaming-start backoff untested in that environment. (extensions/feishu/src/client.ts:416, 513fc9b6e0a4)
  • Exact-head CI remains unresolved: The exact-head baseline check reports test-lines failure and the aggregate gate fails. Its detailed log redirects to a host blocked by the review environment, so these annotations do not establish whether the remaining failure is patch-caused. (513fc9b6e0a4)
  • Established clock-domain direction: Merged fix: keep probe timings and cache windows stable across clock corrections #190894 adopts performance.now() for extension-local windows while retaining epoch contracts; its scope does not implement these two Feishu windows. (fca1c6ec13f4)

Likely related people:

  • Vincent Koc: Raw commit 4df0e10 adds extensions/feishu/src/reply-dispatcher.ts:39 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 4df0e106239d; files: extensions/feishu/src/reply-dispatcher.ts)
  • Glucksberg: Raw commit 60ef923 adds extensions/feishu/src/probe.ts:8 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 60ef92305154; files: extensions/feishu/src/probe.ts)

PR surface

Source 0, Tests +22, Other +2. Total +24 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 4 4 0
Tests 2 23 1 +22
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 5 29 5 +24

Labels

Label changes:

  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦪 silver shellfish, so this older rating label is no longer current.

Label justifications:

  • P2: Clock corrections can cause unnecessary Feishu API requests, stale health results, or extended streaming suppression, with channel-local impact.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Demonstrate streaming-start failure, fallback, clock-step resistance, and recovery through the production transport.
  • Inspect the exact-head test-line failure log and determine whether it requires a patch repair or reflects an outside cause.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-03T22:17:47.706Z sha 8773efb :: needs real behavior proof before merge. :: [P2] Advance the streaming test's monotonic clock | [P2] Allocate the justified regression-test growth

Reviewed November 3, 2026, 7:54 PM ET / November 4, 2026, 00:54 UTC (Revision 2).

The streaming-start failure backoff window is monotonic (performance.now);
the old Date.now spy no longer advances it. Point the spy at performance.now
and add a test-lines allocation for the new probe clock-step coverage.

Co-Authored-By: nebulacoder-v8.0 <[email protected]>
@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review — the Evidence section now includes real-transport proofs (shipped RequestClient/DISCORD_API_URL stub for Discord, shipped Lark SDK over HTTPS_PROXY CONNECT tunnel for Feishu, real imsg CLI subprocess via runCommandWithTimeout for iMessage), red on base / green on candidate with stub hit counts. Voice/streaming changes remain honestly noted as not remotely runnable (missing libopus/mdast in the remote dependency closure).

@clawsweeper

clawsweeper Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 4, 2026
obviyus added a commit that referenced this pull request Nov 4, 2026
…192469)

fix: measure three more cache and retry deadlines with the monotonic clock

Three more deadlines used the wall clock: the Claude catalog filesystem scan cache, a browser extension cache with a 5-minute expiry, and Feishu streaming fallback retry. After the clock moved, they expired early or too late. They now use the monotonic clock. Behavior without a clock change is unchanged.

This sweep includes #192122, #192422 and #192308, with the contributors' commits kept for credit.

Evidence: built shipped entry points, stepping only the process wall clock (no system clock change). Each member was wrong on main twice and right with this change twice, with no-step controls: real Claude catalog filesystem scans; real Chromium with an unpacked extension and a 301-second real expiry; and a signed Feishu webhook with real agent dispatch and a natural streaming HTTP 400 fallback with a 61-second real retry. Details: #192469 (comment).

Thanks @wangmiao0668000666.

Co-authored-by: wangmiao0668000666 <wangmiao0668000666>
Co-authored-by: nebulacoder-v8.0 <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
@obviyus

obviyus commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

Thank you! Your fix is included in #192469, landed in 34ccfee with your commit kept for credit.

@obviyus obviyus closed this Nov 4, 2026
@wangmiao0668000666
wangmiao0668000666 deleted the fix/feishu-clock-elapsed branch November 4, 2026 02:52
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 4, 2026
…penclaw#192469)

fix: measure three more cache and retry deadlines with the monotonic clock

Three more deadlines used the wall clock: the Claude catalog filesystem scan cache, a browser extension cache with a 5-minute expiry, and Feishu streaming fallback retry. After the clock moved, they expired early or too late. They now use the monotonic clock. Behavior without a clock change is unchanged.

This sweep includes openclaw#192122, openclaw#192422 and openclaw#192308, with the contributors' commits kept for credit.

Evidence: built shipped entry points, stepping only the process wall clock (no system clock change). Each member was wrong on main twice and right with this change twice, with no-step controls: real Claude catalog filesystem scans; real Chromium with an unpacked extension and a 301-second real expiry; and a signed Feishu webhook with real agent dispatch and a natural streaming HTTP 400 fallback with a 61-second real retry. Details: openclaw#192469 (comment).

Thanks @wangmiao0668000666.

Co-authored-by: wangmiao0668000666 <wangmiao0668000666>
Co-authored-by: nebulacoder-v8.0 <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
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. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants