Skip to content

Add gateway CLI for storing config in database#7227

Merged
shuyangli merged 6 commits intomainfrom
sl/add-cli-store-config-option
Apr 13, 2026
Merged

Add gateway CLI for storing config in database#7227
shuyangli merged 6 commits intomainfrom
sl/add-cli-store-config-option

Conversation

@shuyangli
Copy link
Copy Markdown
Contributor

@shuyangli shuyangli commented Apr 8, 2026

Fixes #7128.

Fixes #7122.

This gives us e2e flow for enabling config-in-db for a running gateway. Next up we will wire up the UI to edit live configs, and also add e2e tests.

The breakdown is:

  • When --config-file is provided, continue using current behavior
  • When --default-config is provided, continue using default config
  • When nothing is provided and flag is enabled, use config-in-db (this requires a postgres connection in env var).
  • When nothing is provided and flag is disabled, error and fail startup.

We can iterate on the exact API options here (we can deprecate --config-file too) but for now this means existing users don't see any differences and new users can get config-in-db with minimal changes once we flip the flag.


Note

Medium Risk
Adds a new CLI workflow that writes parsed/validated configuration and templates into Postgres, plus changes how template file paths are normalized; mistakes here could lead to incorrect stored template keys or failed startups when switching to config-in-DB.

Overview
Adds a new gateway early-exit CLI command, --store-config, which reads a config glob, validates it, and persists the resulting config (plus any discovered extra templates) into Postgres via write_stored_config.

Refactors startup config loading to reuse a shared load_config_from_path_glob helper and blocks --store-config when gateway.template_filesystem_access is active.

Changes TOML path resolution so file-backed template keys are stored as paths relative to the shared directory prefix (while directory paths like gateway.template_filesystem_access.base_path remain absolute), updating related DB write plumbing and tests accordingly.

Reviewed by Cursor Bugbot for commit 5882069. Bugbot is set up for automated code reviews on this repo. Configure here.

@shuyangli shuyangli force-pushed the sl/config-editing-via-toml branch from 61ea67b to 6e9d3b0 Compare April 8, 2026 15:06
@shuyangli shuyangli force-pushed the sl/add-cli-store-config-option branch from dcd7e6e to 1c2d757 Compare April 8, 2026 15:06
@shuyangli shuyangli force-pushed the sl/config-editing-via-toml branch from 6e9d3b0 to 419dd7f Compare April 8, 2026 15:22
@shuyangli shuyangli force-pushed the sl/add-cli-store-config-option branch from 1c2d757 to 0d660a3 Compare April 8, 2026 15:22
@shuyangli shuyangli force-pushed the sl/config-editing-via-toml branch from 419dd7f to 9bedcbf Compare April 8, 2026 15:36
@shuyangli shuyangli force-pushed the sl/add-cli-store-config-option branch from 0d660a3 to 4fe7a14 Compare April 8, 2026 15:59
@shuyangli shuyangli force-pushed the sl/config-editing-via-toml branch from 9bedcbf to 26709c0 Compare April 8, 2026 15:59
@shuyangli shuyangli force-pushed the sl/config-editing-via-toml branch from 26709c0 to 70b3dca Compare April 8, 2026 16:18
@shuyangli shuyangli force-pushed the sl/add-cli-store-config-option branch from 4fe7a14 to e2c6dee Compare April 8, 2026 16:18
@shuyangli shuyangli force-pushed the sl/config-editing-via-toml branch from 66901b7 to b0f17d7 Compare April 8, 2026 18:39
@shuyangli shuyangli force-pushed the sl/add-cli-store-config-option branch from e2c6dee to 86b4541 Compare April 8, 2026 18:39
@shuyangli shuyangli force-pushed the sl/config-editing-via-toml branch from b0f17d7 to a85514b Compare April 8, 2026 18:55
@shuyangli shuyangli force-pushed the sl/config-editing-via-toml branch 3 times, most recently from 85beeb8 to fdc9aa1 Compare April 8, 2026 19:33
@shuyangli shuyangli force-pushed the sl/add-cli-store-config-option branch from 86b4541 to 738154a Compare April 8, 2026 19:33
@shuyangli shuyangli force-pushed the sl/add-cli-store-config-option branch from 738154a to e8b6282 Compare April 8, 2026 20:33
@shuyangli shuyangli force-pushed the sl/config-editing-via-toml branch from fdc9aa1 to 9888492 Compare April 8, 2026 20:33
@shuyangli shuyangli force-pushed the sl/add-cli-store-config-option branch from e8b6282 to edab501 Compare April 8, 2026 20:37
@shuyangli shuyangli force-pushed the sl/config-editing-via-toml branch 2 times, most recently from 95ea677 to 60adc3e Compare April 8, 2026 20:42
@shuyangli shuyangli force-pushed the sl/config-editing-via-toml branch 2 times, most recently from 085ab56 to 533b3be Compare April 8, 2026 21:12
@shuyangli shuyangli force-pushed the sl/add-cli-store-config-option branch from 15f76cb to 5dc6d5b Compare April 13, 2026 16:57
@shuyangli shuyangli force-pushed the sl/add-cli-store-config-option branch from 63dbb2d to 5ec24e8 Compare April 13, 2026 17:43
@shuyangli shuyangli removed their assignment Apr 13, 2026
Copy link
Copy Markdown
Contributor Author

