Skip to content

[codex] Fix managed Ollama runtime extraction#12

Merged
duetCJackson merged 1 commit into
mainfrom
codex/fix-ollama-runtime-sidecars
Jun 3, 2026
Merged

[codex] Fix managed Ollama runtime extraction#12
duetCJackson merged 1 commit into
mainfrom
codex/fix-ollama-runtime-sidecars

Conversation

@duetCJackson

@duetCJackson duetCJackson commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes the managed Ollama install path for the refreshed macOS v0.30.0 archive, which now requires llama-server and sidecar libraries in addition to the ollama binary.

What changed

  • Pin managed Ollama downloads to v0.30.0 instead of the moving /latest endpoint.
  • Extract the full macOS Ollama archive instead of only the ollama file.
  • Require packaged macOS managed runtimes to include llama-server before treating setup as ready.
  • Keep non-macOS Unix managed downloads explicitly unsupported rather than expanding Linux support.
  • Add Ask AI backend failure logging so future chat errors include the real exception in autodocLog.
  • Add onboarding tests covering full macOS extraction and the missing-llama-server readiness failure.

Root cause

AutoDoc extracted only the ollama binary from ollama-darwin.tgz. Ollama refreshed the v0.30.0 Darwin artifact on June 1 with a runtime layout that needs llama-server and sidecar dylibs. The API server could still start and /api/tags could return OK, but model execution failed with llama-server binary not found.

CodeRabbit follow-up

The Linux URL finding was valid against the old non-macOS Unix branch, but Linux is not a supported AutoDoc platform. Rather than add untested Linux support, this PR now makes that path fail clearly as unsupported while preserving the supported macOS/Windows behavior.

Validation

  • Reproduced the failure in a clean sandbox with the old single-file extraction.
  • Verified the patched extraction in a clean sandbox using the current v0.30.0 artifact; /api/generate returned HTTP 200.
  • npm run test:main:run -- src/main/ipc/__tests__/chat-ipc.test.ts src/main/services/__tests__/ollama-onboarding-install.test.ts
  • npm run test:main:run -- src/main/services/__tests__/ollama-onboarding-install.test.ts
  • npm run typecheck:node

@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced error logging and diagnostics for chat operations
    • Improved macOS Ollama runtime readiness checks
  • New Features

    • Added support for system Ollama detection and adoption on macOS
    • Ollama version pinned to v0.30.0 for stability

Walkthrough

Pins Ollama releases to v0.30.0, requires macOS llama-server in managed runtimes (with an adopted-system-runtime bypass), standardizes chat IPC failure logging to include normalized-history metadata, and extends tests to validate packaged runtime extraction, readiness, and recovery.

Changes

Ollama Runtime and Chat Logging Enhancement

