Skip to content

#882 feat: a stable reason_code on every observation refusal (v0.80.0) - #889

Merged
gregoryfoster merged 6 commits into
mainfrom
feat/882-reason-code
Nov 26, 2026
Merged

gregoryfoster merged 6 commits into
mainfrom
feat/882-reason-code

Conversation

@gregoryfoster

Copy link
Copy Markdown
Member

Part 1 of 2 for #882, the operator's decisions (comment 7172492503); design approved in comment 7175854705. Design doc: docs/plans/2026-11-25-reason-code-ownership-design.md.

What changes

  • ObservationResponse.reason_code: an ObservationReasonCode enum in the OpenAPI schema, so the generated client carries it. It is set on every rejected and null otherwise. reason stays diagnostic text and is unchanged on the wire.
  • What the code is: the reason's slug, the text before : . Three exceptions:
  • Mechanics:
    • ObservationRejected(code, detail=None) now requires a code.
    • Resolvers answer REJECTED with a Refusal, a str subclass that carries .code. Existing callers that compare text keep working.
    • Routes answer through ObservationResponse.rejected(code, reason).
    • New module: src/core/refusals.py.
  • Guards:
    • tests/core/test_refusal_code_sweep.py parses src/ and fails on any refusal site with no code.
    • tests/core/test_refusals.py holds the event and citation slugs inside the enum, and maps every name refusal.
    • An OpenAPI test asserts the enum is in the spec.
  • Docs:
    • PUBLIC_API: the reason_code row, "act on reason_code, log reason", and a code table.
    • API_ASSIGNMENTS, API_ORGS, OBSERVATIONS, CONVENTIONS, RUNBOOK_DESIRED_STATE: the gate is provenance_conflict.
    • API_PEOPLE: the name refusal's code.
  • Release: v0.80.0, with the client regenerated.

Verification

  • Pre-commit unit tier: passed.
  • Full integration (pytest -m integration): 5609 passed, 8 skipped.
  • scripts/pre-ship.sh: passed.

Not in this PR

Part 2 adds ownership on reads: self | other | none | dataset on AssignmentDetail, and parent_ownership on OrgDetail, both folded into the ETag. It also adds the owned_by_dataset refusal, and the ownership principle with its guard.

🤖 Generated with Claude Code

gregoryfoster and others added 3 commits November 25, 2026 21:38
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ObservationResponse.reason_code (an ObservationReasonCode enum in the spec, so
the generated client carries it) is set on every `rejected` and null otherwise.
The code is the reason's slug; the source_key_id gate is `provenance_conflict`
everywhere (its reason text keeps source_key_mismatch / name_provenance_conflict
until #888), and free-text validation messages are `invalid`.

ObservationRejected now requires a code; resolvers answer REJECTED with a
Refusal, a str that carries its code, so text comparisons keep working. A
sweep (tests/core/test_refusal_code_sweep.py) holds every refusal site under
src/ to a code. The design doc gains the operator's approval and the
owned_by_dataset refusal, pulled into scope for the ownership PR.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…_mismatch

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gregoryfoster and others added 2 commits November 26, 2026 00:10
…e is an ordinary refusal

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…dataset test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gregoryfoster
gregoryfoster merged commit 76f0f2b into main Nov 26, 2026
1 check passed
@gregoryfoster
gregoryfoster deleted the feat/882-reason-code branch November 26, 2026 01:39
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.

1 participant