Skip to content

fix(version): keep the npm version check from blocking commits when offline - #597

Merged
di-sukharev merged 1 commit into
di-sukharev:masterfrom
brianrobt:fix/version-check-offline-delay
Nov 11, 2026
Merged

di-sukharev merged 1 commit into
di-sukharev:masterfrom
brianrobt:fix/version-check-offline-delay

Conversation

@brianrobt

@brianrobt brianrobt commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #347. Likely also addresses #311, which was noted as the same symptom.

Problem

Every normal oco run awaits the npm registry version check before
generating a commit message. The request had no timeout, so with no
internet (for example when using a local provider such as Ollama) the
CLI could hang for a long time before doing any work.

Changes

  • Add a 2 second abort timeout to the registry request in
    src/version.ts, so the check is strictly best-effort.
  • Cache the result in ~/.opencommit-version.json, next to the existing
    ~/.opencommit-models.json:
    • successful checks are reused for 24 hours;
    • failed checks are not retried for 30 minutes, so offline runs pay
      the timeout at most once per window;
    • the last known latest version is kept across failed checks, so the
      update notice still works offline.
  • Ignore the cache when the installed version changes, so upgrading
    does not leave a stale update notice.
  • checkIsLatestVersion now uses the cached lookup.

This follows the implementation suggested in the issue thread and
builds on #573.

Tests

test/unit/version.test.ts adds a regression test for a registry that
never responds, plus cache tests: hit, expiry, failed-check window,
offline fallback, installed-version change, and a corrupt cache file.

npm run test:unit, npm run lint and npm run format:check pass
locally.

Introduce a disk-based cache and a network timeout for the npm
registry version check to avoid blocking commit generation when
offline or using a local provider like Ollama (see di-sukharev#347).

- Add `resolveLatestVersion` that wraps `getOpenCommitLatestVersion`
 with a file-based cache stored in `~/.opencommit-version.json`
- Successful checks are cached for 24 hours; failed checks are
 cached for 30 minutes to avoid repeated timeouts on every run
- When offline, fall back to the last known latest version from
 the cache so the update prompt still works after a prior check
- Add a 2-second `AbortSignal` timeout to the fetch call so a
 hanging registry never blocks the CLI startup path
- Invalidate the cache when the installed version changes
- Update `checkIsLatestVersion` to use `resolveLatestVersion`
- Add comprehensive unit tests covering cache hits, misses,
 expiry, fallback, version change and corrupt cache scenarios
@di-sukharev
di-sukharev merged commit 9e81087 into di-sukharev:master Nov 11, 2026
5 checks passed
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.

[Bug]: 70 seconds delay before proceeding if using ollama option with no internet

2 participants