Layer / File(s) Summary
Chat handler error logging
src/main/ipc/chat-ipc.ts
Import logAutodocFailure, add logChatFailure() helper to unify failure logging with request metadata, compute normalizedHistoryLength in chat:send-stream and chat:select-recording-stream, and call the logger in their catch blocks before emitting chat:error.
Ollama manager llama-server support
src/main/services/ollama-manager.ts
Pin Ollama downloads to v0.30.0, add adoptedSystemRuntime flag and macOS llama-server path helper, require llama-server presence in macOS isReady() unless adopted, update Windows download URL, and implement a macOS-only managed extract path that places ollama and llama-server into the runtime and sets executable permissions.
Test coverage for llama-server support
src/main/services/__tests__/ollama-onboarding-install.test.ts
Expose execFileMock in the test harness, update macOS onboarding/recovery mocks to write/assert llama-server, add packaged-runtime tests that verify extraction includes llama-server and that missing-sidecar runtimes are not ready, and verify copied sidecars are executable.

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs:

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title directly describes the main change: fixing managed Ollama runtime extraction to support v0.30.0 with llama-server.
Description check ✅ Passed The description is directly related to the changeset, providing detailed context about the fix including root cause, what changed, and validation steps.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed: one or more packages not found in the registry.

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • LINEAR integration encountered authorization issues. Please disconnect and reconnect the integration in the CodeRabbit UI.

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/main/services/ollama-manager.ts`:
- Around line 465-468: The downloadBinaryUnix function builds an incorrect Linux
URL (uses ollama-linux.tgz) which doesn't exist; change the URL logic in
downloadBinaryUnix to: for darwin keep the existing ollama-darwin.tgz URL, but
for linux pick an architecture suffix from process.arch (map arm64 -> arm64,
otherwise -> amd64) and request ollama-linux-{arch}.tar.zst; also rename
tgzPath/archive variable accordingly and ensure any downstream
filename/extension handling (e.g., extraction logic that references tgzPath) is
updated to use the .tar.zst filename and appropriate extraction flow.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro (Legacy)

Run ID: 5335bd4f-d5b6-4638-9fb8-8ef5031326c9

📥 Commits

Reviewing files that changed from the base of the PR and between fcd92b7 and 0b4f483.

📒 Files selected for processing (3)
  • src/main/ipc/chat-ipc.ts
  • src/main/services/__tests__/ollama-onboarding-install.test.ts
  • src/main/services/ollama-manager.ts

Comment thread src/main/services/ollama-manager.ts Outdated
@duetCJackson duetCJackson force-pushed the codex/fix-ollama-runtime-sidecars branch from 0b4f483 to 413dd88 Compare June 3, 2026 02:05

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/main/services/__tests__/ollama-onboarding-install.test.ts`:
- Around line 212-263: The test's execFileMock currently creates a flat
runtimeDir/ollama which masks the real tar layout; update the mock
implementation in ollama-onboarding-install.test.ts (the execFileMock used when
instantiating OllamaManager) to write both join(rootDir, 'models',
'ollama-runtime', 'bin', 'ollama') and join(rootDir, 'models', 'ollama-runtime',
'lib', 'ollama') (or equivalent nested paths) instead of a single flat file,
then change the assertions that check the extracted binary to assert access on
the bin/ollama path (and/or the lib path) and ensure manager.isReady() checks
align with the new layout so the test verifies the real bin/lib structure rather
than the flat layout.
- Around line 18-32: The functions setArch and loadOllamaManager lack explicit
TypeScript return type annotations; add a return type of void for setArch and
annotate loadOllamaManager with an explicit Promise return type (either a
concrete object type matching the returned bundle or a named interface) so it
satisfies `@typescript-eslint/explicit-function-return-type`; update the
loadOllamaManager signature (the function that returns { OllamaManager,
clearDownloadedComponents, execSyncMock, execFileMock, spawnMock } in tests) to
use a clear exported or inline interface for readability.

