Skip to content

fix(inquiries): delete two phantom routes, and stop 404ing the thread screen - #738

Merged
thinkclay merged 1 commit into
mainfrom
fix/inquiries-phantom-and-access
Sep 10, 2026
Merged

thinkclay merged 1 commit into
mainfrom
fix/inquiries-phantom-and-access

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

Closes #476. Second step on #660.

Two separate faults in one file, and only one of them was the one on the tin.

The phantom routes

GET / and POST / read core.inquiries, which does not exist. They were not a rename of the real table:

core.inquiries (imagined) core.application_inquiries (real)
list filtered on sender_id, recipient_id —
create inserted subject, message, inquiry_type —
actually has — application_id, status, terms, created_by, …

Every inquiry child table — comments, sections, capability responses, reminders, audit log — has a foreign key to application_inquiries. Those two routes described a generic person-to-person messaging feature nobody built.

Deleted rather than implemented, per the method on #660: nothing called them. Inquiries.list() and Inquiries.create() were the only callers and are retired in Scaffald/sdk#23; no hook or screen used either.

The fault that actually mattered, and was not in the issue

While verifying the above, GET /by-application/{applicationId} — the real thread screen — returned 404 for an employer looking at an application their own list had just shown them.

checkApplicationAccess read core.applications with the request client, and RLS does not expose an org's applications to its staff. It answered "Application not found" to the very people it then goes on to authorise. Same fault #608/#649 fixed in employer-applications.ts, in a different file.

Fixing only that turned the 404 into a 200 with a null body, because the inquiry, its sections, comments, capability responses and the application detail were all read the same way. Measured on one employer:

core.applications           RLS: NO   service: yes
core.application_inquiries  RLS: NO   service: yes

So the reads now go through the service client, after checkApplicationAccess has authorised the caller. The authorisation decision is unchanged — same user_id match, same organisation owner, same org-scoped role assignment. Only the read is escalated, which is the difference between "you may not see this" and "this does not exist".

before   404 Application not found
partial  200 null
now      200 inquiry, sections, comments, capabilityResponses,
             application, candidate, job, capabilityQuestions

This is also what makes #690's per-message report control reachable — it renders on this screen.

Found on the way, not fixed here

/v1/inquiries/templates and /v1/inquiries/{id}/history both 404, and both are called by live hooks on this same screen. The router now serves exactly one path. That is #447's territory, not this issue's, so it is reported there rather than folded in.

A note on the SDK tests

Seven tests covered the deleted methods and passed the entire time — against a mock server that answered /v1/inquiries happily while the real endpoint 500'd. A test whose fixture invents the endpoint cannot fail when the endpoint is missing. Retired in Scaffald/sdk#24 with that reasoning left in place.

Verified

schema guard   6/6, core.inquiries removed from BASELINE_BROKEN (3 left, all #658)
deno check     inquiries.ts 5 errors -> 3 (remainder pre-existing access.ok narrowing)
typecheck      12/12
prepush        green

SDK pointer: 4f6730a..e28fa9c.

🤖 Generated with Claude Code

… screen

Closes #476. Second step on #660.

Two separate faults in one file, and only one of them was the one on the tin.

**The phantom routes.** GET / and POST / read core.inquiries, which does not
exist. They were not a rename of core.application_inquiries: the list filtered
on sender_id / recipient_id and the create inserted subject, message and
inquiry_type, none of which are columns on the real table. Every inquiry child
table — comments, sections, capability responses, reminders, audit log — has a
foreign key to application_inquiries. So these two described a generic
person-to-person messaging feature nobody built.

Deleted rather than implemented, per the method on #660: nothing called them.
Inquiries.list() and Inquiries.create() were the only callers and are retired
in Scaffald/sdk#23; no hook or screen used either. Building the table would
have shipped it for an endpoint nothing can reach.

**The fault that actually mattered, and was not in the issue.** While verifying
the above, GET /by-application/{applicationId} — the real thread screen —
returned 404 for an employer looking at an application their own list had just
shown them. checkApplicationAccess read core.applications with the REQUEST
client, and RLS does not expose an org's applications to its staff. It answered
"Application not found" to the very people it then goes on to authorise. That
is the same fault #608/#649 fixed in employer-applications.ts, in a different
file.

Fixing only that turned the 404 into a 200 with a null body, because the
inquiry itself, its sections, comments, capability responses and the
application detail were all read the same way. Measured on one employer:

  core.applications           RLS: NO   service: yes
  core.application_inquiries  RLS: NO   service: yes

So the reads now go through the service client, AFTER checkApplicationAccess
has authorised the caller. The authorisation decision is unchanged — same
user_id match, same organisation owner, same org-scoped role assignment. Only
the read is escalated, which is the difference between "you may not see this"
and "this does not exist".

  before   404 Application not found
  partial  200 null
  now      200 inquiry, sections, comments, capabilityResponses,
               application, candidate, job, capabilityQuestions

Found on the way and NOT fixed here, because it is a different problem
(#447): /v1/inquiries/templates and /v1/inquiries/{id}/history both 404, and
both are called by live hooks on this same screen. The router now serves
exactly one path. Reported on #447 rather than folded in.

Guard 6/6 with core.inquiries removed from BASELINE_BROKEN, leaving 3 entries,
all #658. Deno check on the changed file goes 5 errors -> 3; the remainder are
pre-existing narrowing on access.ok. Typecheck 12/12.
@thinkclay
thinkclay merged commit a9de376 into main Sep 10, 2026
7 of 8 checks passed
@thinkclay
thinkclay deleted the fix/inquiries-phantom-and-access branch September 10, 2026 20:53
@github-actions

Copy link
Copy Markdown
Contributor

📊 Performance Benchmark Results


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.

fix(api): core.inquiries does not exist, so GET/POST /v1/inquiries always 500

1 participant