@BugBot review

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Directory path prefix stripping breaks filesystem template access
    • Modified ResolveRelativePathsVisitor::visit_leaf to skip prefix stripping for directory paths, ensuring they remain absolute as documented.

Create PR

Or push these changes by commenting:

@cursor push d05ef536a6
Preview (d05ef536a6)
diff --git a/crates/tensorzero-core/src/config/path.rs b/crates/tensorzero-core/src/config/path.rs
--- a/crates/tensorzero-core/src/config/path.rs
+++ b/crates/tensorzero-core/src/config/path.rs
@@ -358,10 +358,15 @@
 
         let resolved_path =
             resolve_target_path(self.span_map, span, target_string.as_ref(), error_path)?;
-        let remapped_path = self
-            .shared_path_prefix_to_strip
-            .and_then(|prefix| resolved_path.strip_prefix(prefix).ok())
-            .unwrap_or(resolved_path.as_path());
+
+        let is_directory = resolved_path.is_dir();
+        let remapped_path = if is_directory {
+            resolved_path.as_path()
+        } else {
+            self.shared_path_prefix_to_strip
+                .and_then(|prefix| resolved_path.strip_prefix(prefix).ok())
+                .unwrap_or(resolved_path.as_path())
+        };
         let remapped_path_str = path_to_utf8_string(remapped_path, error_path)?;
 
         let mut inner_table = DeTable::new();
@@ -370,7 +375,7 @@
             Spanned::new(0..0, DeValue::String(Cow::Owned(remapped_path_str))),
         );
 
-        if resolved_path.is_dir() {
+        if is_directory {
             if !is_directory_path(error_path) {
                 return Err(Error::new(ErrorDetails::Config {
                     message: format!(

This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

Comment thread crates/tensorzero-core/src/config/path.rs Outdated
Comment thread crates/tensorzero-core/src/config/path.rs
@Aaron1011 Aaron1011 assigned shuyangli and unassigned Aaron1011 and shuyangli Apr 13, 2026
@shuyangli shuyangli removed their assignment Apr 13, 2026
Copy link
Copy Markdown
Contributor Author

@BugBot review

@Aaron1011 Aaron1011 assigned shuyangli and unassigned Aaron1011 Apr 13, 2026
Aaron1011
Aaron1011 previously approved these changes Apr 13, 2026
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 5882069. Configure here.

Comment thread crates/tensorzero-core/src/config/tests.rs
@shuyangli shuyangli force-pushed the sl/add-cli-store-config-option branch from 04e60b5 to fc53808 Compare April 13, 2026 18:34
Aaron1011
Aaron1011 previously approved these changes Apr 13, 2026
Copy link
Copy Markdown
Member

@GabrielBianconi GabrielBianconi left a comment

Choose a reason for hiding this comment

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

blind

@shuyangli shuyangli added this pull request to the merge queue Apr 13, 2026
Merged via the queue into main with commit ebae68a Apr 13, 2026
77 of 78 checks passed
@shuyangli shuyangli deleted the sl/add-cli-store-config-option branch April 13, 2026 19:49
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.

Store all configs in config-in-database mode Add CLI options for config-in-database mode

3 participants