← Back to PRs

#9803: fix(#9801): auto-build control ui assets on demand

by dead-pool-aka-wilson open 2026-02-05 18:07 View on GitHub →
app: web-ui gateway stale
## Summary Adds automatic build logic for control UI assets when they are missing at runtime. ### Changes - Added `tryAutoBuildControlUi()` function that: - Checks if auto-build is enabled (via OPENCLAW_CONTROL_UI_AUTO_BUILD env var) - Resolves the control UI repo root - Executes scripts/ui.js build with 10-minute timeout - Handles errors gracefully - Integrated auto-build into request handler: attempts build if assets not found - Updated error message to indicate auto-build was attempted ### Testing - Manual verification: Confirm auto-build triggers when assets missing - Error response: Verify updated message appears when build fails - Environment variable: Test OPENCLAW_CONTROL_UI_AUTO_BUILD=0 disables auto-build <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR introduces a new plugin hook (`before_model_select`) and wires it into model selection, plus adds an on-demand Control UI asset build attempt when the UI bundle is missing at runtime. Key codepaths touched: - `src/auto-reply/reply/model-selection.ts` now calls the global hook runner during model selection, passing `{ provider, model, sessionKey, allowedModelKeys, prompt }`. - `src/plugins/types.ts` and `src/plugins/hooks.ts` add the new hook type and runner method. - `src/gateway/control-ui.ts` attempts to run `scripts/ui.js build` once per process when the Control UI assets directory can’t be found. Tests were added for the new hook runner behavior and for the model-selection integration. <h3>Confidence Score: 2/5</h3> - This PR has a couple of correctness issues that can cause confusing runtime behavior and failures in critical paths. - Control UI auto-build can silently fail because non-zero exit statuses aren’t handled, and the enable/disable env var is read only at module load time. On the plugin side, exceptions from the before_model_select hook can bubble up and break model selection if hooks are configured to throw, and hooks may receive an empty allowlist even when the catalog is available/needed for enforcement. - src/gateway/control-ui.ts, src/auto-reply/reply/model-selection.ts <!-- greptile_other_comments_section --> <sub>(5/5) You can turn off certain types of comments like style [here](https://app.greptile.com/review/github)!</sub> <!-- /greptile_comment -->

Most Similar PRs