Skip to content

feat(config): unify config resolution with Settings fallback (Phase 2, #1119) - #1203

Merged
zmanian merged 1 commit into
nearai:stagingfrom
reidliu41:feat/1119-phase2-config-unify
Mar 16, 2026
Merged

zmanian merged 1 commit into
nearai:stagingfrom
reidliu41:feat/1119-phase2-config-unify

Conversation

@reidliu41

Copy link
Copy Markdown
Contributor

Summary

Five config modules ignored their Settings structs, meaning values
saved via config set or the setup wizard had no effect at runtime.
This also closes the Phase 1 gap where auto-generated gateway tokens
were lost on restart.

  • Wire WasmConfig::resolve() to read WasmSettings (7 fields)
  • Wire SandboxModeConfig::resolve() to read SandboxSettings (8 fields)
  • Wire BuilderModeConfig::resolve() to read BuilderSettings (5 fields)
  • Wire resolve_safety_config() to read SafetySettings (2 fields)
  • Wire ClaudeCodeConfig::resolve() to read sandbox.claude_code_enabled, fixing a bug where the setup wizard's choice was silently ignored
  • Preserve ClaudeCodeConfig::from_env() for worker containers (no DB)
  • Persist auto-generated GATEWAY_AUTH_TOKEN to "default" namespace so it survives restarts without requiring an env var
  • Add ENV_MUTEX to all new env-mutating tests for parallel safety

Change Type

  • Bug fix
  • New feature
  • Refactor
  • Documentation
  • CI/Infrastructure
  • Security
  • Dependencies

Linked Issue

Part of #1119 (Phase 2)

Validation

  • cargo fmt
  • cargo clippy --all --benches --tests --examples --all-features
  • Relevant tests pass:
  • Manual testing:

Security Impact

None

Database Impact

None

Blast Radius

Rollback Plan


Review track:

…nearai#1119)

  Five config modules ignored their Settings structs, meaning values
  saved via `config set` or the setup wizard had no effect at runtime.
  This also closes the Phase 1 gap where auto-generated gateway tokens
  were lost on restart.

  - Wire WasmConfig::resolve() to read WasmSettings (7 fields)
  - Wire SandboxModeConfig::resolve() to read SandboxSettings (8 fields)
  - Wire BuilderModeConfig::resolve() to read BuilderSettings (5 fields)
  - Wire resolve_safety_config() to read SafetySettings (2 fields)
  - Wire ClaudeCodeConfig::resolve() to read sandbox.claude_code_enabled,
    fixing a bug where the setup wizard's choice was silently ignored
  - Preserve ClaudeCodeConfig::from_env() for worker containers (no DB)
  - Persist auto-generated GATEWAY_AUTH_TOKEN to "default" namespace so
    it survives restarts without requiring an env var
  - Add ENV_MUTEX to all new env-mutating tests for parallel safety
@github-actions github-actions Bot added size: L 200-499 changed lines risk: low Changes to docs, tests, or low-risk modules labels Mar 15, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the configuration resolution mechanism across several core modules, ensuring that settings persisted via the 'config set' command or the setup wizard are correctly applied at runtime. It addresses a critical gap where previously, certain configuration values and auto-generated gateway tokens were not consistently loaded after application restarts. The changes unify the configuration flow, prioritizing environment variables while falling back to stored settings, and include new tests to validate this behavior.

Highlights

  • Unified Configuration Resolution: Updated several config modules (WasmConfig, SandboxModeConfig, BuilderModeConfig, SafetyConfig, ClaudeCodeConfig) to properly read values from Settings structs, ensuring 'config set' and setup wizard changes are respected.
  • Gateway Token Persistence: Resolved an issue where auto-generated gateway tokens were lost on restart by persisting them to the 'default' settings namespace.
  • Claude Code Config Fix: Fixed a bug where the setup wizard's choice for 'claude_code_enabled' was ignored.
  • Environment Variable Resolution Refinement: Refactored ClaudeCodeConfig::from_env() to use a new resolve_env_only() method, preserving its functionality for worker containers without database access.
  • Test Safety Improvement: Introduced ENV_MUTEX for new environment-mutating tests to ensure parallel safety.
Changelog
  • src/config/builder.rs
    • Modified BuilderModeConfig::resolve to accept settings and use settings.builder as a fallback for configuration values.
    • Added unit tests to verify that resolve correctly falls back to Settings values and that environment variables override Settings.
  • src/config/mod.rs
    • Updated the main Config::resolve function to pass the settings object to the resolve methods of safety, wasm, builder, sandbox, and claude_code configurations.
  • src/config/safety.rs
    • Modified resolve_safety_config to accept settings and use settings.safety as a fallback for max_output_length and injection_check_enabled.
    • Added unit tests to confirm resolve_safety_config's fallback and override behavior.
  • src/config/sandbox.rs
    • Modified SandboxModeConfig::resolve to accept settings and use settings.sandbox for fallback values for most fields, including extra_allowed_domains.
    • Renamed ClaudeCodeConfig::resolve to resolve_env_only and created a new resolve method that incorporates settings.sandbox.claude_code_enabled as a fallback.
    • Added unit tests for SandboxModeConfig and ClaudeCodeConfig to validate settings fallback and environment variable overrides.
  • src/config/wasm.rs
    • Modified WasmConfig::resolve to accept settings and use settings.wasm as a fallback for configuration values like enabled, tools_dir, default_memory_limit, default_timeout_secs, default_fuel_limit, cache_compiled, and cache_dir.
    • Added unit tests to verify WasmConfig::resolve's fallback and override logic.
  • src/main.rs
    • Implemented logic to persist auto-generated GATEWAY_AUTH_TOKEN to the 'default' settings namespace in the database, ensuring its survival across restarts.
Activity
  • No specific activity (comments, reviews, progress updates) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@github-actions github-actions Bot added the contributor: experienced 6-19 merged PRs label Mar 15, 2026

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request is a solid improvement that unifies configuration resolution for several modules (builder, safety, sandbox, wasm, claude_code) to fall back to Settings values from the database. This ensures that settings configured via config set or the setup wizard are correctly applied at runtime. The addition of tests for this new fallback logic is excellent. Furthermore, the change to persist the auto-generated gateway auth token fixes an important bug where the token was lost on restart. I have one minor suggestion to simplify the code.

Comment thread src/config/sandbox.rs
Comment on lines +60 to +66
.unwrap_or_else(|| {
if ss.extra_allowed_domains.is_empty() {
Vec::new()
} else {
ss.extra_allowed_domains.clone()
}
});

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.

medium

The logic inside unwrap_or_else can be simplified. Cloning an empty Vec is efficient, so the if/else block is unnecessary and can be reduced to a single expression.

            .unwrap_or_else(|| ss.extra_allowed_domains.clone());

@zmanian zmanian left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review: APPROVE

Well-structured, low-risk PR that methodically wires 5 config modules to read from persisted Settings as fallback when env vars aren't set. Previously, values set via config set or the setup wizard were silently ignored at runtime.

Modules wired: WasmConfig (7 fields), SandboxModeConfig (8 fields), BuilderModeConfig (5 fields), safety config (2 fields), ClaudeCodeConfig (1 field).

Architecture: Consistent pattern across all modules -- priority chain is env var > settings > hardcoded default. Matches how already-wired modules (AgentConfig, HeartbeatConfig, etc.) work.

Notable decisions:

  • ClaudeCodeConfig cleanly split into resolve(settings) and resolve_env_only() for worker containers without DB access
  • Gateway auth token persisted via db.set_setting() to survive restarts
  • Fully backward compatible -- env vars still take priority, default values match previous hardcoded defaults

Minor suggestions (non-blocking):

  1. Simplify extra_allowed_domains fallback -- the if is_empty() check is unnecessary:
// Before (unnecessary conditional)
.unwrap_or_else(|| {
    if ss.extra_allowed_domains.is_empty() {
        Vec::new()
    } else {
        ss.extra_allowed_domains.clone()
    }
})
// After
.unwrap_or_else(|| ss.extra_allowed_domains.clone())
  1. Add a test for the extra_allowed_domains settings fallback path.
  2. Add a test for ClaudeCodeConfig::from_env() container path to guard against regressions.

CI all green. Safe to merge.

@zmanian
zmanian enabled auto-merge (squash) March 15, 2026 20:50
@zmanian
zmanian merged commit a357972 into nearai:staging Mar 16, 2026
14 checks passed
@ironclaw-ci ironclaw-ci Bot mentioned this pull request Mar 17, 2026
bkutasi pushed a commit to bkutasi/ironclaw that referenced this pull request Mar 28, 2026
drchirag1991 pushed a commit to drchirag1991/ironclaw that referenced this pull request Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor: experienced 6-19 merged PRs risk: low Changes to docs, tests, or low-risk modules size: L 200-499 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants