Put a bounded service around the judgment
Offline quality is useful only if the workflow stays safe under load. admission control: the code that limits which work may enter a service so demand cannot grow without bound protects both provider and application. A worker needs a bounded queue, concurrency limit, deadline, and explicit overload route.
Size the queue from the amount of delay the product can tolerate, not from available memory. Once the oldest job cannot finish inside the customer deadline, accepting more work only hides failure. Reject, shed, or move new decisions to review at that point. Carry a stable logical decision ID through every attempt so dashboards count one customer event separately from provider calls. Deduplicate in-flight work by ticket version and question version; a later customer reply is a new decision rather than a cache hit.
Classify work by consequence. Ordinary queue routing may be reversible and low risk. Refunds, authentication changes, account deletion, and outbound promises stay behind deterministic authorization and human review. A Jev answer can recommend a path; it cannot grant permission.
async function classify(job: TicketJob, signal: AbortSignal) {
if (!queueCapacity.tryAcquire())
return { action: "review", reason: "overload" };
try {
return await withDeadline(1800, signal, () => evaluateTicket(job));
} catch (error) {
return { action: "review", reason: classifyOperationalFailure(error) };
} finally {
queueCapacity.release();
}
}
The 1.8 second deadline is a synthetic example, not a service recommendation. Choose it from the end-to-end customer budget. SDK retries, queue retries, and worker retries must fit one budget; otherwise every layer can multiply attempts during an incident.
Trace this example from input to result
Customer choice
A support lead enables production semantic routing.
Request or event
The ticket-created event enters a bounded worker queue with a stable idempotency key.
Backend behavior
The worker builds minimal state, evaluates independent questions once, applies policy, and records a reversible route or review result.
Customer sees
The ticket appears in the appropriate queue or in review without blocking ticket creation.
Diagnostic reasoning
Separate queue delay, transport failure, semantic error, policy error, and route-write failure using one correlated decision record.
Observe the whole decision record
Logs need enough information to reproduce behavior without copying sensitive state. Store event ID, safe state hash, retrieval/version identifiers, question version, requested and returned model, provider route, request ID, attempt count, latency, usage, raw typed answers, distributions or confidence, policy version, final action, and downstream outcome. Keep raw bodies out of ordinary logs unless an approved safe transform exists.
Use structured error categories instead of a single failed counter. Authentication and validation indicate configuration or code defects. Rate limiting and overload indicate capacity. Connection and deadline errors can arise between the worker and provider. Missing answers or invalid shapes indicate response validation. A route-write conflict belongs after policy. This vocabulary lets an on-call engineer ask for the right evidence and prevents a healthy semantic model from being blamed for a saturated worker pool.
Metrics should describe traffic and failure boundaries: admitted and rejected jobs, queue age, request latency, 429 and 529 responses, timeouts, attempts per logical decision, unavailable rate, token usage, review rate, route distribution, correction rate, and downstream write failures. Dashboards should separate model service health from semantic quality. A healthy API can return a wrong judgment; an accurate offline model can still miss an SLO because the queue is overloaded.
Define service-level objectives around product behavior. A useful SLO might cover the percentage of ticket-created events that receive either a reversible route or a review result within a time budget. That counts safe degradation as completion. Track the automatic-route subset separately so the team cannot meet availability by silently sending everything to review.
| Customer sees | Application does | Jev returns |
|---|---|---|
| Ticket appears promptly in a queue | Measures queue age, bounds request time, and writes an idempotent route | A typed judgment when available |
| Ticket appears in review during an incident | Follows declared degraded policy and records its reason | A service error or no answer; code owns fallback |
Latency rises without more model errors
queue age p95 rises · request latency flat · admitted work stableThe smallest likely boundary is before inference. Check worker saturation, concurrency permits, event redelivery, and downstream state retrieval. Scaling model retries would amplify the wrong part of the system. A controlled test can bypass only the state retrieval dependency for synthetic fixtures and compare queue drain rate, while leaving production customer records untouched.
Diagnose by boundary
Transport and service failures include authentication, validation, rate limiting, overload, connection, and timeout errors. Preserve the provider request ID and Retry-After when present. Retry only transient classes, use exponential backoff with jitter, and stop at the workflow deadline. Authentication and validation require configuration or request fixes, not repetition.
A semantic failure occurs when the service returns a valid typed answer that does not match the reference meaning. Reproduce it with exact state and questions. A policy failure occurs when the judgment is reasonable but the threshold or composition causes the wrong action. An execution failure occurs after policy, such as a queue update writing the wrong ticket version. These require different owners and fixes.
Use idempotency for event redelivery. The decision key can include ticket version, state hash, question version, and policy version. Before writing a route, compare the ticket's current version: a customer reply may have changed the evidence while inference was running. Stale results should be discarded or reevaluated, not applied because they were once confident.
if (ticket.version !== decision.inputTicketVersion) {
return { action: "discard", reason: "stale_state" };
}
await routes.compareAndSet(ticket.id, ticket.version, decision.route);
Dig deeperHow retry storms emerge+
Imagine the SDK retries twice, the worker retries three times, and the queue redelivers the event. One logical decision can produce many provider attempts exactly when capacity is scarce. Count attempts by logical operation, centralize the retry budget, respect overload signals, and use a circuit breaker to move new jobs into the declared degraded path. Recovery should ramp gradually so a backlog does not recreate the incident.
Design degradation and recovery
Choose fallback according to consequence. Low-risk routing can preserve the ticket, assign a general queue, and flag review. An optional ranking feature can show deterministic order. For a safety gate, fail-open or fail-closed is a product risk decision; document who bears each failure. Never turn a service outage into an unreviewed refund or authorization action.
Test degradation before an incident. Inject a provider timeout, repeated 429, overload response, missing answer, queue pause, and conditional-write conflict. Assert the exact customer-visible result and that raw state never appears in the error record. Then restore service and verify that the canary cohort completes before releasing the backlog. A runbook that only describes a provider status page is incomplete because state retrieval, application capacity, policy, and writes can fail independently.
An incident runbook should identify the alert, recent model/question/policy changes, queue state, provider status, request IDs, and containment switch. Containment might disable automatic routing while keeping shadow evaluation, or pause inference entirely to protect the backlog. Recovery verifies credentials and service health, drains a small canary cohort, watches attempt and correction rates, then increases traffic.
Keep a replay queue of safe references or approved sanitized fixtures rather than raw sensitive bodies. After the incident, distinguish unavailable decisions, late decisions, duplicated attempts, and incorrect actions. Update one boundary at a time and test the result.
Write the production operating contract
Your answers stay in this browser. Write enough that another engineer could continue the investigation.
Check your understanding
Operate the decision as a bounded, observable workflow whose degraded path preserves customer work and whose diagnostics isolate the smallest failing boundary.