Skip to content

fix(feishu): clear client cache when replacing test SDK runtime - #86146

Closed
alkor2000 wants to merge 1 commit into
openclaw:mainfrom
alkor2000:fix-83911-feishu-clear-cache-on-sdk-swap
Closed

alkor2000 wants to merge 1 commit into
openclaw:mainfrom
alkor2000:fix-83911-feishu-clear-cache-on-sdk-swap

Conversation

@alkor2000

Copy link
Copy Markdown
Contributor

Summary

Fixes #83911. setFeishuClientRuntimeForTest replaced the module SDK (feishuClientSdk) but did not evict clientCache. A later createFeishuClient call with the same accountId and identical credentials hit the cache and returned the client constructed by the previous SDK instance, so a test that swaps the SDK mid-suite could receive a stale client and make unreliable mock assertions.

The reset path now calls the existing clearClientCache() so any SDK swap also evicts clients built with the old SDK.

Real behavior proof

Behavior or issue addressed: after setFeishuClientRuntimeForTest swaps the SDK, a subsequent createFeishuClient with unchanged credentials should rebuild the client against the new SDK instead of returning the cached client from the old SDK.

Real environment tested: Linux (Ubuntu 24.04, WSL2), Node.js 24.14.0, current PR head. Exercised the real createFeishuClient / setFeishuClientRuntimeForTest from client.ts under the repo's vitest runner (the suite imports the real module; only unrelated sibling modules are mocked). Compared the pre-fix and post-fix code.

Exact steps or command run after this patch: ran the client test suite, including a new regression test that creates a client, swaps the SDK runtime, then creates again with identical credentials.

Evidence after fix: stdout from the vitest run against the real client factory, comparing pre-fix and post-fix:
$ node scripts/run-vitest.mjs extensions/feishu/src/client.test.ts -t 83911
-- BEFORE the fix (reset leaves cache intact): the regression test fails --
x rebuilds the client after setFeishuClientRuntimeForTest replaces the SDK
AssertionError: expected 1 to be 2
Tests 1 failed | 15 passed (16)
-- AFTER the fix (reset clears the cache): the regression test passes --

rebuilds the client after setFeishuClientRuntimeForTest replaces the SDK
Tests 16 passed (16)

Observed result after fix: before the fix the second createFeishuClient hits the stale cache, so the client constructor is called only once and the same client object is returned; after the fix the cache is cleared on SDK swap, so the constructor runs again (called twice) and a new client object is returned. The full client suite (16 tests) passes.

What was not tested: no live Feishu/Lark account was used; the client factory and cache behavior are exercised through the real module under vitest with the Lark SDK constructor mocked, and the before/after comparison shows the regression test captures the exact stale-cache defect.

@openclaw-barnacle openclaw-barnacle Bot added channel: feishu Channel integration: feishu size: XS proof: supplied External PR includes structured after-fix real behavior proof. labels May 24, 2026
@clawsweeper

clawsweeper Bot commented May 24, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I did a careful shell check against current main, and this is already implemented.

Current main already contains the Feishu test-runtime cache invalidation and regression coverage from the merged canonical fix, so this open branch no longer has unique work to land.

So I’m closing this as already implemented rather than keeping a duplicate issue open.

Review details

Best possible solution:

Keep the merged main implementation from #91281 and close this superseded branch rather than resolving its current conflicts.

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

No current-main failure remains: the before-fix stale-cache path is source-proven by the linked issue and PR body, and current main now clears the cache in the SDK swap helper with regression coverage.

Is this the best way to solve the issue?

Yes. Clearing the existing client cache inside the test runtime setter is the narrowest maintainable fix, and current main already implements that shape through the merged replacement PR.

Security review:

Security review cleared: The PR diff only touches a Feishu test-helper reset path and a colocated Vitest regression, with no dependency, workflow, package, credential, or install-script changes.

AGENTS.md: found and applied where relevant.

What I checked:

Likely related people:

  • whiteyzy: Authored the merged replacement PR that added the same Feishu cache invalidation and regression coverage now present on main. (role: implemented canonical fix; confidence: high; commits: 762d8d8e645f; files: extensions/feishu/src/client.ts, extensions/feishu/src/client.test.ts)
  • vincentkoc: Merged the canonical replacement PR and is the committer associated with the current-main fix commit. (role: merger; confidence: high; commits: 762d8d8e645f; files: extensions/feishu/src/client.ts, extensions/feishu/src/client.test.ts)
  • huntharo: Commit 8448f48 added setFeishuClientRuntimeForTest and migrated Feishu client tests to the injectable SDK runtime seam. (role: introduced test runtime seam; confidence: high; commits: 8448f48cc57e; files: extensions/feishu/src/client.ts, extensions/feishu/src/client.test.ts)
  • doodlewind: Commit 5f6e1c1 introduced the multi-account Feishu clientCache and cache reuse behavior that the test runtime setter now invalidates. (role: introduced client cache; confidence: high; commits: 5f6e1c19bd18; files: extensions/feishu/src/client.ts)
  • m1heng: The Feishu plugin manifest describes the Feishu/Lark plugin as community maintained by this handle, making it useful routing context for Feishu behavior follow-up. (role: declared Feishu plugin contact; confidence: medium; files: extensions/feishu/openclaw.plugin.json)

Codex review notes: model internal, reasoning high; reviewed against 44e6caff5401; fix evidence: commit 762d8d8e645f, main fix timestamp 2026-06-13T14:01:15Z.

@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. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. labels May 24, 2026
@clawsweeper

clawsweeper Bot commented May 24, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat.

Where did the egg go?
  • The egg game starts only after the PR passes the real-behavior proof check.
  • Before that, no creature or rarity is rolled. The treat waits for real proof.
  • This is still just collectible flavor: proof affects review readiness, not creature quality.

@BingqingLyu

This comment was marked as spam.

@RomneyDa

Copy link
Copy Markdown
Member

Heads up: this PR needs to be updated against current main before the new required Dependency Guard check can pass.

setFeishuClientRuntimeForTest swapped the SDK but left clientCache
intact, so a later createFeishuClient with identical credentials
returned the client built by the previous SDK instance. Tests that
swap the SDK mid-suite could therefore receive a stale client and
make unreliable mock assertions.

Call clearClientCache() when the runtime SDK is replaced so cached
clients built with the old SDK are evicted. Adds a regression test.

Fixes openclaw#83911
@alkor2000
alkor2000 force-pushed the fix-83911-feishu-clear-cache-on-sdk-swap branch from abf75bc to d693389 Compare May 30, 2026 04:36
@alkor2000

Copy link
Copy Markdown
Contributor Author

Thanks @RomneyDa — rebased onto current main, so the Dependency Guard check now runs and passes. No conflicts; the fix and its regression test are unchanged (+37 across 2 files).

The one remaining red check (build-artifacts) is unrelated to this diff: it fails in scripts/crabbox-wrapper.test.ts, which this PR does not touch, and current main's own CI is red on the same check independently of this change.

@clawsweeper

clawsweeper Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

@clawsweeper clawsweeper Bot closed this Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: feishu Channel integration: feishu P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: supplied External PR includes structured after-fix real behavior proof. 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.

setFeishuClientRuntimeForTest resets the SDK without clearing the client cache

3 participants