fix(editor): resolve getTree cache staleness by using commit SHA instead of branch name #5502
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes stale cache issue when fetching docs.yml content for the Editor.
Short description of the changes made
Modified
getTreeingithub-loader.tsto resolve the branch ref to a commit SHA before caching. Previously, the tree was cached using the branch name (e.g., "main") as the cache key with no revalidation period, causing the cache to potentially live forever even as the branch moved forward.Key changes:
resolveRefToShabefore making the GitHub API callgithub-repo-${owner}-${repo}tag to enable cache invalidation viainvalidateRepoCacheskipCachefunctionality from app branchWhat was the motivation & context behind this PR?
The Editor was showing stale docs.yml content when creating new sessions. The root cause was that
getTreecached the repository tree based on branch name with norevalidateperiod, so once cached, the tree data would never refresh even when new commits were pushed to the branch.Now when the branch moves to a new commit,
getCommitRef(with 5-min TTL) will return the new SHA, resulting in a new cache key forgetTreeand fresh tree data.How has this PR been tested?
Human review checklist
resolveRefToShacall overhead is acceptable (it's cached with 5-min TTL)getCommitRefis acceptable for New Session freshness requirementsskipCachefunctionality still works correctly with the new commit SHA-based cachingLink to Devin run: https://app.devin.ai/sessions/66976b7aab5a4c25b2b2278dd58217a2
Requested by: stephen@buildwithfern.com