# Interactive RFQ resolution

Introduced in API contract **1.9.0**.

Use `POST /v1/resolve` at draft checkpoints with `mode: "interactive"`. The endpoint and service key
are unchanged, and the request still requires `taxonomy:resolve`. This is REST-only: the MCP tool
continues to accept its existing input and always records normal resolution events.

```json
{
  "text": "frozen pork belly",
  "mode": "interactive",
  "locale": "en",
  "includeAttributeMetadata": true
}
```

All existing Resolve inputs, bounds, context, confirmed observations, supporting texts, enrichment,
and language behavior apply. `locale` is a hint, never a language filter. There is no new
`/v1/resolve/interactive` URL. Invalid mode values receive `400 REQUEST_INVALID`; omit `mode` or use
`"ledgered"` for the existing behavior.

API 1.10.0 also supports [applicable-attribute discovery](/docs/applicable-attributes) and
confirmed `observations.trimCode` answers. Keep the original text; send the buyer's choice as a
structured observation on both draft and final requests.

## Response and persistence

The response contains the same `taxonomyRelease`, `resolver`, `result`, and requested optional
metadata as a normal call using the same input and snapshot. **`resolutionEvent` is omitted**:
there is no null, stub or event ID. Matching, scoring, ambiguity, and unresolved output are not
relaxed. A draft can still be unresolved. The response does not echo `mode`.

Since API contract 1.51.0 the response carries **`interactiveDecision`**, `{ decision, reasonCodes }`:
the `auto_tag`, `review` or `no_match` decision and reason codes a recorded Resolve of the same input
derives under the same release and resolver. It is computed by the same function the ledger uses,
from the same result, but nothing is recorded: it has no event ID, cannot receive feedback, and
opens no case or unknown-vocabulary aggregate. A recorded answer never carries it; its decision is
on `resolutionEvent`. Use it to act on a reading without keeping the text, for example a person's
question sent with `inputKind: "question"`.

```json
{
  "taxonomyRelease": { "version": "0.4.297" },
  "resolver": { "version": "1.207.0" },
  "interactiveDecision": { "decision": "auto_tag", "reasonCodes": [] },
  "result": { "selection": { "status": "resolved" } }
}
```

Interactive calls skip the entire event-recording transaction: no resolution events, linked cases,
case occurrences, unknown-vocabulary aggregates, or event-based recheck inputs are created.
`requestReference`, if supplied, has no persistence effect. Authentication verification, best-effort
client usage accounting, and background snapshot refresh can still access PostgreSQL. A loaded
snapshot survives refresh failure; authentication cache misses and expiry still require the database.
No initial snapshot returns `503 TAXONOMY_SNAPSHOT_UNAVAILABLE` with `Retry-After: 1`.

Keep RFQs sanitized and service credentials server-side. Resolve responses, including errors, use
`Cache-Control: no-store`. Do not log draft text or credentials in the caller or intermediary.

## Request allowance

The initial, provisional interactive allowance uses a separate counter per API client **per replica**:
**600 requests in any rolling 60 seconds**, capped at **10 in any rolling second**. At the requested 5 requests/second,
that leaves 300 requests of minute-budget headroom. Normal Resolve retains its existing 600/minute
fixed-window counter; Suggest retains its own 6,000/minute and 200/second limits. Rotating credentials
for the same client does not give it another allowance. No new key, scope, or Redis service is needed.

Successful `RateLimit-*` headers describe the minute budget. `429` headers describe whichever
minute or second window blocks the request and include `Retry-After`. Respect that delay, debounce
draft checkpoints, cancel superseded requests, and discard stale responses. Counters are in-process,
reset on restart, and are not an exact global quota across replicas.

Separate counters protect the normal request allowance, **not reserved compute capacity**. Resolve,
interactive Resolve, and Explore share the existing admission cap (default four concurrent calls);
overload returns `503 RESOLVER_BUSY` with `Retry-After: 1`. The allowance is not a throughput guarantee.
Production sizing, simultaneous traffic capacity, and Raptor-to-Meat-Ontology latency certification
remain separate work; the concurrency setting is unchanged.

