Skip to content

Issue-221: Hunt register and GET /v1/hunts - #234

Merged
zakiyyah-osman merged 5 commits into
devfrom
feat/221-hunt-register
Nov 30, 2026
Merged

zakiyyah-osman merged 5 commits into
devfrom
feat/221-hunt-register

Conversation

@zakiyyah-osman

@zakiyyah-osman zakiyyah-osman commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #221

Adds the hunt register and GET /v1/hunts (A22.7.1): the static list of Discovery hunts that the picker, the plan and the run record will read. It is metadata only, with no network access and no frontend UI.

Parts of the register are not given by the spec. They are listed under "Please check" and recorded as Q-529.

What changed

Contract

  • shared/schemas/hunt-register.schema.json (new): a top-level array, as A22.7.1 writes it, with additionalProperties: false on every object.
    • availability.reason is required when state is disabled and rejected when it is available.
    • calibration is an object or null.
  • Generated types: backend/app/contract/hunt_register_schema.py and frontend/src/contract/generated.ts (D-18). frontend/scripts/generate-contract.js gains huntRegister.
  • shared/README.md: lists the schema.

Backend

  • app/core/hunts/register.py (new): the 10 hunts of A22.2 in table order (H4b is a stage of asteroids, not its own entry). register() returns a copy.
  • app/api/hunts.py (new): GET /v1/hunts, checked against the schema before it is sent (Q-40).
  • app/main.py: includes the router.

Docs

  • Q-529 in docs/decisions/discovery-hunts.md, its index row, the next free id (Q-530) and the routing row in docs/README.md.
  • A22.7.4: new code hunt:<id>:not_built. A22.7.1: off in the reply shape.
  • A4.11: the GET /v1/hunts row. A4.12: a pointer to the hunt: codes.
  • A22 status line: the register is built.

Tests

  • tests/test_hunt_register.py (new): the reply validates against the schema and the generated type; ids are unique and match HuntId; only asteroids is available; every other hunt has its reason and is off; kind, level, weight, version and routes are pinned; bad availability shapes are rejected.
  • tests/test_contract_fixtures.py: existing test changed. It expected a Pydantic model for every schema. This schema's root is an array, so its generated type is an alias; it is now listed in ALIAS_SCHEMAS.

The register

id Hunt kind level weight version availability
variables H1 search off light 0.0.0 not_built
cold_worlds H2 search off light 0.0.0 not_built
asteroids H4 characterisation characterisation heavy 1.0.0 available
runaways H8 search off light 0.0.0 not_built
ir_excess H9 characterisation off light 0.0.0 not_built
dimmers H3 search off light 0.0.0 not_built
active_asteroids H5 search off heavy 0.0.0 not_built
slow_movers H11 search off heavy 0.0.0 not_built
transients H7 context off light 0.0.0 not_built
dark_companions H10 context off light 0.0.0 needs_release:gaia_dr4

calibration is null for all.

