Skip to content

fix(code-index): refresh status routing on workspace-folder changes - #1957

Merged
taltas merged 1 commit into
Zoo-Code-Org:mainfrom
tosinxt:fix/code-index-status-workspace-folders
Oct 8, 2026
Merged

taltas merged 1 commit into
Zoo-Code-Org:mainfrom
tosinxt:fix/code-index-status-workspace-folders

Conversation

@tosinxt

@tosinxt tosinxt commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Related GitHub Issue

Closes: #1857

Description

CodeIndexStatusManager now also subscribes to vscode.workspace.onDidChangeWorkspaceFolders and routes it through the existing updateSubscription(), so a workspace-folder change that changes the selected workspace switches the progress subscription and publishes the new manager's status immediately, without waiting for an active-editor change.

  • No second workspace-selection algorithm: the folder event reuses updateSubscription(), whose "same manager" early return also prevents duplicate subscriptions and redundant publications when the selection doesn't change.
  • The new listener is stored and released with the existing cleanup pattern. dispose() releases it between the editor and progress subscriptions, and each cleanup is logged independently, so a failing cleanup doesn't stop the others; repeated disposal stays safe.
  • Changes stay within the two files from the scope guide; no changeset, per the guide.

Acceptance criteria → tests in code-index-status-manager.spec.ts:

Criterion Test
Folder-only change switches A → B, disposes A's subscription, publishes B immediately; later B updates publish, stale A events are ignored switches to the newly selected workspace on a workspace-folder change alone
Unchanged selection → no duplicate subscription or publication keeps the subscription when a workspace-folder change leaves the selection unchanged
No workspace left → previous subscription released, stale events ignored releases the subscription when a workspace-folder change leaves no workspace
Disposal releases the folder listener; repeated disposal is safe; a cleanup exception doesn't block other cleanup releases the workspace-folder listener on disposal even when its cleanup fails
Existing tests still pass all 12 existing cases unchanged

The local vscode mock gains workspace.onDidChangeWorkspaceFolders; the first test resolves the workspace through the real resolver by changing workspaceFolders, with no editor event.

Test Procedure

Run from src/:

  • pnpm exec vitest run services/code-index/__tests__/code-index-status-manager.spec.ts — before the fix the 4 new tests fail (no folder subscription exists); after it, 16/16 pass.
  • pnpm exec vitest run __tests__/extension.spec.ts services/code-index — 36 files, 848 tests pass.
  • pnpm exec vitest run (full suite) — 9,899 passed; the only failures are the 40 in __tests__/dist_assets.spec.ts, which check for build output in dist/ and fail identically on main without a build.
  • pnpm check-types ✅, pnpm lint ✅ (--max-warnings=0, eslint-suppressions.json unchanged), Prettier ✅.

Not run: the manual multi-root VS Code scenario from the issue. The regression is covered by the deterministic unit tests above.

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Visual Snapshot (UI changes only): N/A, no UI change.
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Visual Snapshots

N/A, no UI change.

Videos (interaction / animation only)

N/A.

Documentation Updates

  • No documentation updates are required.

Additional Notes

None.

Get in Touch

Discord: tosin.py

Status routing only refreshed on active-editor changes, so a
workspace-folder change that switched the selected workspace left the
UI subscribed to the previous manager until the editor changed.

Closes Zoo-Code-Org#1857
@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: Zoo-Code-Org/Zoo-Code/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: b1809310-cf28-45db-9354-045aeb88df9a
📥 Commits

Reviewing files that changed from the base of the PR and between 2baac5e and 62c903c.

📒 Files selected for processing (2)
  • src/services/code-index/__tests__/code-index-status-manager.spec.ts
  • src/services/code-index/code-index-status-manager.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

📜 Recent review details
🧰 Additional context used
📓 Path-based instructions (5)
Check persistence and lifecycle invariants: awaited atomic writes, rollback or explicit partial-failure behavior, cross-window state consistency, stale listeners/watchers, cancellation, idempotency, and safe restart/resume without lost or d...

⚙️ CodeRabbit configuration file

Files:

  • src/services/code-index/code-index-status-manager.ts
  • src/services/code-index/__tests__/code-index-status-manager.spec.ts
Require regression coverage at the lowest valid harness with behavior-focused assertions, including relevant negative, error, false/unset, and boundary cases.

⚙️ CodeRabbit configuration file

Files:

  • src/services/code-index/__tests__/code-index-status-manager.spec.ts
Check strict typing and exhaustive behavior across normal, boundary, error, cancellation, retry, and compatibility paths.

⚙️ CodeRabbit configuration file

Files:

  • src/services/code-index/code-index-status-manager.ts
  • src/services/code-index/__tests__/code-index-status-manager.spec.ts
Verify extension/webview contracts, cancellation and error propagation, VS Code lifecycle correctness, and behavior under retries and partial failure.

⚙️ CodeRabbit configuration file

Files:

  • src/services/code-index/code-index-status-manager.ts
  • src/services/code-index/__tests__/code-index-status-manager.spec.ts
Act as an adversarial second-opinion reviewer.

⚙️ CodeRabbit configuration file

