cache: add WriteEnvelope verbatim atomic writer (MON-5369 §5 first-port generalization)#20
Merged
Merged
Conversation
The §5 first-port generalization (MON-5369, jtk cache). Tier-1 had no way to persist an envelope verbatim: WriteResource always re-stamps FetchedAt, so an invalidation "stale marker" (FetchedAt zeroed) could not survive a round-trip. jtk's Touch/writeRaw needs exactly this. WriteEnvelope writes a caller-supplied envelope verbatim (FetchedAt/TTL/ Version preserved), using env.Resource as the name and requiring env.Instance == loc.InstanceKey — because ReadResource treats a resource/instance mismatch as a miss, it refuses (ErrInstanceMismatch, nothing written) to persist an envelope the next read would reject. WriteResource now delegates to it (behavior unchanged: still stamps a fresh FetchedAt). Purely additive; existing API and go.mod/go.sum untouched. [MON-5369]
rianjs
added a commit
that referenced
this pull request
May 20, 2026
…ore-close [MON-5375] (#22) * docs(state): finalize §6 step 6 + tier-2 deferral for INT-310 tag-before-close [MON-5375] Adds §6.6 close-out retrospective: 5 of 6 port units shipped (jtk-cache, Atlassian shared config, gro, slck, nrq); sfdc parked and explicitly excluded from the v0.1.0 train (no cli-common dependency today). Commons API additions during the rollout: cache.WriteEnvelope (#20) and underscore in the cache-component regex (#21). Both additive; no breaking change required across 5 ports. Codifies the ten reusable patterns that emerged across the matrix: mutation-free Detect/Apply split, Load/LoadForRuntime + cfg!=nil contract, unexported xxxFromNewDir testable seam, malformed-old fails loud before CopyNeeded, companion-plaintext-file dual-probe with parsed-projection equality, 7-var statedirtest.Hermetic, the cleanup- command recovery contract (cleanup must not be blocked by the broken state it exists to wipe), init-gate ordering proof, reflect.DeepEqual on default-applied Config, path-identity dedup. Reaffirms §5b tier-2 deferral: only jtk needs the registry/DAG/fetcher shape today (gro uses tier-1 only; cfl has no cache). Promoting from one consumer would just relocate jtk code. Re-evaluate when cfl gains a cache. Closes #19 * fixup: Codex r1 factual corrections - Atlassian PR numbers: #371→#373 (MON-5369 jtk-cache), #372→#374 (MON-5370 shared config). SHAs were already correct. - Pattern 5 (companion-secret-file dual-probe): format-dependent equality, not a single rule — text key=value uses parsed projection (nrq); opaque blobs use trimmed raw serialized value (gro's token.json). Generic shape described as old/new candidate enumeration + path-identity dedup, not nrq's specific helper trio. - Pattern 9 (material equality): use whole-struct DeepEqual on default-applied Config ONLY when every field is directly comparable and user-meaningful (slck/nrq); build an explicit projection when fields need semantic normalization (gro: OAuthClientPath default equivalence, sorted GrantedScopes). - §5b tier-2 reaffirmation: "second tier-2-shape consumer," not "third" (the criteria are ≥2 consumers). * fixup: Codex r2 — pattern 5 conditional cleanup-helper rule; pattern 9 typo * fixup: Codex r3 nit — narrow gro cleanup-scope wording
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Prerequisite (PR-A) for MON-5369 (jtk cache → cli-common, working-with-state.md §6.4 unit 1). The §5 release-train guardrail's "first port surfaces a tier-1 constraint that generalizes" case — pre-blessed by the architect session.
Why
jtk's
Touchmarks a cache stale by writing an envelope withFetchedAtzeroed. Tier-1 had no verbatim writer:WriteResourcealways re-stampsFetchedAt=now, and the path composer is unexported — so jtk could not expresswriteRawagainst cli-common without duplicating atomic-write + path validation (divergence risk).What (purely additive)
WriteEnvelope[T](loc Locator, env Envelope[T]) error— writes a caller-supplied envelope verbatim (FetchedAt/TTL/Version preserved). Usesenv.Resourceas the resource name; requiresenv.Instance == loc.InstanceKey. BecauseReadResourcetreats a resource/instance mismatch asErrCacheMiss,WriteEnveloperefuses to write a self-inflicted miss: a mismatch returns the newErrInstanceMismatchand writes nothing.WriteResourcenow delegates toWriteEnvelope— behavior unchanged (still stamps a fresh non-zeroFetchedAt; regression-tested).go.mod/go.sumbyte-identical (themake checktidy gate enforces this).Tests
Verbatim zero-
FetchedAtround-trip (readable, not a self-inflicted miss);env.Instance != loc.InstanceKey⇒ErrInstanceMismatch, nothing written; unsafeenv.Resource⇒ErrInvalidName;WriteResourcestill stampsFetchedAt.make checkgreen (lint 0,-raceall packages incl. credstore).Review note
Architect session 019e4019 prescribed this exact identity-safe contract during MON-5369 plan review (round 1). Codex quota is temporarily exhausted; per the workstream's Codex policy it does not block — the same session will review this diff alongside PR-B (jtk) once quota resets.
[MON-5369]