Skip to content

Preflight and Diagnostics

Claude edited this page Nov 12, 2026 · 5 revisions

Checked against v0.7.6 on November 13, 2026.

Preflight and diagnostics

This page covers two support tools: the preflight (also called doctor), which checks that an install can do its job, and the diagnostics bundle, a zip an operator can hand to a reviewer. Both are built so that a problem shows up as a named, actionable line and not as quietly wrong results. For the commands that run them, see CLI reference.

Preflight

The code is kestrel/doctor.py. Each check adds a CheckResult with a name, a status (PASS, WARN, FAIL or INFO), a detail string, a remediation and a blocking flag. A check never raises. When a check cannot run, its row says one of Kestrel's own sentences, chosen by the exception's type. It never shows the exception's class name or its text, which go to the log (_why in kestrel/doctor.py and fixed_reason in kestrel/web/errors.py). DoctorReport.has_blocking_failure is true only for a FAIL that is also marked blocking.

Where it runs

Entry point Mode What happens with the result
kestrel doctor (kestrel/cli.py) Full Prints the report, exits 1 on a blocking failure
kestrel doctor --quick Skips the needle, thinking and schema probes, and the ATS shape probe Same
Desktop launch (run_preflight in kestrel/desktop/shell.py) Quick Logged only. A blocking failure is a warning in the log, and the app still starts
Settings, Setup page "Verify" (verify() in kestrel/services/setup_state.py) Full Saved to doctor_report.json in the data folder
kestrel setup, final step (step_doctor) Full Printed

On the Models page, the health check puts its technical detail under Show details. Only Verify saves the report. The Setup page reads it back to say whether the models were verified, using the rows num_ctx, needle, thinking off and schema honored.

The desktop launch never blocks, by design: the operator needs the app open to fix things from inside it.

Checks, in order

