Skip to content

fix(agent-workspaces): inject Vertex AI config into workspace at creation time - #1877

Merged
benoitf merged 1 commit into
openkaiden:mainfrom
fbricon:worktree-GH-1861
May 13, 2026
Merged

benoitf merged 1 commit into
openkaiden:mainfrom
fbricon:worktree-GH-1861

Conversation

@fbricon

@fbricon fbricon commented May 13, 2026

Copy link
Copy Markdown
Contributor

When a Vertex AI model is selected, ensureModelSecret now populates
the workspace configuration with the required environment variables
(CLAUDE_CODE_USE_VERTEX, CLOUD_ML_REGION, ANTHROPIC_VERTEX_PROJECT_ID)
and mounts the ADC credentials file. Previously this was only done
by the onboarding panel, which silently skipped it when a connection
already existed.

Fixes #1861

@fbricon
fbricon requested a review from a team as a code owner May 13, 2026 17:11
@fbricon
fbricon requested review from benoitf and gastoner and removed request for a team May 13, 2026 17:11
@coderabbitai

coderabbitai Bot commented May 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: f3eed6fa-6456-4311-bf43-84418e707f4b

📥 Commits

Reviewing files that changed from the base of the PR and between 7f92147 and 56d421e.

📒 Files selected for processing (2)
  • packages/main/src/plugin/agent-workspace/agent-workspace-manager.spec.ts
  • packages/main/src/plugin/agent-workspace/agent-workspace-manager.ts
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: linter, formatters
  • GitHub Check: smoke-e2e-tests (dev) / ubuntu-24.04 (ollama)
  • GitHub Check: smoke-e2e-tests (prod) / ubuntu-24.04 (ollama)
  • GitHub Check: typecheck
  • GitHub Check: Windows
  • GitHub Check: unit tests / windows-2025
  • GitHub Check: Linux
  • GitHub Check: unit tests / ubuntu-24.04
  • GitHub Check: macOS
  • GitHub Check: unit tests / macos-15
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use /@/ path aliases instead of relative paths for imports outside the current directory's module group; use relative imports only for sibling modules within the same directory

Files:

  • packages/main/src/plugin/agent-workspace/agent-workspace-manager.ts
  • packages/main/src/plugin/agent-workspace/agent-workspace-manager.spec.ts
packages/main/src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

packages/main/src/**/*.{ts,tsx}: Use ipcHandle() to expose handlers in the main process with naming convention <registry-name>:<action> (e.g., container-provider-registry:listContainers)
Use apiSender.send() to send events from main process to renderer for real-time updates
Long-running operations should use TaskManager.createTask() with title and action configuration

Files:

  • packages/main/src/plugin/agent-workspace/agent-workspace-manager.ts
  • packages/main/src/plugin/agent-workspace/agent-workspace-manager.spec.ts
packages/{main,renderer,preload}/src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Container operations must include engineId parameter to identify the container engine

Files:

  • packages/main/src/plugin/agent-workspace/agent-workspace-manager.ts
  • packages/main/src/plugin/agent-workspace/agent-workspace-manager.spec.ts
