Repository navigation
fix(community): run Leiden in a worker so its timeout can fire - #3478
Conversation
…fire leiden.detailed is synchronous and never returns on some graphs (graphology/graphology#557), so the Promise.race timeout could not fire and the one-community fallback was unreachable. Run it in a worker thread and terminate the worker on timeout. Fixes abhigyanpatwari#3476
|
@drakeo338 is attempting to deploy a commit to the NexusCore Team on Vercel. A member of the Team first needs to authorize it. |
GitNexus Review · PR #3478No issues found in 4 changed files. SummaryThis appears to be a focused community-processing and worker-execution change. Its blast classification is critical, although the file-level risk is low. 🔴 CRITICAL blast radius. A worker-thread change to community processing in The core changes are in Impact lands in the 🔀 Structural changes ·
|
🤖 Agent context for GitNexus Review · PR #3478This comment carries deterministic graph detail for coding agents and reviewers who want the receipts — the main review comment carries the human summary.
What changedSymbol Changes (24)
Changed Files (4)
What it affectsArchitecture Impact
Blast Radius
Direct dependents (d1)
Indirect dependents (d2)
Transitive dependents (d3)
|
koriyoshi2041
left a comment
There was a problem hiding this comment.
Reviewed exact head faf3ab69. I reran npx vitest run test/unit/community-processor.test.ts on macOS: 23/23 passed. The regression exercises the real 105-node non-terminating graph, and the worker-backed path returned the one-community timeout fallback within the 500 ms guard instead of blocking the event loop. I also checked the worker lifecycle paths: message/error clear the timer, timeout terminates the worker, and an unexpected pre-settlement exit rejects. No correctness issue found in this scope.
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The Icebug fallback path overwrites the new Graphology timeout reason, concealing degraded single-community results.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Moves synchronous Graphology Leiden execution to a worker so community detection can time out and degrade gracefully.
Changes:
- Runs vendored Leiden in a terminable worker thread.
- Adds regression coverage using the non-terminating graph from #3476.
| File | Description |
|---|---|
gitnexus/src/core/ingestion/community-processor.ts |
Adds worker-based Leiden execution and timeout handling. |
gitnexus/test/unit/community-processor.test.ts |
Tests timeout fallback and updates worker mocks. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
magyargergo
left a comment
There was a problem hiding this comment.
Reviewed 81448a89c0308224ee52f74c4d1aaf8512be6b86.
The worker change fixes the reported hang: the real fixture returns the timeout fallback and the process exits. I'm requesting changes because the new test fails the test typecheck that CI runs. The second inline comment covers a gap in the termination regression.
I also reproduced the existing fallback-metadata finding. When Icebug fails and Graphology then times out, runCommunityEngine overwrites the timeout reason with the Icebug error. Preserve both reasons and cover that full chain. I used a shortened deadline to exercise this path.
Verification on Linux, Node 24.19.0:
- 37 focused tests passed, including community detection and runtime-asset checks.
- Production typechecking passed. Test typechecking failed with TS2351 at the new graph constructor; the same check passed on base
df49f908with the same dependencies. - Deleting only
worker.terminate()in a disposable copy still left all 23 community tests green, while the standalone process stayed alive beyond five seconds.
Full suites, macOS/Windows runtime checks and large-graph memory benchmarks were not run. GitHub CI is awaiting approval.
Keep the Icebug failure and Graphology timeout in the diagnostic when both engines fall back. Preserve the existing single-error message.
Use the existing typed graph builder and preserve the original 105-node, 128-edge insertion order. The child returns its result and must exit naturally so the parent can detect a leaked worker.
Assert the hanging fixture returns the timeout fallback and exits naturally. Cover Icebug and auto failures followed by a Graphology timeout through processCommunities. Removing worker termination fails the child-process test; reverting diagnostic composition fails both fallback-chain tests.
Include the real worker shutdown regression in the existing Windows/macOS platform-sensitive test inventory.
🔄 What's new in this push (
|
|
Addressed all three review findings in 2cd074b, a7c23c2, 9c952f3, and 7b0a929. Each thread has the fix and verification evidence and is now resolved.
Validation on the published tree:
The four published files match the validated local files byte for byte. No new dependency or production abstraction was added. |
CI Report✅ All checks passed Pipeline Status
Test Results
✅ All 25544 tests passed Code CoverageTests
📋 View full run · Generated by CI |


Refs #3476.
Summary
Covers the Leiden community-detection timeout item from the list in #3476.
Motivation / context
The Leiden timeout never fired: graphology's Leiden runs synchronously on the main thread, so the timer could not run until it finished. The call now runs in a worker thread so the timeout can fire and fall back to one community.
Areas touched
gitnexus/(CLI / core / MCP server)gitnexus-web/(Vite / React UI).github/(workflows, actions)eval/or other toolingAGENTS.md,CLAUDE.md,.cursor/,llms.txt, etc.)Scope & constraints
In scope
community-processor.tsand its unit testExplicitly out of scope / not done here
Implementation notes
Testing & verification
Ran only
test/unit/community-processor.test.tson HEAD (23 passed, 0 failed); nothing else was run, so the boxes stay unticked.cd gitnexus && npm testcd gitnexus && npm run test:integration(if core/indexing/MCP paths changed)cd gitnexus && npx tsc --noEmitcd gitnexus-web && npm test(if web changed)cd gitnexus-web && npx tsc -b --noEmit(if web changed)gitnexus-web/e2e/)Risk & rollout
Checklist
AGENTS.md/ overlays changed: headers, scope block, and changelog updated per project conventions📝 Summary by GitNexus
Summary
This appears to be a focused community-processing and worker-execution change. Its blast classification is critical, although the file-level risk is low.
🔴 CRITICAL blast radius. A worker-thread change to community processing in
community-processor.ts, reaching three direct and transitive dependents.The core changes are in
runCommunityEngine,runIcebugLeiden, andrunIcebugWorkeringitnexus/src/core/ingestion/community-processor.ts. The related tests are ingitnexus/test/unit/community-processor.test.tsandgitnexus/test/helpers/leiden-timeout-child.ts, with worker-thread coverage also ingitnexus/scripts/cross-platform-tests.ts.Impact lands in the
Ingestion,Unit,Passes, andPipeline-phasesmodules, and the changed code appears in 5 affected flows. Review the worker execution and timeout behavior first, then check the related test coverage.Added by GitNexus for PR #3478. Edit freely — this block is replaced on the next review, everything above it is left untouched.