Skip to content

refactor(cache): add GetWithTeamID method to SnapshotCache#2587

Open
AdaAibaby wants to merge 3 commits intoe2b-dev:mainfrom
AdaAibaby:feature/eng-3544-snapshot-cache-team-id
Open

refactor(cache): add GetWithTeamID method to SnapshotCache#2587
AdaAibaby wants to merge 3 commits intoe2b-dev:mainfrom
AdaAibaby:feature/eng-3544-snapshot-cache-team-id

Conversation

@AdaAibaby
Copy link
Copy Markdown

  • Add new SQL query GetLastSnapshotByTeam with teamID filtering
  • Implement GetWithTeamID method in SnapshotCache
  • Use composite cache key (sandboxID:teamID) to avoid collisions
  • Mark Get method as deprecated
  • Add unit tests for new functionality
  • Fixes ENG-3544: scope GetLastSnapshot query by teamID to avoid post-fetch ownership check

This is the foundation for subsequent PRs that will update individual handlers (sandbox_get, sandbox_pause, sandbox_resume, sandbox_connect) to use the new GetWithTeamID method, ensuring ownership validation at the database level.

- Add new SQL query GetLastSnapshotByTeam with teamID filtering
- Implement GetWithTeamID method in SnapshotCache
- Use composite cache key (sandboxID:teamID) to avoid collisions
- Mark Get method as deprecated
- Add unit tests for new functionality
- Fixes ENG-3544: scope GetLastSnapshot query by teamID to avoid post-fetch ownership check

This is the foundation for subsequent PRs that will update individual handlers
(sandbox_get, sandbox_pause, sandbox_resume, sandbox_connect) to use the new
GetWithTeamID method, ensuring ownership validation at the database level.
@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented May 7, 2026

We require contributors to sign our Contributor License Agreement, and we don't have @adababys on file. You can sign our CLA at https://e2b.dev/docs/cla . Once you've signed, post a comment here that says '@cla-bot check'

@qodo-code-review
Copy link
Copy Markdown

ⓘ You've reached your Qodo monthly free-tier limit. Reviews pause until next month — upgrade your plan to continue now, or link your paid account if you already have one.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

The introduction of a composite cache key in GetWithTeamID breaks the existing Invalidate method, which only deletes the simple sandboxID key, leading to stale snapshot data. The new test file contains a duplicate package declaration that will cause a compilation error.

Comment thread packages/api/internal/cache/snapshots/snapshot_cache.go
Comment thread packages/api/internal/cache/snapshots/snapshot_cache_test.go Outdated
- Update Invalidate method to delete team-scoped cache keys using DeleteByPrefix
- Add InvalidateWithTeamID method for precise cache invalidation
- Prevent stale snapshot data from persisting in cache after invalidation
- Fixes cache pollution issue identified in code review

The composite cache key (sandboxID:teamID) introduced in the previous commit
required updating the invalidation logic to ensure all related cache entries
are properly cleared, not just the simple sandboxID key.

This fix ensures:
1. Invalidate(sandboxID) deletes both simple key and all team-scoped keys
2. InvalidateWithTeamID(sandboxID, teamID) deletes only the specific team's key
3. No stale snapshot data persists after invalidation
@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented May 7, 2026

We require contributors to sign our Contributor License Agreement, and we don't have @adababys on file. You can sign our CLA at https://e2b.dev/docs/cla . Once you've signed, post a comment here that says '@cla-bot check'

@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented May 7, 2026

We require contributors to sign our Contributor License Agreement, and we don't have @adababys, @AdaAibaby on file. You can sign our CLA at https://e2b.dev/docs/cla . Once you've signed, post a comment here that says '@cla-bot check'

@AdaAibaby
Copy link
Copy Markdown
Author

We require contributors to sign our Contributor License Agreement, and we don't have @adababys, @AdaAibaby on file. You can sign our CLA at https://e2b.dev/docs/cla . Once you've signed, post a comment here that says '@cla-bot check'

@cla-bot check

@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented May 7, 2026

We require contributors to sign our Contributor License Agreement, and we don't have @adababys on file. You can sign our CLA at https://e2b.dev/docs/cla . Once you've signed, post a comment here that says '@cla-bot check'

@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented May 7, 2026

The cla-bot has been summoned, and re-checked this pull request!

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.

3 participants