Schema reference for the Trinity Beast Translation Service — 11 tables and 302 columns in the live database after the migration of November 18, 2026: jobs and quotes, the per-pair estimate record, the 127-language catalog, per-language tuning, the parameter store, model catalog, task orchestration and the glossary, with the 9 functions of the engine.
39 columns
| Column | Data Type | Default | Nullable | Description |
|---|---|---|---|---|
id PK | uuid | gen_random_uuid() | NO | Internal UUID, generated by the database |
job_id | varchar(64) | — | NO | Public job identifier, unique, used in every API response: 12 hex digits, a hyphen and 16 more (e.g., 019e4b8a37bc-1f2e3d4c5b6a7980) |
state | varchar(20) | queued | NO | Job state: queued, running, finalizing, succeeded, partial, failed, cancelled. There is no completed state; a fully delivered job is succeeded. |
submitted_at | timestamptz | now() | NO | When the job was submitted |
started_at | timestamptz | — | YES | When processing began |
completed_at | timestamptz | — | YES | When the job reached a terminal state |
submitted_by | varchar(50) | admin-api | YES | Which path created the job, e.g. admin-api (direct submission), retry-failed (admin retry) or retry-customer (a customer's free retry) |
docs | jsonb | — | NO | Array of document names in this job |
langs | jsonb | — | NO | Array of target language codes, each already resolved through the 127-language catalog |
options | jsonb | {} | YES | Job options (chunk-size overrides, skip_validation, routing). A retry inherits its parent's options. |
progress | jsonb | {} | YES | Per-pair progress snapshot |
errors | jsonb | [] | YES | Error details for failed pairs |
bedrock_invocations | integer | 0 | YES | Bedrock calls counted from successful pairs |
total_chunks | integer | 0 | YES | Document chunks processed |
total_pairs | integer | 0 | YES | Document-language pairs in this job |
succeeded_pairs | integer | 0 | YES | Pairs delivered |
failed_pairs | integer | 0 | YES | Pairs that failed |
elapsed_seconds | integer | — | YES | Wall-clock duration in seconds |
step_function_arn | text | — | YES | Legacy. The Step Functions pipeline was retired on June 27, 2026, so new jobs leave this empty. |
retry_of | varchar(64) | — | YES | job_id of the job this one retries |
idempotency_key | varchar(128) | — | YES | Client-provided idempotency key |
cloudfront_invalidation_ids | jsonb | [] | YES | CloudFront invalidations issued for library documents |
search_index_rebuilt | boolean | false | YES | Whether the search index was rebuilt after this job |
notification_sent | boolean | false | YES | Whether the completion notice went out (prevents a second email) |
created_at | timestamptz | now() | NO | Row creation time |
updated_at | timestamptz | now() | NO | Last change |
reason | text | — | YES | Cancellation or failure reason |
model | varchar(50) | claude-sonnet-4.6 | YES | The agent for the whole job (qwen3-235b, deepseek-v3, mistral-large, claude-haiku-5.5, claude-sonnet-4.6, claude-opus-4.8), or per-language when each language has its own agent. The column default is a legacy value: an admin retry now writes the original job's model, and a customer's free retry runs on the agent stored on the quote. |
execution_mode | varchar(30) | realtime | YES | realtime or batch |
s3_input_uri | text | — | YES | Batch inference input location |
s3_output_uri | text | — | YES | Batch inference output location |
task_id | varchar(48) | NULL | YES | Parent task in the Task Organizer (translation_tasks.task_id). NULL for a standalone job. |
cancelled_by | text | — | YES | Who or what cancelled the job. enqueue-failed marks a job whose queue messages never went out, so it never started. |
quote_id | varchar(64) | — | YES | The customer quote this job serves, set on the parent job and on its free retry. NULL for internal jobs. Backfilled by the migration for existing jobs. |
first_enqueued_at | timestamptz | — | YES | Set at the first successful queue send. A job counts as started only from this moment, or once the worker reports, which is how a start failure is told apart from a slow start. |
est_duration_seconds | integer | — | YES | How long the job should take from submit until every pair is done, written when the job is created; a customer's original job builds it from the per-pair estimates its quote showed. The status ETA reads it first. NULL for a job created before 2026-11-06. |
estimator_version | text | — | YES | The estimator that made the estimate, e.g. eta-hist-2, so a later method can be compared with the jobs this one estimated. NULL for a job created before 2026-11-06. |
translation_jobs_pkey — UNIQUE on idtranslation_jobs_job_id_key — UNIQUE on job_ididx_translation_jobs_state — on stateidx_translation_jobs_submitted_at — on submitted_at DESCidx_translation_jobs_task_id — on task_id WHERE task_id IS NOT NULLidx_translation_jobs_quote_id — on quote_id WHERE quote_id IS NOT NULL (new)first_enqueued_at matters: a paid job that never reached the queue must be refunded, and a slow job must not be. The LPO writes the job row first, then sends one queue message per language, and stamps first_enqueued_at on the first send that succeeds. A job with no stamp and no worker report never started, and its quote enters the start-failure refund; a job with the stamp is simply in progress.
est_duration_seconds, estimator_version) arrived with migration 2026-11-06-01. The job keeps its own estimate so the status ETA is a single read, and the estimate and actual of each of its pairs live in section 10.
8 columns
| Column | Data Type | Default | Nullable | Description |
|---|---|---|---|---|
id PK | bigint | auto-increment | NO | Event identifier |
job_id | varchar(64) | — | NO | Job this event belongs to (translation_jobs.job_id) |
event_type | varchar(30) | — | NO | Event type, e.g. lang_started, lang_succeeded, lang_failed, lang_rejected. The server also writes replace_on_pages when it brings a delivered page up to date with the customer's Replace on pages entries (the places changed per entry, never the customer's text), and staff_correction_email with the outcome of the email sent when we correct a customer's pages |
doc | varchar(200) | — | YES | Document name, for pair-level events |
lang | varchar(12) | — | YES | Target language code. Widened from 5 to 12 characters so regional and script codes such as zh-TW and fa-AF fit. |
detail | jsonb | {} | YES | Event detail. New values: lang_rejected {"reason":"target_is_source"} (the page is already in the target language, never retried); lang_failed {"error":"enqueue-failed"} (written by the LPO for languages that were never sent); lang_failed {"error":"cancel-state-unknown"} (the worker could not confirm the job was still live before publishing, so it refused to publish). lang_started now also records source_provenance and lang_runtime_source. |
created_at | timestamptz | now() | NO | Event time |
metrics | jsonb | — | YES | Per-pair metrics reported by the worker |
translation_job_events_pkey — UNIQUE on ididx_translation_job_events_job_id — on job_ididx_translation_job_events_created_at — on created_at DESC71 columns
The 71 columns read best in four groups: what was quoted, how the quote moved through its life, how its money came back when something was not delivered, and what was estimated beside what actually happened. Rows with a green edge arrived with this release (migration 2026-10-09-03). Internal cost columns are not published.
| Column | Data Type | Default | Nullable | Description |
|---|---|---|---|---|
id PK | bigint | auto-increment | NO | Internal identifier |
quote_id | varchar(64) | — | NO | Public quote identifier: qt- plus the first 12 characters of a UUID (e.g., qt-a1b2c3d4-e5f). Unique. |
api_key_id | varchar(128) | — | NO | API key that requested the quote. Dashboard reads now match every translation key of the same user. |
doc_url | text | — | NO | URL of the first document (see doc_urls for all of them) |
doc_name | varchar(255) | — | NO | Name of the first document |
doc_size_bytes | integer | — | NO | Size of the document in bytes. Nothing over 300 KB (307,200 bytes) is ever quoted. |
estimated_chunks | integer | — | NO | Estimated translation chunks |
difficulty | varchar(21) | standard | NO | Difficulty: standard, technical or complex |
code_blocks | integer | 0 | NO | Code blocks detected |
diagrams | integer | 0 | NO | Mermaid diagrams detected |
langs | jsonb | — | NO | Target languages, canonical codes after alias conversion and de-duplication (up to 12) |
lang_count | integer | — | NO | Number of target languages |
total_price | numeric(10,4) | — | NO | The price the customer pays (USD) |
model | varchar(50) | claude-sonnet-4.6 | YES | The agent the customer chose, or per-language when the quote was auto-routed (the map is in model_by_lang). The column default is legacy; the quote handler always writes this column. |
execution_mode | varchar(20) | express | NO | Delivery mode, express for every customer quote today |
protected_terms | jsonb | [] | YES | The customer's brand terms, protected during translation |
created_at | timestamptz | now() | NO | Quote creation time |
updated_at | timestamptz | now() | NO | Last change |
| Column | Data Type | Default | Nullable | Description |
|---|---|---|---|---|
state | varchar(21) | pending | NO | Lifecycle: pending, accepted, expired, superseded, refunded, partially_refunded. There is no CHECK on this column. |
expires_at | timestamptz | — | NO | Quote expiry, 72 hours after creation (a requote gets its own 72 hours) |
accepted_at | timestamptz | — | YES | When the customer accepted and paid |
declined_at | timestamptz | — | YES | Legacy decline time |
stripe_payment_intent_id | varchar(128) | — | YES | Stripe PaymentIntent for this quote |
stripe_charge_id | varchar(128) | — | YES | Stripe Charge after payment |
job_id | varchar(64) | — | YES | The parent translation job created at acceptance |
doc_urls | jsonb | — | YES | Every document URL in the quote, trimmed and de-duplicated (up to 42) |
doc_count | integer | 1 | NO | Number of documents |
total_pairs | integer | 0 | NO | Documents × languages |
doc_names | jsonb | — | YES | {"<url>":"<name>"}: the delivered file name of each document |
source_langs | jsonb | — | YES | {"<name>":{"lang":"<code>|auto","provenance":"stated|declared|detected|auto"}}: each document's source language and how we know it |
doc_fingerprints | jsonb | — | YES | {"<name>":{"url","alg":"tbfp1","content_sha256","raw_size","translatable_size"}}: the content fingerprint compared when the quote is accepted |
pair_prices | jsonb | — | YES | {"<name>":{"<lang>":3.0}}: the price of every pair, so any refund is exact |
model_by_lang | jsonb | — | YES | {"<lang>":"<model>"} when auto-routed; {} for an explicit agent |
superseded_by | varchar(64) | — | YES | The newer quote that replaced this one (a requote, or a dashboard re-quote with supersedes_quote_id) |
requoted_from | varchar(64) | — | YES | The older quote this one was created to replace |
accept_claimed_until | timestamptz | — | YES | The accept claim. A second accept of the same quote inside this window is answered at once with tbts_quote_accept_in_progress, so one quote can never be charged twice. |
tbfp1, a SHA-256 of the translatable content). Same content and same price: the job proceeds. Changed content at the same price: it proceeds with a notice. A new price or a rule change: the old quote is marked superseded, a new one is made (requoted_from points back), and accept answers 409 tbts_quote_requoted. A page that grew past 300 KB is refused with 400 tbts_doc_too_large and no new quote.
| Column | Data Type | Default | Nullable | Description |
|---|---|---|---|---|
refunded_at | timestamp | — | YES | When the last refund was issued |
refund_amount | numeric(10,2) | NULL | YES | Amount of the last refund (USD) |
refund_id | varchar(255) | NULL | YES | Stripe Refund ID of the last refund |
refunded_total | numeric(10,2) | 0 | NO | Everything refunded on this quote so far, from every kind of refund (cancel, admin, failed pairs). Backfilled from refund_amount for existing refunded quotes. |
cancelled_at | timestamptz | — | YES | When the customer cancelled |
cancelled_by | text | — | YES | Who cancelled |
refund_due | numeric(10,2) | — | YES | Cancel refund awaiting approval |
refund_status | text | — | YES | Cancel refund state (the approval flow) |
failed_refund_status | text | — | YES | The failed-pair refund machine: window_open, retrying, due, issuing, issued, none, error (CHECK tq_failed_refund_status_check) |
failed_refund_trigger | text | — | YES | start_failed (the paid job never started) or job_terminal (the job finished with failed pairs) |
failed_refund_window_ends_at | timestamptz | — | YES | End of the 72-hour window in which the customer can use the free retry |
failed_refund_due | numeric(10,2) | — | YES | Amount due for the undelivered pairs |
failed_refund_amount | numeric(10,2) | — | YES | Amount actually refunded |
failed_refund_pairs | jsonb | — | YES | The refunded document-language pairs |
failed_refund_id | text | — | YES | Stripe Refund ID (idempotency key txfr-{quote_id}, so it can never be sent twice) |
failed_refund_at | timestamptz | — | YES | When the failed-pair refund was issued |
failed_refund_attempts | integer | 0 | NO | Stripe attempts so far (the limit is refund.failed_pair_max_attempts) |
failed_refund_last_error | text | — | YES | Last Stripe error, for the operator |
retry_job_id | text | — | YES | The job of the one free retry |
retry_count | integer | 0 | NO | Free retries used (at most one) |
These columns arrived on 2026-11-06 with migration 2026-11-06-01. The quote keeps the delivery estimate the customer saw, and once the job ends the server writes back what actually happened, so every quote can be checked against its own promise. Only quotes made since then carry an estimate, and only those are written back.
| Column | Data Type | Default | Nullable | Description |
|---|---|---|---|---|
est_delivery_seconds | integer | — | YES | The delivery time shown with the quote, from acceptance until every translation is delivered (delivery.estimated_seconds in the API) |
estimator_version | text | — | YES | The estimator that made the estimate, e.g. eta-hist-2. The write-back runs only for a quote that has one. |
est_history_cutoff | timestamptz | — | YES | Where the history the estimate read ends. The re-price at acceptance reuses it, so it reads the same history the customer was quoted from. |
pair_estimates | jsonb | — | YES | Per document and language: chunks, bytes, start offset, processing seconds, tokens and the basis of each figure. Internal; never sent to a customer. A customer's original job copies it into translation_pair_runs. |
actual_delivery_seconds | integer | — | YES | The actual delivery time: from the original job's submit to its finish (delivery.actual_seconds in the API) |
actual_completed_at | timestamptz | — | YES | When the original job finished |
pair_actuals | jsonb | — | YES | Per document and language, from its latest attempt: the outcome, the job that produced it, the number of attempts, and the processing and queue seconds. Internal. |
actuals_recorded_at | timestamptz | — | YES | When the actuals were last written back. The write-back runs at completion, at a cancel, in the stuck-job sweep and in the refund sweep, and is safe to run more than once. |
translation_quotes_pkey — UNIQUE on idtranslation_quotes_quote_id_key — UNIQUE on quote_ididx_quotes_api_key — on api_key_ididx_quotes_expires — on expires_at WHERE state = 'pending'idx_quotes_state — on stateidx_quotes_failed_refund_active — on failed_refund_status WHERE it is window_open, retrying, due or issuing (new: the 15-minute refund sweeper reads only live rows)refunded_total, and every refund is clamped to what is left, so a pair can never be refunded twice. The automatic failed-pair refund (failed_refund_*) runs behind refund.failed_pair_enabled, switched on 2026-10-11; the free retry (retry_job_id, retry_count) and the start-failure refund work from deploy.
application_parameters. This table is cached in Valkey with a 27-hour TTL, so the cache always outlives the nightly refresh. The Valkey hash is tx:params. Every parameter that governs translation behavior — token estimation factors, operational limits, refund rules and batch config — lives here. Internal cost parameters are not published. Every LPO container reads Valkey first, then Aurora, then a built-in safe default that is always above zero. A parameter change therefore needs no code deploy. The nightly sync applies it, or an admin can apply it at once with this call: POST /admin/translate/params/reload.6 columns · 46 rows captured live on 2026-10-10, plus 6 refund rows from this release
| Column | Data Type | Default | Nullable | Description |
|---|---|---|---|---|
key PK | varchar | — | NO | Parameter key in dot-notation (e.g., bedrock.sonnet46.realtime.input_per_1m, refund.failed_pair_enabled) |
value | text | — | NO | Parameter value (numeric stored as text for flexibility) |
description | text | '' | NO | Human-readable explanation of what this parameter controls |
category | varchar | general | NO | Grouping category: token_estimation, cost_controls, customer_pricing, batch_config, refund |
updated_at | timestamptz | now() | NO | Last modification timestamp |
updated_by | varchar | system | NO | Who last changed this parameter (admin email, sync-job, kiro) |
| Category | Rows | What It Controls |
|---|---|---|
token_estimation | 14 | Tokens-per-byte ratio, output/input multiplier, cache hit rate, speed factors per model, and the history estimator's buffer and sample settings (estimation.history_*). Used to estimate a job's tokens and duration before submission: the history settings govern the estimate, and the fixed ratios are its last resort. |
cost_controls | 6 | The controls.daily_token_limit row is stored but not read: the daily token limit that runs is a fixed 50M combined tokens in the server code, checked when a job is submitted and before a customer is charged. controls.max_docs_per_request is now '42', a mirror of the code constant and not read for enforcement: the real limits (12 languages, 42 documents, 300 KB, 9 quotes per batch) are constants in internal/txlimits. |
customer_pricing | ~9 | Tier discount factors and quote validity (72 hours). Internal cost parameters are not published. |
batch_config | ~6 | S3 bucket for batch inference, IAM role ARN, polling interval (33s), JSONL processing config. |
refund | 6 | The failed-pair refund machine: refund.failed_pair_enabled (on since 2026-10-11; code default 'false'), refund.failed_pair_window_hours (72), refund.failed_pair_max_attempts (3), refund.sweep_interval_minutes (15, a multiple of 3 clamped to 3–60), refund.failed_pair_since (set in the same statement that turns the flag on) and refund.start_failure_since (stamped by migration 03b at deploy). |
GET /admin/translate/params (list all), POST /admin/translate/params (upsert), POST /admin/translate/params/reload (force cache refresh). Dashboard: GET/POST/DELETE /dashboard/api/translate/params.
Corrected 2026-08-12 — no lookupModelID() function exists. This entry previously claimed that function consulted the catalog to resolve models and enforce blocked regions. It doesn't exist anywhere in the codebase, and nothing reads this table's blocked=true rows — they document intent, not a control. Region blocking (specifically, the hard rule that no Canadian region is ever used) is actually enforced by FAILOVER_REGIONS in tbi-translate-worker/translator/engine.py being a fixed allow-list that simply never contains a Canadian region, backed by an import-time assertion that fails fast if one is ever added. See Trinity-Beast-TBI-Translation-Engine.html §12.1 for the real mechanism. Model-ID resolution for an active job reads directly from this table's live rows via ordinary SQL — there is no dedicated named function performing that lookup.
12 columns · 20 rows
| Column | Data Type | Default | Nullable | Description |
|---|---|---|---|---|
id PK | integer | auto-increment | NO | Auto-incrementing identifier |
friendly_name | varchar | — | NO | Human-friendly model name used in API requests (e.g., claude-sonnet-4.6, qwen3-235b) |
display_name | varchar | — | NO | Marketing display name (e.g., "Claude Sonnet 4.6", "Qwen3 235B") |
bedrock_model_id | varchar | — | NO | Full Bedrock model ARN/ID (e.g., us.anthropic.claude-sonnet-4-6) |
region | varchar | — | NO | AWS region where this model is invoked. HARD RULE: ca-central-1 and ca-west-1 are NEVER used. |
inference_type | varchar | — | NO | Invocation method: realtime (InvokeModel) or batch (CreateModelInvocationJob) |
priority | integer | 1 | NO | Preference order when multiple entries exist for the same friendly_name (lower = preferred). Used for regional failover. |
enabled | boolean | true | NO | Whether this catalog entry is active. Disabled entries are skipped during model resolution. |
notes | text | '' | NO | Admin notes (why it's blocked, performance observations, etc.) |
verified_at | timestamptz | now() | NO | When this model was last verified to be responding correctly in its region |
created_at | timestamptz | now() | NO | When this catalog entry was created |
blocked | boolean | false | NO | Hard block — entries with blocked=true are documentation of regions/models that must NEVER be used (CA regions). Unlike enabled=false (temporarily off), blocked entries represent permanent policy constraints. |
The translation engine routes models through one of three format families based on their prefix. Each family has its own request/response JSON structure — the engine handles this transparently via DetectFamily(), BuildRequestBody(), and ParseResponseText() in internal/bedrock/formats.go:
| Family | Prefix Match | Models |
|---|---|---|
anthropic | anthropic.*, us.anthropic.* | Claude Haiku 5.5, Claude Sonnet 4.6, Claude Opus 4.8 |
openai | qwen.*, deepseek.*, mistral.* | Qwen3 235B, DeepSeek V3, Mistral Large |
nova | amazon.nova.* | (Reserved — Nova Pro removed from active roster due to HTML tag dropping) |
ca-central-1 and ca-west-1 have blocked=true entries in this catalog as a record of the policy. The enforcement is the worker's fixed FAILOVER_REGIONS allow-list, which never contains a Canadian region and is backed by an import-time assertion (see the correction above). This is a hard architectural constraint, not a temporary disable.
GET /translate/task/{task_id}.16 columns
| Column | Data Type | Default | Nullable | Description |
|---|---|---|---|---|
task_id PK | varchar(48) | — | NO | Public task identifier |
task_type | varchar(24) | admin_batch | NO | acceptance (a customer's batch acceptance) or admin_batch (internal) |
state | varchar(24) | queued | NO | Task state: queued, running, succeeded, partial, failed, cancelled |
customer_email | varchar(255) | — | YES | Where the one task-level completion email goes (acceptance tasks) |
quote_ids | jsonb | [] | NO | Quotes bundled into this task (up to 9) |
job_ids | jsonb | [] | NO | Child jobs of this task |
total_jobs | integer | 0 | NO | Child jobs submitted |
completed_jobs | integer | 0 | NO | Jobs that succeeded |
failed_jobs | integer | 0 | NO | Jobs that failed |
cancelled_jobs | integer | 0 | NO | Jobs that were cancelled |
notification_sent | boolean | false | NO | Prevents a second completion email |
submitted_at | timestamptz | now() | NO | When the task was created |
completed_at | timestamptz | — | YES | When every child job reached a terminal state |
created_at | timestamptz | now() | NO | Row creation time |
updated_at | timestamptz | now() | NO | Last change |
recorded_job_ids | text[] | ARRAY[] | YES | Jobs already counted, so a repeated completion never counts twice |
translation_tasks_pkey — UNIQUE on task_idcreate_translation_task(task_id, task_type, customer_email, quote_ids, job_ids, total_jobs) — Creates the task recordget_task_status(task_id) — Returns task + all jobs in one call (JOIN)get_active_tasks() — Returns all non-terminal tasks (poll loop query)record_task_job_completed(task_id, job_id, job_state) — Atomic counter update + "all done?" booleanmark_task_notified(task_id) — Idempotent notification flag setcancel_task_remaining(task_id, reason) — Cancel all pending jobs, close tasktranslation_jobs.task_id is a nullable link column (with a partial index on non-NULL values) from each child job to its parent task; it is not a declared foreign key. Jobs created outside the Task Organizer (direct POST /admin/translate) have task_id = NULL.
tuning_lang row, so every one of the 127 languages starts from proven settings instead of guesses.18 columns · 127 rows
| Column | Data Type | Default | Nullable | Description |
|---|---|---|---|---|
lang_code PK | varchar(12) | — | NO | Language code. Widened from 5 to 12 characters for codes such as zh-TW. |
display_name | varchar(50) | — | NO | Language name |
script_family | varchar(20) | — | NO | Script family (latin, cjk, indic, arabic, cyrillic, ...). Drives preprocessor density and chunk sizing. |
max_chunk_kb | integer | 15 | NO | Maximum chunk size in KB for this language |
max_code_tags | integer | 81 | NO | Maximum code tags per chunk before a forced split (a multiple of 3) |
token_expansion_factor | numeric(3,2) | 1.00 | NO | Expected output/input token ratio |
max_retries | integer | 1 | NO | Retry attempts per chunk on validation failure |
retry_chunk_shrink_pct | integer | 30 | NO | How much smaller a retried chunk is (30 = 70% of the original) |
model_override | varchar(100) | NULL | YES | Engine-level model override for this language |
temperature | numeric(2,1) | 0.3 | NO | Bedrock temperature for this language |
max_output_tokens | integer | 4096 | NO | Output token ceiling per Bedrock call |
priority | integer | 6 | NO | Processing priority (lower runs first). The 116 seeded rows use 12. |
enabled | boolean | true | NO | Whether this profile is active |
notes | text | — | YES | Operational notes. Seeded rows say which tuning row they were copied from. |
updated_at | timestamptz | now() | NO | Last change |
updated_by | varchar(100) | system | NO | Who last changed the row |
density_lift_threshold | numeric(4,3) | NULL | YES | Auto-tuned. Density ratio above which a container is lifted whole. Tightened by telemetry when the tag drop rate passes 3%. Floor 0.015. |
density_max_prose | integer | — | YES | Auto-tuned. Most prose characters a container may hold and still be lifted |
translation_language_profiles_pkey — UNIQUE on lang_code_auto_tune_density_threshold() reads the last 7 days of translation_chunk_telemetry (code tags in versus out) and tightens the density threshold for a language that keeps dropping tags: 3–6% drop rate → -0.005, 6–12% → -0.01, above 12% → -0.015, never below 0.015. It runs once per container lifetime per language.
get_language_profile(p_lang) returns one profile row and is kept unchanged for compatibility. The worker now reads get_language_runtime(p_lang) (section 8), which joins the profile to its catalog row.
GET /translate/languages resolve codes against it, which is why an unsupported code can never be quoted, charged and silently mistranslated. The rows are generated from one file, migrations/data/translation_language_catalog.tsv: the 75 Amazon Translate languages together with the 119 of Qwen 3.17 columns · 127 rows
| Column | Data Type | Default | Nullable | Description |
|---|---|---|---|---|
lang_code PK | varchar(10) | — | NO | Canonical code, e.g. es, zh-TW, fa-AF |
english_name | varchar(120) | — | NO | English name (e.g., Persian, Tagalog (Filipino)) |
source | varchar(40) | aws_translate | NO | Where the row first came from. A re-run of the catalog migration never changes it. |
status | varchar(20) | supported | NO | supported, blocked or unverified (CHECK). An admin's choice here always survives a re-run. |
notes | text | — | YES | Admin notes |
created_at | timestamptz | now() | NO | Row creation time |
updated_at | timestamptz | now() | NO | Last change |
updated_by | varchar(120) | system | NO | Who last changed the row |
native_name | varchar(96) | — | YES | The language's own name for itself (Español, 日本語), shown in the dashboard picker |
script | varchar(4) | — | YES | ISO 15924 script code (Latn, Arab, Hans, ...). CHECK tsl_script_present requires both script and native name. |
rtl | boolean | false | NO | Written right to left. True for 15 languages; their delivered files are marked dir="rtl". |
word_spaced | boolean | true | NO | False for the 8 languages written without spaces (ja, zh, zh-TW, yue, th, lo, km, my), so the term-spacing check skips them |
base_lang | varchar(10) | — | YES | The parent language of a regional form (es-MX → es). Foreign key tsl_base_fk to this table. |
tuning_lang | varchar(10) | — | YES | Whose chunk limits and prompts this language borrows (fa → Urdu, ko → Japanese) |
provenance | varchar(48) | manual | NO | Why the row exists: aws_translate, qwen3 or both |
target_allowed | boolean | true | NO | Whether the language can be ordered as a target (true for all 127) |
default_model | varchar(32) | — | YES | The auto-routing agent for this language. claude-sonnet-4.6 for am, ha, mn, ps and so; empty for the rest, which run on Qwen 3 235B. An admin's value survives a re-run. |
translation_supported_languages_pkey — UNIQUE on lang_codeidx_translation_supported_languages_status — on statusget_language_runtime(p_lang) (new) returns 24 columns: the catalog row LEFT JOINed to its profile, matched case-insensitively. The worker calls it once per language and caches the answer for 15 minutes, falling back to a generated snapshot (translator/language_catalog_snapshot.json) if Aurora is unreachable, so a language never fails because a lookup did.
nb → no, zh-Hant → zh-TW, iw → he, any ar-XX → Modern Standard Arabic ar) live in migrations/data/translation_language_aliases.tsv, are generated into the LPO (internal/txlangs/aliases_gen.go) and the worker snapshot, and are published in the aliases field of GET /translate/languages. They are converted quietly, before any limit is counted. A region tag that is neither a catalog code nor an alias, such as en-US or es-AR, is not in the file: the resolver reduces it to its base language separately. Arabic dialects keep their own codes (arz, apc, ...).
23 columns
| Column | Data Type | Default | Nullable | Description |
|---|---|---|---|---|
id PK | bigint | auto-increment | NO | Row identifier |
job_id | varchar(50) | — | NO | Job the chunk belongs to |
doc | varchar(200) | — | NO | Document name |
lang | varchar(12) | — | NO | Target language. Widened from 5 to 12 characters. |
chunk_index | integer | — | NO | Position of the chunk in the document |
attempt | integer | 1 | NO | Attempt number for this chunk |
chunk_size_bytes | integer | — | NO | Chunk size in bytes |
input_tokens | integer | — | YES | Bedrock input tokens |
output_tokens | integer | — | YES | Bedrock output tokens |
expansion_ratio | numeric(4,2) | — | YES | Output/input token ratio actually observed |
sentinel_count | integer | — | YES | Sentinels sent with the chunk |
sentinels_restored | integer | — | YES | Sentinels found and restored in the answer |
sentinel_integrity | boolean | — | YES | Whether every sentinel came back intact |
code_tags_in | integer | — | YES | Code tags in the source chunk |
code_tags_out | integer | — | YES | Code tags in the translated chunk (the auto-tuner compares the two) |
validation_passed | boolean | — | YES | Whether the chunk passed validation |
validation_errors | jsonb | — | YES | Validation failures, if any |
duration_ms | integer | — | YES | Time spent on the chunk |
model_used | varchar(100) | — | YES | Bedrock model ID that answered |
status | varchar(20) | — | NO | Chunk outcome |
error_class | varchar(50) | — | YES | Error category |
error_detail | text | — | YES | Error text |
created_at | timestamptz | now() | NO | Row creation time |
translation_chunk_telemetry_pkey — UNIQUE on ididx_chunk_telemetry_job — on job_ididx_chunk_telemetry_doc_lang — on doc, langidx_chunk_telemetry_lang — on lang, status76 columns on November 10, 2026
On November 10, 2026 the table had 76 columns, which read best in five groups: which pair it is, what was estimated, what the worker measured, when each stage happened, and the run facts that explain a miss. Throughout the table, NULL means unknown and 0 means counted, and none happened.
| Column | Data Type | Default | Nullable | Description |
|---|---|---|---|---|
id PK | bigint | auto-increment | NO | Row identifier |
job_id | varchar(64) | — | NO | The job the pair ran in (translation_jobs.job_id) |
doc | varchar(200) | — | NO | Document name |
lang | varchar(16) | — | NO | Target language code |
quote_id | varchar(64) | — | YES | The customer quote, filled from the job row; NULL for an internal job |
is_customer | boolean | — | NO | Whether this is a customer pair, filled from the job row |
retry_of | varchar(64) | — | YES | The job this one retries, filled from the job row |
record_origin | text | live | NO | live, or backfill for the 60-day history rebuilt on 2026-11-06 |
Written by the server before the pair runs. Every column here is NULL on a backfill row, because no estimate existed then.
| Column | Data Type | Default | Nullable | Description |
|---|---|---|---|---|
estimate_origin | text | — | YES | quote (a customer's original job copies the estimate its quote showed), submit (computed when the job was created) or late (the worker's record arrived before the estimate) |
estimator_version | text | — | YES | The estimator that made it, e.g. eta-hist-2 |
est_created_at | timestamptz | — | YES | When the estimate was made |
est_history_cutoff | timestamptz | — | YES | Only pairs finished before this moment were read, so an estimate never sees its own run |
est_model_key | text | — | YES | The agent the estimate assumed |
est_source_bytes | integer | — | YES | The document size the estimate used; NULL when it was not known |
est_chunks | integer | — | YES | Estimated chunks |
est_density_verdict | text | — | YES | NULL today: a document's density is not measured before the job runs. Measuring it at the quote is planned. |
est_density_score | integer | — | YES | NULL today, for the same reason |
est_start_offset_seconds | integer | — | YES | Estimated wait from submit until this language starts |
est_processing_seconds | integer | — | YES | Estimated time for this document in this language |
est_input_tokens | bigint | — | YES | Estimated input tokens |
est_output_tokens | bigint | — | YES | Estimated output tokens |
est_basis | jsonb | — | YES | How the estimate was made: the history read, the settings in force, where the size and the agent came from, and the group behind each figure |
The inputs as the worker found them in the bytes it actually translated.
| Column | Data Type | Default | Nullable | Description |
|---|---|---|---|---|
model_id | text | — | YES | The Bedrock model ID that translated |
model_key | text | — | YES | The agent's rate key, e.g. qwen3235b |
source_lang | text | — | YES | The source language used |
source_bytes | integer | — | YES | Size of the source the worker translated, in bytes |
source_sha256 | char(64) | — | YES | SHA-256 of those bytes |
chunk_markers | integer | — | YES | Chunk markers in the source |
split_mode | text | — | YES | markers, prescan or whole |
part_count | integer | — | YES | Parts the document was split into |
chunk_count | integer | — | YES | Chunks translated |
density_verdict | text | — | YES | translatable, challenging or too_dense |
density_score | integer | — | YES | The worker's density score |
density_components | jsonb | — | YES | The parts that make up that score |
density_multiplier | numeric(4,2) | — | YES | The language multiplier the density check applied |
density_metrics | jsonb | — | YES | The density measurements: numbers and metric names only, never document text |
worker_time_estimate_seconds | integer | — | YES | The worker's own processing-time estimate from its density check |
Each stage of the pair, and three generated spans that split the time a customer waits into queue wait, start and processing.
| Column | Data Type | Default | Nullable | Description |
|---|---|---|---|---|
job_submitted_at | timestamptz | — | YES | When the job was submitted, filled from the job row |
message_sent_at | timestamptz | — | YES | When the language's queue message was sent |
message_received_at | timestamptz | — | YES | When the worker received it |
receive_count | integer | — | YES | How many times the message was received; more than 1 means it was delivered again |
pair_started_at | timestamptz | — | YES | When the worker began this pair |
lang_started_at | timestamptz | — | YES | When the pair's lang_started event was logged, once its source was read and its language resolved |
translate_started_at | timestamptz | — | YES | When translation began |
translate_finished_at | timestamptz | — | YES | When translation ended |
published_at | timestamptz | — | YES | When the translated page was written |
pair_finished_at | timestamptz | — | YES | The moment the pair's outcome was decided |
queue_wait_seconds | numeric | generated | YES | message_received_at − job_submitted_at |
start_offset_seconds | numeric | generated | YES | lang_started_at − job_submitted_at |
processing_seconds | numeric | generated | YES | pair_finished_at − lang_started_at |
What happened, recorded as data rather than left in log lines, so a miss can be explained long after the logs are gone.
| Column | Data Type | Default | Nullable | Description |
|---|---|---|---|---|
outcome | text | — | YES | succeeded, failed, rejected, skipped or cancelled |
outcome_reason | text | — | YES | The reason or error, up to 500 characters; not_run for a pair a finished job never ran |
actual_source | text | — | YES | Who wrote the actuals: worker, event_fallback (rebuilt from the pair's events when no worker record arrived) or backfill |
tokens_source | text | — | YES | meter (the engine's token meter), summed (added up from results, as before the meter) or none |
bedrock_calls | integer | — | YES | Model calls |
input_tokens | bigint | — | YES | Input tokens |
output_tokens | bigint | — | YES | Output tokens |
truncations | integer | — | YES | Replies cut off at their token cap |
ceiling_calls | integer | — | YES | Calls made at the model's own output ceiling |
cap_escalations | integer | — | YES | Times a token cap was raised |
transport_retries | integer | — | YES | Calls retried after a transport error |
bedrock_seconds | numeric(10,1) | — | YES | Time spent inside model calls |
engine_retries | integer | — | YES | Validation retries |
gate_attempts | integer | — | YES | Boundary-gate attempts across the parts |
gate_retried_parts | integer | — | YES | Parts the boundary gate sent back to be translated again |
prose_parts | integer | — | YES | Parts translated on the prose path |
prose_gate_noteworthy | integer | — | YES | Prose-gate results other than clean |
hint_fallbacks | integer | — | YES | Parts that had no usable chunk hint |
parts | jsonb | — | YES | The same facts for each part |
glossary | jsonb | — | YES | The glossary summary of the pair, sent by the worker: counts and entry IDs only, never the terms. Empty means the pair had no glossary. Added on November 8, 2026. |
runs | integer | 0 | NO | Worker records received for this pair |
recorded_at | timestamptz | — | YES | When the actuals were written |
created_at | timestamptz | now() | NO | Row creation time |
updated_at | timestamptz | now() | NO | Last change |
translation_pair_runs_pkey — UNIQUE on idtranslation_pair_runs_pair_key — UNIQUE on job_id, doc, lang (one row per pair)idx_pair_runs_history — on pair_finished_at DESC WHERE outcome = 'succeeded' (the estimator's history window)idx_pair_runs_model_history — on model_key, pair_finished_at DESC WHERE outcome = 'succeeded' (an agent's own history)idx_pair_runs_quote — on quote_id WHERE quote_id IS NOT NULLidx_pair_runs_doc — on doc, pair_finished_at DESC (a document's latest recorded chunk count)POST /admin/translate/pair-record/{job_id}; that endpoint fills quote_id, is_customer, retry_of and job_submitted_at from the job's own row, never from the payload. When no worker record arrives, the server rebuilds the actuals from the pair's events as the job ends. The 60-day backfill of 2026-11-06 rebuilt 2,101 earlier pairs, so the estimator had real history from its first day. No job purges this table: the history is what the estimates are made of. The read-only view translation_pair_estimate_review lines each estimate up against its actual and splits a miss into queue, size, density and retry causes.
PUT /translate/glossary, which replaces the whole glossary in one transaction. We manage ours through /admin/translate/glossary. The TBI Translation Engine guide (10.4) explains how the engine uses the glossary.A customer entry can also carry a Replace on pages wording, which the server replaces with the translation on that customer's delivered pages, and an entry we add for a customer carries the name of the staff member who added it.
16 columns
| Column | Data Type | Default | Nullable | Description |
|---|---|---|---|---|
id PK | bigint | auto-increment | NO | Row identifier |
account_id FK → users.id | uuid | — | YES | The customer account that owns the entry. Empty means the entry belongs to our own glossary. |
target_lang | varchar(16) | — | NO | The target language of the entry |
source_term | text | — | NO | The term in the source document. It cannot be empty. |
target_term | text | — | NO | The translation of the term. It cannot be empty. |
also_accept | text[] | {} | NO | Other forms of the translation that also count as correct |
label_only | boolean | false | NO | When true, the entry is used only where the term stands alone, for example in a heading, a label or a button |
note | text | — | YES | Where one of our entries comes from. Customer entries have no note. |
created_at | timestamptz | now() | NO | When the entry was created |
updated_at | timestamptz | now() | NO | The last change to the entry |
updated_by | text | — | NO | Who changed the entry last |
source_lang | varchar(16) | — | YES | The language the source term is written in. Empty means any source language. Added on November 10, 2026. |
replace_on_pages | text | — | YES | The wording the customer saw on a delivered page, replaced there by target_term (Replace on pages). Empty means the entry is used for new jobs only. Customer entries only. Added by the migration of November 18, 2026. |
replace_doc | text | — | YES | The document where the wording is replaced. A document is chosen by its file name, so a wording for faq.html is replaced in the faq.html of every one of the account's quotes. Empty means every document. It narrows the replacement only: the term is used in every new job as before. Added by the migration of November 18, 2026. |
staff_added_by | text | — | YES | Empty means the account added the entry. Otherwise the staff member who added it for the customer, as staff:<name>. The customer sees "Added by us", never the name. Set only when we insert the entry, so an entry of the customer's that we change keeps it empty. The mark stays while the entry's language, source language and term (ignoring case) stay the same. A customer change to any of them makes a new row without the mark. Added by the migration of November 18, 2026. |
replace_result | jsonb | — | YES | The entry's totals at the last full check of the customer's pages, {"places":N,"pages":M,"checked_at":"..."}. Written by the server, counts only. Empty on an entry without a wording, and from the moment a wording is added or the entry's wording, document, translation or label_only changes, until the next check writes it. The next check also empties it on an entry whose source term is or contains one of the account's brand terms or one of the engine's own protected names, because such an entry corrects no pages. Added by the migration of November 18, 2026. |
idx_glossary_scope_lang — on (account_id, target_lang)translation_glossary_entries_pkey — UNIQUE on iduq_glossary_scope_lang_srclang_source — UNIQUE on the account, the target language, the source language (empty for any) and the source term in lower case. Each glossary has at most one entry for a term in a language and source language.account_id → users.id (deleted with the account)| Function | Inputs | Returns | Purpose |
|---|---|---|---|
record_chunk_telemetry |
19 inputs: the job, document, language, chunk, attempt, size, tokens, sentinels, code tags, validation result, duration, model, status and error | bigint |
Writes one row to translation_chunk_telemetry (section 9) and returns its ID. It also computes the token ratio and whether every sentinel came back. |
The worker calls record_chunk_telemetry for every chunk attempt, through the admin API (handler.py, _record_telemetry). It runs with the rights of the caller.
Two pictures tell the whole schema. The first follows the money and the work: a quote becomes a job, a job writes events, telemetry and one estimate-versus-actual row per pair, and a batch groups quotes under one task. The second is the configuration every job reads: which languages exist, how each one is tuned, what each model costs.
erDiagram
translation_tasks ||--o{ translation_jobs : "task_id (1 task = N jobs)"
translation_quotes ||--o{ translation_jobs : "quote_id (parent job + free retry)"
translation_quotes ||--o| translation_quotes : "superseded_by / requoted_from"
translation_jobs ||--o{ translation_job_events : "job_id (audit trail)"
translation_jobs ||--o{ translation_chunk_telemetry : "job_id (per-chunk metrics)"
translation_jobs ||--o{ translation_pair_runs : "job_id (one row per pair)"
translation_quotes ||--o{ translation_pair_runs : "quote_id (customer pairs)"
translation_quotes {
varchar quote_id UK
varchar job_id
varchar retry_job_id
varchar superseded_by
text failed_refund_status
numeric refunded_total
}
translation_jobs {
varchar job_id UK
varchar quote_id
varchar task_id
varchar retry_of
timestamptz first_enqueued_at
}
translation_tasks {
varchar task_id PK
jsonb quote_ids
}
translation_pair_runs {
bigint id PK
varchar job_id
varchar doc
varchar lang
varchar quote_id
text outcome
}
erDiagram
translation_supported_languages ||--o| translation_language_profiles : "lang_code"
translation_supported_languages |o--o{ translation_supported_languages : "base_lang (regional form)"
translation_supported_languages ||--o{ translation_jobs : "every language resolved here"
translation_language_profiles ||--o{ translation_jobs : "per-language tuning"
bedrock_model_catalog ||--o{ translation_jobs : "model selection"
translation_parameters ||--o{ translation_jobs : "rates, caps, refund rules"
translation_supported_languages {
varchar lang_code PK
bool rtl
bool word_spaced
varchar base_lang FK
varchar tuning_lang
varchar default_model
}
translation_language_profiles {
varchar lang_code PK
int max_chunk_kb
numeric density_lift_threshold
}
translation_quotes.job_id → translation_jobs.job_id (the parent job, set at acceptance)translation_jobs.quote_id → translation_quotes.quote_id (new: set on the parent job and on its free retry, so both directions are one lookup)translation_quotes.retry_job_id → translation_jobs.job_id (new: the one free retry)translation_quotes.superseded_by / requoted_from → translation_quotes.quote_id (new: a requote and the quote it replaced)translation_jobs.task_id → translation_tasks.task_id (link column, partial index on non-NULL)translation_job_events.job_id and translation_chunk_telemetry.job_id → translation_jobs.job_idtranslation_pair_runs.job_id → translation_jobs.job_id and translation_pair_runs.quote_id → translation_quotes.quote_id (new: link columns without foreign keys, one row per (job_id, doc, lang) through translation_pair_runs_pair_key)translation_supported_languages.lang_code → translation_language_profiles.lang_code, and base_lang → lang_code of the same table (foreign key tsl_base_fk)translation_glossary_entries.account_id → users.id (a customer's entries; our own entries have no account)| Key Pattern | Type | TTL | Content |
|---|---|---|---|
tx:job:{id} | Hash | None while live; 6 days once the job ends | Live job state (status, progress, per-pair results). The customer status endpoints read it first and fall back to Aurora. |
tx:active | Set | Managed | Currently running job IDs (at 12 or more the LPO logs a warning and still queues; nothing caps concurrency) |
tx:history | List | None (capped) | Completed job summaries, newest first |
tx:idempotency:{key} | String | 24h | Idempotency deduplication |
tx:params | Hash | 27 h | translation_parameters cache, refreshed nightly by the sync job (Bedrock rates included) and on reload |
tx:supported_langs | Hash | 27 h | Language code → status, the compact form of the catalog |
tx:lang_catalog | String (JSON) | 27 h | The full 127-row catalog. Every LPO container also refreshes its copy in place every 15 minutes, so a language change reaches every container without a restart. |
tx:chunk-hash:* | String | Permanent | Per-chunk content hashes (delta detection) |
dashboard:notifications:seen:user:{users.id} | String | — | Dashboard notification badge, now per user across every translation key (one fallback read of the old per-key value) |
autoops:bedrock:tokens:input:daily | String | 24h | Today's input token count |
autoops:bedrock:tokens:output:daily | String | 24h | Today's output token count |
X-Admin-Key header.| Endpoint | Method | Purpose |
|---|---|---|
/admin/translate | POST | Submit a translation job (up to 42 documents and 12 languages, or "all" for the internal 11) |
/admin/translate/status/{job_id} | GET | Real-time per-pair progress |
/admin/translate/queue | GET | Active queue with all running/queued jobs |
/admin/translate/health | GET | System health (active jobs, queue depth) |
/admin/translate/history | GET | Job history (last 50) |
/admin/translate/eta | GET | Delivery estimate for a job not yet submitted (?docs=, ?langs=, optional ?model=, ?chunks=), from the same history estimator the quote uses: medians of similar pairs in translation_pair_runs plus the 3% buffer |
/admin/translate/eta/calibrate | POST | The figures the next estimate would use per language (group, sample count, median) and the settings in force, read from Aurora on the spot; nothing is built or cached |
/admin/translate/cancel/{job_id} | POST | Cancel a running job |
/admin/translate/retry-failed/{job_id} | POST | Retry only the failed pairs of a partial job, on the same model as the original job. On a customer job it uses the quote's one free retry. |
/admin/translate/params | GET/POST | List all / upsert translation parameters |
/admin/translate/params/reload | POST | Refresh the Valkey cache from Aurora |
/admin/translate/languages | GET/POST | List the catalog / update one language (a new code needs its English name, native name, script and tuning language) |
/admin/translate/languages/reload | POST | Refresh the catalog in place |
/admin/translate/refund/{quote_id} | POST | Full or partial refund, allowed on accepted or partially_refunded quotes and clamped to what is left |
/admin/translate/refund-approve/{quote_id} | POST | Approve a customer's cancel refund |
/admin/translate/refund-sweep | POST | Run one pass of the 15-minute failed-pair refund sweeper now |
GET /translate/models (there is no admin models route), and the live catalog with its limits and aliases is the public GET /translate/languages. Dashboard equivalents: GET/POST/DELETE /dashboard/api/translate/params, POST /dashboard/api/translate/params/reload — same functionality, different auth path (magic link session vs admin key).
11 tables and 302 columns in the live database after the migration of November 18, 2026, plus 9 functions (section 6, sections 7 and 8, and section 12) and the review view translation_pair_estimate_review. The table count was read on November 10, 2026. The column count was read live on November 18, 2026: 298 columns before migration 2026-11-18-01, which adds four to translation_glossary_entries. The column lists of eight tables were first read on October 10, 2026 and include the release migrations. translation_jobs, translation_quotes and translation_pair_runs were read again on November 7, 2026. bedrock_model_catalog was not part of the first read and keeps its earlier column list. The glossary migrations of November 8, 2026 added translation_glossary_entries (section 11), the column translation_pair_runs.glossary, and four translation_parameters rows in the category glossary. Row counts change daily, so read them live rather than from a page.
| Table | Columns | Purpose |
|---|---|---|
translation_jobs | 39 | Job orchestration and state |
translation_job_events | 8 | Granular audit trail |
translation_quotes | 71 | Customer quotes, Stripe payment, requotes, refunds and the delivery estimate |
translation_parameters | 6 | Operational configuration store |
bedrock_model_catalog | 12 | Multi-provider model registry |
translation_tasks | 16 | Parent-child task orchestration |
translation_language_profiles | 18 | Per-language tuning + auto-tuning |
translation_supported_languages | 17 | The 127-language catalog |
translation_chunk_telemetry | 23 | Per-chunk metrics |
translation_pair_runs | 76 | Estimate versus actual, one row per pair |
translation_glossary_entries | 16 | Our glossary and each customer's glossary |