Skip to content

ucode: add --skip-preflight to skip per-launch auth/gateway re-validation#195

Open
Edwinhe03 wants to merge 1 commit into
databricks:mainfrom
Edwinhe03:edwin-he/ucode-no-preflight
Open

ucode: add --skip-preflight to skip per-launch auth/gateway re-validation#195
Edwinhe03 wants to merge 1 commit into
databricks:mainfrom
Edwinhe03:edwin-he/ucode-no-preflight

Conversation

@Edwinhe03

@Edwinhe03 Edwinhe03 commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

What

Every ucode <agent> launch re-runs configure_shared_state, which does an auth login check, a token fetch, an AI Gateway v2 probe, and (outside provider mode) model discovery — ~5–10s of network round-trips — even when a prior ucode configure already validated all of it. Managed/headless launchers (e.g. omnigent) that run configure once and then launch repeatedly pay this on every turn.

Change

Add a launch-only --skip-preflight flag (distinct from the configure-only --skip-validate, which skips the post-configure model smoke test). It threads through _launch_tool as configure_shared_state(skip_preflight=True):

  • configure_shared_state assembles the shared workspace state (profile, base URLs, auth mode) up front, then returns early when skip_preflight is set; otherwise it falls through into the preflight block (auth + AI Gateway validation, then model discovery). One function, one shared assembly — no parallel state builder and no inverted not skip_preflight guard.
  • The profile is resolved from ~/.databrickscfg at most once per launch — in the skip branch (trusting the prior configure) or after databricks auth login on the full path, never both.
  • The PAT/bearer is already exported by apply_pat_environment, and the AI Gateway was verified by the earlier configure, so the skipped work is redundant. Previously-discovered model lists are preserved (not clobbered with empties).

Wired into every launch command (codex / claude / gemini / opencode / copilot / pi). Default off — behavior is unchanged unless a caller opts in.

--help

$ ucode codex --help

 Usage: ucode codex [OPTIONS]

 Launch Codex via Databricks.

╭─ Options ─────────────────────────────────────────────────────────────────────╮
│ --provider        TEXT  Route through a Unity Catalog Model Provider Service    │
│                         (<catalog>.<schema>.<name>). Skips Databricks model     │
│                         pinning; pass before any `--` separator.                │
│ --skip-preflight        Skip the per-launch Databricks auth + AI Gateway        │
│                         re-validation, trusting a prior `ucode configure`.       │
│ --help                  Show this message and exit.                             │
╰────────────────────────────────────────────────────────────────────────────────╯

Tests

New tests in tests/test_cli.py:

  • TestConfigureSharedStateSkipPreflightconfigure_shared_state(..., skip_preflight=True) makes no ensure_databricks_auth / ensure_ai_gateway_v2 / get_databricks_token / model-discovery calls (each patched to raise if hit), still rebuilds base_urls + persists state, and resolves the profile when None.
  • TestSkipPreflightFlag--skip-preflight on every launch command threads through _launch_tool to configure_shared_state as skip_preflight=True (and defaults to False without the flag).
$ uv run pytest tests/test_cli.py -k preflight
10 passed, 80 deselected

$ uv run pytest         # full unit suite
858 passed, 8 skipped

ruff + ty clean.

Manual verification

Configured against a real staging workspace (ucode configure --profiles <p> --agents claude --use-pat), then launched the same agent with and without the flag (claude --version execs the real binary and exits, so the launch is observable end-to-end):

$ ucode claude --version                    # DEFAULT — preflight runs
✔ Databricks auth already available for https://…staging.cloud.databricks.com
✔ Unity AI Gateway detected
  Model: system.ai.claude-opus-4-5
✔ Starting Claude Code
2.1.206 (Claude Code)
elapsed: 7.39s

$ ucode claude --skip-preflight --version   # preflight skipped
  Model: system.ai.claude-opus-4-5
✔ Starting Claude Code
2.1.206 (Claude Code)
elapsed: 0.79s

--skip-preflight drops the auth + AI Gateway round-trips (7.39s → 0.79s, ~7s saved), and the agent still launches on the correctly-resolved model — confirming the trusted state (base URLs rebuilt, model lists preserved) is intact.

This pull request and its description were written by Isaac.

@Edwinhe03 Edwinhe03 force-pushed the edwin-he/ucode-no-preflight branch from ddf72cd to 2ef7d98 Compare July 9, 2026 00:33
@Edwinhe03 Edwinhe03 requested a review from lilly-luo July 9, 2026 00:36
Comment thread src/ucode/cli.py Outdated
Comment thread src/ucode/cli.py Outdated
@Edwinhe03 Edwinhe03 force-pushed the edwin-he/ucode-no-preflight branch from 2ef7d98 to e05650b Compare July 10, 2026 17:52
@lilly-luo

Copy link
Copy Markdown
Collaborator

this is great! can you put the --help outputs on the PR description and have some examples to confirm this is working? before merge

lilly-luo
lilly-luo previously approved these changes Jul 10, 2026

@lilly-luo lilly-luo 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.

ideally also rename to --skip-preflight

@Edwinhe03 Edwinhe03 changed the title ucode: add --no-preflight to skip per-launch auth/gateway re-validation ucode: add --skip-preflight to skip per-launch auth/gateway re-validation Jul 10, 2026
@Edwinhe03 Edwinhe03 force-pushed the edwin-he/ucode-no-preflight branch 3 times, most recently from f3fe6a7 to 5782bcf Compare July 10, 2026 21:22
…tion

Every `ucode <agent>` launch re-runs configure_shared_state, which does an auth
login check, a token fetch, an AI Gateway v2 probe, and (outside provider mode)
model discovery — ~5-10s of network round-trips — even when a prior
`ucode configure` already validated all of it. Managed/headless launchers (e.g.
omnigent) that run configure once and then launch repeatedly pay this on every
turn.

Add a launch-only `--skip-preflight` flag (distinct from the configure-only
`--skip-validate`, which skips the post-configure model smoke test). It threads
through _launch_tool as configure_shared_state(skip_preflight=True).
configure_shared_state now assembles the shared workspace state (profile, base
URLs, auth mode) up front and returns early when skip_preflight is set;
otherwise it falls through into the preflight block (auth + AI Gateway
validation, then model discovery). The PAT/bearer is already exported by
apply_pat_environment and the gateway was verified by the earlier configure, so
the skipped work is redundant, and the saved model lists are preserved.

Wired into every launch command (codex/claude/gemini/opencode/copilot/pi),
default off.

Co-authored-by: Isaac
@Edwinhe03 Edwinhe03 force-pushed the edwin-he/ucode-no-preflight branch from 5782bcf to c21003a Compare July 10, 2026 21:34
@Edwinhe03 Edwinhe03 requested a review from lilly-luo July 10, 2026 22:17
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.

2 participants