Repository navigation
fix(api): the CCPA disclosure under-reported, and delete-user destroyed data on a path that failed (#652, #653) - #663
Merged
Conversation
…ed data on a path that failed (#652, #653) Two P0s from the schema-reference sweep (#660). They share a root cause that is worth stating first, because the obvious fix for it does not work. A head-count against a table the client cannot read comes back as: {status: 204, error: null, count: null} No error is raised. So `res.count ?? 0` reports a confident zero for data it never looked at — and checking `error` instead, which is what this looks like it needs, changes nothing. Measured against a live stack, not assumed. The only dependable signal is that `count: "exact"` always yields a number when the query actually ran, so a null count means it did not. ## #652 — CCPA data summary The disclosure told a user with 2 education records, 6 skills, 3 work experiences and 3 certifications that professional_information was `hasData: false, itemCount: 0`. Eight of the thirteen counts were failing, not five as first filed: core.profiles -> does not exist; identity is core.users core.education -> core.user_education core.profile_skills -> core.user_skills core.work_experience -> core.user_experience core.feedback -> logs.user_feedback core.certifications -> exists, but is the catalogue and has no user_id id_verifications -> keyed worker_user_id, not user_id reviews -> keyed author_user_id, not reviewer_user_id The last three are the ones a table-name audit misses: the table is right and the filter is wrong, which fails exactly as silently. A category that cannot be counted now fails the request rather than shrinking the total, since a partial disclosure understates what is held. Verified both ways against a live stack: 14 when healthy, and 500 naming the category when one count is broken. Platform feedback is left out of the Communications label rather than counted as zero. logs.user_feedback is unreachable — PostgREST does not expose the `logs` schema and it grants only postgres — so the feedback router is broken for the same reason. Called out in the code rather than papered over. The admin queue read core.profiles too, so every request row showed a blank name for whoever filed it. It now reads core.users, and resolves emails through the auth admin API since they live in auth.users. ## #653 — admin delete-user The issue as filed said data was left behind and success reported. That was wrong, and the truth is worse. Every relevant table cascades from core.users, and core.users cascades from auth.users, so the hand-written cascade was redundant — but six of its eight statements were no-ops anyway, because `.schema("core")` applies only to the statement it is written on and the rest addressed `public`. No result was checked, so the errors were discarded. The two statements that did work ran first. Ten RESTRICT and NO ACTION references then block the delete for any user who has verified a work log or created a task or punchlist. Reproduced: delete from core.user_skills ... -- succeeds delete from core.profile ... -- succeeds delete from core.users ... -- ERROR: violates foreign key constraint -- work_logs_verified_by_user_id_fkey The operator saw "Failed to delete user profile" while that user's skills and personal details were already gone, with no transaction to roll back. Now: check the seven RESTRICT relations before writing anything and answer 409 naming what blocks it; release the three nullable verification pointers, which are audit attributions rather than content; then delete the auth user and let the cascade do the rest. Verified against a live stack — 409 with the profile intact for a blocked user, 200 with a full cascade for a clean one. ## Tests Pinned as rules rather than table names, so a rename cannot make either fail quietly again. Confirmed non-vacuous: all seven fail against the unfixed code. Schema guard baseline drops 45 -> 33 references, 24 -> 13 table names. API suite 317 passed / 80 failed against 310 / 87; failure sets diffed by name, zero newly failing. Co-Authored-By: Claude Opus 5 <[email protected]>
This was referenced Aug 27, 2026
Closed
thinkclay
added a commit
that referenced
this pull request
Sep 2, 2026
…le at all Every /v1/feedback endpoint failed for any client, for two independent reasons (#665): 1. PostgREST does not serve the `logs` schema. config.toml exposes auth, public, core, storage, data, onet, engagement and community. 2. logs.user_feedback granted only `postgres` — no service_role, no authenticated. Same class as #481 and #654. Migration 350 takes the smaller of the two routes offered in the issue: move the table rather than expose a ninth schema. That keeps the exposed-schema list stable across all three environments, and core is already the convention for user-scoped data. `logs` held nothing else. The table is empty, so nothing is migrated but the definition. SET SCHEMA carries its indexes, constraints, RLS setting and all three policies, which were already correct and role-scoped — select/insert to authenticated on `user_id = auth.uid()`, ALL to service_role. What was missing was never the policies but the grants beneath them: a policy cannot widen access past an absent GRANT, which is why even service_role could not read it. Verified against the running stack. Before, PostgREST answered "Could not find the table in the schema cache". Now it resolves the table and answers 42501 for `anon` — which is the correct outcome, since feedback requires auth and only authenticated and service_role are granted. As `authenticated`, the count runs. The CCPA data summary counts platform feedback again. #663 left it out of the Communications category rather than reporting a silent zero in a statutory disclosure; with the table reachable, the category is "Reviews, platform feedback" and its count includes both. Closes #665 Co-Authored-By: Claude Opus 5 <[email protected]>
thinkclay
added a commit
that referenced
this pull request
Sep 2, 2026
…le at all Every /v1/feedback endpoint failed for any client, for two independent reasons (#665): 1. PostgREST does not serve the `logs` schema. config.toml exposes auth, public, core, storage, data, onet, engagement and community. 2. logs.user_feedback granted only `postgres` — no service_role, no authenticated. Same class as #481 and #654. Migration 350 takes the smaller of the two routes offered in the issue: move the table rather than expose a ninth schema. That keeps the exposed-schema list stable across all three environments, and core is already the convention for user-scoped data. `logs` held nothing else. The table is empty, so nothing is migrated but the definition. SET SCHEMA carries its indexes, constraints, RLS setting and all three policies, which were already correct and role-scoped — select/insert to authenticated on `user_id = auth.uid()`, ALL to service_role. What was missing was never the policies but the grants beneath them: a policy cannot widen access past an absent GRANT, which is why even service_role could not read it. Verified against the running stack. Before, PostgREST answered "Could not find the table in the schema cache". Now it resolves the table and answers 42501 for `anon` — which is the correct outcome, since feedback requires auth and only authenticated and service_role are granted. As `authenticated`, the count runs. The CCPA data summary counts platform feedback again. #663 left it out of the Communications category rather than reporting a silent zero in a statutory disclosure; with the table reachable, the category is "Reviews, platform feedback" and its count includes both. Closes #665 Co-Authored-By: Claude Opus 5 <[email protected]>
thinkclay
added a commit
that referenced
this pull request
Sep 2, 2026
…le at all Every /v1/feedback endpoint failed for any client, for two independent reasons (#665): 1. PostgREST does not serve the `logs` schema. config.toml exposes auth, public, core, storage, data, onet, engagement and community. 2. logs.user_feedback granted only `postgres` — no service_role, no authenticated. Same class as #481 and #654. Migration 350 takes the smaller of the two routes offered in the issue: move the table rather than expose a ninth schema. That keeps the exposed-schema list stable across all three environments, and core is already the convention for user-scoped data. `logs` held nothing else. The table is empty, so nothing is migrated but the definition. SET SCHEMA carries its indexes, constraints, RLS setting and all three policies, which were already correct and role-scoped — select/insert to authenticated on `user_id = auth.uid()`, ALL to service_role. What was missing was never the policies but the grants beneath them: a policy cannot widen access past an absent GRANT, which is why even service_role could not read it. Verified against the running stack. Before, PostgREST answered "Could not find the table in the schema cache". Now it resolves the table and answers 42501 for `anon` — which is the correct outcome, since feedback requires auth and only authenticated and service_role are granted. As `authenticated`, the count runs. The CCPA data summary counts platform feedback again. #663 left it out of the Communications category rather than reporting a silent zero in a statutory disclosure; with the table reachable, the category is "Reviews, platform feedback" and its count includes both. Closes #665 Co-Authored-By: Claude Opus 5 <[email protected]>
thinkclay
added a commit
that referenced
this pull request
Sep 2, 2026
…le at all Every /v1/feedback endpoint failed for any client, for two independent reasons (#665): 1. PostgREST does not serve the `logs` schema. config.toml exposes auth, public, core, storage, data, onet, engagement and community. 2. logs.user_feedback granted only `postgres` — no service_role, no authenticated. Same class as #481 and #654. Migration 350 takes the smaller of the two routes offered in the issue: move the table rather than expose a ninth schema. That keeps the exposed-schema list stable across all three environments, and core is already the convention for user-scoped data. `logs` held nothing else. The table is empty, so nothing is migrated but the definition. SET SCHEMA carries its indexes, constraints, RLS setting and all three policies, which were already correct and role-scoped — select/insert to authenticated on `user_id = auth.uid()`, ALL to service_role. What was missing was never the policies but the grants beneath them: a policy cannot widen access past an absent GRANT, which is why even service_role could not read it. Verified against the running stack. Before, PostgREST answered "Could not find the table in the schema cache". Now it resolves the table and answers 42501 for `anon` — which is the correct outcome, since feedback requires auth and only authenticated and service_role are granted. As `authenticated`, the count runs. The CCPA data summary counts platform feedback again. #663 left it out of the Communications category rather than reporting a silent zero in a statutory disclosure; with the table reachable, the category is "Reviews, platform feedback" and its count includes both. Closes #665 Co-Authored-By: Claude Opus 5 <[email protected]>
thinkclay
added a commit
that referenced
this pull request
Sep 2, 2026
…/feedback works (#712) * feat(profiles)!: delete the employers route, which addressed a table in no schema `GET /v1/profiles/employers/{slug}` has never returned a response. It queried `core.employers`, and information_schema has no `employers` table in any schema and no `employer_id` column anywhere in `core` — the route was written against a schema that does not exist, not one that drifted. The handler also counted jobs by `employer_id`, so there was nothing to repair toward. `employer` in this product is an organization: `core.organizations` carries `owner_user_id`, and `core.jobs.organization_id` is the real FK. `GET /v1/profiles/organizations/{slug}` already does what this route appears to want, and works (#617). Deleted: the route, the SDK's `EmployerProfile` / `profiles.getEmployer` / `useEmployerProfile` (Scaffald/sdk#21, pointer bumped here), the scf-core wrapper hook and its re-export, and the five Deno tests plus the `createTestEmployerProfile` helper that inserted into `core.employers`. `core.employers` is dropped from BASELINE_BROKEN — with the route gone the entry is stale, and the reference test fails on a stale entry rather than letting it rot. BREAKING CHANGE: `GET /v1/profiles/employers/{slug}` is gone, along with `profiles.getEmployer`, `useEmployerProfile` and `EmployerProfile`. It never returned a response, so no working behaviour is removed. Use `GET /v1/profiles/organizations/{slug}` and `useOrganizationProfile`. Closes #618 Co-Authored-By: Claude Opus 5 <[email protected]> * fix(feedback): move user_feedback into core, so the router is reachable at all Every /v1/feedback endpoint failed for any client, for two independent reasons (#665): 1. PostgREST does not serve the `logs` schema. config.toml exposes auth, public, core, storage, data, onet, engagement and community. 2. logs.user_feedback granted only `postgres` — no service_role, no authenticated. Same class as #481 and #654. Migration 350 takes the smaller of the two routes offered in the issue: move the table rather than expose a ninth schema. That keeps the exposed-schema list stable across all three environments, and core is already the convention for user-scoped data. `logs` held nothing else. The table is empty, so nothing is migrated but the definition. SET SCHEMA carries its indexes, constraints, RLS setting and all three policies, which were already correct and role-scoped — select/insert to authenticated on `user_id = auth.uid()`, ALL to service_role. What was missing was never the policies but the grants beneath them: a policy cannot widen access past an absent GRANT, which is why even service_role could not read it. Verified against the running stack. Before, PostgREST answered "Could not find the table in the schema cache". Now it resolves the table and answers 42501 for `anon` — which is the correct outcome, since feedback requires auth and only authenticated and service_role are granted. As `authenticated`, the count runs. The CCPA data summary counts platform feedback again. #663 left it out of the Communications category rather than reporting a silent zero in a statutory disclosure; with the table reachable, the category is "Reviews, platform feedback" and its count includes both. Closes #665 Co-Authored-By: Claude Opus 5 <[email protected]> --------- Co-authored-by: Claude Opus 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #652. Closes #653.
The shared root cause, and why the obvious fix doesn't work
A head-count against a table the client cannot read comes back as:
{"status": 204, "error": null, "count": null}No error is raised. So
res.count ?? 0reports a confident zero for data it never looked at — and checkingerrorinstead, which is exactly what this looks like it needs, changes nothing. Measured against a live stack, not assumed:count: "exact"always yields a number when the query actually ran, so a null count is the only dependable signal that it didn't. I built the fix with theerrorcheck first, and the break-test caught it still returning 200 with a quietly smaller total.#652 — the CCPA disclosure
A user with 2 education records, 6 skills, 3 work experiences and 3 certifications was told
professional_information: hasData: false, itemCount: 0.Eight of thirteen counts were failing, not the five originally filed:
core.profilescore.userscore.educationcore.user_educationcore.profile_skillscore.user_skillscore.work_experiencecore.user_experiencecore.feedbacklogs.user_feedbackcore.certificationsuser_idid_verificationsworker_user_id, notuser_idreviewsauthor_user_id, notreviewer_user_idThe last three are what a table-name audit misses: the table is right and the filter is wrong, which fails exactly as silently.
A category that can't be counted now fails the request rather than shrinking the total — a partial disclosure understates what's held, which is the whole defect.
hasData: false, itemCount: 0hasData: true, itemCount: 14200, itemCount silently8500naming the categoryPlatform feedback is left out of the Communications label rather than counted as zero:
logs.user_feedbackis unreachable — PostgREST doesn't expose thelogsschema and it grants onlypostgres— so the feedback router is broken for the same reason. Stated in the code rather than papered over.The admin queue read
core.profilestoo, so every row showed a blank name for whoever filed the request. Now readscore.users, with emails resolved through the auth admin API since they live inauth.users.#653 — admin delete-user
The issue as I filed it was wrong, and the truth is worse.
I claimed data was left behind and success reported. In fact every relevant table cascades from
core.users, andcore.userscascades fromauth.users— verified in a rolled-back transaction, all counts went to 0. So the hand-written cascade was redundant. Six of its eight statements were no-ops regardless, because.schema("core")applies only to the statement it's written on and the rest addressedpublic, with no result checked.The two statements that did work ran first. Ten RESTRICT/NO ACTION references then block the delete for any user who verified a work log or created a task:
The operator saw "Failed to delete user profile" while that user's skills and personal details were already gone, with no transaction to roll back. Retrying did nothing more.
Now
409naming what blocks itwork_logs.verified_by_user_id,user_skills.verified_by,skill_evidence.verified_by) — audit attributions, not content; holding a deletion hostage to one would make any reviewer undeletableThe NOT NULL ownership references (
tasks,punchlists,organization_documents, …) can't be released and shouldn't be silently deleted — removing a person shouldn't remove work others depend on — so they're reported for a human decision.409 blockedBy: [{tasks:18},{punchlists:3}], profile intact (was: 500, profile destroyed)200, all rows cascaded, pointer releasedOne honest caveat, in the code: if the auth delete fails for an unrelated reason after the release step, those pointers stay released — an audit attribution is lost, no record is destroyed, and retrying is safe.
Tests
Pinned as rules rather than table names, so a rename can't make either fail quietly again — including that
count === nullis the failure signal, since checkingerrorlooks like a fix and isn't.Confirmed non-vacuous: all seven fail against the unfixed code (they show up as "newly passing" when the route changes are stashed).
Two flaws in my tests surfaced while writing them —
"education"matched a count label, andreviewer_user_idmatched my own explanatory comment — so assertions now read comment-stripped code.🤖 Generated with Claude Code