In `@src/main/services/ollama-manager.ts`:
- Around line 465-489: downloadBinaryUnix extracts Linux archives with a
bin/ollama layout but getBinaryPath() currently expects runtimeDir/ollama;
update the runtime resolution so Linux uses runtimeDir/bin/ollama (or move the
extracted bin/ollama into runtimeDir) to match where the binary actually lands:
modify getBinaryPath() (and any callers like isReady(), spawn calls, and chmod
invocations in downloadBinaryUnix()) to prefer join(runtimeDir, 'bin', 'ollama')
on non-darwin platforms (or perform a post-extract relocation of bin/* into
runtimeDir and then keep getBinaryPath() unchanged), ensuring
chmod(this.getBinaryPath()), access checks in isReady(), and subsequent spawn
use the real path.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro (Legacy)

Run ID: ee316573-cd6e-4677-b324-006749e4d567

📥 Commits

Reviewing files that changed from the base of the PR and between 0b4f483 and 413dd88.

📒 Files selected for processing (3)
  • src/main/ipc/chat-ipc.ts
  • src/main/services/__tests__/ollama-onboarding-install.test.ts
  • src/main/services/ollama-manager.ts

Comment thread src/main/services/__tests__/ollama-onboarding-install.test.ts Outdated
Comment thread src/main/services/__tests__/ollama-onboarding-install.test.ts Outdated
Comment thread src/main/services/ollama-manager.ts
@duetCJackson duetCJackson force-pushed the codex/fix-ollama-runtime-sidecars branch from 413dd88 to bb43e25 Compare June 3, 2026 02:51

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/services/ollama-manager.ts (1)

549-551: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

llama-server needs executable permission when copied from installed runtime.

The copyDirectoryContentsIfMissing method only sets executable permission on ollama, but llama-server also needs chmod 0o755 on macOS. When adopting from an installed runtime, copyFile may not preserve the source file's mode, causing llama-server to be non-executable and model execution to fail despite isReady() returning true.

🔧 Proposed fix
       await copyFile(sourcePath, destPath)
-      if (!IS_WIN && entry.name === 'ollama') {
+      if (!IS_WIN && (entry.name === 'ollama' || entry.name === 'llama-server')) {
         await chmod(destPath, 0o755)
       }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/services/ollama-manager.ts` around lines 549 - 551, In
copyDirectoryContentsIfMissing, ensure the copied runtime binaries get
executable bits set: when iterating entries (check entry.name), in addition to
setting chmod(destPath, 0o755) for 'ollama' on non-Windows (IS_WIN), also apply
the same chmod for 'llama-server' (macOS/adopted runtime cases) so the copied
llama-server is executable; update the condition that references entry.name to
include 'llama-server' and call chmod(destPath, 0o755) accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/main/services/ollama-manager.ts`:
- Around line 549-551: In copyDirectoryContentsIfMissing, ensure the copied
runtime binaries get executable bits set: when iterating entries (check
entry.name), in addition to setting chmod(destPath, 0o755) for 'ollama' on
non-Windows (IS_WIN), also apply the same chmod for 'llama-server'
(macOS/adopted runtime cases) so the copied llama-server is executable; update
the condition that references entry.name to include 'llama-server' and call
chmod(destPath, 0o755) accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro (Legacy)

Run ID: 235e66ad-afa9-49e7-8f31-b12e750987c7

📥 Commits

Reviewing files that changed from the base of the PR and between 413dd88 and bb43e25.

📒 Files selected for processing (3)
  • src/main/ipc/chat-ipc.ts
  • src/main/services/__tests__/ollama-onboarding-install.test.ts
  • src/main/services/ollama-manager.ts

@duetCJackson duetCJackson force-pushed the codex/fix-ollama-runtime-sidecars branch from bb43e25 to 2c78b5f Compare June 3, 2026 14:06
@duetCJackson duetCJackson force-pushed the codex/fix-ollama-runtime-sidecars branch from 2c78b5f to 418553e Compare June 3, 2026 14:08
@duetCJackson duetCJackson marked this pull request as ready for review June 3, 2026 14:10

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/services/ollama-manager.ts (1)

193-198: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Don't treat a copied lone ollama binary as a complete adopted macOS runtime.

Line 196 still copies only which ollama into ollama-runtime, but Line 197 now bypasses the new llama-server readiness check. start() then launches that copied binary from runtimeDir, so macOS dev fallbacks can still hit the same missing-sidecar failure this PR is fixing for managed downloads. Either keep using the discovered system binary in place, or copy the full runtime bundle instead of a single file.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/services/ollama-manager.ts` around lines 193 - 198, The PR currently
copies only the lone system "ollama" executable returned by findSystemOllama()
into getBinaryPath() and marks adoptedSystemRuntime=true, which bypasses the new
llama-server readiness/sidecar checks in start() and can cause the same
missing-sidecar failure; instead either (A) stop copying and use the discovered
system binary in-place by storing its path (from findSystemOllama()) and
avoiding copyFile/marking adoptedSystemRuntime, or (B) copy the full macOS
runtime bundle (not just the single binary) into runtimeDir so the sidecar files
are present before setting adoptedSystemRuntime; update
canUseSystemRuntimeFallback()/findSystemOllama() handling and ensure start()
checks the same readiness for the adopted runtime path you choose.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/main/services/ollama-manager.ts`:
- Around line 193-198: The PR currently copies only the lone system "ollama"
executable returned by findSystemOllama() into getBinaryPath() and marks
adoptedSystemRuntime=true, which bypasses the new llama-server readiness/sidecar
checks in start() and can cause the same missing-sidecar failure; instead either
(A) stop copying and use the discovered system binary in-place by storing its
path (from findSystemOllama()) and avoiding copyFile/marking
adoptedSystemRuntime, or (B) copy the full macOS runtime bundle (not just the
single binary) into runtimeDir so the sidecar files are present before setting
adoptedSystemRuntime; update canUseSystemRuntimeFallback()/findSystemOllama()
handling and ensure start() checks the same readiness for the adopted runtime
path you choose.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro (Legacy)

Run ID: 62c3881d-c604-4c25-b7b7-e6532acbd705

📥 Commits

Reviewing files that changed from the base of the PR and between bb43e25 and 418553e.

📒 Files selected for processing (3)
  • src/main/ipc/chat-ipc.ts
  • src/main/services/__tests__/ollama-onboarding-install.test.ts
  • src/main/services/ollama-manager.ts

@duetCJackson duetCJackson merged commit b326c78 into main Jun 3, 2026
8 checks passed
@duetCJackson duetCJackson deleted the codex/fix-ollama-runtime-sidecars branch June 26, 2026 20:19
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