Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.

fix/openclaw config merge#53

Closed
castabar wants to merge 2 commits into
mainfrom
fix/openclaw-config-merge
Closed

fix/openclaw config merge#53
castabar wants to merge 2 commits into
mainfrom
fix/openclaw-config-merge

Conversation

@castabar
Copy link
Copy Markdown
Contributor

@castabar castabar commented May 5, 2026

  • fix(install.sh): reattach stdin to /dev/tty when piped
  • fix(openclaw): merge config instead of replacing

Kimchi Summary

What changed

Fixes OpenClaw configuration merging to preserve existing user settings (temperature, max_tokens, custom fallbacks) instead of overwriting them. Also improves the install script to handle non-interactive environments (e.g., curl | bash).

Why

Previously, running kimchi would wipe out existing OpenClaw configuration values like temperature or max_tokens when updating model settings. This change ensures user customizations are preserved during configuration updates.

Key changes

  • internal/tools/openclaw.go:
    • Added --merge flag to openclaw config set CLI commands for agents.defaults.model.fallbacks and agents.defaults.models (both sequential and batch paths)
    • Modified writeOpenClawViaCLI to run fallbacks and models as separate --merge operations after the main --batch-json call
    • Refactored writeOpenClawDirect to merge into existing model and models maps rather than replacing them, preserving existing fallbacks and catalog entries
  • scripts/install.sh:
    • Added TTY detection: uses /dev/tty when stdin is not a terminal, or prompts user to manually run kimchi if no TTY is available

Impact

  • Breaking change: None; additive preservation of existing config
  • Migration: Users who previously lost custom settings will need to re-add them manually once; subsequent runs will preserve their configuration
  • Install script: Now supports piped installation methods (e.g., curl ... | bash) without hanging or failing to launch Kimchi

castabar and others added 2 commits May 5, 2026 15:35
When installing Kimchi via 'curl ... | bash', stdin is a pipe from
curl and is already at EOF. This caused the first-run API key prompt
to immediately fail with 'error: read API key: EOF'.

Redirect kimchi's stdin from /dev/tty when the script detects it is
running in a non-TTY context, so the interactive prompt still works.
If no TTY is available, skip auto-launch and print a helpful message.

Co-Authored-By: Kimchi <noreply@kimchi.dev>
OpenClaw's config set defaults to replace mode, which causes
the setup to fail when users already have model entries in
agents.defaults.models or agents.defaults.model.fallbacks.

Changes across all three code paths:

1. Batch JSON mode (writeOpenClawViaCLI):
   - Split batch to only cover non-conflicting fields
     (provider block + primary).
   - Use separate openclaw config set --merge calls for
     agents.defaults.model.fallbacks and agents.defaults.models.

2. Sequential CLI mode (writeOpenClawViaCLISequential):
   - Add --merge flag for agent.defaults.model.fallbacks.
   - Add --merge flag for agent.defaults.models.

3. Direct file-writing mode (writeOpenClawDirect):
   - Merge Kimchi model catalog into existing defaults["models"]
     instead of replacing it entirely.
   - Merge into existing defaults["model"] map instead of
     overwriting, preserving keys like temperature and max_tokens.
   - Append Kimchi fallbacks to existing fallbacks array.

Co-Authored-By: Kimchi <noreply@kimchi.dev>
@kimchi-review
Copy link
Copy Markdown

kimchi-review Bot commented May 5, 2026

Kimchi Code Review

Property Value
Commit 5b38527
Author @castabar
Files changed 0
Review status Completed
Comments 2 (1 info, 1 warning)
Duration 46s

Summary

📊 Review Score: 85/100 (overall code quality — 0 lowest, 100 highest)
⏱️ Estimated effort to review: 2/5 (1 = trivial, 5 = very complex)

🧪 Tests: no — No test files were modified or added in the diff to cover the new --merge behavior or the TTY handling in the install script.

📝 Found 2 issue(s). See inline comments for details.

What to expect

Kimchi will analyze the changes in this pull request and post:

  • A summary of the overall changes
  • Inline comments on specific lines with findings categorized by issue type

The review typically completes within a few minutes. This comment will be updated once the review is ready.

Interact with Kimchi
  • @kimchi review — re-trigger a full review on the latest commit
  • @kimchi summary — regenerate the PR summary
  • @kimchi ignore — skip this PR (no review will be posted)
  • Reply to any inline comment to ask follow-up questions or request clarification
Configuration

Reviews are configured by your organization admin.
Review instructions, excluded directories, and severity thresholds can be adjusted per repository in the Kimchi dashboard.


Powered by Kimchi — AI-powered code review by CAST AI

Copy link
Copy Markdown

@kimchi-review kimchi-review Bot left a comment

Choose a reason for hiding this comment

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

📊 Review Score: 85/100 (overall code quality — 0 lowest, 100 highest)
⏱️ Estimated effort to review: 2/5 (1 = trivial, 5 = very complex)

🧪 Tests: no — No test files were modified or added in the diff to cover the new --merge behavior or the TTY handling in the install script.

📝 Found 2 issue(s). See inline comments for details.

return fmt.Errorf("openclaw config set: %s: %w", string(out), err)
}

// Merge fallbacks so existing entries are preserved.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️⚠️ Error Handling

The error return from json.Marshal is discarded when marshaling fallbacksJSON. While unlikely to fail for a simple string slice, if it does return an error, fallbacksJSON could be nil and string(nil) would result in an empty string being passed to the openclaw config set command, potentially clearing the user's fallback configuration instead of merging.

💡 Suggestion: Check the error from json.Marshal: fallbacksJSON, err := json.Marshal(...); if err != nil { return fmt.Errorf("marshal fallbacks: %w", err) }

modelMap = make(map[string]any)
}
modelMap["primary"] = providerName + "/" + reg.Main().Slug
// Merge fallbacks so existing entries are preserved.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ℹ️🔧 Maintainability

The type assertion existingFallbacks, _ := modelMap["fallbacks"].([]any) discards the boolean ok-value. If the existing config has fallbacks stored as a different type (e.g., []string instead of []any from JSON decoding), the assertion fails silently and existingFallbacks becomes nil, causing the append to effectively replace rather than merge the fallbacks.

💡 Suggestion: Consider logging a warning if the type assertion fails, or use reflection to handle type conversion safely if the source data format is uncertain.

@castabar
Copy link
Copy Markdown
Contributor Author

castabar commented May 5, 2026

Consolidated into #50 — the openclaw merge fix is now part of the same branch.

@castabar castabar closed this May 5, 2026
@castabar castabar deleted the fix/openclaw-config-merge branch May 5, 2026 14:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant