Skip to content

fix(notice): ignore a cached answer written by a different binary - #35

Closed
sunny-wego wants to merge 1 commit into
mainfrom
claude/foundations-issues-audit-7ug0hz
Closed

sunny-wego wants to merge 1 commit into
mainfrom
claude/foundations-issues-audit-7ug0hz

Conversation

@sunny-wego

Copy link
Copy Markdown
Collaborator

Candidate for v1.2.5. Fixes a false notice reported from the field on 1.2.4, and closes the gap that #33 structurally could not.

The report

$ wego version
1.2.4
Your wego channel now serves 1.2.3 (you have 1.2.4). Run `wego update -y`.
$ wego update
Already up to date (1.2.4, ring stable).
$ cat ~/.config/wego/.update-check
1.2.3

The ring was correct throughout — the 1.2.4 promote finished green and update agreed. The lie was local. .update-check still held the answer read while cli/stable served 1.2.3, and the throttle governs the network read, not the message, so the notice reported that answer for the whole window without re-fetching.

Why #33 could not fix this

#33 deletes the file after a swap, from update.ts — which runs in the binary performing the swap. The swap here was performed by 1.2.3, which predates that code.

A write-side fix only ever covers users whose previous binary already had it. Same shape as the 1.2.0 user-agent bug: the fixer has to be the old version.

And it never covers a reinstall at all

curl … | sh replaces the binary and writes only install.json — I checked renderInstallScript, there is no other write. update.ts doesn't run, so nothing on that path clears the cache.

That matters more than it first looks. Reinstalling is the only recovery for a stranded 1.2.0 install, and a 1.2.0 binary is pinned to the legacy bridge, so its notice cached 1.1.0. Reinstall it onto 1.2.4 and it says "your channel now serves 1.1.0" indefinitely. The recovery path was the worst-affected one.

The fix: move the check to the reader

.update-check becomes two lines — the channel's answer, then the version that wrote it — and a cache whose stamp isn't the running version is ignored. The reader doesn't care how the binary changed, so it covers update, reinstall and manual copy alike.

Both directions of the format change were measured, not assumed:

old build reads a two-line file looksLikeVersion("1.2.4\n1.2.3") → false → silent, not a mangled version
new build reads a one-line file no stamp → "not mine" → ignored — the right answer for every file in the field today

So it degrades to a missed notice, never a false one, and every stale cache self-heals on first run.

Suppressed for reporting, remembered for throttling

Deliberate, and the alternative is worse. Falling through to a fresh fetch would be one command more correct — and would re-fetch on every command for a whole window whenever that fetch fails, which is the per-invocation network call the skipped-unclaimable path already exists to avoid.

Honouring the throttle costs at most one window of silence. A missed notice is the right failure here: the bug being fixed is a notice that was confidently wrong. It self-heals at the next window, when the normal path fetches and stamps.

#33's delete-on-swap stays. The two are complementary — deletion saves a read on the common path, the stamp covers every path deletion cannot reach.

Tests

Three fail against shipped 1.2.4, including the field report reproduced exactly:

(fail) buildVersionNoticeDeps > round-trips the stored answer and the throttle stamp
(fail) a cache written by another binary > says nothing rather than announcing a rollback that did not happen
(fail) a cache written by another binary > ignores a pre-stamp cache, which is what a reinstall leaves behind

Two are guards, labelled as such: a cache that is this binary's own must still report (or the change would silence every legitimate throttled notice), and a pre-stamp file must read back with writtenBy undefined.

The shared stored() fixture now stamps with the version under test by default, so the existing throttle and network tests keep measuring throttling rather than accidentally measuring staleness.

Check Result
bun test 1486 pass, 1 fail (the known root-permissions skill.test.ts case, which fails on a clean tree too)
bun run typecheck clean
bun run lint 8 warnings / 1 info, the existing baseline

For anyone already seeing it

rm ~/.config/wego/.update-check clears it now. Otherwise it expires with the window, and this release prevents it recurring.

