fix(iwiki): stop fetchAllPages from rejecting every space walk before it starts - #849
Merged
Merged
Conversation
… it starts The 'initial queue is empty' guard ran after tryDrain(), which had already dispatched the root request: tryDrain shifts the only queue entry, so the queue is always empty by then and the promise rejected with 'fetchAllPages: rootId 队列为空' on every call, before any response could arrive. Zero-latency mocks hid it — the first response beat the rejection and populated allPages, so the catch guard (allPages.length === 0) swallowed the error. Check the guard before tryDrain() and seed the queue only for a non-empty rootId, so it rejects exactly when there is nothing to walk. Also drop the dead '!stopped' from the drain loop (tryDrain already returns when stopped, and stopped cannot change inside the synchronous loop — oxlint no-unmodified-loop-condition, the hit Tencent#836 flags), and write the file's user-facing messages in English per the repo rule.
jeff-r2026
self-requested a review
September 27, 2026 02:36
|
No findings. The PR description includes sufficient testing, including a representative real-CLI verification for the runtime behavior change. The previously reported findings section is empty, so there are no earlier findings to mark resolved. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #848.
Problem
fetchAllPagesrejects every call withfetchAllPages: rootId 队列为空before the first request can return, soteamai import --from-iwiki <space-id>(and the iwiki-dual Space path) can never list a space's pages. Root cause and reproduction are in #848: the "initial queue is empty" guard runs aftertryDrain(), which has already shifted the rootId, so the queue is always empty at that point and the promise rejects on every call. Zero-latency mocks hid it — the first response beat the rejection and populatedallPages, letting the catch guard swallow the error; with real latency the rejection always wins.Fix (
src/utils/iwiki-client.ts)tryDrain(), and seed the queue only for a non-empty rootId, so it now rejects exactly when there is nothing to walk (its original purpose) and every real walk gets to start.&& !stoppedfrom the drain loop:tryDrainalready returns whenstopped, andstoppedonly changes inside async callbacks, so the condition never changes within the synchronous loop. This is theno-unmodified-loop-conditionhit that oxlint rollout: bugs found in the baseline, and next rules to evaluate #836 says to check first — verified as redundant here, now removed so the planned lint rollout stays clean.src/,docs/,skill-data/,README*).Tests
New
src/__tests__/iwiki-client.test.ts(6 tests) mocksgetSpacePageTreewith deferred promises (resolve on a later macrotask), which is what makes the suite able to catch a regression — the same tests fail 5/5 onmain:On this branch: 6/6 pass, plus the existing
iwiki-dual.test.ts(4) andiwiki-review-apply.test.ts(2).npx tsc --noEmitclean;npm run lint0 warnings (--deny-warnings).Real-CLI verification (
b19682e)npm run build, thennode dist/index.js import --from-iwiki 12345against a sandboxHOME, a local team-repo fixture and a placeholder token. The iWiki MCP endpoint is only reachable inside Tencent, so the network itself fails here — which is exactly what makes the two runs comparable: the same unreachable endpoint, the only difference being when the walk gives up.Before (main): rejects instantly with the bogus guard error, before any request:
After (this branch): the walk starts, the root request really goes out, its network failure is reported per node (in English), and the command ends the way a failed walk is designed to: