Skip to content

fix: guard semantic cache Cleanup with sync.Once to prevent double-close panic - #3532

Merged
Pratham-Mishra04 merged 1 commit into
devfrom
05-15-fix_cleanup_once_check_added_for_semantic_cache
May 15, 2026
Merged

fix: guard semantic cache Cleanup with sync.Once to prevent double-close panic#3532
Pratham-Mishra04 merged 1 commit into
devfrom
05-15-fix_cleanup_once_check_added_for_semantic_cache

Conversation

@Pratham-Mishra04

Copy link
Copy Markdown
Collaborator

Summary

The Cleanup method on the semantic cache plugin could panic if called more than once, because close(stopCh) would be invoked on an already-closed channel. This happens when the plugin is registered against multiple interface caches, causing the harness to invoke Cleanup multiple times.

Changes

  • Introduced a sync.Once field (cleanupOnce) on the Plugin struct to guard the body of Cleanup, ensuring close(stopCh) and the subsequent wait/sweep logic execute exactly once regardless of how many times Cleanup is called.

Type of change

  • Bug fix

Affected areas

  • Plugins

How to test

Register the semantic cache plugin against multiple interface caches and trigger shutdown. Verify that Cleanup is called more than once without panicking.

go test ./plugins/semanticcache/...

Breaking changes

  • No

Security considerations

None.

Checklist

  • I read docs/contributing/README.md and followed the guidelines
  • I added/updated tests where appropriate
  • I updated documentation where needed
  • I verified builds succeed (Go and UI)
  • I verified the CI pipeline passes locally if applicable

Copy link
Copy Markdown
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@coderabbitai

coderabbitai Bot commented May 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 977e2549-4bbd-44ed-a25b-2c121b7c1f7a

📥 Commits

Reviewing files that changed from the base of the PR and between 4f33dd8 and ca0a335.

📒 Files selected for processing (1)
  • plugins/semanticcache/main.go

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved semantic cache plugin stability by making the cleanup operation safe to call multiple times without causing errors.

Walkthrough

The Plugin struct now includes a cleanupOnce sync.Once field to guard cleanup execution. The Cleanup() method refactors its stop/wait/final-sweep sequence to run inside cleanupOnce.Do(...), ensuring idempotent and panic-safe cleanup on repeated calls.

Changes

Cleanup Idempotency Implementation

Layer / File(s) Summary
Cleanup guard and method refactoring
plugins/semanticcache/main.go
Plugin struct adds cleanupOnce sync.Once field and Cleanup() method wraps stop signal, writer drain, loop termination, and accumulator sweep inside cleanupOnce.Do(...) to prevent panics from closing an already-closed channel and ensure single execution.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A fence of Once guards the gate,
No double-close to seal our fate.
One brave sweep, one gentle close,
Cleanup idempotent—all cleanup flows! 🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main fix: adding sync.Once guard to Cleanup method to prevent double-close panic.
Description check ✅ Passed The description covers all major sections of the template: summary explaining the problem, changes made, bug fix type, plugins area, testing steps, and checklist, though some optional items remain unchecked.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 05-15-fix_cleanup_once_check_added_for_semantic_cache

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


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

@greptile-apps

greptile-apps Bot commented May 15, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5

Safe to merge; the fix is minimal, correct, and well-scoped to the panic scenario described.

The change is a single, focused addition of sync.Once around an already-correct cleanup sequence. The only gap is that no regression test was added to lock in the new behavior, so the guard could silently disappear in a future refactor.

plugins/semanticcache/main.go — verify the lack of a regression test is acceptable given the existing Cleanup test suite.

Important Files Changed

Filename Overview
plugins/semanticcache/main.go Wraps Cleanup body in sync.Once to prevent double-close panic on stopCh; no regression test added for the new guard.

Reviews (1): Last reviewed commit: "fix: cleanup once check added" | Re-trigger Greptile

Comment thread plugins/semanticcache/main.go
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Pratham-Mishra04 commented May 15, 2026

Copy link
Copy Markdown
Collaborator Author

Merge activity

  • May 15, 6:18 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • May 15, 6:19 PM UTC: @Pratham-Mishra04 merged this pull request with Graphite.

@Pratham-Mishra04
Pratham-Mishra04 merged commit 6f1d08a into dev May 15, 2026
15 of 16 checks passed
@Pratham-Mishra04
Pratham-Mishra04 deleted the 05-15-fix_cleanup_once_check_added_for_semantic_cache branch May 15, 2026 18:19
akshaydeo pushed a commit that referenced this pull request May 15, 2026
…e-close panic (#3532)

## Summary

The `Cleanup` method on the semantic cache plugin could panic if called more than once, because `close(stopCh)` would be invoked on an already-closed channel. This happens when the plugin is registered against multiple interface caches, causing the harness to invoke `Cleanup` multiple times.

## Changes

- Introduced a `sync.Once` field (`cleanupOnce`) on the `Plugin` struct to guard the body of `Cleanup`, ensuring `close(stopCh)` and the subsequent wait/sweep logic execute exactly once regardless of how many times `Cleanup` is called.

## Type of change

- [x] Bug fix

## Affected areas

- [x] Plugins

## How to test

Register the semantic cache plugin against multiple interface caches and trigger shutdown. Verify that `Cleanup` is called more than once without panicking.

```sh
go test ./plugins/semanticcache/...
```

## Breaking changes

- [x] No

## Security considerations

None.

## Checklist

- [ ] I read `docs/contributing/README.md` and followed the guidelines
- [ ] I added/updated tests where appropriate
- [ ] I updated documentation where needed
- [ ] I verified builds succeed (Go and UI)
- [ ] I verified the CI pipeline passes locally if applicable
akshaydeo pushed a commit that referenced this pull request May 20, 2026
…e-close panic (#3532)

## Summary

The `Cleanup` method on the semantic cache plugin could panic if called more than once, because `close(stopCh)` would be invoked on an already-closed channel. This happens when the plugin is registered against multiple interface caches, causing the harness to invoke `Cleanup` multiple times.

## Changes

- Introduced a `sync.Once` field (`cleanupOnce`) on the `Plugin` struct to guard the body of `Cleanup`, ensuring `close(stopCh)` and the subsequent wait/sweep logic execute exactly once regardless of how many times `Cleanup` is called.

## Type of change

- [x] Bug fix

## Affected areas

- [x] Plugins

## How to test

Register the semantic cache plugin against multiple interface caches and trigger shutdown. Verify that `Cleanup` is called more than once without panicking.

```sh
go test ./plugins/semanticcache/...
```

## Breaking changes

- [x] No

## Security considerations

None.

## Checklist

- [ ] I read `docs/contributing/README.md` and followed the guidelines
- [ ] I added/updated tests where appropriate
- [ ] I updated documentation where needed
- [ ] I verified builds succeed (Go and UI)
- [ ] I verified the CI pipeline passes locally if applicable
@akshaydeo akshaydeo mentioned this pull request May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants