Skip to content

Issue-222: Hunt refusal codes and API errors - #239

Open
zakiyyah-osman wants to merge 3 commits into
devfrom
feat/222-hunt-codes
Open

zakiyyah-osman wants to merge 3 commits into
devfrom
feat/222-hunt-codes

Conversation

@zakiyyah-osman

@zakiyyah-osman zakiyyah-osman commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #222

What changed

  • backend/app/core/hunts/codes.py: one builder per hunt: namespace of A22.7.4 (including not_built) and a parser. Unknown hunts, namespaces, suffixes and badly formed segments raise HuntCodeError.
  • backend/app/api/hunts.py: the seven errors of A22.7.1 in the {error, detail} body, and check_hunts() for the empty, unknown and disabled cases.
  • backend/app/core/hunts/register.py: reason strings now come from the builders. The register data is unchanged.
  • shared/hunt-codes.json: every code with its proposed words, and every error with its status.
  • Docs: Q-531, refusals.md, shared/README.md.

For review (Q-531, open)

  • Code segments are lowercase a-z, digits and _, as the register schema already requires.
  • A22.7.4 gives no words for no_sector or outside_footprint, so they are null. Hunt picker card (against fixtures) #225 / Results by hunt and the row card (against fixtures) #226 will need to word them.
  • <where> is square_<index> for pixel hunts and patch for catalogue hunts; the builder and parser refuse anything else.
  • The hunt:disabled detail names the hunt and the reason in plain words, with no raw code (Q-477).

Limits

  • No route calls check_hunts() yet, and the routes behind hunt_not_in_run, row_not_found, hunt_not_done and route_not_available do not exist. Their status and body are tested through a temporary route.
  • The claim-words test covers only the codes that have words.

Tests

  • Backend: ruff, ruff format, mypy and the contract check are clean. Full pytest after the review fixes and the <where> check (02a4e45): 1922 passed, 5 skipped (sky assets not baked locally).
  • Frontend: contract check, typecheck, lint, format check and build pass. Vitest: 3423 passed, 5 skipped, 1 todo on two reruns. The first full run had 10 failures, including at least one 5 s timeout, that did not recur.
  • After the review fixes only the src/test/ Vitest files (38 passed) and the Prettier check of hunt-codes.json were rerun locally; the frontend results above are from the first commit.
  • CI on the first commit: ci-gate passed, including the backend job, the frontend typecheck, lint, test and build job, all four Playwright shards and the engine speed check. e2e was not run locally.

🤖 Generated with Claude Code

One builder per hunt: code namespace of A22.7.4 with a parser, the seven
hunt errors of A22.7.1, and shared/hunt-codes.json with the codes, their
proposed words and the errors. The register now uses the builders. Q-530
records the shapes the spec does not state.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@JoottunAtish JoottunAtish left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is clean work. It covers all of #222, the code shapes and error statuses match A22.7.4 and A22.7.1, and the hunt-code and register tests pass locally (50 passed). One blocker, then some smaller points.

Blocking

