Skip to content

fix(refs): the persisted latest_tags cache is an offline fallback, never fresh data - #108

Merged
github-actions[bot] merged 1 commit into
mainfrom
feat/latest-tag-offline-fallback
Sep 6, 2026
Merged

github-actions[bot] merged 1 commit into
mainfrom
feat/latest-tag-offline-fallback

Conversation

@atrawog

@atrawog atrawog commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Summary

The persisted cache: git: latest_tags cache (the per-host charly.yml) is re-contracted as an OFFLINE FALLBACK, never fresh data — the root fix for the plugin-resolution staleness anomaly: a fresh run minutes after v2026.249.2212 was tagged still resolved plugin-deploy-pod to the stale v2026.242.0932 ("latest tag").

Root cause (R1)

GitClient loads the persisted latest_tags map at construction and served any entry younger than LatestTagTTL (1h) as fresh — so every new process within the TTL served a tag list up to an hour old. GitLatestTag itself sorts by CalVer correctly (fetch-order was never the bug); the 1h persisted-TTL reuse was. The original TTL rationale (the 152-concurrent-ls-remote throttling storm) is a WITHIN-ONE-PROCESS batch problem the in-process cache already solves; cross-process, resolution correctness outranks throttling (tags in this org land minutes apart).

New contract

  • In-process cache (1h TTL): unchanged — the batch-dedupe layer.
  • Persisted latest_tags entries load into a separate persistedTags map and are served ONLY when the network fetch fails (offline tolerance, loud stderr line). A fresh process with a reachable network ALWAYS re-probes.
  • save() writes the union (fresh values winning) so a save that never fetched a repo preserves its fallback entry.
  • ClearCache/CacheStatus/WarmUp updated to the split model (fallback entries don't count as warm).

How tested

$ go build ./refs/ && go vet ./refs/
build=0 vet=0
$ go test -count=1 ./refs/
ok  	github.com/opencharly/spec/refs	11.099s
$ go test -count=1 ./...
exit=0   (18 packages ok — refs, proc, transport, spec, ...)

New tests (refs/latest_tag_fallback_test.go, all fail without the change):

  • TestLatestTag_PersistedEntryIsOfflineFallbackOnly — persisted v2026.242.0932 + reachable network → fresh v2026.249.2212 returned and persisted (the anomaly repro).
  • TestLatestTag_OfflineFallbackOnFetchFailure — failed fetch → persisted tag served.
  • TestLatestTag_FetchFailureWithoutFallback — no fallback → error propagates.
  • TestLatestTag_InProcessBatchDedupeStays — two lookups, one fetch (dedupe intact).
  • TestGitClientCacheAndPersist updated: the persisted latest tag loads as fallback, never into the fresh cache (the old assertion WAS the bug's contract).

Rulebook compliance

  • R0: skills loaded per dispatcher (git-workflow, root-cause-analyzer, go) before acting.
  • R1: full RCA above — mechanism (persisted-TTL-as-fresh), missed control (fresh-process re-probe), blast radius (every fresh charly process resolving version-less @github refs), root fix (offline-fallback re-contract). No remediation preceded it.
  • R2: the whole cutover in one PR — load, serve, save, clear, status, warm-up, docs (freshness-policy + TTL comment blocks), and tests all moved to the new model; no partial rename.
  • R3: one canonical freshness model; the fetch seam (gitLatestTagFetch) is the single injection point; no copy of the cache logic added.
  • R4: no workaround — the fix changes the serving contract, not a TTL knob; no sleeps/retries added. The offline fallback is a declared resilience behavior, loud on stderr, not a silent fallback branch.
  • R4a: the freshness-policy doc claimed "a long TTL is safe" — the code held the intent (correctness); the prose was wrong and is fixed WITH the code.
  • R5: the old contract ("persisted entries served within TTL") is deleted outright, including the test that asserted it and both doc blocks that described it. No shim remains.
  • R6: git status inspected; feat branch; no force-push, no hook bypass, no direct main push.
  • R7: coverage that fails without the change (proven: the repro test asserts the fresh-tag outcome the pre-fix code could not produce); commands, outputs, exit codes retained above.
  • R8: the persisted cache file is a user-visible artifact — its write path (union semantics, version stamp) is exercised by the updated round-trip tests.
  • R9: n/a — no binary packaging change (library-only).
  • R10: full go test -count=1 ./... green on the final committed tree from a checkout outside /tmp (the proc package's $TMPDIR-premise tests require it — environmental, documented in the test output itself).

Change classification

  • Class: Go library behavior fix (spec/refs git-layer freshness contract) + tests.
  • Verification gate: go build/go vet/go test -count=1 ./... (the spec-module Go gate), pasted above.
  • Attribution tier: fully tested and validated (full gate green on the final tree; changed path executed via the new tests).

Assisted-by: pi openrouter/deepseek/deepseek-v4-flash-0731 (fully tested and validated)

…ver fresh data

A fresh process served a persisted latest-tag entry for the whole 1h TTL —
a run minutes after a tag push resolved plugin refs to the stale tag
(v2026.242.0932 served after v2026.249.2212 landed). GitLatestTag sorts
correctly; the persisted-TTL-as-fresh model was the bug.

New contract: the in-process 1h cache stays the batch-dedupe layer; the
persisted entries load into a separate persistedTags map and are served
ONLY when the network fetch fails (loud stderr, offline tolerance). save
writes the union (fresh wins); clear/status/warm-up follow the split.
Docs (freshness policy + TTL block) re-written with the contract.
@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown

Review — PASS

Head SHA: 64282fe8caa2e4ec484cfc34989e85f8991feeca (branch: feat branch, base f9c12472faaa)

Security screen: PASS — no scope mismatch (diff matches the described load/serve/save/clear/status/docs/tests cutover), no secrets/exfiltration, no new deps, no weakened guardrails, no embedded directives. The gitLatestTagFetch package var is a legitimate test seam.

Checklist: All applicable rules PASS or NA.

  • A1/A2/A3: Body is complete with summary, RCA, new contract, pasted gate output (go build/go vet/go test -count=1 ./... all green), rulebook compliance, and the *Assisted-by: pi openrouter/deepseek/deepseek-v4-flash-0731 (fully tested and validated)* footer. Tier justified — the changed LatestTag path executes via the new repro tests.
  • R1: Real RCA (persisted-TTL-as-fresh), no forbidden framing. The "environmental" mention in R10 explains a test premise (proc's $TMPDIR requirement), not a dismissed failure — output is green.
  • R2/R3/R4/R5: One atomic cutover; single canonical freshness model via mergedLatestTags; no workaround (contract change, not a TTL knob); old contract deleted outright including the asserting test and both doc blocks.
  • R10: Full go test -count=1 ./... green; new tests fail without the change (repro asserts the fresh-tag outcome the pre-fix code could not produce); in-process dedupe preserved.
  • Architecture: placement CORRECT — a bug fix to existing core refs git-client code, no new capability moved into core, no alias growth, no new sdk-kit import.
  • B18: Diff is gofmt-clean, no dead code or lint-visible issues.

Minor note (non-blocking): the body claims "WarmUp updated to the split model" but no WarmUp hunk appears in the diff; since CacheStatus now uses mergedLatestTags and the change is otherwise coherent and fully tested, this is a bookkeeping overstatement, not a material defect.

Verdict: PASS


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

View action run

@github-actions
github-actions Bot enabled auto-merge (squash) September 6, 2026 22:31
@github-actions
github-actions Bot merged commit e1f6b61 into main Sep 6, 2026
2 checks passed
charly-auto-merge Bot added a commit that referenced this pull request Sep 6, 2026
atrawog added a commit that referenced this pull request Sep 7, 2026
…ack (the #108 warm-up-hang regression) (#109)

#108 (the offline-fallback cutover) moved the persisted latest_tags entries
from fresh-data-with-TTL to OFFLINE-FALLBACK-ONLY — correctly, fixing the
stale-latest-tag bug — but WarmUp's cold-check kept consulting ONLY the
in-process maps. Those start empty in every fresh process, so every project
load re-probed the ENTIRE collected corpus (measured live: 193-194 repos x 2
ls-remote ops per process, on a host whose persisted cache already held 316
latest_tags + 279 default_branches entries). The pre-#108 model served the
persisted entry as fresh, so the prefetch found ~1 cold repo and returned
instantly — which is why the old runs passed.

Under concurrent bed runs the re-probe fanout (10 warm-up workers x N
processes) trips GitHub's documented throttling threshold (the 152-concurrent-
ls-remote storm this very layer was built to prevent), and every throttled
fetch then burns its 30s-deadline x 3 bounded retries — a 23s warm-up
(measured, healthy network) stretching into tens of minutes per process: the
observed deterministic hang at 'fetching git metadata for 194 repo(s)'.

The fix restores the prefetch to a UX batch, never a resolution: a repo whose
PERSISTED latest_tags fallback has an entry is prefetch-warm. The freshness
contract is untouched — the on-demand LatestTag path still re-probes the
network in every fresh process (the offline-fallback tests keep guarding it);
a repo pinned at immutable tags never resolves a latest tag at all, so for
those repos the probe was pure waste. A genuinely cold repo (no persisted
entry) still prefetches, unit-pinned.

Co-authored-by: atrawog <[email protected]>
@aitrawog
aitrawog deleted the feat/latest-tag-offline-fallback 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.

1 participant