Skip to content

feat(api): error envelope + validate-first atomicity (policy R1/R2/R4) - #247

Merged
Levalicious merged 1 commit into
developfrom
feature/api-error-policy
Oct 8, 2026
Merged

Levalicious merged 1 commit into
developfrom
feature/api-error-policy

Conversation

@Levalicious

Copy link
Copy Markdown
Owner

Implements the error half of docs/api-error-policy.md (adopted 2026-10-08): the server no longer hides failures from the model.

What changed

  • R1 — visible failures. ToolError + stable codes (ENTITY_NOT_FOUND, ENDPOINT_MISSING, COLLISION, LIMIT_EXCEEDED, INVALID_REGEX, INVALID_FILE, NO_MATCHES, TYPE_NOT_FOUND, VALIDATION_FAILED). The request handler converts them into isError: true with a JSON envelope {error: {tool, code, message, details}}. Protocol errors are now reserved for genuine server faults.
  • R2 — validate-first, atomic. create_entities (collisions were checked mid-write), create_relations, add_observations (validated inside the write loop → partial batches), sequentialthinking — all validate the whole request before touching state; failures list every offender in one round-trip.
  • R4 — drops→errors. Missing relation endpoints, all-missing open_nodes, unknown get_entities_by_type types, unknown get_neighbors/random_walk starts, invalid regex, kb_load file errors, unlinked thoughts. Duplicates and ensure-absent deletes keep succeeding (their ledgers arrive in the follow-up ledger PR).
  • search_nodes's NL-guard now returns the same envelope shape (NO_MATCHES + suggestedRegex detail).

Evidence

  • 13 existing protocol-error assertions converted to envelope checks (parseToolError helper in test-utils); new API error policy test block proves atomicity (failed batches leave nothing behind) and envelope shape.
  • Fuzz (30 agents, ~366k calls): protoErr = 0 across every tool — all 25.8k create_entities rejections, 14.3k relation rejections, 10.3k get_neighbors rejections etc. now arrive as visible toolErr.
  • Full suite: 183/183.

🤖 Generated with Claude Code

Implements docs/api-error-policy.md: errors are signal.

- ToolError + stable codes; the request handler converts them into visible
  structured tool errors (isError + JSON envelope) — protocol errors are
  now reserved for genuine server faults (R1)
- validate-first, all-or-nothing batches for create_entities,
  create_relations, add_observations, sequentialthinking (R2; fixes the
  mid-loop partial application in add_observations)
- silent drops become errors (R4): missing relation endpoints
  (ENDPOINT_MISSING), all-missing open_nodes, unknown type, unknown
  get_neighbors/random_walk starts, invalid regex, kb_load file errors,
  unlinked thoughts
- search NL-guard returns the same envelope (NO_MATCHES + suggestion)
- tests: 13 protocol-error assertions converted to envelope checks; new
  policy block (atomicity proofs, envelope shape); fuzz now shows
  protoErr=0 with every rejection visible as toolErr
- full suite 183/183

Co-Authored-By: Claude Code <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Per-op benchmark — p50 cycles (base vs head)

base runs: 5, head runs: 5 (median of mins) · freq-correction ×1.0025 · threshold head−base > max(40 cyc, 5%)

op base head* Δ Δ%
lookup 115.1 116 +0.9 +0.8%
read_entity 40.1 40 -0.1 -0.2%
neighbors_d1 797.1 803 +5.9 +0.7%
neighbors_d2 2593.2 2630 +36.8 +1.4%
find_path_d6 177552 178534 +982.0 +0.6%
search 1172840 1175146 +2306.0 +0.2%
entities_by_type 14039 14073 +34.0 +0.2%
random_walk_d5 1321.6 1309 -12.6 -1.0%
inc_walker_visit 17.5 18 +0.5 +2.9%
structural_sample 2576249 2587993 +11744.0 +0.5%
compute_merw_psi 905814 910844 +5030.0 +0.6%
create_entity 833 810 -23.0 -2.8%
create_relation 784 786 +2.0 +0.3%

* head frequency-corrected to base via the reference op.

No regressions beyond threshold.

@Levalicious
Levalicious merged commit 0eb45a3 into develop Oct 8, 2026
12 checks passed
@Levalicious
Levalicious deleted the feature/api-error-policy branch October 8, 2026 06:11
@Levalicious Levalicious mentioned this pull request Oct 8, 2026
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