run_doctor() runs these:

  1. Python 3.12 (blocking if wrong) and uv present (WARN only).
  2. Config valid. Loads settings.yml and runs the filters.yml guard against a sample context. A bad rule is a blocking FAIL. See Filter rules.
  3. Profile configured. WARN when only profile.example.yml exists.
  4. Settings layer. Doctor reads the same effective settings as the app, with saved setting rows over env and YAML, through a sync SQLite connection (_db_overrides_sync). If that read fails it falls back to YAML, adds a WARN, and treats tier routing as unknown. An unreachable Ollama is then a warning and not a block.
  5. Ollama checks, only when some tier runs on a local server (ollama_needed()):
    • Ollama reachable (blocking).
    • Models present (blocking). The remediation points at the Pull and Build buttons on Settings, System first and the terminal commands second.
    • Model fit (WARN, never FAIL). Compares weights plus about 20 percent and 1 GB of cache headroom against detected memory.
    • num_ctx per tier (blocking). See below.
    • Needle test, thinking off, and schema honored (full mode only).
    • Local AI checks, which only read: nothing is sent and nothing is changed. Each is its own row, and a check that cannot run says "unverified" and is never a pass. They are the backend address (WARN when the local backend is not on this computer), Ollama's cloud features (reported as "not seen turned off" when the setting cannot be seen, because Kestrel can read Ollama's settings file and its own environment but not the environment Ollama was started with), installed models with a -cloud tag (WARN, because their prompts go to Ollama's servers), the model digests compared with the tested catalog (a moved tag warns, a tag not in the catalog is unknown), and a connection spot check. The spot check lists the remote address of each connection Ollama's server and model runners hold while the model probes run; the Ollama tray app, which checks for its own updates, is left out. --quick skips it. In every mode an observed address is written as "a public address: " with no address or port, and IPv6 addresses are written in brackets.
  6. In-process embeddings, when the embed tier uses the bundled CPU model. WARN when files are missing or the model id does not match.
  7. Browser (PDF). Which browser the render ladder will use. WARN, never FAIL, because everything except PDF output works without one. See Document engine.
  8. OLLAMA_NUM_PARALLEL and OLLAMA_KEEP_ALIVE. WARN when OLLAMA_NUM_PARALLEL is below the largest configured concurrency, or OLLAMA_KEEP_ALIVE is unset.
  9. Ingest contact. WARN when ingest.user_agent has no @ or names example.com. The shipped default, Kestrel/1.0 (+https://kestrelapp.co), links to the project and carries no contact address, so a fresh install warns until one is set. SEC EDGAR requires a real contact, so an EDGAR source refuses to run, and EDGAR company research is skipped, until one is present. The generated SEC source carries its own user_agent built from the profile email, which the doctor row does not read. See Security and privacy model.
  10. Hosted mode, routing, keys and the Tier 3 frontier row. Informational, or WARN for a tier that names an external backend while Hosted mode is off, a missing key, or an unacknowledged disclosure. Never blocking.
  11. MCP port. Blocking FAIL only when MCP is enabled and its port is already bound.
  12. Database. WARN when uninitialized or when the revision differs from the shipped migration head. A database written by a newer build says so.
  13. ATS shapes (full mode only). For each enabled source whose kind is in _ATS_KINDS (the thirteen company-board kinds from greenhouse to breezy), fetches one posting and checks for a title, a URL or external id, and a description. A missing field is a WARN naming it, since an upstream payload may have changed. These are live network calls to the boards you enabled.

When no tier needs Ollama (a hosted-only setup), every Ollama row is reported as INFO instead, and nothing is probed (_skip_ollama_checks, _skip_local_checks). A hosted-only setup with a local embed tier still checks that embeddings can run.

The context-window check

Ollama's OpenAI-compatible endpoint cannot set num_ctx per request, so a model without an explicit value gets the model default, which is far too small. A long posting is then cut with no error, and the evaluation is quietly wrong. This is the most likely cause of "runs fine, results are bad" (CLAUDE.md). The check has two parts, because the first can be wrong.

Part 1: metadata, per tier

_check_num_ctx() compares each tier's baked-in num_ctx against that tier's own required budget. A single global threshold would fail tier 1 for no reason, so each tier gets its own.

def input_budget(tier, s):
    jd = s.pipeline.max_jd_tokens
    return {
        "tier1": 1200 + 400 + 400,
        "tier2": jd + 2500 + 1500 + 1000,
        "tier3": jd + 2500 + 2000 + 1000,
        "docsel": 2000 + 1500 + 500,
        "trigger": 1500 + 400,
    }[tier]

def required_num_ctx(tier, s):
    max_tokens = s.llm.tiers[tier].max_tokens or 512
    return input_budget(tier, s) + max_tokens + 200   # 200 = structural overhead

With the shipped settings (pipeline.max_jd_tokens is 6000), the required values and the shipped num_ctx in kestrel/resources/models/Modelfile.* are:

Tier Input budget max_tokens Required Shipped num_ctx
tier1 2000 300 2500 4096
tier2 11000 4000 15200 16384
tier3 11500 6000 17700 20480
docsel 4000 1500 5700 8192
trigger 1900 600 2700 4096 (uses kestrel-tier1)

The trigger tier reuses the kestrel-tier1 model, so there is no separate derived model for it. Raising pipeline.max_jd_tokens raises the tier 2 and tier 3 requirements, and the check then fails until the model is rebuilt with a larger window.

OllamaClient.effective_num_ctx() (kestrel/llm/client.py) reads the num_ctx line from /api/show. The outcomes are:

  • Not set: blocking FAIL, "Ollama default applies".
  • Set below the requirement: blocking FAIL naming both numbers.
  • Otherwise: PASS.
  • Model not built: blocking FAIL pointing at kestrel models build.

Tiers on an external backend are skipped, because hosted tiers set no local num_ctx.

Part 2: the needle test

Metadata can lie, so _check_needle() measures. It runs once per unique derived model, filled to the largest input budget of the tiers that share it. It builds a prompt that starts with MEMORIZE THIS SECRET CODE: NEEDLE-<random hex>, follows it with filler words equal in number to the token budget, and asks the model to repeat the code. The filler runs about 1.1 tokens per word, so the prompt slightly overfills the budget on purpose, since a truncation probe has to meet or exceed the window. Thinking is turned off (reasoning_effort="none") and the reply is compared with the code.

  • The code is returned: PASS.
  • The code is missing: blocking FAIL, "effective context is below N; rebuild with a larger num_ctx".
  • The reply is empty, or runs on at length without the code: WARN, not FAIL, with "context not verified". An empty reply means the model was not ready yet. A model that talks before it answers says nothing about its window, so waiting will not help; the remediation is an instruct build that answers briefly, not a thinking build.
  • The call times out: WARN, not FAIL. A timeout shows the model was cold, not that its window is short. The remediation is to rerun with the model warm or set OLLAMA_KEEP_ALIVE=2h. Without this rule the same machine would pass or fail depending on whether the weights happened to be loaded.

Related probes

  • Thinking off. Sends a trivial prompt and WARNs if a <think> span survives reasoning_effort="none".
  • Schema honored. Sends a tiny JSON schema through response_format, exactly as the pipeline does, and blocks if the reply is not the demanded JSON. Some models ignore response_format when thinking is off (the code cites Ollama issue 14645), and every pipeline call would then quarantine.

docs/PROMPT_BUDGETS.md has the measured prompt sizes behind these budgets. It quotes the same max_jd_tokens (6000) and tier 1 slice (at most 1200 tokens) that kestrel/doctor.py uses.

The diagnostics bundle

The code is kestrel/services/diagnostics.py. The About page offers two buttons: Download diagnostics (GET /about/diagnostics, which streams a temp file and then deletes it) and Save diagnostics (POST /about/diagnostics/save, which writes the zip to the Downloads folder, falling back to Kestrel's exports folder). The zip is named kestrel-diagnostics-<version>-<timestamp>.zip. A build happens in a thread under a .part name and is renamed on success, so a failure never leaves a broken zip behind.

What is inside

The CONTENTS tuple in the module is the source of truth, and the About page and the bundled README.txt list exactly it.

Member Content
README.txt The contents list and the exclusions
summary.json Version, frozen or source run, Python and platform, detected hardware, active hardware profile, data folder path, schema revision, run mode, confidential mode flag, hosted mode state (backend names and models, key presence as a boolean, never values), row counts per table, Tier 0 set-asides by rule name, evaluations by model id, pursuits by status, and the last 5 runs and 10 scrapes. Each scrape row carries its counts, including dropped_outside_area and dropped_unrelated_title, the roles dropped before storage (see Filter rules)
doctor.json The saved preflight report if one exists, otherwise the result of a fresh doctor --quick
settings.redacted.yml Effective settings with secret values replaced by <redacted>, plus the names (not values) of relevant environment variables
logs/ The last 2,000 lines of each log file, scrubbed
quarantine.json The last 20 quarantine rows: tier, model, error, time, and the raw response cut to 500 characters
roles.json The newest 500 roles by ID (ROLE_ROWS): title, organization, location as posted and as read (country, state, city), remote type, stage, the reason it was set aside, the posting's site name, first-seen and posted dates, and each scoring pass (tier, model, prompt version, verdict, scores, the five dimension scores, warning-sign kinds). No posting text
packages.txt Installed Python packages and versions

What is never inside

The EXCLUDED tuple: .env and every key or token value, profile.yml, document masters and variants, posting descriptions and URLs, contacts and outreach drafts, and the database file itself. roles.json is the one place that carries job titles and organization names, deliberately, so a tester can name a role by the ID shown on its Evaluation tab. It is scrubbed like every other text member. The site name is only the host of the posting address. When Confidential mode is on but the employer cannot be confirmed hidden, titles, organizations, site names and set-aside reasons in roles.json, and the excerpts in quarantine.json, are replaced with a "withheld" notice (conservative=True).

Tier 0 set-asides are counted by rule id only. tier0_rejects_by_rule() reads the stored blocker:<id>: <detail> and keeps only the id, and only when it is a rule in the shipped default filters.yml. Any other id, which might embed an employer name in an operator-written rule, is reported as custom. See Filter rules.

Scrubbing

Every text member goes through one scrubber from make_scrubber():

  1. Every secret value Kestrel currently holds (the data folder .env, and system environment variables if the operator opted in) is replaced wherever it appears, longest first, including its JSON-escaped form, because log events are JSON and an escaped key would slip past an exact match.
  2. Anything shaped like a bearer token, an x-api-key header, or an sk- or om- key is masked regardless of settings.
  3. In confidential mode, the current employer is replaced with the operator's placeholder, using the same map as the list views.

Settings are redacted by key name: a string under a key containing key, secret, token or password becomes <redacted>. Numbers and booleans stay, so max_tokens remains readable, and api_key_env is kept because it names a variable and holds no secret.

The members that can leak

quarantine.json is the exception for posting text. A quarantined model response can echo part of the posting it was given. It is cut to 500 characters and scrubbed, and the About page tells the tester they may delete that file from the zip before sending. roles.json names roles and employers but quotes no posting text.

Reading a bundle

Start with doctor.json for failing rows, then the counts in summary.json (for example a pile of t0_reject rows under one rule, or evaluations all on one unexpected model), then the tail of the newest log. If a stage keeps failing, quarantine.json shows which tier and model and what the raw reply looked like. When a tester names one role, find its ID in roles.json to see its location as parsed, which rule set it aside and what each scoring pass decided, without asking for the posting.

The log also holds page_change lines, one per page change in the desktop window, written by POST /api/diag/page (see REST API). They carry timings and the two in-app paths, and they are how a report of a flash between pages is checked against what the window measured: whether the cross-fade ran, how long the page took to arrive and to draw, and for an in-place change (inplace) the fetch and swap times (fetch_ms, swap_ms).

Adding a check

  1. Write _check_<name>(rep, ...) in kestrel/doctor.py using rep.add(name, status, detail, remediation, blocking=...). Never raise: catch specific errors and report them.
  2. Call it from run_doctor() in the right place. Anything that needs a live model belongs behind if not quick.
  3. Decide on blocking deliberately. Block only when continuing would produce wrong results, as with num_ctx. Use WARN when a feature degrades but the rest works, as with the browser.
  4. If it applies only when Ollama is used, add its name to OLLAMA_ROWS so a hosted-only setup reports it as INFO.
  5. Tests: tests/test_doctor_schema.py and tests/test_doctor_ingest_contact.py show the pattern, and need no live service.

Doctor never changes anything on a third-party site. It probes your own local model server and, in full mode, makes read-only requests to the job boards you already enabled.

Related

Clone this wiki locally