Skip to content

fix(itg): encode remotes in filesystem-safe cache keys (audit #13) - #252

Merged
sbalabanov merged 3 commits into
mainfrom
audit/fix-13-itg-key-mismatch
Aug 4, 2026
Merged

fix(itg): encode remotes in filesystem-safe cache keys (audit #13)#252
sbalabanov merged 3 commits into
mainfrom
audit/fix-13-itg-key-mismatch

Conversation

@sbalabanov

@sbalabanov sbalabanov commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Encode repository remotes into a slash-free component before constructing ITG cache keys. This lets toStorageKey and FloorKey use the same path.Join layout without URL or SSH remotes accidentally creating filesystem path segments.

Intent

Make ITG cache keys portable across storage backends, including filesystem-based implementations, while ensuring writes, reads, and prefix listings derive identical keys for URL, path, and SSH remotes.

Changes

  • Percent-encode reserved path characters while preserving readable remote names.
  • Build cache entry keys and listing prefixes with path.Join.
  • Add table-driven round-trip coverage for URL, plain-path, and SSH remotes.
  • Verify the stored remote component is readable, slash-free, and decodes to the original remote.
  • Treat existing entries under the old key format as cold cache data; they will be regenerated rather than migrated.

Test Plan

  • go test ./core/itg/cache/...
  • ./tools/bazel test //core/itg/cache:cache_test --test_output=errors
  • make gazelle
  • aifx verify
  • go test ./... passes outside integration tests; integration requires TANGO_REPO_REMOTE

Revert Plan

Revert the commits from this PR to restore the previous ITG cache-key format.

Jira Issues

None.

@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.

@xytan0056

Copy link
Copy Markdown
Contributor

ITG local cache is designed for disk path lookup.

Comment thread core/itg/cache/cache.go Outdated
sbalabanov-zz and others added 2 commits August 3, 2026 21:27
…motes

toStorageKey used filepath.Join to construct cache keys, which collapses
double slashes in URL-style remotes (e.g. "https://github.com/x" becomes
"https:/github.com/x") and uses platform-dependent separators. FloorKey
used string concatenation preserving the original remote. This mismatch
meant FloorKey could never discover entries written for URL-style remotes.

Replace filepath.Join with explicit string concatenation in toStorageKey
so both paths produce identical key prefixes. Pre-fix URL-remote entries
were already undiscoverable by FloorKey, so nothing is lost.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@sbalabanov
sbalabanov force-pushed the audit/fix-13-itg-key-mismatch branch from 28783de to f53448d Compare August 3, 2026 21:31
@sbalabanov sbalabanov changed the title fix(itg): build cache keys consistently with list prefixes for URL remotes (audit #13) fix(itg): encode remotes in filesystem-safe cache keys (audit #13) Aug 3, 2026
@sbalabanov
sbalabanov marked this pull request as ready for review August 3, 2026 21:32
@sbalabanov
sbalabanov requested review from a team as code owners August 3, 2026 21:32
@sbalabanov

Copy link
Copy Markdown
Contributor Author

ITG local cache is designed for disk path lookup.

Nothing in the ITG cache contract says that. The very general ITG cache needs to be distributed, with local caching as an optimization.

Comment thread core/itg/cache/cache.go Outdated

// encodeRemote returns a filesystem-safe, reversible remote key component.
func encodeRemote(remote string) string {
return base64.RawURLEncoding.EncodeToString([]byte(remote))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

encode so that when name characters can be preserved, they are preserved, base64 hides the name

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Switched remote encoding from Base64 to URL path escaping in 1e95661. This preserves recognizable remote characters while escaping each slash as %2F, so the remote remains one reversible path component. The tests now assert the exact readable encoding and round-trip decoding.

[addressed by agent]

@sbalabanov
sbalabanov merged commit 775d7b8 into main Aug 4, 2026
9 of 10 checks passed
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