Picking the repo was itself informative — entirehq/entire-search's own description says "This repo does not include code search, that is in the Peregrine repo," which is exactly the two-adjacent-services split the reporter was probing.
User
ok, let's now do the 401 improvement PR for the cli
Assistant
Let me look at how the command surfaces errors today, especially under --json.
Assistant
Now I have everything I need. Let me implement.
Assistant
Builds clean. Now the classification layer:
Assistant
Now the fan-out tests:
Assistant
Let me verify end-to-end against the real service, using the audience override that provably makes every cell 401.
Assistant
Wait — this changes a factual claim I made. The cell client carries the login JWT, not an exchanged identity token. Let me check what search actually sends.
Assistant
That reframes things. Let me test the same bearer against code search, and read entire-search's audience config.
Assistant
Before I finalize the wording, let me verify what fanOutCells actually builds — two comments claim it mints identity tokens.
Assistant
Two comments (and CLAUDE.md) describe a token flow that was deliberately removed in 3df7ea461. Let me fix the wording that depends on it.
Assistant
Now the CLAUDE.md token rule, which states the removed flow as fact:
Assistant
The wrapper already prefixes "semantic search:" — my message repeated it. Fixing:
Assistant
That reads well. Now the full check suite:
Assistant
Lint clean after the final format pass. Committing and opening the PR:
Assistant
PR open:
User
but that error isn't helping the user at all either, right?
Assistant
You're right, and the --code suggestion is the weakest part — code search answers a different question. Someone searching their session history for "webhook" doesn't want file matches. Let me check what a genuinely useful local fallback would be.
Assistant
Let me check what the CLI actually offers as a reporting path before I rewrite the message.
Assistant
You're right. Let me fix the message, then be straight about what the CLI can and can't do here.
Assistant
Correct — and the --code suggestion was the worst part of it. I've dropped it and now assert against it in the tests:
code
search failed: semantic search: your credentials were rejected in aws-eu-central-1 — the search
service refused a login that works everywhere else, so retrying and logging in again are both dead
ends; 'entire doctor bundle' packages the details for a bug report
I probed prod directly. The issue's diagnosis is wrong — it's not an audience mismatch, and it's not a CLI bug.
What the probes show
All against aws-eu-central-1.api.entire.io, from my own (us-home) account:
Bearer
/api/v1/semantic-search/search/v1/search
/api/v1/search/api/search
aud=https://eu.entire.io
200 + results
200
aud=https://us.entire.io
200
—
aud=https://entire.io (the advertised one)
401 {"error":"Unauthorized"}
401 token verification failed: InvalidAudience
not.a.jwt
401 {"error":"Unauthorized"}
400 missing field q
Point by point against the report:
eu.entire.io NXDOMAIN is a red herring.aud is an opaque identifier, never dialed. au.entire.io and in.entire.io are also NXDOMAIN; only us.entire.io resolves.
The EU cell accepts aud=https://eu.entire.io on the semantic route — I get 200 with real results. It rejectshttps://entire.io, the audience the well-known advertises, with the exact {"error":"Unauthorized"} body they saw. So suggested fix #1 would break search for everyone.
"The failure precedes request parsing" is validation ordering, not auth. Code search does verify tokens (wrong aud → InvalidAudience); it just deserializes q first, which is why a garbage token gets a 400 there.
Decisive: code search worked for them with the same bearer at the same host — and both routes get the identical*api.Client from fanOutCells (cmd/entire/cli/search_cmd.go:556, cmd/entire/cli/search_v4.go:161). Their token, audience and issuer are demonstrably accepted in that cell. Only the semantic service refuses it.
Their {"error":"Unauthorized"} is byte-identical to what a garbage token produces — i.e. the semantic service treated a valid token as unusable.
Actual cause
Server-side and account-scoped, in the semantic-search stack (entire-search/query-serve) — almost certainly identity resolution for home_jurisdiction: eu. That claim is the only meaningful difference between their token and my working one (mine carries home_jurisdiction: us plus foreign_iss from the cross-juris exchange). It fits every observation: region-independent for them, EU cell fine for a us-home account, web app failing on Sessions but not Code. This belongs in the search service repo.
CLI-side work that's still warranted
A 401 sentinel in search/search.go so a rejected credential isn't a bare search service error (401): Unauthorized and --json can distinguish it from zero results. That's #1923's machine-readable ask, in the right category.
Not their fix #2 — classifying this as regional unavailability would mask a server bug as geography. errNoRegionAvailable (search_v4.go:423) already exists for the real thing (gateway 404, no query-serve in the cell).
doctor search-reachability check is reasonable, low priority.
Want me to post this as a comment on #2121 (and/or open the corresponding one on the search service repo), or draft the 401-sentinel PR?
Reading the source pinned the failure down much further than my earlier terminal-only diagnosis:
http.StatusUnauthorized appears once in non-test internal/searchapi — server.go:145, the resolveUserID failure branch. So the reporter's 401 is that line, definitively.
Of its three core-JWT failure modes, my probes eliminate two (audience/issuer are fine for eu; they used GitHub device flow so provider=github with a numeric provider_user_id). What's left is GetUserByGithubID → sql.ErrNoRows → user not found in Entire (auth.go:85-88, SELECT id FROM users WHERE github_id = ?) — the EU-home account has no users row in the entiredb that service reads.
server.go:144 logs the actual reason at warn level and the client never sees it, so the issue leads with that as the one-step confirmation, plus the reporter's github_id 80194665 to grep for.
Two things the write-up adds beyond the original report:
A second, independent finding. Completing the probe matrix showed entire-search accepts a token minted for another jurisdiction's audience in either cell (all four combos 200), while peregrine strictly rejects the mismatch with InvalidAudience. Peregrine's strictness confirms the CLI's per-jurisdiction minting is correct; entire-search's laxness is worth its own look.
An explicit "don't apply the suggested fix." Minting the advertised https://entire.io audience would break semantic search for everyone and fail peregrine outright — so the issue says so up front, before someone acts on cli#2121's headline.
I also asked them to reconsider returning a bare 401 for "verified token, unknown user" — it's currently byte-identical to not.a.jwt, which is what turned this into a multi-day external investigation.
Still open on our side, if you want it: the CLI 401 sentinel so this stops surfacing as a raw search service error (401): Unauthorized and --json can distinguish it from zero results. I haven't touched any code.
search failed: semantic search: your credentials were rejected in aws-eu-central-1 — the same login
serves code search and every other Entire command, so logging in again is unlikely to help; try
'entire search --code'
What's in it
search.ErrCellUnauthorized — CellV4 classifies 401/403 the way it already classifies its two 404s, wrapping the status and the service's own message so debug logs keep the only clue to which auth stage refused.
Its own fan-out bucket, kept inside failed so coverage flags and accounting don't change.
Priority when nothing answered: credential rejection > transport/5xx > repo-filter miss > undeployed region. A rejection is the one outcome certain to repeat.
A partial-failure warning naming the rejecting regions, since "search failed in 1 of 2 regions" reads as transient.
Explicitly not reclassified as regional unavailability (#2121's fallback ask) — that would mask a server bug as geography and promise a rollout that never comes. errNoRegionAvailable still covers the genuine case.
One correction to what I told you earlier. I said the CLI sends a per-jurisdiction identity token. It doesn't — CellClientFactory.ClientFor passes the login JWT straight through. 3df7ea461 ("Use login JWTs directly for cell auth") removed that exchange, but four places still describe the old flow, including the CLAUDE.md token rule. That stale documentation is precisely what sent both the reporter and me auditing token audiences. I corrected all four and flagged the drive-by in the PR as splittable.
It doesn't change the diagnosis — code search and semantic search share one client, which was always the load-bearing argument — and it actually strengthens it: the deployed ENTIRE_CORE_JWT_AUDIENCE for the eu-central-1 query pod lists all eight hosts including https://eu.auth.entire.io, so audience is now ruled out by config, not just by probe.
mise run check is green end to end (lint 0 issues; unit, integration and canary all pass), plus seven new test cases and a prod verification that normal search still works.
Two things I left alone and noted in the PR: the older sentinels double the semantic search: prefix (fixing them changes strings #1923 quotes), and entire doctor still has no search-reachability check — #2121's third ask.
One thing needs your call: issue #196 states the CLI sends an identity token, which I now know is wrong. The conclusion there is unaffected, but the justification is inaccurate on a bug report someone will act on. Want me to post a correction comment?
Being honest about the ceiling here. No CLI change makes this search succeed. The index is server-side and there's no local substitute, so the message can only buy two things: that retrying and re-authenticating are both dead ends (the #2121 reporter burned days on exactly that reflex, then wrote a deep and partly wrong diagnosis), and the one action that changes anything. That's a smaller claim than my last message made, and it's the true one.
What would actually help is a local fallback — #1923's second ask — and that's a feature, not a message. I checked feasibility rather than guessing, and there's a catch worth knowing before anyone scopes it: local checkpoint trees reference blobs the clone doesn't have. git grep over entire/checkpoints/v1 here does find matches, but takes 30s+ and triggers upload-pack: not our ref fetches. So a local search would silently answer from partial data — and "no history" from a partial index is the #1923 failure mode all over again. That's why I didn't fake one in this PR.
The narrower piece that would genuinely pay off is #2121's third ask: a search-reachability check in entire doctor. It's where this error now sends people, so it's the natural next PR — an EU account today gets a working enable, working capture, working push, and a search command that cannot work, with nothing saying so.
PR #2124 is updated (message, tests, commit body, and the PR description now states the ceiling instead of overselling). Lint clean, tests green.
Want me to take the entire doctor check next, or leave it for the server-side fix to land first?