**/*.spec.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.spec.{ts,tsx,js,jsx}: Use test() instead of it() for test cases in Vitest unit tests
Use vi.mock(import('...')) for auto-mocking modules in unit tests; avoid manual mock factories when possible
Use vi.resetAllMocks() in beforeEach hooks instead of vi.clearAllMocks() for resetting mocks between tests
When an auto-mocked function or class method needs a real implementation, use vi.mocked(...) with the prototype pattern for class methods: vi.mocked(MyClass.prototype.myMethod).mockImplementation(...)

Files:

  • packages/main/src/plugin/agent-workspace/agent-workspace-manager.spec.ts
🧠 Learnings (2)
📚 Learning: 2026-03-09T08:47:09.657Z
Learnt from: benoitf
Repo: kortex-hub/kortex PR: 1077
File: packages/main/src/plugin/skill/skill-manager.ts:80-109
Timestamp: 2026-03-09T08:47:09.657Z
Learning: In the kortex-hub/kortex repository, IPC handlers (via ipcHandle()) may be registered directly inside feature manager/service classes (e.g., SkillManager in packages/main/src/plugin/skill/skill-manager.ts) rather than exclusively in packages/main/src/plugin/index.ts. Treat this as an accepted design pattern for files under the plugin directory. Reviewers should not require centralization in index.ts; allow IPC registration proximity to the feature that owns the handler. When reviewing code, accept direct ipcHandle() registrations inside feature managers and ensure the pattern is consistently applied across similar feature-manager modules.

Applied to files:

  • packages/main/src/plugin/agent-workspace/agent-workspace-manager.ts
  • packages/main/src/plugin/agent-workspace/agent-workspace-manager.spec.ts
📚 Learning: 2026-05-12T17:14:02.153Z
Learnt from: MarsKubeX
Repo: openkaiden/kaiden PR: 1850
File: packages/renderer/src/lib/agent-workspaces/AgentWorkspaceList.svelte:66-70
Timestamp: 2026-05-12T17:14:02.153Z
Learning: When reviewing code that uses `AgentWorkspaceSummaryUI.runtime`, treat it as a required, non-null `string` per the `openkaiden/kdn-api` 0.12.0 schema. Therefore, code like `a.runtime.localeCompare(b.runtime)` is safe and should not trigger warnings about possible `undefined`/`null` values or suggestions to use nullish coalescing/optional chaining for `runtime` (unless the current local types still mark `runtime` as optional, indicating a schema/version mismatch).

Applied to files:

  • packages/main/src/plugin/agent-workspace/agent-workspace-manager.ts
  • packages/main/src/plugin/agent-workspace/agent-workspace-manager.spec.ts
🔇 Additional comments (6)
packages/main/src/plugin/agent-workspace/agent-workspace-manager.ts (2)

140-143: LGTM!


192-192: ⚖️ Poor tradeoff

Confirm that the kdn CLI (external tool) expands $HOME in host mount paths at runtime.

The code at line 192 correctly transforms ~/ prefixes to $HOME/ for credentials file paths that will be mounted. However, this repository does not contain the kdn CLI implementation itself, and the unit tests only verify that the literal $HOME/... string is written to workspace.json. Verification of actual runtime expansion requires either:

  1. Testing with the actual kdn CLI to confirm $HOME resolves to the host user's home directory
  2. Reviewing the kdn CLI's mount path handling logic (external repository)
  3. End-to-end integration tests that verify mounts actually work

The pattern is used consistently across multiple test cases with no reported failures, but confirm with kdn CLI documentation or implementation.

packages/main/src/plugin/agent-workspace/agent-workspace-manager.spec.ts (4)

535-554: LGTM!


556-587: LGTM!


589-610: LGTM!


612-623: LGTM!


📝 Walkthrough

Walkthrough

Detects vertexai credentials in ensureModelSecret, applies Vertex AI workspace configuration (env vars and application-default-credentials read-only mount with ~ expansion), and skips vault secret creation. Tests cover merging/deduplication, path expansion, and incomplete-credentials behavior.

Changes

Vertex AI Workspace Configuration

Layer / File(s) Summary
Vertex AI configuration implementation
packages/main/src/plugin/agent-workspace/agent-workspace-manager.ts
Adds a vertexai branch in ensureModelSecret that delegates to applyVertexAiConfiguration. The helper validates credential fields, sets CLAUDE_CODE_USE_VERTEX, CLOUD_ML_REGION, ANTHROPIC_VERTEX_PROJECT_ID, removes any existing ADC target mount, and adds a read-only ADC host-to-target mount with ~/ expansion.
Vertex AI configuration tests
packages/main/src/plugin/agent-workspace/agent-workspace-manager.spec.ts
Four tests: valid Vertex AI credentials populate workspaceConfiguration without calling secretManager.create; environment variables and mounts are merged/deduplicated when workspaceConfiguration exists; ~ in credentials path is expanded to $HOME for host and target mounts; incomplete credentials do not apply configuration.

Sequence Diagram(s)

sequenceDiagram
  participant AgentWorkspaceManager
  participant applyVertexAiConfiguration
  participant WorkspaceConfiguration
  participant SecretManager
  AgentWorkspaceManager->>applyVertexAiConfiguration: delegate with vertexai credentials
  applyVertexAiConfiguration->>WorkspaceConfiguration: set env vars and ADC read-only mount (expand ~/)
  AgentWorkspaceManager--x SecretManager: skip secretManager.create (no secret created)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

  • openkaiden/kaiden#1537: Adds onboarding/UI and persisted settings for Claude-on-VertexAI configuration that complements this backend workspace configuration.
  • openkaiden/kaiden#1762: Related changes to AgentWorkspaceManager.ensureModelSecret; #1762 adds automatic kdn vault secret creation while this PR special-cases vertexai to set workspaceConfiguration instead.

Suggested reviewers

  • gastoner
  • benoitf
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: injecting Vertex AI configuration into workspaces at creation time via ensureModelSecret.
Description check ✅ Passed The description clearly explains the change, detailing the environment variables and credentials mounting added to workspace configuration and how it fixes the prior limitation.
Linked Issues check ✅ Passed The PR directly addresses the requirements in issue #1861 by implementing Vertex AI configuration injection at workspace creation time to match the onboarding flow behavior.
Out of Scope Changes check ✅ Passed All changes are focused on Vertex AI workspace configuration and directly support the objective of fixing the authentication issue described in issue #1861.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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)
packages/main/src/plugin/agent-workspace/agent-workspace-manager.ts (1)

135-143: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Vertex AI config is skipped when any workspace secrets already exist.

Line 135 returns before the Vertex AI branch, so a workspace with pre-existing workspaceConfiguration.secrets never gets the required Vertex env vars/mounts. That can still cause auth failures for Vertex models.

Suggested fix
 async ensureModelSecret(options: AgentWorkspaceCreateOptions): Promise<void> {
   if (!options.model) return;

-  if (options.workspaceConfiguration?.secrets?.length) return;
-
   const connectionInfo = this.providerRegistry.getInferenceConnectionCredentials(options.model);
   if (!connectionInfo) return;

   if (connectionInfo.llmMetadataName === 'vertexai') {
     this.applyVertexAiConfiguration(options, connectionInfo.credentials);
     return;
   }
+
+  if (options.workspaceConfiguration?.secrets?.length) return;
🤖 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 `@packages/main/src/plugin/agent-workspace/agent-workspace-manager.ts` around
lines 135 - 143, The current early return when
options.workspaceConfiguration?.secrets?.length is truthy prevents Vertex AI
configuration from being applied; update the logic so Vertex AI env/mount setup
always runs when
providerRegistry.getInferenceConnectionCredentials(options.model) yields
connectionInfo with connectionInfo.llmMetadataName === 'vertexai'. Concretely,
either move the vertexai branch (check connectionInfo.llmMetadataName ===
'vertexai' and call this.applyVertexAiConfiguration(options,
connectionInfo.credentials)) before the secrets check, or change the secrets
guard to skip only secret creation but not the vertexai branch; keep references
to options.workspaceConfiguration,
providerRegistry.getInferenceConnectionCredentials,
connectionInfo.llmMetadataName, and applyVertexAiConfiguration to locate and
modify the code.
🤖 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 `@packages/main/src/plugin/agent-workspace/agent-workspace-manager.ts`:
- Around line 135-143: The current early return when
options.workspaceConfiguration?.secrets?.length is truthy prevents Vertex AI
configuration from being applied; update the logic so Vertex AI env/mount setup
always runs when
providerRegistry.getInferenceConnectionCredentials(options.model) yields
connectionInfo with connectionInfo.llmMetadataName === 'vertexai'. Concretely,
either move the vertexai branch (check connectionInfo.llmMetadataName ===
'vertexai' and call this.applyVertexAiConfiguration(options,
connectionInfo.credentials)) before the secrets check, or change the secrets
guard to skip only secret creation but not the vertexai branch; keep references
to options.workspaceConfiguration,
providerRegistry.getInferenceConnectionCredentials,
connectionInfo.llmMetadataName, and applyVertexAiConfiguration to locate and
modify the code.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: f49cb52f-af16-4118-99f8-3176060828d2

📥 Commits

Reviewing files that changed from the base of the PR and between b608d83 and 7f92147.

📒 Files selected for processing (2)
  • packages/main/src/plugin/agent-workspace/agent-workspace-manager.spec.ts
  • packages/main/src/plugin/agent-workspace/agent-workspace-manager.ts
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: smoke-e2e-tests (prod) / ubuntu-24.04 (ollama)
  • GitHub Check: smoke-e2e-tests (dev) / ubuntu-24.04 (ollama)
  • GitHub Check: macOS
  • GitHub Check: typecheck
  • GitHub Check: Linux
  • GitHub Check: Windows
  • GitHub Check: unit tests / macos-15
  • GitHub Check: unit tests / windows-2025
  • GitHub Check: unit tests / ubuntu-24.04
  • GitHub Check: linter, formatters
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use /@/ path aliases instead of relative paths for imports outside the current directory's module group; use relative imports only for sibling modules within the same directory

Files:

  • packages/main/src/plugin/agent-workspace/agent-workspace-manager.ts
  • packages/main/src/plugin/agent-workspace/agent-workspace-manager.spec.ts
packages/main/src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

packages/main/src/**/*.{ts,tsx}: Use ipcHandle() to expose handlers in the main process with naming convention <registry-name>:<action> (e.g., container-provider-registry:listContainers)
Use apiSender.send() to send events from main process to renderer for real-time updates
Long-running operations should use TaskManager.createTask() with title and action configuration