Files:

  • src/services/code-index/code-index-status-manager.ts
  • src/services/code-index/__tests__/code-index-status-manager.spec.ts

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Code index status now follows the currently selected workspace when workspace folders change, keeping progress information aligned with the active workspace.
    • Status updates from a workspace that is no longer active are ignored, and status tracking is released when no workspace remains.
    • Cleanup of workspace change tracking is handled safely, including when cleanup encounters an error.

Walkthrough

CodeIndexStatusManager now refreshes its active progress subscription when workspace folders change. It also disposes the workspace-folder listener during cleanup. Tests cover subscription changes, stale events, and disposal.

Changes

Code-index status routing

Layer / File(s) Summary
Workspace-change routing and lifecycle
src/services/code-index/code-index-status-manager.ts, src/services/code-index/__tests__/code-index-status-manager.spec.ts
The status manager listens for workspace-folder changes and updates its active progress subscription. Tests check changed and unchanged selections, removal of all workspaces, stale progress events, and listener cleanup.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 62c90

The workspace-change status routing is mergeable after normal checks; no actionable lifecycle failure remains established.

🚥 Pre-merge checks | ✅ 7 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Lifecycle Resource Cleanup ⚠️ Warning The new workspace-folder listener can leak on initialization failure. CodeIndexStatusManager.init() registers workspaceFoldersSubscription at lines 20–23, then calls updateSubscription() at line… Make CodeIndexStatusManager.init() transactional. Store the new editor and workspace-folder subscriptions in local variables, and dispose every subscription already created if any later initialization step throws; clear the instance field…
✅ Passed checks (7 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Issue #1857 requires status routing to refresh on workspace-folder changes, switch progress subscriptions, publish the new status immediately, reject stale events, avoid duplicate subscriptions when t…
Out of Scope Changes check ✅ Passed The diff changes only code-index-status-manager.ts and its focused test file. The production change directly implements issue #1857. The mock update and added tests support the required workspace-fo…
Regression Evidence ✅ Passed PASS. The changed folder-event routing has focused unit coverage in code-index-status-manager.spec.ts: manager switching with immediate publication, stale-event rejection, unchanged selection withou…
Security Boundaries ✅ Passed PASS. The changed production path only registers vscode.workspace.onDidChangeWorkspaceFolders and calls the existing updateSubscription() (`src/services/code-index/code-index-status-manager.ts:19-…
Persistence Integrity ✅ Passed PASS: The pull request changes only workspace-folder and progress subscription routing in CodeIndexStatusManager and related tests. The changed code adds event listeners, disposes subscriptions, and…
Title check ✅ Passed The title clearly and concisely describes the main change: refreshing code-index status routing when workspace folders change.
Description check ✅ Passed The description follows the repository template. It identifies the linked issue, explains the implementation, lists acceptance criteria and tests, reports known full-suite failures, and completes the …
Full details: Lifecycle Resource Cleanup

Explanation

The new workspace-folder listener can leak on initialization failure. CodeIndexStatusManager.init() registers workspaceFoldersSubscription at lines 20–23, then calls updateSubscription() at line 24. If that call throws, the new listener remains registered. CodeIndexScope.init() assigns statusManager only after manager.init() returns, so its failure path leaves the manager inaccessible; extension.ts catches the error and does not dispose the failed manager. The existing status-manager test confirms that initialization can throw during the initial status publication. A retry or extension shutdown can therefore retain the failed listener, and a retry can add another listener.

Resolution

Make CodeIndexStatusManager.init() transactional. Store the new editor and workspace-folder subscriptions in local variables, and dispose every subscription already created if any later initialization step throws; clear the instance fields before rethrowing. Add a regression test that forces initial update/publication to throw and verifies both listeners are disposed. Alternatively, make CodeIndexScope retain the status manager before initialization and dispose it when initialization fails.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Review status

Thanks for contributing. This comment tracks the review sequence and the next action.

Current step: Awaiting fresh human maintainer or CODEOWNER approval.

Automated review is complete for the latest commit but does not replace human approval.

Review-state labels are managed by this workflow; do not edit them manually. community-approved is managed the same way — do not add or remove it manually. It signals a fresh community code approval for the current head as an advisory priority only; maintainer review is still required.

@codecov

codecov Bot commented Oct 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions github-actions Bot added coderabbit-review-active Required CI passed; CodeRabbit review is active awaiting-coderabbit Waiting for CodeRabbit to approve the latest commit labels Oct 8, 2026
@github-actions github-actions Bot added awaiting-maintainer CodeRabbit approved; waiting for a human maintainer and removed coderabbit-review-active Required CI passed; CodeRabbit review is active awaiting-coderabbit Waiting for CodeRabbit to approve the latest commit labels Oct 8, 2026

@WebMad WebMad left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Thanks for the contribution. See you in the next PRs :)

(Not a core contributor, just a reviewer)

@github-actions github-actions Bot added the community-approved Fresh community approval on the current head; maintainer review still required label Oct 8, 2026
@taltas
taltas enabled auto-merge October 8, 2026 23:19
@taltas
taltas added this pull request to the merge queue Oct 8, 2026
Merged via the queue into Zoo-Code-Org:main with commit 2681ccb Oct 8, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-maintainer CodeRabbit approved; waiting for a human maintainer community-approved Fresh community approval on the current head; maintainer review still required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Code-index status subscription is not refreshed when workspace folders change

3 participants