Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add in memory cache for lockdown mode#1416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
JoannaaKL merged 22 commits intomainfromlockdown-mode-more-tools
Nov 21, 2025
Merged

Conversation

@JoannaaKL
Copy link
Contributor

@JoannaaKLJoannaaKL commentedNov 17, 2025
edited
Loading

Improving lockdown mode:

  • added a dependency onhttps://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, likeGetIssue will return an error in lockdown mode. Tools returning a list of items, likeGetIssueComments 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.)

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

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.
typeRepoAccessCachestruct {
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.

JoannaaKL reacted with thumbs up emoji
Copy link
ContributorAuthor

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

JoannaaKLand others added8 commitsNovember 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 implementationCo-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>* Final verification completeCo-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>---------Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>Co-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>
* Initial plan* Implement RepoAccessCache as a singleton patternCo-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>* Complete singleton implementation and verificationCo-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>* Remove cacheIDCounter as requestedCo-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>---------Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>Co-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>
@JoannaaKLJoannaaKL changed the titleLockdown mode more toolsAdd in memory cache for lockdown modeNov 18, 2025
@JoannaaKLJoannaaKL marked this pull request as ready for reviewNovember 18, 2025 14:44
@JoannaaKLJoannaaKL requested a review froma team as acode ownerNovember 18, 2025 14:44
CopilotAI review requested due to automatic review settingsNovember 18, 2025 14:44
Copilot finished reviewing on behalf ofJoannaaKLNovember 18, 2025 14:49
Copy link
Contributor

CopilotAI 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 ongithub.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:

  • ReplacesShouldRemoveContent function with aRepoAccessCache that caches repository privacy status and user push access per-repository
  • Integrates the cache into five lockdown-enabled tools:GetIssue,GetIssueComments,GetSubIssues,GetPullRequest,GetPullRequestReviewComments, andGetPullRequestReviews
  • 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
FileDescription
third-party/github.com/muesli/cache2go/LICENSE.txtBSD-3-Clause license for new cache2go dependency
third-party-licenses.*.mdUpdated license documentation for all platforms (darwin, linux, windows)
go.mod, go.sumAdded muesli/cache2go dependency at commit 518229cd8021
pkg/lockdown/lockdown.goComplete rewrite: introduces RepoAccessCache with singleton pattern, per-repo caching with per-user permission tracking, and configurable TTL
pkg/lockdown/lockdown_test.goNew test file with TTL eviction test
pkg/github/issues.goUpdated GetIssue, GetIssueComments, GetSubIssues, GetIssueLabels to accept and use cache parameter
pkg/github/pullrequests.goUpdated GetPullRequest, GetPullRequestReviewComments, GetPullRequestReviews to accept and use cache parameter
pkg/github/tools.goAdded cache parameter to DefaultToolsetGroup and passed to IssueRead and PullRequestRead tool constructors
pkg/github/issues_test.go, pullrequests_test.go, server_test.goUpdated test signatures to create and pass cache instances using stubRepoAccessCache helper
internal/ghmcp/server.goInitializes cache singleton when lockdown mode is enabled, with optional TTL configuration
cmd/github-mcp-server/main.goAdded --repo-access-cache-ttl flag and plumbing to StdioServerConfig
cmd/github-mcp-server/generate_docs.goUpdated to pass cache instance (with nil client) to DefaultToolsetGroup

Copy link
Collaborator

@SamMorrowDrumsSamMorrowDrums 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
ContributorAuthor

JoannaaKL commentedNov 20, 2025
edited
Loading

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 changesNov 21, 2025
Copy link
Collaborator

@SamMorrowDrumsSamMorrowDrums 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 reacted with heart emoji
@JoannaaKLJoannaaKL merged commit28b868d intomainNov 21, 2025
16 checks passed
@JoannaaKLJoannaaKL deleted the lockdown-mode-more-tools branchNovember 21, 2025 09:34
@t3xash0rnyt0ad777-commits
Copy link

On Fri, Nov 21, 2025, 3:35 AM JoannaaKL ***@***.***> wrote: Merged#1416 <#1416> into main. — Reply to this email directly, view it on GitHub <#1416 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/BXWTFNRT3RXMBZSURBPSHZL353MHDAVCNFSM6AAAAACMLHGHTCVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMRRGA4TENJQGA4DINA> . You are receiving this because you are subscribed to this thread.Message ID: ***@***.*** com>

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

Copilot code reviewCopilotCopilot left review comments

@SamMorrowDrumsSamMorrowDrumsSamMorrowDrums approved these changes

@tonytrgtonytrgAwaiting requested review from tonytrg

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

5 participants

@JoannaaKL@t3xash0rnyt0ad777-commits@SamMorrowDrums@tonytrg

[8]ページ先頭

©2009-2025 Movatter.jp