Please check (Q-529, "Open (built)"): Kevin, Moon

  1. New reason code hunt:<id>:not_built. A22.7.4 had no code for a hunt whose code is not merged. Hunt refusal codes and API errors #222 should include it in its builder.
  2. level: off for every disabled hunt (A22.10.1). off is added to the schema and to A22.7.1, which had left it out although A22.4.1 has it.
  3. asteroids is still characterisation. A22.10.1 needs the measurement's own check for that level, and I found no Gaia DR3 spectra check in backend/ or frontend/src. It is available and runs Discovery today.
  4. asteroids version 1.0.0 is not in the spec.
  5. asteroids title and summary now say only what runs today ("Known rocks"). Predict-first, spectra and precovery (HN-5, HN-11) are not built. Wording to be confirmed before the picker (Hunt picker card (against fixtures) #225) shows it.
  6. weight: light for H2 and H9 covers their catalogue stages only. Their pixel stages are heavy (A22.4.2), so HN-1 should not schedule lanes from this field alone.
  7. weight: light for H7 and H10, and kind: search for H2 (the spec says "search, then characterisation").
  8. Routes: only VSX (H1), dated 2026-11-18 as in the A22.7.3 example. The spec also marks the H2 and H8 routes verified but gives no URL, so none is listed. The VSX page's exact wording is still [verify].
  9. Summaries come from the mock-up, except variables (reworded to "checked against", A22.3.6), asteroids (item 5) and active_asteroids (newly written).
  10. Releases are short names taken from the A22.2 "Main data" column.

Related work

  • Hunt refusal codes and API errors #222 builds the reason codes. The two kinds of reason string here are written by hand and should move to its builder.
  • HN-2 covers hunt-*.schema.json; this PR adds only the register schema.
  • Out of scope, as in the ticket: the Hunt protocol (HN-1), the plan on POST /v1/scans, run records, rows and any UI.

Test results (local, offline)

  • Backend: pytest 1873 passed, 5 skipped; ruff check, ruff format --check and mypy clean; contract --check passes (bake-fixtures, area-fixtures and demo-pack --check passed before the review fixes).
  • Frontend: 3410 tests passed, 5 skipped, 1 todo; contract check, typecheck and format check pass (build passed before the review fixes); lint 0 errors, 4 warnings in files this PR does not touch.
  • Not run: Playwright e2e (no UI change).

A local code review before the first push found no blocking issues. The changes requested in review are in the last two commits.

Done when (from #221)

  • GET /v1/hunts returns every hunt of A22.2 and validates against the schema.
  • Generated frontend types exist for the schema (D-18).
  • Tests pass locally; no network.

🤖 Generated with Claude Code

Add hunt-register.schema.json, the static register of the ten hunts of
A22.2 and the endpoint that serves it, checked against the schema.
Only asteroids is available. Values the spec does not state are
recorded as Q-529, with the new reason code hunt:<id>:not_built.

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.

The register, endpoint, schema and tests look solid. CI is green, the contract check passes, and Q-529 doesn't collide with any other ID. One contract fix is needed before merge.

Blocking

Hunts that are not built claim a level that requires merged code. These are in backend/app/core/hunts/register.py (L188-282), and the schema's level enum (shared/schemas/hunt-register.schema.json L752-755) has no other option.

Nine of the ten hunts are disabled with hunt:<id>:not_built (or needs_release), but they still carry a real level:

  • experimental: variables, cold_worlds, runaways, dimmers, active_asteroids, slow_movers
  • characterisation: ir_excess
  • context: transients, dark_companions

A22.10.1 makes each level a requirement. Experimental needs "the code is merged and its known-object match works", Characterisation needs the measurement's own check, and Context needs "the adapter works". A hunt that is not built is Off ("not in the picker, or disabled with a reason").

The picker (A22.3.2, #225) groups rows by level taken from the register. As things stand, it would list six unbuilt hunts under Experimental, whose copy says they "run and return recoveries of known objects only". It would also list H9 under Characterisation, the group that is ticked by default.

off is already in the spec: A22.4.1's Hunt protocol has level: Literal["off", "experimental", "validated", "characterisation", "context"]. Only the A22.7.1 reply shape leaves it out. Q-529 item 6 notes this gap but settles it the other way.

Fix:

  1. Add "off" to the level enum in the schema and regenerate both contract files.
  2. Give every unbuilt hunt level: "off".
  3. Update EXPECTED in backend/tests/test_hunt_register.py (L392-403). Optionally, add a test that a disabled not_built entry always has level off.
  4. Reword Q-529 to follow A22.4.1 and A22.10.1, and record the A22.7.1 vs A22.4.1 conflict there.

Non-blocking

  • asteroids text (register.py L208-218): the summary and title mention spectra and precovery, which aren't built yet (HN-5, HN-11). Please reword this before #225 shows it. Also check that the H4 spectra check against Gaia DR3 is merged; A22.10.1 needs it for characterisation.
  • weight: H2 and H9 are marked light, but their pixel stages are heavy (A22.4.2). HN-1 lane scheduling shouldn't rely on this field alone; consider a per-stage weight or heavy.
  • Generated HuntAvailability: it doesn't encode the schema's if/then/else on reason. That's expected from the generator, and check() covers it.
  • Reason strings: they are written by hand. As noted in the PR, they should move to #222's builder.
  • VSX route: its wording is still [verify] in A22.9.1, and verified_at 2026-11-18 just repeats the A22.7.3 example.
  • docs/decisions/discovery-hunts.md: consider giving the hunt-register entry its own heading, so later entries that aren't A22.15 rows have a home.

Docs

  • A4.11 (docs/architecture/endpoints.md): add a row for GET /v1/hunts (built, #221, backend/app/api/hunts.py, A22.7.1, Q-529).
  • A4.12 (docs/architecture/refusals.md): add a pointer to the hunt: namespace in A22.7.4, including the new hunt:<id>:not_built.
  • A22.7.1: once the blocking fix is in, add off to the reply shape.

zakiyyah-osman and others added 2 commits November 29, 2026 11:11
A22.10.1 lets only merged code claim a level, so every disabled hunt is
now off. Add off to the schema's level enum and A22.7.1, record the
conflict with A22.4.1 in Q-529, and add GET /v1/hunts to A4.11 and the
hunt: codes to A4.12.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Shorten the asteroids title and summary to Discovery as built, give
Q-529 its own heading and record that weight cannot describe the pixel
stages of H2 and H9.

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

Copy link
Copy Markdown
Collaborator Author

Fixed the blocker: every unbuilt hunt is now level: "off", off is in the schema and A22.7.1, and Q-529 records the conflict with A22.4.1. Added the A4.11 row and the A4.12 pointer.

Non-blocking: reworded the asteroids title and summary to what runs today, gave Q-529 its own heading, and noted the weight limitation there (values unchanged). Reason strings wait for #222. The VSX wording is still [verify].

One question: I found no Gaia DR3 spectra check in backend/ or frontend/src. A22.10.1 needs the measurement's own check for characterisation, but asteroids is available and runs Discovery. I've left it as characterisation. Is that right, or should it be something else?

@zakiyyah-osman

Copy link
Copy Markdown
Collaborator Author

@MintHerbs details on the CI failure, since you're looking into it.

Playwright shard 1/4 failed once on 72207c74 and passed on a re-run of the same commit, so it looks flaky.

Test: frontend/e2e/build.spec.ts:465, "the last frame of a build is the normal render of the same plan and seed".
Failed attempts: similarity 0.864 (channelMin 0.848, colourDelta 33.97), then 0.748 on retry (channelMin 0.705, colourDelta 42.88). The test needs at least 0.97.
Rest of that shard: 42 tests passed.
This PR: the only frontend change since the previous green run (b9e75795) is the level type in frontend/src/contract/generated.ts.
Failed job: https://github.com/0ffrian/SphereX/actions/runs/46237467928/job/141266612215

@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.

Review: approve with nits

Thanks, this is a clean, well-scoped PR. It stays inside #221 (backend and contract only, no UI), the "Please check" list made the open points easy to review, and the PR body is accurate.

What I checked

  • Tests: tests/test_hunt_register.py and tests/test_contract_fixtures.py pass offline (SX_OFFLINE=1): 242 passed. I did not rerun the full suite, ruff, mypy or the frontend tests; I'm relying on your local results for those.
  • Contract (D-18): node scripts/generate-contract.js --check reports src/contract/generated.ts matches shared/schemas/.
  • Live endpoint: I ran the branch locally. GET /v1/hunts returns 200 with all 10 hunts, in A22.2 table order. Only asteroids is available; the other nine are disabled with a reason.
  • Schema (A22.7.1):
    • The array root matches the spec.
    • additionalProperties: false is set on every object.
    • calibration is an object or null.
    • The availability if/then/else is correct draft-07: reason is required when the hunt is disabled and rejected when it is available.
    • The reason pattern accepts hunt:dark_companions:needs_release:gaia_dr4.
  • Q-40: backend/app/api/hunts.py checks the body against the schema before sending it.
  • Enums (A22.4.1): kind, level and weight match. Adding off to A22.7.1 is the right call: A22.4.1 and A22.10.1 both have it, so A22.7.1 was the outlier.
  • Decisions bookkeeping:
    • Q-529 is free on dev.
    • The next free id moves to Q-530.
    • The index row and the docs/README.md routing range are updated.
    • "Open (built)" is the right status.
    • The Q-523 reference in the endpoints.md row is correct (PD-11 Contract).
  • Existing test change: listing the schema in ALIAS_SCHEMAS in test_contract_fixtures.py is justified, because the generated type for an array root is an alias, not a model.
  • Docs: in sync. That covers the A22 status line, A22.7.1, A22.7.4, A4.11, refusals.md and shared/README.md. No UML is needed yet: A22 already lists the hunt diagrams as still to do, and HN-1 can add /v1/hunts to the component diagram.

Nits (non-blocking)

  1. No test for the refuse-to-serve path. Nothing checks what happens when the register fails validation. A small test that monkeypatches register() to return a bad entry (for example a disabled hunt without reason) and expects a 5xx would pin the Q-40 behaviour. A follow-up is fine.
  2. Hand-written reason strings. register.py builds the hunt:<id>:... strings by hand. You already flagged that #222's builder should take them over. Please make sure #222 picks up not_built as well as the A22.7.4 codes.
  3. Q-529 readability. The entry is one very long table cell. Consider splitting the ten points into a numbered list under the table in a later docs pass, so each one can be answered on its own.

"Please check" (Q-529)

Accepted as written:

  • 1, the new hunt:<id>:not_built code
  • 2, level: off for unbuilt hunts
  • 4, asteroids at 1.0.0
  • 7, weight: light for H7 and H10, and kind: search for H2
  • 8, VSX as the only route. Listing a route only where the spec gives a URL is the honest choice. Keep the VSX wording marked [verify], and add no H2 or H8 routes until their URLs are verified.
  • 9, the summaries
  • 10, short release names

Still open, to settle in Q-529 before the picker (#225) and HN-1 read these fields. They don't block this merge:

  • 3, the asteroids level. A22.10.1 requires the measurement's own check for characterisation, and the Gaia DR3 spectra check doesn't exist yet. Either move H4 to experimental until it lands, or keep characterisation and record it in Q-529 as a deliberate exception.
  • 5, the title and summary. "Known rocks", describing only what runs today, is the right direction. We'll confirm the final wording when #225 builds the picker.
  • 6, weight for H2 and H9. light describes only their catalogue stage; their pixel stages are heavy (A22.4.2). Either make weight the heaviest stage, or document in A22.4.1 that it is the catalogue stage, so HN-1 doesn't schedule lanes from this field alone.

Kevin, as owner of core/hunts/, please weigh in on 3 and 6.

Approving. Nice work.

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

Copy link
Copy Markdown
Collaborator Author

Thanks @MintHerbs. I've addressed the nits in a2eccdae:

The asteroids level, title wording and weight (points 3, 5 and 6) are still open.

@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.

Approved with nits. Re-reviewed at a2eccda. All four blockers from my earlier review are fixed:

  • off is in the level enum, the schema, and the regenerated types on both sides.
  • Every unbuilt hunt is off, H10 included.
  • EXPECTED is updated, with a disabled-implies-off test.
  • Q-529 records the A22.7.1 vs A22.4.1 conflict.

The A4.11 and A4.12 doc fixes are in. The refuse-to-serve test was added, and Q-529 is a numbered list. CI is green.

Nits (non-blocking):

  1. H4 is still characterisation (register.py:84), but its Gaia DR3 spectra check isn't built yet (A22.10.1). It's recorded openly as Q-529 point 3. Settle it before #225 reads level: either move H4 to experimental or state it as an exception.
  2. #222 should pick up hunt:<id>:not_built and replace the hand-built reason strings in register.py. Add a line to #222's scope.
  3. A22.7.2 (docs/architecture/discovery-hunts.md ~407) still lists the levels without off. Add a half-sentence there.
  4. dark_companions summary: "DPAC's dark-companion table" is more accurate than "Gaia's own black-hole table".
  5. The VSX route is still [verify]. The verified_at date is the review date, not a fresh check.

Name DPAC's dark-companion table in the H10 summary, add `off` to the
level note in A22.7.2, and record H4's level as a stated exception in
Q-529 until the spectra check is built.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@zakiyyah-osman
zakiyyah-osman added this pull request to the merge queue Nov 30, 2026
@zakiyyah-osman

Copy link
Copy Markdown
Collaborator Author

Thanks for the re-review. On the nits (09eef667):

  1. H4 characterisation: kept, and recorded in Q-529 point 3 as a stated exception until the Gaia DR3 spectra check is built. Kevin and Moon still need to confirm, before Hunt picker card (against fixtures) #225 reads level.
  2. Hunt refusal codes and API errors #222: added a scope line for hunt:<id>:not_built and replacing the hand-built reason strings.
  3. A22.7.2: the level note now mentions off.
  4. dark_companions summary: now names DPAC's dark-companion table (also noted in Q-529 point 9).
  5. VSX route: unchanged. It stays [verify], and verified_at has not been refreshed with a new check.

CI is green, after a re-run for the flaky build.spec.ts:465 test.

Merged via the queue into dev with commit db5cbcc Nov 30, 2026
16 of 18 checks passed
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 register: hunt-register.schema.json and GET /v1/hunts

3 participants