Refs #33.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Tna7gh6pBHkr8zFHL3BqFs


Generated by Claude Code

Reported from the field on 1.2.4, on every command:

    $ wego version
    1.2.4
    Your wego channel now serves 1.2.3 (you have 1.2.4). Run `wego update -y`.
    $ wego update
    Already up to date (1.2.4, ring stable).
    $ cat ~/.config/wego/.update-check
    1.2.3

The ring was correct throughout - the 1.2.4 promote finished green and `update`
agreed. The lie was local: `.update-check` still held the answer read while
`cli/stable` served 1.2.3, and the throttle governs the network READ rather than
the message, so the notice reported that answer for the whole window without
re-fetching.

WHY THE EXISTING FIX COULD NOT COVER IT. #33 deletes the file after a
swap, from `update.ts` - which runs in the binary PERFORMING the swap. The swap
here was performed by 1.2.3, which predates that code. A write-side fix only ever
covers users whose PREVIOUS binary already had it, which is the same shape as the
1.2.0 user-agent bug.

AND IT NEVER COVERS A REINSTALL AT ALL. `curl … | sh` replaces the binary and
writes only `install.json` (`apps/api` `renderInstallScript` - checked, there is
no other write). `update.ts` does not run, so nothing on that path clears the
cache. That matters because reinstalling is the ONLY recovery for a stranded
1.2.0 install, and a 1.2.0 binary is pinned to the legacy bridge, so its notice
cached 1.1.0 - reinstall it onto 1.2.4 and it says "your channel now serves
1.1.0" forever. The recovery path was the worst-affected one.

So the check moves to the READER, which does not care how the binary changed.
`.update-check` becomes two lines - the channel's answer, then the version that
wrote it - and a cache whose stamp is not the running version is ignored.

Both directions of the format change were measured, not assumed:

  old build reads two lines   `looksLikeVersion("1.2.4\n1.2.3")` is false, so it
                              goes silent rather than reporting a mangled string
  new build reads one line    no stamp -> "not mine" -> ignored, which is the
                              right answer for every file in the field today

SUPPRESSED FOR REPORTING, REMEMBERED FOR THROTTLING. Falling through to a fresh
fetch would be one command more correct and would re-fetch on EVERY command for a
whole window whenever that fetch fails - the per-invocation network call the
unclaimable path already exists to avoid. Honouring the throttle costs at most one
window of silence, and a missed notice is the right failure here: the bug being
fixed is a notice that was confidently wrong. It self-heals at the next window,
when the normal path fetches and stamps.

The delete-on-swap from #33 stays. The two are complementary - deletion saves a
read on the common path, the stamp covers every path deletion cannot reach.

Verified: three tests fail against shipped 1.2.4 and pass here, including the
field report reproduced exactly. Two more are guards - a cache that IS this
binary's own must still report, and the pre-stamp file must read back with no
writer. `bun test` 1486 pass / 1 fail (the known root-permissions
`skill.test.ts` case, which fails on a clean tree too); typecheck clean; lint at
the 8-warning / 1-info baseline.

```release-note
`wego` no longer reports a stale release-channel version after an update or a
reinstall, which could wrongly claim the channel had been rolled back.
```

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tna7gh6pBHkr8zFHL3BqFs

Copy link
Copy Markdown
Collaborator Author

Closing without merging. The approach is superseded by a simpler one: stop caching the answer at all.

Why

.update-check does two jobs, and only one is load-bearing:

Job Mechanism Needed for
when did we last ask the file's mtime throttling the network read — the real purpose
what did it say the file's content repeating the notice on every command inside the window

Everything this PR added — the two-line format, writtenBy, the reader-side guard, the fixture stamping — exists to keep the second job honest. So does #33's delete-on-swap. The throttle needs none of it.

Guarding a cache whose other comparison input can change underneath it is a losing position, and today made that concrete: three defects in one afternoon, all in this area, each one a fix for the previous fix.

