Auto-Optimize (GSO)
Auto-Optimize measures a Genie Agent against its benchmark corpus, diagnoses failures, and tests targeted configuration changes. It is powered by the Genie Space Optimizer package in packages/genie-space-optimizer/.
Unlike the IQ Scanner, which produces an instant rule-based readiness score, Auto-Optimize runs a bounded optimization job against the live Agent. Every attempt is evaluated, accepted only when accuracy improves and question-level paired evidence supports the change, and persisted for audit.
Four-task pipeline
The current Lakeflow Job is a linear four-task DAG:
| # | Task | Responsibility |
|---|---|---|
| 1 | Intake & Snapshot | Validate the run envelope, retain the trigger-time rollback snapshot, and write the run_manifest artifact. |
| 2 | Benchmark QC & Repair | Review question clarity and question-to-SQL alignment, validate SQL and ground-truth data, and—only when allowed for the run—repair or replace hard failures before persisting benchmark_qc. |
| 3 | Optimize | Apply low-risk Agent quality enrichment, run the baseline evaluation, and execute the bounded patch/evaluation loop. |
| 4 | Publish & Audit | Resolve the stamped terminal reason, mark the champion when eligible, generate a best-effort audit summary, capture postflight IQ, and write terminal run state. |
Each task receives the complete job parameter set and exchanges durable state through Delta by run_id. There is no notebook chaining or task-value handoff.
Benchmark quality review
Each run has an explicit benchmark policy. The Workbench defaults to review only: GSO reviews the native benchmark questions captured in the pre-run snapshot, excludes invalid questions from that run's evaluation corpus, and does not generate, repair, push, or ledger any live benchmark mutation. Turning on Allow GSO to repair and add benchmarks enables the bounded repair, replacement, and live merge behavior used by earlier runs. That permission allows GSO to update both question wording and expected SQL after re-validation; it never allows GSO to delete an existing live benchmark.
Benchmark QC separates five kinds of evidence: question quality,
question-to-SQL alignment, SQL validity, data validity, and review-system
health. A benchmark with a hard semantic or validation error is excluded from
the evaluation working set. Repair-enabled runs replace excluded questions
toward the configured target; review-only runs retain only the accepted native
subset. Wording that is weak but still has one defensible answer remains
eligible with a warning. A semantic-review outage is recorded as
review_not_run; it is never silently reported as a successful review.
Quality counters and finding groups use the same final per-question
disposition. Multiple findings on one question do not inflate the counts, and
native review-only questions retain their space_question_id throughout QC.
Duplicate-normalized questions remain a separate mutation-ledger diagnostic.
Bounded data profiles are advisory rather than proof that a filter value does not exist. This distinction is especially important for metric views. When the ground-truth SQL executes and returns rows, execution overrides a profile-only value miss. If execution cannot confirm the query, the profile miss remains a non-repairing warning; a confirmed zero-row result is the hard data-validity failure.
Repair-enabled runs re-review every changed benchmark. If rewriting a question reveals a follow-up expected-SQL correction, GSO applies that correction in a later bounded repair round and reviews the result again. A benchmark leaves the repair loop only when it passes, has no coherent actionable proposal, or exhausts the configured repair limit. The reported repaired count includes only benchmarks that finish trusted; the mutation ledger separately records every question or SQL change that was actually published. Rows that exhaust the repair limit are preserved in the live Agent and excluded only from the current run's evaluation corpus. Failed generated replacement candidates remain in the repair-sweep telemetry; they are never presented as live benchmark exclusions.
Generation targets 30 valid questions and the working set is capped at 40 — no evaluation ever runs on more than 40 questions, and an already-valid corpus of 30–40 is retained and evaluated in full. A run may proceed with fewer when generation or bounded repair cannot reach the 30 target. For repair-enabled runs, GSO performs a final count-driven top-up after comprehensive review and deduplication: up to three LLM calls, each requesting at most 10 net-new questions. It stops early at 30 valid questions or after two consecutive calls add no valid unique questions. Review-only runs never enter this loop.
At least 15 valid questions are required to optimize. When bounded top-up is
exhausted, a corpus of 15–29 proceeds; fewer than 15 causes Optimize to perform
no evaluation or configuration mutation, and Publish & Audit records a terminal
SKIPPED summary with reason INSUFFICIENT_VALID_BENCHMARKS. The
benchmark_qc artifact records each top-up call's requested, generated,
accepted, rejected, and duplicate counts together with the final stop reason.
These bounds come from TARGET_BENCHMARK_COUNT (30), MAX_BENCHMARK_COUNT
(40), and MIN_VALID_BENCHMARK_COUNT (15). Setting GSO_NEW_SIZING=0 restores
the legacy 24/29 target and ceiling.
The benchmark_qc artifact records structured findings, review coverage,
quality counts, and proposed repairs. The Benchmark Changes panel surfaces
trusted, warning, and excluded counts alongside the mutation ledger. Long
mutation groups are disclosures; Added starts collapsed so generated
benchmark SQL does not dominate the run page.
Before review, and again after any repair or regeneration sweep, GSO
deduplicates normalized question text. The deterministic winner order is:
user/Genie-authored, SQL-valid, curated/P0, then stable input order. Every
rejected duplicate is recorded as a non-mutating excluded ledger row with
reason duplicate_normalized_question; benchmark_qc also records the
retained question id.
The final corpus is written directly to
genie_benchmarks_<domain> as a Delta table with nested inputs and
expectations structs. MLflow is not used for dataset persistence, run
tracking, model registration, or evaluation; it is used only for LLM tracing.
The job's LLM calls go through Unity AI Gateway by default (the genie_llm_route
job parameter follows the app's GENIE_LLM_ROUTE), run as the app service
principal, and are tagged gso-optimize with the run's run_id. See
LLM calls.
Optimization loop
The Optimize task uses a full-benchmark hill-climbing loop:
Iteration 0 is the baseline. Later rows are patch attempts. A candidate is accepted only when both acceptance conditions hold; otherwise its patches and iteration are marked rolled back and the live serialized configuration is restored.
- Its full-evaluation accuracy is strictly greater than the best accepted accuracy.
- Its question-level paired evidence passes at
p <= 0.10.
Paired evidence gate
Genie generation is stochastic, so a candidate can score higher than its control by chance. Accuracy alone therefore cannot distinguish a real improvement from run-to-run noise. The gate reuses the official control and candidate evaluation rows already returned by the Eval-Run API, so it adds no Genie evaluations, API calls, or runtime cost.
Rows are aligned by the stable benchmark question id. GOOD counts as correct; BAD and NEEDS_REVIEW count as non-correct. Questions where the two runs disagree are the discordant pairs: a win is control non-correct and candidate correct, a loss is the reverse. An exact one-sided sign test over those pairs must reach p <= 0.10, under the null that a disagreement is equally likely to favor either configuration.
The gate fails closed. Evidence is rejected when rows are missing, a question id is missing or duplicated, the two row sets do not match, a row is unscored, or there are no discordant pairs. The typed evidence reason is one of paired_evidence_passed, insufficient_paired_evidence, no_discordant_pairs, missing_rows, missing_question_id, duplicate_question_id, question_id_mismatch, or unscored_row.
Wins, losses, ties, discordant count, p-value, threshold, and the evidence reason are persisted in the iteration reflection for both accepted and rolled-back attempts, and the decision reason records why a candidate was accepted or rejected.
The controller stores attempt mode, hypothesis, decision, decision reason, best accuracy, retry memory, terminal reason, and champion state on genie_opt_iterations. Terminal stamping adds the terminal reason without overwriting the attempt's existing accept/reject decision.
Levers
The strategist selects from the configured levers for each attempt:
| Lever | Area | Typical changes |
|---|---|---|
| 1 | Tables & columns | Table and column descriptions, synonyms |
| 2 | Metric views | Governed metric definitions and routing |
| 3 | Table-valued functions | Parameterized query patterns |
| 4 | Join specifications | Preferred relationships and join keys |
| 5 | Instructions & examples | Business vocabulary, routing rules, constraints, examples |
| 6 | SQL expressions | Reusable filters, measures, expressions, and worked SQL |
Lever 0 (Proactive Enrichment) is a preparatory stage that always runs before the adaptive lever loop. It is not user-selectable and is not shown as a toggle.
Before baseline evaluation, a narrow Agent-quality phase may also fill low-risk curation gaps such as an empty top-level Agent description, thin instructions, and prompt-matching flags. Format assistance is enabled on visible columns, while entity matching is allocated deterministically to eligible string columns using UC types, cardinality, benchmark references, and RLS safeguards. These flags are not proposed by the LLM lever loop. The post-enrichment description is persisted separately because Genie stores description as Agent metadata, outside serialized_space.
For wide schemas, column ranking can use workspace-scoped
system.query.history after filtering to finished SELECT statements that
reference configured assets and excluding the GSO service principal. Two
strict Databricks-generated profiling signatures are also excluded: the
WITH SampledData null/distinct-count batch and the exploded
approx_top_k(...).item.item AS value query. Ordinary CTEs and ordinary
approx_top_k analytics remain eligible.
Metric view advisor
Metric view advice is available from two surfaces:
- An optimization run can persist proposals discovered from generated and curated SQL when Metric view suggestions is enabled.
- The Agent's IQ Score can request space-scoped advice without starting an optimization run. This path seeds candidate fingerprints from the Agent's curated SQL. After a candidate exists, matching query-history traffic contributes demand and recency evidence to its score; query history does not seed recurring measures itself. A genuinely new Agent with no curated SQL therefore correctly returns no recurring measures, even if unrelated query history exists.
Recommendations bundle compatible measures at one grain and show validation facts
and evidence rather than presenting the ranking score as a probability. A measure
is identified by its expression and the tables it reads, so the same aggregate over
two tables is two suggestions, each in its own table's view. A table named without
its catalog or schema counts as that table when the Agent has exactly one table by
that name; otherwise the measure is not proposed. A row count such as COUNT(*)
belongs to the one table its query reads, and joins that table's view; over a join
it names no table and isn't proposed. Over a derived table or a CTE it names no table
either, and isn't proposed. A rejection recorded before this change still hides its
measure, except one recorded under a retired merged key, or over a derived-table
COUNT(*) or a struct-field measure, which can show its measure once more. A user can
approve a recommendation from the card, choose the target schema, and complete a
fresh entitlement check. Workbench then creates the metric view under that user's
OBO identity and attaches it to the live Genie Agent in the same request. If
creation succeeds but attachment fails, the result is reported as partial success
and can be retried safely. If a metric view with that name already exists,
Workbench attaches it only when its definition matches the recommendation
(Unity Catalog's reformatting of the stored YAML is ignored). A different or
unreadable definition is refused, and the existing view is left untouched. An
existing view you don't own is recorded as user-created, and Workbench never drops it.
The approval result names the view's owner, and offers the copy-ready GRANT for
the optimizer only when you own the view, because only the owner can run it. Once
an approval shows that someone else owns the view, the card's detail stops
offering the GRANT too, until you leave the page. A run's create-and-attach
results and a card already marked attached still show the GRANT whoever owns the
view. If a create or its record times out, approving again finds the view and
finishes the job.
In run setup, Create and attach creates only the recommendations you select, and they must share one target schema. The permission check covers exactly the selected recommendations. Start stays disabled while nothing is selected, while the selection spans schemas, and while the check runs. If the check does not pass, the run continues in suggest-only mode. The permission check runs once the selection has settled. If a run's create times out, or its record can't be written, the run leaves the view in place and never drops it, and a later run finishes the job: it adopts a matching view you own.
This Genie v2 deployment round-trips attached metric views under
data_sources.tables. Workbench normalizes UC-confirmed metric views on read, so
the IQ Score and Model tab treat them as governed metric views. Once attached, a
proposal leaves the active recommendation cards/count and appears in the attached
summary. The Model tab's Semantic Blueprint shows the live Agent model together
with governed, curated, and proposed measures, metric-view structure, measure
lineage, and advice-only join findings.
Generated metric views keep the SQL as written in the Agent: text values keep their capitalization, and date functions keep their units. Every table and column name is quoted, so names with spaces or reserved words work. A recurring measure that combines columns from more than one table isn't proposed yet; when that's all the scan finds, the IQ scan says so. A proposal made by an earlier version of the advisor can't be created as is: it shows a re-scan notice instead of its create action, isn't offered for a run, and doesn't show its DDL. Re-scan the Agent for a current suggestion. If the re-scan proposes the same view again, the older card goes away; if not, the older card stays, marked. A proposal found by an earlier version of the advisor shows only its re-scan notice: no graph node, no configuration preview and no lift label. When a re-scan reshapes a view, only the newest undecided proposal for it is listed. A proposal whose view was created or registered stays listed even when a newer proposal names the same view. When a run creates no metric view, the run output says why, including approved proposals that are no longer available.
When a run attaches an approved metric view, it re-runs the full benchmark suite with the view attached. The view is kept only if accuracy on the questions it affects doesn't fall and accuracy on the whole suite doesn't fall either. The affected questions are live benchmark questions whose recorded evidence or SQL uses one of the view's measures, so a view that no benchmark question exercises is not attached. If none of those questions can be graded, the view is detached and can be measured again in the next run. After a kept view, the optimizer judges every later change against the new accuracy, so no change is credited with the view's gain. Iteration 0 keeps its pre-attach score as the baseline, and the kept view is its own step after it: the run headline shows the view's gain as the improvement over that baseline, and the run's audit trajectory lists the step. A kept metric view or an enrichment pass that beats the baseline before the first lever counts as the improvement, both on the live card and when the run finishes. If attaching the view fails in a way that leaves it unclear whether Genie applied the change, the run reads the Agent's live configuration and removes the view if it landed. If anything fails after the view is attached, the run restores the Agent's previous configuration; if even that fails, the run reports it, and when the run ends it reads the Agent's live configuration and names any such view that is still attached. The metric view itself is never dropped.
Evaluation and leakage safety
Current runs use Genie's native benchmark Eval-Run API as the sole evaluation
harness and persist the official evaluation run identifiers, status, question
counts, correctness counts, and needs-review counts. Headline accuracy is
num_correct / num_questions for native evaluation rows.
A transient eval-service fault does not sink a run that has already committed
real improvement. EVALUATION_TIMEOUT and EVALUATION_CANCELLED are retried up
to two extra times (three attempts total) before the loop surfaces a failure,
and terminal stamping falls back to the best persisted iteration so a late blip
cannot overwrite a committed champion with the baseline. EVALUATION_FAILED is
not retried — it means the evaluation genuinely failed.
Benchmark expected SQL is evaluation truth and must never become inference-visible configuration. The optimizer's leakage firewall blocks patches that copy or closely echo benchmark answer material into instructions, examples, descriptions, or other Agent content.
Terminal outcomes
The loop stamps one of the typed reasons below. Publish & Audit uses that stamped reason and never re-derives it from accuracy.
| Terminal reason | Run status | Champion publish |
|---|---|---|
TARGET_REACHED | CONVERGED | Yes |
MAX_ATTEMPTS | MAX_ITERATIONS | Yes |
NO_NEW_HYPOTHESIS | STALLED | No |
EVAL_INVALID | FAILED | No |
CONFIG_VALIDATION_FAILED | FAILED | No |
LOOP_STATE_INVALID | FAILED | No |
EVAL_BUDGET_EXHAUSTED | STALLED | No |
INSUFFICIENT_VALID_BENCHMARKS | SKIPPED | No; Optimize does not run |
| Missing or unknown | STALLED | No, fail closed |
Publishing is an idempotent Delta champion mark. Accepted patches are already applied to the live Agent by the loop; Publish & Audit does not replay them. The Workbench therefore presents the champion as live immediately and does not ask the user to keep or apply it. When live monitoring observes terminal state, it automatically runs and persists the full Workbench IQ scan so the Score tab reflects the current Agent. Audit-summary generation and the GSO-owned postflight IQ snapshot are soft-failing and cannot prevent the final status write.
History, revert, and discard
Optimization History separates View Details and Revert Options into different columns. The benchmark-handling column records whether the run was review-only or repair-enabled and, for repair-enabled runs, how many live benchmark additions or SQL updates it made.
One Revert Options action opens a dialog with two independent choices:
- Agent config: restore the run's champion or its pre-run baseline.
- Benchmarks: restore the champion iteration's benchmark block, preserve the current live benchmark block, or restore the run's pre-run baseline benchmark block.
The dialog defaults to restoring both the champion config and its benchmarks. It previews how many benchmarks either historical snapshot will add, remove, or update and requires confirmation before replacing the live Agent. A history revert does not change the historical run status. Champion config restores the captured post-enrichment description when available; legacy runs preserve the current description.
Optimization History compares the live Agent configuration and benchmark block independently with every visible captured baseline and champion. Runs removed from Workbench history are excluded from this comparison. A green Live badge means both components match the same version. If they match different known versions—for example, champion config with baseline benchmarks—the history shows the state as mixed without treating it as external drift. If either component matches no visible captured version, a warning names the changed component, including benchmark-only edits made directly in the Genie UI or API. For older runs that predate authoritative captures, the UI reports that history is incomplete instead of claiming an external change. Returning to the Workbench tab after a direct Genie UI edit forces a fresh live-state check.
The post-run surface states that a published champion is already live and offers
Roll back changes as an optional recovery action. Rollback restores the
complete trigger-time snapshot, including the original benchmark block and
top-level description, then marks the run DISCARDED only after restoration
succeeds. The Workbench automatically refreshes the IQ score again after a
successful rollback or History Revert Options action.
Both paths snapshot live state before a two-part serialized-config/description mutation. If the description update fails after the serialized config succeeds, the optimizer attempts compensation and never reports success for the partial operation.
History revert is disabled while any run for the same Agent is active. The backend also reconciles all same-Agent runs and returns a conflict if one remains QUEUED, IN_PROGRESS, or RUNNING.
Terminal runs also have Remove from history. After confirmation, the run
disappears for everyone from Optimization History and the unified History
chart. This is a Workbench display tombstone: it does not change the live Genie
Agent, delete the Databricks workflow run, or purge GSO Delta audit records.
The action requires CAN_EDIT or CAN_MANAGE on the Agent and is unavailable
while the selected run is active. Lakebase must be available so the removal is
durable across app restarts.
Permission model
The app service principal owns optimizer Delta state and executes the Lakeflow Job. A history action therefore reads internal state with the SP, but separately authorizes the requesting OBO user against the target Genie Agent. The user must have CAN_EDIT or CAN_MANAGE; the SP's broader access never substitutes for user authorization.
The SP also needs read access (USE CATALOG, USE SCHEMA, SELECT) to every schema the Agent references. The Auto-Optimize tab shows the missing GRANTs and disables Start until they are in place, including for a schema whose grants it could not read. The trigger endpoint enforces the same check for callers that skip the UI: it refuses with a 403, before any run is recorded, when a schema is definitely not granted, and proceeds with a logged warning when the Grants API cannot answer.
See Authentication & Permissions for setup and required grants.
Durable state
The main current-run sources of truth are:
| Table | Contents |
|---|---|
genie_opt_runs | Run envelope, trigger snapshot, status, champion pointer, terminal reason |
genie_opt_stages | Four-task and nested-stage timeline |
genie_opt_iterations | Baseline/attempt evaluation and controller state |
genie_opt_patches | Applied and rolled-back patch records |
genie_opt_benchmark_mutations | Benchmark QC additions, removals, and changes |
genie_benchmarks_<domain> | Direct Delta handoff of the deduplicated benchmark corpus to Optimize |
genie_opt_artifacts | Typed JSON payloads keyed by artifact kind — run_manifest, space_metadata, benchmark_qc, space_quality_enrichment, publish_record, operator_proposed_joins (Join Advisor seeds), and the six wide_schema_* kinds (inventory, evidence, selection_plan, audit, profile_telemetry, prompt_telemetry) |
genie_opt_scan_snapshots | Optional paired preflight/postflight IQ snapshots |
Four further tables are created alongside these and hold the metric view advisor's durable state. They are populated as spaces are analyzed and users make decisions; an individual table can still be empty when no corresponding proposal, consent, created object, or rejection has occurred:
| Table | Grain | Contents |
|---|---|---|
genie_opt_mv_candidates | (target_space_id, dedup_fingerprint) | Metric view proposals and their human approve/reject decisions |
genie_opt_mv_consents | probe_id | Entitlement probes and the scoped consent recorded against them |
genie_opt_mv_created_objects | (run_id, suggestion_id) | Both metric views created by Workbench under OBO (OBO_CREATED) and user-created metric views verified and registered with Workbench (USER_CREATED), plus their attach/detach lifecycle |
genie_opt_mv_suppressions | (target_space_id, measure_fingerprint) | Per-measure rejection records that prevent a rejected measure from resurfacing when proposal bundle membership changes |
The grains follow each entity's lifecycle: candidates and suppressions are
space-scoped, consents are probe-scoped and can predate a run, and created-object
records are keyed by run and suggestion. A registered USER_CREATED object is
hosted by a sentinel advice run, preserving the same (run_id, suggestion_id)
key as an OBO_CREATED object.
Workbench stores removed-history tombstones separately in Lakebase table
genie.hidden_optimization_runs; GSO audit tables remain immutable.
The Workbench prefers Lakebase synced reads for UI views and falls back to direct Delta reads where needed. Mutating integration paths use the configured SQL Warehouse and SP-owned state.
Operator-proposed joins (Join Advisor seeds)
A run can carry operator-proposed joins — data-grounded candidate joins a user
seeded from the Model tab's Join Advisor. These are
advice, not a pre-applied config edit. On trigger, the pending seeds are passed
as proposed_join_seeds and written best-effort as a run-scoped
operator_proposed_joins artifact in genie_opt_artifacts. At loop start the
optimizer reads that artifact and injects each seed into the LLM prompt as a
hypothesis to validate. Only joins that hold are added via add_join_spec; the
patch allowlist has no remove_join_spec, which is exactly why the Workbench seeds
advice instead of declaring a join a later run could not undo. A missing or
unreadable artifact simply means no operator advice — the run proceeds as normal.
Triggering from the UI
- Open an Agent and select Optimize.
- Configure levers, target accuracy, attempt budget, model, and whether GSO may repair or add live benchmarks. Repair is off by default.
- Start the run. The UI submits
POST /api/auto-optimize/triggerand polls the run status. - Review the attempt ladder, question results, patches, benchmark QC, audit summary, and terminal outcome.
- The accepted state is already live. Optionally roll it back to the trigger snapshot, or later use Revert Options to choose a past config and benchmark scope independently. The IQ score refreshes automatically when the run finishes.
Refreshable Agent and run links
Workbench stores the current Agent, tab, and monitored optimization run in the page query string. Refreshing the browser therefore restores the same Optimize view instead of returning to the Agent list. Browser back and forward navigation also restore prior tabs and run views.
The View Run action on an Agent's Score tab includes the active run ID and opens that run's live monitoring view directly. These links do not bypass normal Workbench or Databricks authorization checks.
Source files
packages/genie-space-optimizer/databricks.yml— four-task job definitionpackages/genie-space-optimizer/src/genie_space_optimizer/jobs/— task notebookspackages/genie-space-optimizer/src/genie_space_optimizer/optimization/unified_loop.py— optimizer controllerpackages/genie-space-optimizer/src/genie_space_optimizer/optimization/publish.py— publish and auditpackages/genie-space-optimizer/src/genie_space_optimizer/integration/— trigger, apply, discard, and history revertbackend/routers/auto_optimize.py— Workbench API bridge
Related documentation
- Optimization Guide — practitioner playbook for diagnosing benchmark failures and choosing the right fix surface
- Debug GSO runs with Genie Code
- Authentication & Permissions
- IQ Scanner
- Join Advisor — how operator-proposed join seeds enter a run
- Semantic Model (Blueprint) — visualize the model being optimized
- Operations Guide