Skip to content

Conversation

@JoannaaKL
Copy link
Contributor

@JoannaaKL JoannaaKL commented Nov 17, 2025

Improving lockdown mode:

  • added a dependency on https://github.com/muesli/cache2go, to use its map with ttl implementation
  • used cache from the above instead of custom implementation
  • adding tests
  • passing lockdown cache to tools: GetIssueComments, GetSubIssues, GetPullRequest, GetPullRequestReviewComments, GetPullRequestReviews

The bigger difference is that lockdown mode uses a cache with configureable TTL. That's because to fetch repo permissions like collaborators we need to do a graphql call which is costly, so we want to minimise number of calls we make.
Tools that are expected to return one result, like GetIssue will return an error in lockdown mode. Tools returning a list of items, like GetIssueComments will filter out comments that were added by the user without push access.
One caveat - Copilot is treated as non-collaborator and content created by it is filtered too. :D (I have a second pr to address that.)

Screenshots CleanShot 2025-11-20 at 11 29 38@2x CleanShot 2025-11-20 at 11 30 07@2x CleanShot 2025-11-20 at 11 08 50@2x CleanShot 2025-11-20 at 11 15 31@2x CleanShot 2025-11-20 at 11 17 16@2x

@JoannaaKL JoannaaKL force-pushed the lockdown-mode-more-tools branch from a6fb6ea to 5562335 Compare November 17, 2025 15:57
isPrivate, hasPushAccess, err := repoAccessInfo(ctx, client, username, owner, repo)
// RepoAccessCache caches repository metadata related to lockdown checks so that
// multiple tools can reuse the same access information safely across goroutines.
type RepoAccessCache struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

is there not a well tested library we can use?

The impl looks fine, but Id prefer a general cache impl from a tested public lib.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can try this one go get github.com/muesli/cache2go

JoannaaKL and others added 8 commits November 18, 2025 10:03
* Initial plan

* Replace custom cache with cache2go library

- Added github.com/muesli/cache2go dependency
- Replaced custom map-based cache with cache2go.CacheTable
- Removed manual timer management (scheduleExpiry, ensureEntry methods)
- Removed timer field from repoAccessCacheEntry struct
- Updated GetRepoAccessInfo to use cache2go's Value() and Add() methods
- Updated SetTTL to flush and re-add entries with new TTL
- Used unique cache names per instance to avoid test interference
- All existing tests pass with the new implementation

Co-authored-by: JoannaaKL <[email protected]>

* Final verification complete

Co-authored-by: JoannaaKL <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: JoannaaKL <[email protected]>
* Initial plan

* Implement RepoAccessCache as a singleton pattern

Co-authored-by: JoannaaKL <[email protected]>

* Complete singleton implementation and verification

Co-authored-by: JoannaaKL <[email protected]>

* Remove cacheIDCounter as requested

Co-authored-by: JoannaaKL <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: JoannaaKL <[email protected]>
@JoannaaKL JoannaaKL changed the title Lockdown mode more tools Add in memory cache for lockdown mode Nov 18, 2025
@JoannaaKL JoannaaKL marked this pull request as ready for review November 18, 2025 14:44
@JoannaaKL JoannaaKL requested a review from a team as a code owner November 18, 2025 14:44
Copilot AI review requested due to automatic review settings November 18, 2025 14:44
Copilot finished reviewing on behalf of JoannaaKL November 18, 2025 14:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds an in-memory caching layer for lockdown mode to reduce redundant GraphQL API calls when checking repository access permissions. It introduces a dependency on github.com/muesli/cache2go for TTL-based caching and refactors the lockdown implementation from a simple function to a cache-backed service with configurable TTL.

Key changes:

  • Replaces ShouldRemoveContent function with a RepoAccessCache that caches repository privacy status and user push access per-repository
  • Integrates the cache into five lockdown-enabled tools: GetIssue, GetIssueComments, GetSubIssues, GetPullRequest, GetPullRequestReviewComments, and GetPullRequestReviews
  • Adds CLI flag --repo-access-cache-ttl (default 5m) to configure cache expiration

Reviewed Changes

Copilot reviewed 16 out of 17 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
third-party/github.com/muesli/cache2go/LICENSE.txt BSD-3-Clause license for new cache2go dependency
third-party-licenses.*.md Updated license documentation for all platforms (darwin, linux, windows)
go.mod, go.sum Added muesli/cache2go dependency at commit 518229cd8021
pkg/lockdown/lockdown.go Complete rewrite: introduces RepoAccessCache with singleton pattern, per-repo caching with per-user permission tracking, and configurable TTL
pkg/lockdown/lockdown_test.go New test file with TTL eviction test
pkg/github/issues.go Updated GetIssue, GetIssueComments, GetSubIssues, GetIssueLabels to accept and use cache parameter
pkg/github/pullrequests.go Updated GetPullRequest, GetPullRequestReviewComments, GetPullRequestReviews to accept and use cache parameter
pkg/github/tools.go Added cache parameter to DefaultToolsetGroup and passed to IssueRead and PullRequestRead tool constructors
pkg/github/issues_test.go, pullrequests_test.go, server_test.go Updated test signatures to create and pass cache instances using stubRepoAccessCache helper
internal/ghmcp/server.go Initializes cache singleton when lockdown mode is enabled, with optional TTL configuration
cmd/github-mcp-server/main.go Added --repo-access-cache-ttl flag and plumbing to StdioServerConfig
cmd/github-mcp-server/generate_docs.go Updated to pass cache instance (with nil client) to DefaultToolsetGroup

Copy link
Collaborator

@SamMorrowDrums SamMorrowDrums left a comment

Choose a reason for hiding this comment

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

I think Tony's comment makes sense and broadly this is very clear. I'd encourage stacked PRs for the separate tools files perhaps just to make review burden lower, but I'm really happy with the direction and @Chuxel will be very happy to see this arrive.

@JoannaaKL
Copy link
Contributor Author

JoannaaKL commented Nov 20, 2025

I think Tony's comment makes sense and broadly this is very clear. I'd encourage stacked PRs for the separate tools files perhaps just to make review burden lower, but I'm really happy with the direction and @Chuxel will be very happy to see this arrive.

I addressed Tony's comment and this pr uses muesli/cache2go as a cache.

SamMorrowDrums
SamMorrowDrums previously approved these changes Nov 21, 2025
Copy link
Collaborator

@SamMorrowDrums SamMorrowDrums left a comment

Choose a reason for hiding this comment

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

Thanks for changes @JoannaaKL hope the merge conflict with Go SDK work Isn't too painful for Adam after this. 😅

@JoannaaKL JoannaaKL merged commit 28b868d into main Nov 21, 2025
16 checks passed
@JoannaaKL JoannaaKL deleted the lockdown-mode-more-tools branch November 21, 2025 09:34
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.

4 participants