Skip to content

EPIC: the API addresses a schema that partly does not exist — 45 references, 14 route files #660

Closed

Description

@thinkclay

Rollup for a full trace of the API surface: every KNOWN_GAPS route traced to the screen that calls it, and every .from() in every route file checked against the schema.

Two independent failure modes came out of it, and they are worth separating because only one of them is visible to any existing test.

1. Routes that call tables which do not exist — 45 references, 24 names, 14 files

Invisible to the contract test, to typecheck and to the API suite. A wrong table name is indistinguishable from an empty result unless somebody happens to load the page. This has been found one endpoint at a time for months (#476, #481, #482, #618) and each instance looked like an isolated typo.

Guard, so it stops growing: #651 — parses every .from() against the checked-in generated types, fails on anything new, and fails again when a fixed entry is left in the baseline.

Ordered by consequence

issue why it is where it is
P0 #652 CCPA disclosure reports hasData: false to a user with 14 records. Statutory.
P0 #653 Admin delete-user leaves certifications, applications and reviews behind, and returns success.
P1 #654 core.review_links grants only postgres — breaks review collection end to end, including the emailed link. One migration.
P1 #655 Org member list 500s; core.organization_members was never created. Membership is role_assignments.scope_org_id.
P1 #657 Wrong-schema cluster: webhooks, team job assignments, three office admin routes. Mechanical.
P1 #656 The whole /v1/onet router reads core.onet_*; the 40-table onet schema is seeded and unreachable.
P2 #658 Three routers built on tables that were never created — soft-skill history (8 refs), profile import (5), completion nudges. Needs decisions, not renames.
P2 #659 /v1/user-profiles/{userId} 500s on an unknown id instead of 404.
P2 #618 /v1/profiles/employers/{slug} queries core.employers; no consumer. Probably delete.

Dependency

#651 (guard, merged first — everything else removes entries from its baseline)
  ├── #652, #653   ← independent, highest consequence, do first
  ├── #654         ← one migration, unblocks review links
  ├── #655 ─── depends on nothing; reuse lib/org-access.ts from #617
  ├── #657, #656   ← mechanical renames, parallelisable
  └── #658, #659, #618 ← each needs a product decision first

#652 and #653 share a root cause with #657 but are listed separately because their consequence is not "an endpoint 500s" — it is a compliance statement and a data-deletion guarantee that are both wrong while appearing to work.

2. SDK contract gaps — 59, of which 16 are user-visible

Full tracing posted on #447. Every gap resolved to the UI that calls it through a parsed import graph.

verdict count
MOUNTED — a routed screen calls it and gets an error 16
UNMOUNTED — a component calls it, no screen renders that component 5
NO_CONSUMER — a hook exists, nothing imports it 28
NO_HOOK — an SDK method exists, no hook wraps it 10

43 of 59 have no product behind them. The recommendation is to retire that SDK surface rather than implement it — building it ships endpoints nothing can call. Four gaps were closed this way already (#616, #617) by tracing first and implementing only what a screen actually calls.

What is genuinely solid

Worth stating, because the list above reads as a teardown and the surface is mostly healthy:

  • 313 registered routes; only 21 have no SDK caller. The API and the SDK are well matched — this is not a sprawling surface with a thin client.
  • Of 165 literal GET routes probed live, 152 answered correctly. The failures are concentrated in a handful of files, not spread across the codebase.
  • The routes that were repaired during this work — reviews, skills analytics, work logs, organizations — held up under live probing including their authorization boundaries.
  • The schema itself is fine. In almost every case the data exists and is correctly modelled; the route is looking in the wrong place.

Method

The tracer was wrong twice before it was right, in both directions, so the numbers above are the ones that survived validation against nine hand-verified cases. Details of the failure modes and the fixes are on #447 and #651 — worth reading before trusting any similar sweep.

Activity

  1. added
    bug
    on Aug 27, 2026
  2. thinkclay commented on Aug 27, 2026

    @thinkclay
    ContributorAuthor

    #652 and #653 are done — #663 (merged).

    One correction to this epic: #653's description was wrong. I claimed the broken deletes leave data behind and report success. Every one of those tables cascades from core.users, verified in a rolled-back transaction, so the deletion happens anyway. The real defect is that ten RESTRICT/NO ACTION references block the final delete after the two working hand-deletes have already run — so the endpoint destroys a user's skills and profile and then reports failure. Retitled and corrected on the issue.

    Both P0s shared a root cause worth knowing before touching the rest of this epic: a head-count against an unreadable table returns {status: 204, error: null, count: null}. No error is raised, so count ?? 0 reports a confident zero — and checking error instead does not fix it. count === null is the only dependable signal. Any of the remaining issues that count rows will hit this.

    Schema guard baseline is down 45 → 33 references, 24 → 13 table names.

    New issue from the work: #665 — the /v1/feedback router queries .schema("logs"), which PostgREST does not expose and which grants only postgres. Note the #651 guard cannot catch that class, since it skips schemas absent from types.ts and logs is absent precisely because it is unexposed.

    Next by consequence: #654 (one migration, unblocks review links end to end), then #655.

  3. thinkclay commented on Aug 27, 2026

    @thinkclay
    ContributorAuthor

    #654 and #655 are done — #667 (merged). Epic status: 4 of 9 closed.

    Two things worth carrying into the remaining issues.

    review_links needed policies, not just grants. The table had RLS enabled and no policies at all, so the grant alone would have left it failing closed. Migration 347 adds four owner-scoped policies alongside the grants. If #481's remaining tables are the same shape, a grants-only migration will not be enough there either — check pg_policies per table, not just role_table_grants.

    RLS can make a wrong fix look right. core.role_assignments carries one policy — user_id = auth.uid() — so the first version of the members list returned a one-member organization out of fifteen, with a 200 and a plausible-looking body. It needed the service client behind canReadOrgInternals. Anything in this epic that lists other people's rows will hit the same trap, and it does not announce itself.

    Also fixed in passing, both found only by probing rather than reading:

    • GET /v1/reviews/links selected with no subject_user_id filter, leaning entirely on a policy that did not exist.
    • Revoking another user's link answered 200 and did nothing — an UPDATE matching no rows is not an error.
    • firstOf was referenced by the new members handler but defined privately in work-logs.ts; it typechecks and throws at runtime. Now lib/postgrest.ts.

    Schema guard baseline: 45 → 32 references since this epic opened.

    Migration 347 is applied locally only — it needs applying to dev/preview/prod with the next deploy.

    Remaining: #657 and #656 (mechanical renames, parallelisable), then #658, #659, #618, #665 (each needs a product decision).

  4. thinkclay commented on Sep 10, 2026

    @thinkclay
    ContributorAuthor

    Pointing at #728 — the iOS/Android store readiness epic — because this issue is now on its critical path rather than being general API-correctness work.

    Two of its children were re-verified today against the running stack:

    GET /v1/inquiries   500  Could not find the table 'core.inquiries'   (#476)
    core.employers      MISSING                                          (#482)
    

    Both stores exercise the app during review, so a core screen returning 500 is a rejection risk. #476 additionally makes part of #690 unreachable: the per-message report control the stores require shipped and is correct, but the inquiry screen it renders on cannot load.

    #728 sequences this epic first, on the reasoning that landing the schema work here may resolve #476, #482 and #658 together rather than three separate fixes. If that reading of the scope is wrong, say so on #728 and I will re-sequence.

  5. thinkclay commented on Sep 10, 2026

    @thinkclay
    ContributorAuthor

    Deployed and verified across all three environments.

    Functions and migrations were a month apart — the api edge function had not shipped since 2026-08-12, while migrations 348–350 were unapplied everywhere. Deploying functions first would have shipped broken endpoints, since feedback.ts now reads core.user_feedback (350) and moderation.ts reads core.content_reports/user_blocks (349). Migrations went first in each environment.

    Pre-flight on 348, which deletes duplicate role_assignments rows before adding its unique constraint — it would have been a destructive change on production authorization data:

    total rows rows 348 would delete
    dev / preview / prod 97 / 96 / 92 0 / 0 / 0

    No duplicates anywhere, so it was purely additive.

    Migrations — 337, 347, 348, 349, 350, 351 applied and recorded. All three ledgers now read unrecorded: 0. Dev had genuinely never had 337: preview and prod each had 6 notification cron jobs, dev had 0. It does now.

    Functions — all three on cf5d17f88, smoke green (dev 5/5, preview 11/11, prod 7/7).

    The fixes, verified end to end against dev and preview with a real authenticated user:

    endpoint dev preview
    /ccpa/data-summary 200 200
    /reviews/links 200 200
    /feedback/user-feedback 200 200
    /moderation/blocks 200 200
    /work-logs/public-feed 200 200

    The CCPA 200 is the meaningful one: after #663 a failed count fails the request, so a 200 proves all thirteen counts resolved — every table and every filter column. Before this session it returned 200 while silently reporting zero.

    Production was verified at the schema level rather than by creating an account in a live auth system: every table and column the CCPA handler reads confirmed present, core.employers confirmed gone, review-link grants confirmed on authenticated and service_role.

    Three commits have landed on main since (#724, #726, #729) — all docs and CI, nothing under supabase/functions or supabase/migrations, so the deployed commit is functionally current.

  6. thinkclay commented on Sep 10, 2026

    @thinkclay
    ContributorAuthor

    Progress on the schema half. Two landed today.

    #707 first, because the guard could not be trusted to measure anything else while three of its seven baseline entries described a stale catalogue rather than broken routes. That issue said regenerating types.ts locally "silently deletes the application_status enum" and treated it as local drift. The causality was backwards: migration 344 dropped that enum on purpose five migrations ago, because it was never used and its vocabulary was not the app's. The local database was right; types.ts was stale in the other direction. Regenerated after diffing to a temp file — the only removal across 271 diff lines is that enum (#736).

    Then #476. Two faults in one file, and only one was the one on the tin:

    Baseline now

    before  7 entries, 3 of them not actually broken
    now     3 entries, all #658
    
    core.soft_skills_ratings       8
    core.profile_import_data       5
    core.profile_completion_nudges 1
    

    So the schema half of this epic is #658 and nothing else — and #658 is the one the issue body already flags as needing product decisions rather than renames.

    Two things for whoever takes it:

    1. The SDK contract half (SDK/api contract drift: 85 SDK methods call endpoints that don't exist #447) is untouched. Two live MOUNTED gaps on the inquiry screen are reported there.
    2. Green SDK tests are not evidence a gap is closed. Seven covering the deleted methods passed the entire time against a mock that invented the endpoint while the real one 500'd.
  7. thinkclay commented on Sep 10, 2026

    @thinkclay
    ContributorAuthor

    The schema half of this epic is complete. #741 landed #658, and BASELINE_BROKEN in the #651 guard is now empty:

    when #651 landed   7 entries (24 names / 45 refs at the time of the sweep)
    after #736         4 — three were a stale catalogue, not broken routes (#707)
    after #738         3 — core.inquiries deleted, not built (#476)
    after #741         0 — two tables created, one route retired (#658)
    

    Every route in the API now reads a table that exists. Because the guard's second assertion demands stale entries be removed, the baseline can only go down, and anything that appears in it from here is a regression rather than inherited debt.

    Three things from the last stretch worth recording against the method section:

    What remains is the SDK contract half — #447. Untouched by this stretch except for two live MOUNTED gaps reported there (/v1/inquiries/templates and /{id}/history, both called by hooks on the thread screen) and four methods retired by deletion.

    One caveat on "every route reads a real table": the guard checks table names only. #482's remaining half — a route selecting five columns that don't exist on a table that does — is outside its reach and still open.

  8. thinkclay commented on Sep 11, 2026

    @thinkclay
    ContributorAuthor

    Part 1 of this epic is complete. BASELINE_BROKEN in table-references-exist.test.ts is empty, and the test fails on a stale entry as well as a new one — so it can only stay empty.

    The count in the title was 45 references across 24 names and 14 files. All of them are resolved:

    issue outcome
    P0 #652 closed
    P0 #653 closed
    P1 #654 closed
    P1 #655 closed
    P1 #657 closed — four wrong-schema refs; the fifth was a false positive in the guard's own parser
    P1 #656 closed — O*NET rewritten against the real onet schema, including the skills endpoint, which needed more than a rename
    P2 #658 closed — two tables created (#741), the third route retired
    P2 #659 closed
    P2 #618 closed — route, SDK method, hook and tests deleted; no consumer
    — #476 closed — the messaging concept was never built; routes deleted rather than given a table
    — #481 closed — the grants half
    — #482 closed — last one, in #743

    Two things worth recording, because both were not what the sweep recorded and would have been re-derived otherwise:

    #657's fifth row was never a defect. office-communities.ts:146 already read .schema("core").from("users"). The guard reported community.users because its parser buffers to the next semicolon and takes the first .schema() in the statement — and that line sits in a Promise.all([...]) whose first element is .schema("community"). One statement, two chains, one schema. The parser now takes the nearest .schema() preceding each .from(), with a regression test.

    #482 was half-done and half-mis-scoped. The employers half went with #618. The organizations half had already been repaired at the select by #617 — but the response schema above it was never updated, so the endpoint answered 200 while its published contract was wrong in six ways: description and industry are objects declared as strings, size/location/founded_year exist in no table in any schema, and address was returned undeclared. Nothing caught it because @hono/zod-openapi documents rather than validates, and the SDK's msw handler hand-wrote the declared shape — so the tests asserted against a response the API cannot produce.

    That last pattern is worth generalising, since it has now produced three wrong contracts that a green suite certified (#618's employers, #482's organizations, and the envelope defect in #744): a mock written from the type can never catch a mismatch between the type and the API.

    Part 2 remains

    #447 — the SDK contract half, KNOWN_GAPS currently at 60. Actively in progress; two more live MOUNTED gaps were identified there today. Not touched from here to avoid duplicating that work.

    #744 was filed out of #482: two of the three public profile routes wrap in { data } and one does not, while the SDK declares all three bare. It is the same silent-drift class as this epic but needs a public-API decision rather than a fix.

  9. thinkclay commented on Sep 15, 2026

    @thinkclay
    ContributorAuthor

    Closing the epic: every phantom-schema child (#651–#659, #476, #481, #482, #616–#618) is closed. #447 (SDK/api contract drift) stays open on its own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions