Skip to content

fix(ui): show health checks as they finish instead of after the slowest - #870

Merged
runkids merged 3 commits into
mainfrom
runkids/doctor-stream
Nov 12, 2026
Merged

runkids merged 3 commits into
mainfrom
runkids/doctor-stream

Conversation

@runkids

@runkids runkids commented Nov 12, 2026

Copy link
Copy Markdown
Owner

Type

  • Bug fix
  • Small improvement (docs, typo, minor refactor)
  • Feature proposal (proposals/ only — see CONTRIBUTING.md)
  • Approved feature or large change (the linked issue has the approved label)

Linked Issue

None. Found while using the dashboard: the Doctor page showed a skeleton for about 30 seconds.

What and why

skillshare doctor -g on an affected machine took 30.2s wall time but only 1.4s of CPU. The plugin check waited out its 30-second budget on native CLIs that never answered. The Doctor page could not show anything until the whole run finished, and the server's 30-second write timeout sat right at that edge, so /api/doctor was sometimes cut off.

  1. Stream health checks (fix(ui)). doctor --json prints each check as a {"check": ...} line when the internal _SKILLSHARE_DOCTOR_STREAM variable is set; without it the output is unchanged. New GET /api/doctor/stream relays them as Server-Sent Events, then sends the full result as done. It has no write deadline and stops doctor when the client leaves. The Doctor page shows checks as they arrive, with a skeleton row while more are coming. Run again keeps the previous result on screen until the new one is done. GET /api/doctor stays for API users and is now bound to the request context.
  2. Show the server's reason when a stream fails (fix(ui)). The audit, diff and doctor streams send an error event with a reason, but createSSEStream handled it like a dropped connection and showed a generic message. It now shows the server's reason and keeps the generic message for a real disconnect.
  3. Skip Git reads in the hooks check when no hooks are configured (fix(doctor)). The check loaded the full hooks inventory, which runs git version and five git config reads twice even with no hooks. Doctor now reads the hooks section first (new hooks.Service.Source()) and previews a sync only when there is something to check. The dashboard Hooks page still uses List().

Docs: the Web API table in website/docs/reference/commands/ui.md and its four translations list the new endpoint.

Verification

  • make check in the devcontainer: passed.
  • UI: pnpm run build, pnpm lint (0 errors; the 53 warnings already exist on main), pnpm test (888 passed).
  • New tests: CLI stream unit tests, relayDoctorChecks unit test, TestDoctor_JSON_StreamPrintsEachCheckBeforeResult, TestDoctor_HooksNotConfiguredRunsNoGit (failed before the fix), sseStream.test.ts (failed before the fix), and a doctorFromChecks count test.
  • End to end: ran skillshare ui with doctor's hook-related Git calls slowed by one second each. The page showed 17 checks within 1s and the remaining checks and version box at 8.8s.

Not covered

  • No handler-level test for handleDoctorStream: it runs os.Executable(), which is the test binary under go test. The relay is unit-tested, and the CLI stream format is integration-tested.
  • Why some native plugin CLIs time out is a separate problem; this PR only stops it from blocking the page.

Checklist

  • I've read CONTRIBUTING.md, including its AI-assisted contributions section
  • I've reviewed every line of the diff and can explain it
  • Tests included and passing (make check) — for code changes
  • No unrelated changes in the diff
  • Scope is focused — one concern per PR — three commits, all found while fixing the slow Doctor page; the stream error fix also affects the audit and diff pages. Happy to split if preferred.

The Doctor page waited for the whole `doctor --json` run before showing
anything. One slow check, such as plugin checks waiting on a native CLI
that does not answer, kept the page on a skeleton for 30 seconds, and the
server's 30-second write timeout could cut the response off entirely.

`doctor --json` now prints each check as a {"check": ...} line when the
internal _SKILLSHARE_DOCTOR_STREAM variable is set, before its usual
result. The new GET /api/doctor/stream relays those lines as Server-Sent
Events and sends the full result as `done`; it has no write deadline and
stops doctor when the client leaves. The page shows checks as they
arrive and replaces them with the final result.
The audit, diff and doctor streams send an `error` event with the reason,
but the shared EventSource helper treated it like a dropped connection
and showed only a generic message. It now uses the reason the server
sent, and keeps the generic message for a real disconnect.
…igured

The hooks check loaded the full hooks inventory, which also scans
unmanaged native and Git hooks twice: about 12 git calls even with no
hooks configured, none of which doctor reports. Doctor now reads the
hooks section first and previews a sync only when there is something to
check.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T02:36:11.403964Z dfc6a94 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@runkids
runkids merged commit 65f3c8d into main Nov 12, 2026
9 checks passed
@runkids
runkids deleted the runkids/doctor-stream branch November 12, 2026 02:43
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.

1 participant