What replaces it

The file becomes a pure timestamp. Nothing is stored, so nothing can go stale, and the bug class is deleted rather than defended against. writeLatest, UpdateCheckState.latest, writtenBy, the known plumbing, #33's deletion and roughly five tests about persisting, clearing and not-corrupting the stored answer all go with it.

The behaviour change, stated plainly: you are told about a new version once per window rather than on every command inside it. That persistence is a real thing being given up — the original comment called it out as deliberate, "a stale install keeps being told, for free". "For free" was the false economy: free in network terms, expensive in correctness terms.

The diagnosis in this PR still stands and is worth keeping in the record — a cache written by one binary and read by another describes a comparison that no longer holds, and curl … | sh writes only install.json, so no write-side fix can ever cover a reinstall. The conclusion changed, not the analysis.

Superseded by the follow-up PR.


Generated by Claude Code

@sunny-wego sunny-wego closed this Sep 14, 2026
sunny-wego pushed a commit that referenced this pull request Sep 14, 2026
`.update-check` did two jobs and only one was load-bearing:

  mtime    when we last asked      -> throttles the network read. The real point.
  content  what the channel said   -> lets the notice repeat on every command
                                      inside the window.

Everything that has gone wrong in this area today was the second job.

A stored answer is HALF of a comparison. The other half - the running version -
changes on every update and every reinstall, and this file can observe neither.
Defending that position cost three defects in one afternoon: the reinstall-hint
misfire, the delete-on-swap that only helps when the PREVIOUS binary already had
it (#33), and the two-line `writtenBy` stamp meant to cover what deletion
structurally cannot (#35, now closed). Each was a fix for the one before it.

So the cache goes. The file is a timestamp; its content is never written and
never read. Nothing is stored, so nothing can go stale, and the bug class is
deleted rather than guarded.

WHAT CHANGES FOR A USER. The notice fires ONCE per window - on the command that
crosses it - instead of on every command inside it. That persistence was
deliberate ("a stale install keeps being told, for free"), and "for free" was the
false economy: free in network terms, expensive in correctness terms. Being told
once a day is a reminder; being told fifty times a day is noise. The narrow loss
is a message missed because its one invocation had stderr discarded.

REMOVED: `writeLatest` and its atomic write-then-rename, `UpdateCheckState.latest`,
the `known` plumbing, `update.ts`'s delete-on-swap and its `updateCheckPath` dep,
and `readChannelVersion`'s three-way return - `""` on a 404 versus `null` on
everything else existed only to decide what could overwrite storage, so a
distinction that no longer changes behaviour is gone too.

`cached` is renamed `throttled`, because nothing is cached and a reader should
not have to discover that.

TESTS: about ten disappear because the behaviour they pinned does not exist -
round-tripping the answer, clearing it on a 404, keeping it on a 5xx, not
corrupting it with a garbage body, not truncating it on claim, still nagging when
the write fails. Four of those collapse into one case asserting the single rule
that replaced them: every way of not knowing is silence. One is added, pinning
the file's emptiness as the design rather than an oversight, so reintroducing a
write means deleting a test that says why not to.

Net 299 deletions against 108 insertions.

VERIFIED ON A REAL BINARY, not only in units - a 1.2.5 build against a loopback
channel serving 1.9.9:

    run 1   A new wego is available: 1.2.5 -> 1.9.9. Run `wego update -y`.
    run 2   (silent)
    run 3   (silent)
    requests made: 1        .update-check: 0 bytes

`bun test` 1472 pass / 1 fail (the known root-permissions `skill.test.ts` case,
which fails on a clean tree too); typecheck clean; lint at 7 warnings / 1 info,
one BELOW the 8-warning baseline on main.

```release-note
`wego` now mentions a new release once a day rather than on every command, and no
longer reports a version it read before the binary changed underneath it.
```

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tna7gh6pBHkr8zFHL3BqFs
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.

2 participants