Files:

  • packages/main/src/plugin/agent-workspace/agent-workspace-manager.ts
  • packages/main/src/plugin/agent-workspace/agent-workspace-manager.spec.ts
packages/{main,renderer,preload}/src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Container operations must include engineId parameter to identify the container engine

Files:

  • packages/main/src/plugin/agent-workspace/agent-workspace-manager.ts
  • packages/main/src/plugin/agent-workspace/agent-workspace-manager.spec.ts
**/*.spec.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.spec.{ts,tsx,js,jsx}: Use test() instead of it() for test cases in Vitest unit tests
Use vi.mock(import('...')) for auto-mocking modules in unit tests; avoid manual mock factories when possible
Use vi.resetAllMocks() in beforeEach hooks instead of vi.clearAllMocks() for resetting mocks between tests
When an auto-mocked function or class method needs a real implementation, use vi.mocked(...) with the prototype pattern for class methods: vi.mocked(MyClass.prototype.myMethod).mockImplementation(...)

Files:

  • packages/main/src/plugin/agent-workspace/agent-workspace-manager.spec.ts
🧠 Learnings (2)
📚 Learning: 2026-03-09T08:47:09.657Z
Learnt from: benoitf
Repo: kortex-hub/kortex PR: 1077
File: packages/main/src/plugin/skill/skill-manager.ts:80-109
Timestamp: 2026-03-09T08:47:09.657Z
Learning: In the kortex-hub/kortex repository, IPC handlers (via ipcHandle()) may be registered directly inside feature manager/service classes (e.g., SkillManager in packages/main/src/plugin/skill/skill-manager.ts) rather than exclusively in packages/main/src/plugin/index.ts. Treat this as an accepted design pattern for files under the plugin directory. Reviewers should not require centralization in index.ts; allow IPC registration proximity to the feature that owns the handler. When reviewing code, accept direct ipcHandle() registrations inside feature managers and ensure the pattern is consistently applied across similar feature-manager modules.

Applied to files:

  • packages/main/src/plugin/agent-workspace/agent-workspace-manager.ts
  • packages/main/src/plugin/agent-workspace/agent-workspace-manager.spec.ts
📚 Learning: 2026-05-12T17:14:02.153Z
Learnt from: MarsKubeX
Repo: openkaiden/kaiden PR: 1850
File: packages/renderer/src/lib/agent-workspaces/AgentWorkspaceList.svelte:66-70
Timestamp: 2026-05-12T17:14:02.153Z
Learning: When reviewing code that uses `AgentWorkspaceSummaryUI.runtime`, treat it as a required, non-null `string` per the `openkaiden/kdn-api` 0.12.0 schema. Therefore, code like `a.runtime.localeCompare(b.runtime)` is safe and should not trigger warnings about possible `undefined`/`null` values or suggestions to use nullish coalescing/optional chaining for `runtime` (unless the current local types still mark `runtime` as optional, indicating a schema/version mismatch).

Applied to files:

  • packages/main/src/plugin/agent-workspace/agent-workspace-manager.ts
  • packages/main/src/plugin/agent-workspace/agent-workspace-manager.spec.ts

@fbricon
fbricon requested a review from serbangeorge-m May 13, 2026 17:14
@fbricon

fbricon commented May 13, 2026

Copy link
Copy Markdown
Contributor Author

It's a quick n' dirty fix until we implement #1834

@codecov

codecov Bot commented May 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

…tion time

When a Vertex AI model is selected, ensureModelSecret now populates
the workspace configuration with the required environment variables
(CLAUDE_CODE_USE_VERTEX, CLOUD_ML_REGION, ANTHROPIC_VERTEX_PROJECT_ID)
and mounts the ADC credentials file. Previously this was only done
by the onboarding panel, which silently skipped it when a connection
already existed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Fred Bricon <fbricon@gmail.com>
@benoitf
benoitf force-pushed the worktree-GH-1861 branch from 7f92147 to 56d421e Compare May 13, 2026 19:05
@benoitf

benoitf commented May 13, 2026

Copy link
Copy Markdown
Contributor

(hit the rebase button to see if e2e tests are passing now)

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.

Workspaces: Claude Vertex AI resource fails to authenticate when added via Settings, but works during Onboarding

2 participants