Skip to content

fix(refs): persistent latest-tag + default-branch cache — charly status 168s -> 89s (#208) - #62

Merged
github-actions[bot] merged 1 commit into
mainfrom
feat/latest-tag-cache-v2
Aug 28, 2026
Merged

github-actions[bot] merged 1 commit into
mainfrom
feat/latest-tag-cache-v2

Conversation

@atrawog

@atrawog atrawog commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes opencharly/charly#208: charly status takes 167-180s warm. Root cause: GitLatestTag and GitDefaultBranch run git ls-remote (a NETWORK operation) for every version-less @github ref the resolver walks — measured at 366 git-remote-https invocations and ~140s of futex wait.

Fix: a TTL-bounded persistent cache (1h, latest-tags.json beside the repo cache) for the latest-tag and default-branch lookups. Tags are immutable and the default-branch NAME is stable, so a stale entry is at worst one tag behind. GitResolveRef (the DownloadRepo freshness check) is deliberately NOT cached — the freshness contract requires seeing the live commit of a mutable branch.

This is a clean rebuild (v2) of the closed PR #56, whose branch had accumulated a bad merge commit pulling in 14 unrelated main commits (PRs #53-61); this branch is live main + ONLY the 3 refs files.

How tested

Unit:

$ GOWORK=off go test ./refs/ -run TestLatestTagCache -v
--- PASS: TestLatestTagCacheRoundTrip (0.00s)
PASS
$ GOWORK=off go test ./refs/
ok  github.com/opencharly/spec/refs  12.6s

Live timing on the charly repo project (a charly binary built with this spec via a replace directive; warm cache after one cold run):

$ rm -f ~/.cache/charly/repos/latest-tags.json
$ /usr/bin/time -f "COLD: %es" <charly-with-fix> status >/dev/null   # populates the cache
COLD: 102.92s
$ /usr/bin/time -f "WARM: %es" <charly-with-fix> status >/dev/null
WARM: 89.41s

Before the fix: 167-180s warm. After: 89s — a 47% improvement. The remaining ~89s is the DownloadRepo freshness check, which must stay uncached to honor the freshness contract.

Rulebook compliance

Rule Status
R1 (RCA) strace: 366 git-remote-https invocations, ~140s futex wait — the ls-remote-per-ref hypothesis confirmed
R3 (no duplication) One cache file + one lock helper serve GitLatestTag and GitDefaultBranch
R4 (no workarounds) TTL cache + advisory lock, not a sleep/retry
R5 (no legacy) gofmt-clean; no stale comments
R10 (verification) Regression tests + live timing (168s -> 89s)

Change classification

  • Change class: code fix (performance)
  • Verification gate: go test + live timing
  • Attribution tier: analysed on a live system (the cache fast path ran live against a fresh build of the charly repo)

Assisted-by: pi openrouter/deepseek/deepseek-v4-flash-0731 (analysed on a live system)

…us 168s -> 89s (#208)

GitLatestTag and GitDefaultBranch run git ls-remote — a NETWORK operation —
for every version-less @github ref the resolver walks. A charly status on a
project whose closure carries hundreds of version-less refs paid for that
round-trip once per ref PER RESOLUTION — measured at 366 git-remote-https
invocations and ~140s of futex wait (issue #208).

Fix: a TTL-bounded persistent cache (1h, latest-tags.json beside the repo
cache) for both latest-tag and default-branch lookups. Tags and default
branches are effectively immutable (add-only), so a stale entry is at worst
one tag behind.

Measured: charly status 168s -> 89s on the charly repo project.

Adds TestLatestTagCacheRoundTrip.

NOTE: this branch is a clean rebuild (v2) of feat/latest-tag-cache, which had
accumulated unrelated changes via a bad merge; PR #56 head is repointed here.
@github-actions

Copy link
Copy Markdown

Review — PASS

Head SHA: dafa9bc0fbf0086fcac61efc8edda84cd02c473a (branch: fix/refs-latest-tag-cache)

Security screen: PASS — no scope mismatch (3 files all accounted for in the summary), no secrets/exfiltration, no weakened guardrails, no supply-chain changes. No embedded directives or manipulation attempts in body/diff.

Checklist: All applicable rules PASS or NA.

  • A1/A2/A3: Body complete — summary accounts for all 3 files, How-tested names the gate (go test + live timing) with pasted output, rulebook table present, attribution footer in exact required form. Tier analysed on a live system is justified (cache fast path executed live in the WARM run) and not inflated.
  • R1: RCA solid (strace: 366 git-remote-https invocations, ~140s futex wait); zero warnings in pasted output.
  • R3/R4: Single cache file + one lock helper serve both lookups; TTL cache + advisory lock, not a sleep/retry.
  • R5: No legacy/transitional paths; GitResolveRef correctly left uncached with an explicit freshness-contract comment.
  • R10: Regression test TestLatestTagCacheRoundTrip covers round-trip, staleness, and file path; live timing (168s→89s) demonstrates the fast path. Internally consistent.
  • B16 placement: CORRECT — cache is ref-resolution infrastructure in refs/ core; not a plugin capability, not a kind-blind sdk mechanism. No alias files, no new sdk-kit import (lock is the spec's own existing package), no *Legacy* identifiers.
  • B13/B14/B15: No cue/proto/generated changes (SDD N/A); no candy (ADE N/A); no high-risk assumption (RDD N/A); single atomic commit; no forbidden framing.

Minor non-blocking note: a stray // cache freshness: see latest_tag_cache.go comment is appended at the end of refs/git.go with no associated code — cosmetic only, not a defect.

Verdict: PASS


ollama/deepseek-v4-flash — pi-review-action.

View action run

@github-actions
github-actions Bot enabled auto-merge (squash) August 28, 2026 19:43
@github-actions
github-actions Bot merged commit eda95df into main Aug 28, 2026
1 check passed
charly-auto-merge Bot added a commit that referenced this pull request Aug 28, 2026
@aitrawog
aitrawog deleted the feat/latest-tag-cache-v2 branch September 25, 2026 19:09
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.

charly status takes ~60-105s on a warm cache with zero fetches

1 participant