The release includes result-preserving long-input optimizations in the shared resolver: fuzzy
matching reuses identical query windows while retaining the earliest winning span; unapplied
vocabulary scans stop at the longest reviewed term; and identical supporting descriptions reuse
matching work within one request while retaining every source's evidence. There is no cross-request
draft cache, input truncation, or change to scoring, selection, or resolver provenance.

A checksum-verified published `0.4.80` archive (865 concepts, 2,884 terms) was used for local
database-independent checks. Before the fix, five repeated 4,086-character supporting texts took
**21.75 seconds**. Full-response hashes remain identical for all nine benchmark inputs, including
that case; 125 additional full resolver responses match the pre-fix implementation exactly.
The final local loopback HTTP run sent 150 requests at 5 requests/second across all nine cases,
including the long-input case: **150 HTTP 200, zero event responses, p50 23.57 ms, p95 215.79 ms,
maximum 362.48 ms**. The long case took 283.20 ms in the preceding individual check. The snapshot
was preloaded and authentication stubbed; database access during resolution was forbidden.
Production capacity, simultaneous mixed-endpoint traffic, snapshot-publication spikes, and the
Raptor network path are not certified by this local check. No production load test or Docker
cleanup is required or implied by this release.

## Draft to submission

1. Use Suggest for debounced keystrokes and interactive Resolve after pauses or draft edits.
2. Present the existing ambiguity/unresolved information; trim answers can use
   `observations.trimCode` within the reviewed coverage. An assisted or human-reviewed identity can
   be sent through `selection`; retain `unassistedSelection` and the supplied provenance in the
   workflow audit record.
3. On user-confirmed submission, resolve again without `mode` (or with `"ledgered"`), setting
   `requestReference` to the RFQ ID. Use that response's `resolutionEvent` for feedback. It is a new
   resolution, not promotion of a draft; a newer published release can change the result.
4. Keep the manual form available on failures. Interactive requests can be retried within a bounded
   deadline because they create no resolution event. Do not blindly retry an uncertain ledgered
   submission: `requestReference` is correlation, not an idempotency key.

```ts
const draft = await client.resolveMeatProduct(
  { text: rfqText, mode: "interactive", includeAttributeMetadata: true },
  { signal: abortController.signal },
);
// draft.resolutionEvent is absent; display draft.result.

const confirmed = await client.resolveMeatProduct({
  text: finalRfqText,
  requestReference: supplyRequestId,
});
const eventId = confirmed.resolutionEvent.id; // Still guaranteed for normal calls.
```

The client exports `InteractiveResolveMeatProductInput` and `InteractiveResolveMeatProductResponse`
alongside the existing ledgered types. When the mode is only known at runtime, the response is a
union; check for `resolutionEvent` before using it.

## Local verification — 30 August 2026

- Final API tests passed 266 cases, the client passed nine, and all 1,417 domain tests passed
  with two workers. An existing 385-row batch test had exceeded its 10-second timeout under default
  local parallelism; its 19-test file also passed in isolation (3.62 seconds of test execution).
  No assertion failure or response difference was found, and no test deadline was increased.
- The original interactive implementation passed CI, including the real-database draft/ledger
  comparison against an isolated test database. Locally that integration test is skipped without a
  dedicated `TEST_DATABASE_URL`, along with 24 existing database integration tests. The configured
  published local database is not repurposed as a test database.
- Tests cover result parity (including ambiguous/unresolved and multilingual inputs), omitted events,
  forbidden database access for drafts, default/explicit ledger recording, both limiter windows and
  cross-mode isolation, authentication, input validation, shared concurrency, snapshot refresh/failure,
  privacy, MCP compatibility, and client response types/cancellation.
- Type checking, API build, formatting, API generation checks, and deployment-routing tests passed.
  Lint retains two pre-existing warnings in untouched files.
- Only `/v1/resolve` changes in the 25-path public OpenAPI contract. Shared components, all admin
  paths, and frozen API artifacts remain unchanged. OpenAPI's current metadata version is 1.9.0.
- Production rollout evidence and current application image revisions are recorded in
  [the deployment runbook](https://github.com/MeatBorsa/meat-taxonomy/blob/main/docs/production-deployment.md).
