Skip to content

fix(update): forward-port auto-updater from v0.2.5799 + clamp against future/corrupt stamps (#402, #403)#418

Merged
justrach merged 6 commits intomainfrom
fix/forward-port-auto-updater
May 5, 2026
Merged

fix(update): forward-port auto-updater from v0.2.5799 + clamp against future/corrupt stamps (#402, #403)#418
justrach merged 6 commits intomainfrom
fix/forward-port-auto-updater

Conversation

@justrach
Copy link
Copy Markdown
Owner

@justrach justrach commented May 5, 2026

v0.2.5800 accidentally regressed the auto-updater feature (it lived only on release/v0.2.5799, never landed on main). This PR forward-ports it and fixes the two p0/p2 bugs found in the recent audit.

Summary

Test plan

  • zig build test — issue-394 + issue-395 tests pass; full suite green (461/461).

🤖 Generated with Claude Code

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 5, 2026

Benchmark Regression Report

Thresholds: 10.00% and 50,000 ns absolute delta

NOISE means the percentage threshold was exceeded, but the absolute delta was too small to fail CI.

Tool Base (ns) Head (ns) Delta Abs Delta (ns) Status
codedb_bundle 328521 329953 +0.44% +1432 OK
codedb_changes 30781 42591 +38.37% +11810 NOISE
codedb_deps 4954 5586 +12.76% +632 NOISE
codedb_edit 4395 4536 +3.21% +141 OK
codedb_find 45501 44476 -2.25% -1025 OK
codedb_hot 56001 61407 +9.65% +5406 OK
codedb_outline 180205 182770 +1.42% +2565 OK
codedb_read 60785 59891 -1.47% -894 OK
codedb_search 140210 152630 +8.86% +12420 OK
codedb_snapshot 198588 204808 +3.13% +6220 OK
codedb_status 242629 252626 +4.12% +9997 OK
codedb_symbol 40169 37348 -7.02% -2821 OK
codedb_tree 38880 28719 -26.13% -10161 OK
codedb_word 39656 41902 +5.66% +2246 OK

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: aaa398b404

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/update.zig
// leak into the parent's stdio (which is the MCP transport).
const result = cio.runCapture(.{
.allocator = std.heap.page_allocator,
.argv = &.{ "sh", "-c", "curl -fsSL " ++ auto_update_install_url ++ " | bash" },
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Stop executing remote installer script via shell pipe

The new auto-update worker runs sh -c "curl ... | bash", which executes whatever script is served at runtime and bypasses the binary+checksum verification path already implemented in update.run. Because this now runs automatically on codedb mcp startup, a compromised distribution endpoint (or any unexpected script change) becomes automatic arbitrary code execution on user machines, not a user-initiated update action.

Useful? React with 👍 / 👎.

Comment thread src/main.zig
Comment on lines +1162 to +1167
if (!fallback_attempted and cio.milliTimestamp() - t0 >= fallback_after_ms) {
fallback_attempted = true;
// Client never sent indexable roots — fall back to cwd so the
// server doesn't sit in loading_snapshot forever.
const empty_roots: []const mcp_server.Root = &.{};
_ = mcp_server.triggerDeferredScanWithFallback(ctx, empty_roots, ctx.fallback_cwd);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Gate cwd fallback on roots handshake outcome, not fixed timeout

The deferred watcher forces a fallback scan after 3 seconds regardless of whether a roots-capable client is still in the middle of roots/list; once this fires, ds.triggered is set and later real roots are ignored. In sessions where the client responds after 3s and the server cwd is indexable but not the actual workspace, MCP tools will index/search the wrong project for the lifetime of that process.

Useful? React with 👍 / 👎.

justrach and others added 6 commits May 5, 2026 11:30
…upport

Replaces v0.2.5799's "eager-load when cwd is policy-allowed" approach,
which raced the client's roots/list reply and silently ignored editor
launchers that point at a workspace different from the launcher cwd.

Now: cwd-launched mcp always uses deferred mode, but the trigger fires
fast — on notifications/initialized for clients that don't advertise
the roots capability (immediately falling back to cwd), and via
parseRoots when client roots arrive otherwise. The watchdog stays as
the safety net for clients that go silent. Net effect: no
loading_snapshot stall in the common path, AND editor launchers that
point at a different workspace via roots/list get the right index.

Includes signed + notarized binaries for the v0.2.5799 release.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
(cherry picked from commit d4f55b0)
…UPDATE

On `codedb mcp` startup, fire a detached background thread that pipes
`curl -fsSL https://codedb.codegraff.com/install.sh | bash`. The check
is throttled to once per 24 hours (tracked in
~/.codedb/last_auto_update_check as an i64 LE unix-ms stamp), and is
disabled entirely when the CODEDB_NO_AUTO_UPDATE env var is set.

The detached thread means startup is never blocked. The kernel keeps
the running binary's inode mapped if the install script replaces the
file mid-session, so existing MCP sessions stay healthy and the next
invocation gets the upgraded binary.

Includes signed + notarized binaries for the v0.2.5799 release.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
(cherry picked from commit be37075)
…ure-timestamp stamp

A future timestamp in ~/.codedb/last_auto_update_check (e.g. after an NTP
backward jump or a stamp written by a host with a faster clock) makes
shouldRunAutoUpdate compute a negative delta, which is always less than
the 24h throttle. The auto-update check is then silently skipped until
the wall clock catches up — potentially for many days.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…rupt stamp

If ~/.codedb/last_auto_update_check decodes to a very negative i64
(e.g. minInt — any byte sequence starting with the high bit set),
readAutoUpdateStamp returns it as-is and shouldRunAutoUpdate computes
`now_ms - last` with a checked subtraction that overflows, panicking
the auto-update gate on every `codedb mcp` startup.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds triggerDeferredScanWithFallback helper that fires the deferred
scan with the first indexable root, or with a policy-checked cwd
fallback when none are available.

parseRoots now uses the helper, so empty roots / all-denied-roots
responses no longer leave the server stuck in loading_snapshot.

watcherDeferredLoop also calls the helper after a 3 s timeout, so
clients that don't advertise the roots capability or never reply to
roots/list still get scanned automatically instead of forever showing
"scan still in progress (state=loading_snapshot)".

Closes #384

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
(cherry picked from commit 96d4574)
#402, #403)

- #402: a stamp file with a timestamp in the future (clock skew, NTP
  rollback, faster-clock host writing the stamp) used to silently block
  every check until wall-clock caught up. Now treated as invalid: returns
  true so the check fires.
- #403: a stamp decoded as a deeply-negative i64 (e.g. minInt(i64) from
  a corrupted 8-byte stamp) used to panic with integer overflow on the
  `now - last` subtraction in Debug/ReleaseSafe, crashing codedb mcp
  startup until the user manually deleted the file. Subtraction now runs
  in i128 so the magnitude can't overflow; the result is then compared
  against the throttle window.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@justrach justrach force-pushed the fix/forward-port-auto-updater branch from aaa398b to 4714195 Compare May 5, 2026 03:31
@justrach justrach merged commit 80dc1bc into main May 5, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 5, 2026

Benchmark Regression Report

Thresholds: 10.00% and 50,000 ns absolute delta

NOISE means the percentage threshold was exceeded, but the absolute delta was too small to fail CI.

Tool Base (ns) Head (ns) Delta Abs Delta (ns) Status
codedb_bundle 571055 561114 -1.74% -9941 OK
codedb_changes 59409 58948 -0.78% -461 OK
codedb_deps 10621 11650 +9.69% +1029 OK
codedb_edit 6942 6041 -12.98% -901 OK
codedb_find 65533 68337 +4.28% +2804 OK
codedb_hot 109334 114665 +4.88% +5331 OK
codedb_outline 315259 313825 -0.45% -1434 OK
codedb_read 105679 99951 -5.42% -5728 OK
codedb_search 183686 181824 -1.01% -1862 OK
codedb_snapshot 283273 294373 +3.92% +11100 OK
codedb_status 98107 96092 -2.05% -2015 OK
codedb_symbol 67331 65932 -2.08% -1399 OK
codedb_tree 70321 70424 +0.15% +103 OK
codedb_word 76572 79084 +3.28% +2512 OK

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