Skip to content

fix(cli): generated service aggregate health check fails on sqlite/libSQL — and intermittently on postgres #1259

Description

@rickylabs

Summary

The generated example service's aggregate /health check uses Prisma's tagged $queryRaw\SELECT 1`form. The libSQL adapter rejects that form, so a scaffolded **sqlite** project ships a service whose/healthreportsdatabase: unhealthy. The same Invalid `prisma.$queryRaw()` invocationerror was also observed on **postgres** during ascaffold.runtime` run, so the defect may not be engine-specific.

Discovered while implementing #1158 (PR #1220).

Evidence

sqlitebehavior.service-health fails; this is why #1158 excludes that one gate from the new scaffold.runtime.sqlite tier (recorded as drift D-15, with the gate retained unchanged in scaffold.runtime).

postgres — a full scaffold.runtime run returned passed=51 failed=1:

service health probe failed for users:
  https://localhost:44677/health -> 0: fetch failed;
  http://localhost:3001/health  -> 503: {"status":"unhealthy","checks":[{"name":"database","healthy":false,
      "message":"Invalid `prisma.$queryRaw()` invocation: Raw query failed…"}]};
  http://localhost:46435/health -> 200: Healthy

That run had a known confounder: several concurrent e2e suites from other worktrees were running on the same host, and the probe resolved three endpoints with contradictory verdicts — the signature of cross-run interference. An isolated re-run is in progress; this issue will be updated with the result. It is filed now regardless, because the sqlite failure is reproducible and independent of that confounder.

Why it matters

A user scaffolding a sqlite project gets a service that reports itself unhealthy out of the box. Nothing in the scaffold warns them.

Relevant code

  • Generated health check: the tagged queryRaw\SELECT 1` form in the generated engine module (packages/cli/src/kernel/assets/embedded.generated.ts; note the template also carries a queryRawUnsafe(...)` variant).
  • packages/cli/src/kernel/templates/database/generate-engine-mod.ts:35 currently reads
    const healthQuery = provider.engine === 'sqlite' ? 'SELECT 1' : 'SELECT 1'; — a vestigial ternary whose branches are identical, suggesting an engine-specific health path was once intended and never landed.

Suggested direction (needs design)

  • Use a call form the libSQL adapter supports (e.g. the parameterless/unsafe variant, or the driver adapter's own connectivity probe) rather than a tagged template.
  • Decide whether the health query should genuinely differ per engine, and either implement that or delete the vestigial ternary.
  • Once fixed, re-include behavior.service-health in the scaffold.runtime.sqlite gate list and drop the exclusion in packages/cli/e2e/suites/scaffold/capability-suites.ts.

Acceptance

  • A scaffolded sqlite project's /health reports database: healthy.
  • Root-caused on postgres: either confirmed as cross-run interference only, or fixed.
  • behavior.service-health restored to the sqlite tier, exclusion removed.
  • The vestigial healthQuery ternary is resolved either way.

Refs #1158, PR #1220.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions