Skip to content

fix: allow extension to load when offline - #27

Merged
patlux merged 5 commits into
patlux:mainfrom
k3-2o:fix/offline-startup
Aug 2, 2026
Merged

fix: allow extension to load when offline#27
patlux merged 5 commits into
patlux:mainfrom
k3-2o:fix/offline-startup

Conversation

@k3-2o

@k3-2o k3-2o commented Jul 23, 2026

Copy link
Copy Markdown

Problem

Pi refuses to start when offline because fetchCommandCodeModels() at extension init throws when it can't reach the API. This blocks the entire editor with:

Error: Failed to load extension: Unable to connect. Is the computer able to access the url?

Trade-off

Models won't appear in the model selector until the user runs /reload after reconnecting. This is documented in the changelog.

Testing

  • 38/39 existing tests pass (1 pre-existing flaky abort-timing test)
  • Verified manually: pi starts offline without error, /reload repopulates models when online

The model fetch at startup throws and blocks pi from starting when
there's no network. Catch the error and register the provider with
an empty model list instead.
@k3-2o
k3-2o force-pushed the fix/offline-startup branch from 71f853a to 811f908 Compare July 23, 2026 10:19
@k3-2o

k3-2o commented Jul 23, 2026

Copy link
Copy Markdown
Author

Closing based on what was read in issue #5 and PR #6.

But based on their new v1, these guys are slowly becoming pi — funny as hell. Only fair they let pi use the Go plan if it's an inspiration source 🤷

@k3-2o k3-2o closed this Jul 23, 2026
StrayDragon added a commit to StrayDragon/pi-commandcode-provider that referenced this pull request Jul 31, 2026
Catch model fetch errors at startup so pi can start without network.
When offline, the provider registers with an empty model list.
Run /reload once connected to refresh the model catalog.

Incorporates upstream PR patlux#27 from @k3-2o.
@patlux patlux reopened this Aug 1, 2026
Persist the last valid Command Code model catalog and use it when live model discovery fails. Keep first-time offline startup non-fatal, surface clear warnings, and cover cached model selection with unit and pi integration regression tests.
@patlux

patlux commented Aug 1, 2026

Copy link
Copy Markdown
Owner

I reproduced the startup failure against both pi 0.75.5 and 0.82.1 by pointing COMMANDCODE_MODELS_URL at an unreachable local endpoint.

I pushed follow-up changes that make the fallback useful when Command Code is already selected:

  • cache the last validated model catalog at <agent-dir>/commandcode-models.json (~/.pi/agent/commandcode-models.json by default)
  • resolve the location through the host's getAgentDir(), so OMP uses its own agent directory and PI_CODING_AGENT_DIR is respected
  • keep COMMANDCODE_MODELS_CACHE as an explicit override for tests and custom setups
  • use the cached catalog when model discovery fails, so cached models remain selectable offline
  • keep a first offline start without a cache non-fatal and emit a clear warning
  • validate cache contents and write updates atomically
  • keep live models usable if the cache cannot be written
  • add unit coverage for network, HTTP, JSON, corrupt-cache, and write-failure cases
  • add real pi integration coverage for first offline startup, agent-directory path resolution, and selecting a cached model while discovery is offline
  • add OMP path coverage for its isolated agent directory
  • make the pi integration test hermetic with a temporary home, mock auth, and isolated agent directory

Validation:

  • npm test — pass (81 tests; OMP compatibility test skipped because omp is not installed)
  • pi 0.75.5 compatibility and PI_CODING_AGENT_DIR path resolution — manually verified
  • npm run format:check — pass
  • git diff --check — pass
  • npm pack --dry-run — pass

patlux added 2 commits August 2, 2026 01:37
Resolve the Command Code model cache through the host's getAgentDir helper so pi, OMP, and PI_CODING_AGENT_DIR use their own agent state directory instead of the official Command Code client directory.
Resolve GHSA-j3f2-48v5-ccww so npm audit --audit-level=moderate passes in CI.
@patlux
patlux self-requested a review as a code owner August 2, 2026 08:31
Assert the empty catalog path recovers live models and writes a cache once discovery is available again, including the real pi extension entrypoint used by /reload.

@patlux patlux left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Looks good.

Offline discovery no longer blocks pi startup, last-known-good models stay selectable from the host agent-dir cache, recovery after an empty offline start is covered, and CI is green after the protobufjs lockfile bump.

@patlux
patlux merged commit c8c85a8 into patlux:main Aug 2, 2026
10 checks passed
@patlux

patlux commented Aug 2, 2026

Copy link
Copy Markdown
Owner

Shipped in pi-commandcode-provider@0.4.3 / GitHub release v0.4.3.

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