Skip to content

fix(kernel): send profile as object so KERNEL_PROFILE_NAME works#1474

Open
boatri wants to merge 1 commit into
vercel-labs:mainfrom
boatri:fix/kernel-profile-object
Open

fix(kernel): send profile as object so KERNEL_PROFILE_NAME works#1474
boatri wants to merge 1 commit into
vercel-labs:mainfrom
boatri:fix/kernel-profile-object

Conversation

@boatri

@boatri boatri commented Jun 22, 2026

Copy link
Copy Markdown

Fixes #1473

Summary

  • connect_kernel() sent the create-browser profile field as a bare string; Kernel's API expects an object ({ name, save_changes }), so every open with KERNEL_PROFILE_NAME set failed with a 400 at JSON-decode time.
  • Send { name, save_changes: true } instead. save_changes defaults to true so cookies/logins persist across sessions, matching the documented profile behavior (the SDK default is false, which would load the profile but silently never persist).
  • Extract a small kernel_profile_from_env() helper and add unit tests for the object shape and the unset/empty cases.

Why

With KERNEL_PROFILE_NAME set, agent-browser open always failed:

✗ Kernel API error (400): can't decode JSON body: json: cannot unmarshal
  string into Go struct field BrowserRequest.profile of type map[string]json.RawMessage

The API expects the @onkernel/sdk BrowserProfile shape ({ id?, name?, save_changes? }), not a string. Posting to POST /browsers directly with the same pre-existing profile, varying only the profile field:

profile value Status
"my-profile" (string, old behavior) 400 cannot unmarshal string into ... profile
{ "name": "my-profile", "save_changes": true } (this PR) 200, browser created

So the string is rejected at decode time regardless of whether the profile exists — purely a serialization mismatch.

Test plan

  • cargo fmt --manifest-path cli/Cargo.toml -- --check
  • cargo clippy --manifest-path cli/Cargo.toml -- -D warnings (clean)
  • cargo test --manifest-path cli/Cargo.toml — new unit tests pass:
    • test_kernel_profile_from_env_is_object_not_string
    • test_kernel_profile_from_env_unset_or_empty
  • End-to-end against a real Kernel account with a pre-created profile:
    • KERNEL_PROFILE_NAME=<profile> agent-browser open … now returns 200 (was 400)
    • Wrote localStorage in session A, closed, reopened the same profile in session B → value persisted (confirms save_changes: true)

connect_kernel() serialized the create-browser `profile` field as a bare
string, but Kernel's API expects an object (`{ name, save_changes }`). Every
open with KERNEL_PROFILE_NAME set was rejected at JSON-decode time with a 400
("cannot unmarshal string into ... profile of type map[string]json.RawMessage"),
regardless of whether the profile existed.

Send `{ name, save_changes: true }`. save_changes defaults to true so cookies/
logins persist across sessions, matching the documented profile behavior (the
SDK's own default is false, which would silently not persist).

Add unit tests covering the object shape and the unset/empty cases.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

@boatri is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

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.

Kernel provider: KERNEL_PROFILE_NAME always fails with HTTP 400 (profile sent as string, API expects object)

1 participant