Skip to content

fix(ui): repair botched-merge syntax errors that break app boot (#111)#112

Merged
elder-plinius merged 2 commits into
elder-plinius:mainfrom
lyubomir-bozhinov:fix/ui-init-duplicate-response-111
Jul 24, 2026
Merged

fix(ui): repair botched-merge syntax errors that break app boot (#111)#112
elder-plinius merged 2 commits into
elder-plinius:mainfrom
lyubomir-bozhinov:fix/ui-init-duplicate-response-111

Conversation

@lyubomir-bozhinov

Copy link
Copy Markdown
Contributor

What & why

Fixes #111 — the Web UI is stuck on "Initializing…", all links/buttons dead, only GET /api/selfimprove/ledger looping in the terminal.

Root cause: docs/index.html is one big classic <script>. A series of bad auto-merges left duplicated old/new copies of the same LLM-call code side by side, producing JavaScript syntax errors. A syntax error means the browser never executes any of that script — so navigateTo and every handler are undefined, the health poll never runs (status stays "Initializing…"), and only a previously-scheduled poller keeps firing. The server itself is healthy (/api/healthok:true).

Because a JS engine reports only the first syntax error per script, these were layered — each fix revealed the next. There were eight.

The fixes (all in docs/index.html)

Site Scar Fix
_safeLLMCallOnce duplicate response decl + leftover pre-refactor fetch one call, backend-aware endpoint/headers (OpenRouter and Venice, backend.key), cancellable AbortController kept
safeLLMCall entire function duplicated (old truncated head + new loop referencing an undefined backend) reunified: backend resolution + agent/server routing + model chain + fallback loop
runLLMJudge two function bodies concatenated (one nested, never closed) keep the complete qItem/cancellation variant
runBenchmarks, autoApplyRecommendations old "ANY LLM backend" guard left unclosed before the new "reachable (key or local mode)" guard drop dead old guard / restore missing }
benchmark auto-apply button, config-optimizer, self-improve, CTF call duplicated option objects / double catch collapse to the newer _noFallback/cancellable variant

Net −58 lines (dead duplicated code removed). No behavior removed — the newer, local-mode-aware / cancellable variants are kept; Venice + OpenRouter + agent/server + model-fallback all preserved.

Regression test

src/__tests__/ui-inline-scripts-parse.test.ts (new) compiles every classic inline <script> with node:vm — exactly how a browser parses it — with zero new dependencies. It fails on current main with Identifier 'response' has already been declared and passes after the fix, guarding the whole class of "the app won't boot because the script won't parse" regressions.

Verification (macOS)

  • RED→GREEN: the new test fails on main, passes after the fix.
  • Full suite 646 green; typecheck clean.
  • Headless Chromium boot: #connectionText now reads "Connected", typeof navigateTo === 'function', client-side navigation works, 0 uncaught JS errors (was: stuck "Initializing…", navigateTo undefined).

Verified on macOS only. The LLM-call reconstructions are validated for parse + boot and preserve the pre-merge behavior of both merge halves; I couldn't exercise live provider calls without keys, so a maintainer spot-check of a real OpenRouter/Venice/local run is welcome.

Closes #111

…st parse

Compiles every classic inline <script> in docs/index.html with node:vm
(how a browser parses it). Fails on current main with 'Identifier
response has already been declared' — the duplicate declaration in
_safeLLMCallOnce that stops the whole SPA from booting.
…r-plinius#111)

docs/index.html is a single classic <script>. Eight scars from bad
auto-merges (duplicated old/new versions of the same LLM-call sites left
side by side) made the script fail to PARSE, so nothing ran: the UI stuck
on "Initializing…", every link/handler dead, only the pre-registered
selfimprove/ledger poller still firing.

A parse error surfaces one at a time (the engine stops at the first), so
these were only visible once each prior one was fixed. Repaired:

- _safeLLMCallOnce: duplicate `response` decl + a leftover pre-refactor
  fetch; restored backend-aware endpoint/headers (OpenRouter + Venice,
  backend.key) and kept the cancellable AbortController.
- runLLMJudge: two function bodies concatenated (one nested, never closed).
- safeLLMCall: the whole function duplicated (old truncated head + new
  loop that referenced an undefined `backend`); reunified into one
  function with backend resolution, agent/server routing, model chain and
  the fallback loop.
- runBenchmarks / autoApplyRecommendations: old "ANY LLM backend"
  guard left un-closed before the new "reachable (key or local mode)"
  guard — dropped the dead old guard / restored the missing brace.
- generateAnalysis auto-apply button, config-optimizer, self-improve and
  CTF call sites: duplicated option objects / double catch collapsed to
  the newer (_noFallback / cancellable) variant.

Verified on macOS: new regression test compiles every classic inline
<script> with node:vm (the RED baseline failed with "Identifier response
has already been declared"); full suite 646 green; headless-Chromium boot
now reaches "Connected", navigateTo is defined, zero uncaught errors.
@beunwa

beunwa commented Jul 22, 2026

Copy link
Copy Markdown

It fix the problem for me (on linux)

@lyubomir-bozhinov

Copy link
Copy Markdown
Contributor Author

Thanks for testing, @beunwa — much appreciated. I could only verify on macOS, so a Linux confirmation is exactly the cross-platform datapoint this needed. 🙏

@elder-plinius
elder-plinius merged commit 7824041 into elder-plinius:main Jul 24, 2026
1 check passed
@lyubomir-bozhinov
lyubomir-bozhinov deleted the fix/ui-init-duplicate-response-111 branch July 25, 2026 12: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.

APP doesn't initialize - unresponsive

3 participants