1. Q-530 is already taken by #238. #238 was opened 11 minutes earlier and also records its decision as Q-530, with "Next free" set to Q-531. Please renumber this PR's decision to Q-531 and set "Next free" to Q-532, in:

  • docs/decisions/discovery-hunts.md (the "Hunt codes and errors" section and the header line)
  • docs/decisions/README.md (the index row and the Next free line)
  • docs/README.md (the Discovery hunts routing row; #238 edits the same row, so rebase after it merges)
  • docs/architecture/refusals.md
  • shared/README.md
  • the docstring in backend/app/core/hunts/codes.py

Should fix before the scan route uses check_hunts

2. The hunt:disabled message shows the raw code (backend/app/api/hunts.py:33-35). The message reads "Hunt 'dark_companions' is disabled: hunt:dark_companions:needs_release:gaia_dr4." The scan screen shows detail as-is (frontend/src/app/area/scanStore.ts, failView), so the user would see the code (Q-477). Word the message in plain prose, or put the reason in its own field.

Non-blocking

  1. Placeholders in shared/hunt-codes.json. Q-531 should say where each placeholder gets its value. {release} would fill with gaia_dr4 rather than "Gaia DR4" (the register's releases has the readable name), and {criterion} with r_lt_18 rather than "r < 18". {percent}, {square}, {count} and {why} are not parts of the code at all.
  2. <where> for catalogue hunts. These hunts cover the whole patch, not one square (A22.4, R-10). Say what <where> holds for them, for example patch.
  3. HUNT_IDS (codes.py:99-100). The way it is derived depends on the generated type's exact shape. Add a comment pointing at test_hunt_ids_are_the_register_ids.
  4. The AST guard only catches string literals that start with hunt:. An f-string or a joined string gets past it. A note in the test is enough.
  5. The register.py:5 docstring lost detail: it changed from hunt:<id>:not_built to not_built.
  6. shared/hunt-codes.json is hand-written, with no schema. Say so in shared/README.md, so nobody expects the generator to produce it.
  7. check_hunts could move into core/hunts/ when the scan route starts using it.

Please also keep an eye on CI: your first Vitest run had 10 failures that did not come back.

Renumber the decision to Q-531 (#238 takes Q-530), word the hunt:disabled
detail without the raw code, set <where> to "patch" for catalogue hunts,
say where each placeholder comes from, and make the review's small doc and
comment fixes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@zakiyyah-osman

zakiyyah-osman commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator Author

Thanks for the review. Pushed in 55c9d53:

1. Renumbered to Q-531, "Next free" is Q-532 (also updated the docstring in api/hunts.py). I'll rebase once #238 merges.

2. hunt:disabled now words the reason in plain prose. From the code, the scan and live-area failed cards build their text from the error code rather than detail, but other views do show detail, so it's worth having either way.

3–4. Q-531 now gives proposed placeholder sources (no reply field holds {why} yet) and sets <where> to patch for catalogue hunts.

5–8. Done. On 6: an f-string that starts with hunt: is caught; a joined string isn't, and the note says that.

9. Leaving until the scan route uses check_hunts.

Q-531 states this form and the row schema of PR #238 requires it, but the
builder and parser accepted any segment.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@JoottunAtish JoottunAtish left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed at 02a4e45. Thanks for the quick turnaround: everything from the last review is fixed, and CI is green. Approving.

What I checked:

  • Q-531 is renumbered everywhere, and "Next free" is Q-532.
  • The hunt:disabled message is now plain prose and has a test.
  • The placeholder sources are recorded in Q-531.
  • The <where> rule (square_<n> or patch) is recorded and enforced in the parser, and every code in #238's fixture parses under it.
  • The comment, docstring and README points are all done.

Moving check_hunts into core/hunts/ can wait until the scan route uses it, as you said.

Nits (non-blocking, fine as a follow-up)

  1. One fact, two decisions. #238's Q-530 point 10 states the same <where> rule as Q-531 point 2. Let Q-531 own it, since the rule lives in codes.py, and have Q-530 refer to it. Whichever PR merges second can do this when it rebases.
  2. Release names are duplicated. backend/app/api/hunts.py:29 hard-codes RELEASE_NAMES = {"gaia_dr4": "Gaia DR4"}, but register.py already has releases=("Gaia DR4",), and Q-531 point 3 names the register as the source. A new needs_release hunt would quietly fall back to "a later data release". Read the name from the register, or add a test that every needs_release reason has an entry.
  3. Malformed reason gives a 500. hunt_disabled calls codes.parse(reason) (api/hunts.py:39), so a malformed availability.reason would raise HuntCodeError and return a 500 instead of the 422. This can't happen today, because every reason is built by codes.
  4. Wording. For the dark-companions hunt the message reads "'Gaia DR4 dark companions' cannot run. It opens with Gaia DR4.", which names Gaia DR4 twice.

After #238 merges, rebase for the routing row in docs/README.md and the "Next free" line. Q-531 still needs Kevin's and Moon's confirmation.

@MintHerbs MintHerbs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved

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.

Hunt refusal codes and API errors

3 participants