Running record of implementation batches against
ai-capability-implementation-plan.md.
Each entry records what was built, what was measured, and what was not.
Status: COMPLETE. Audit status for row 27 moves Partial → Complete.
Baseline commit: 9bd780b.
The platform showed what SQL it generated and whether it validated, but
never described it. SqlIntelligencePanel rendered the statement type
and referenced tables; nothing said how the tables were joined, what was
filtered, what was aggregated, or at what grain.
agent/sql_validator.py gained describe_sql(), which reads the AST
validate_sql already parsed. No second parser, no model call, no
new dependency.
The deciding argument was not cost or latency, though it wins on both: an explanation that hallucinates a join is worse than no explanation, because it renders beside a real validator verdict and reads as authoritative. A parse cannot be wrong about the statement it parsed. Recorded as decision D-009.
Each was found by probing the real AST before writing the function, and each is now pinned by a test.
SUM(x) in both SELECT and HAVING
is one aggregate to a reader and two nodes to the parser. De-duplicated.ORDER BY misreported as the result’s ordering. Searching
the tree finds the ORDER BY inside OVER (...) first on a statement
that has no ordering of its own. Fixed by reading the statement’s own
order argument rather than searching.UNION reported as DISTINCT. sqlglot sets distinct on a set
operation to encode UNION rather than UNION ALL — a different fact
from SELECT DISTINCT. Would have mislabelled every plain UNION.
Caught by a probe after the first implementation passed its other tests.agent.nodes.validate_sql_node writes enforce_row_limit’s output back
to state["sql"] — verified by reading the node — so the TOP n a
caller sees is this platform’s governance cap, not the query’s
intent. Reporting it as query behaviour would present a control as
authorship. The cap already has an owner in the result gate.group_by is the grain the statement
declares, not “sales by region”. Naming what a column means belongs to
semantic/.WHERE email = '...'), and this string is rendered in a UI and may be
logged.| File | Why |
|---|---|
agent/sql_validator.py |
+SqlJoinFact, +SqlShape, +describe_sql(). Added beside summarize_sql, not widening it — that function has two live callers (api.main, api.artifacts) whose tuple unpacking a changed signature would break |
api/schemas.py |
+SqlJoinOut; six optional fields on SqlSummaryOut, each with a default, so the frozen model stays backward compatible (CLAUDE.md §6.3) |
api/main.py |
_sql_summary_out populates them, inside its own try so an undescribable shape costs the description and never the statement type |
frontend/src/lib/types.ts |
+SqlJoin; optional fields on SqlSummary |
frontend/src/components/sql/SqlIntelligencePanel.tsx |
Six rows added to the existing metadata grid — no new component |
frontend/src/i18n/locales/*/translation.json ×5 |
7 keys each |
tests/test_sql_validator.py |
+TestDescribeSql, 15 tests |
frontend/.../SqlIntelligencePanel.test.tsx |
4 tests |
Server returns structured facts; the frontend renders them through i18n. Emitting English prose server-side would have made the feature untranslatable in a five-locale app.
| Check | Result |
|---|---|
pytest tests/test_sql_validator.py |
73 passed (15 new) |
pytest validator + hardening + mssql + api_ask + api_artifacts + agent_nodes + restricted_column + tests/security/ |
868 passed |
pytest (full suite) |
7215 passed, 11 deselected (was 7197 – exactly the 18 new tests, no regression) |
npm run test |
1150 passed, 88 files (was 1147) |
npx tsc --noEmit |
Clean |
ruff / black on changed files |
Clean (2 findings of my own, both fixed — see below) |
npm run lint |
2 warnings on SqlIntelligencePanel.tsx, pre-existing (same file and lines in the session baseline) |
npm run build |
Succeeds |
End-to-end through _sql_summary_out |
Correct shape; unparseable SQL and absent SQL both yield None, not a partial |
Two self-inflicted lint findings, both fixed rather than suppressed:
an unsorted import block in api/main.py (from my insertion), and
B017 pytest.raises(Exception) in my own test — replaced with an
assertion on validate_sql(...).is_valid, which is what the test
actually meant.
validate_sql untouched. describe_sql is a separate function; a
test asserts the validator still rejects DELETE while describe_sql
happily describes it — proving the helper is not, and cannot be
mistaken for, a gate.summarize_sql untouched, pinned by a test, so both existing
callers are unaffected.tests/security/ (25 files) passes.Decisions 2 (accessibility), 3 (translation), 4 (Word/Excel — deferred by you) and 5 (certification) were kept out, per the instruction not to combine unrelated work.
Status: COMPLETE. Audit status for row 60 moves Partial → Complete.
Baseline commit: 933cfff.
The UI had aria labels, focus management and responsive layout throughout, and 53 of 88 test files already query by role or label — but nothing asserted any of it stayed true. No automated accessibility check existed at all.
Before proposing any dependency I checked what the installed stack could
already do. oxlint 1.82 ships a jsx-a11y plugin that was simply not
enabled — the config listed only react, typescript, oxc.
Enabling it cost zero new dependencies and immediately surfaced 28 findings. So half the gap closed for free.
axe-core, not vitest-axeYou approved vitest-axe if justified. It is not the better choice,
by your own criteria:
vitest-axe |
axe-core (chosen) |
|
|---|---|---|
| Version | 0.1.0, pre-1.0 | 4.14.0 |
| Last modified | 2025-01-22 (~21 months) | 2026-10-15 (2 days) |
| What it is | A thin matcher around axe-core | Deque’s actual engine |
vitest-axe wraps this same engine. For a repository that digest-pins
container images and justifies every CVE ignore individually, depending
on the maintained first-party engine and writing the ~15-line matcher
ourselves is the cheaper long-term position. Dev dependency only;
dependencies is untouched.
Of the 28 jsx-a11y findings, the eight that looked like real defects
included ShareModal’s access-mode radios and ui/card.tsx’s
CardTitle. Rather than mass-fix, I rendered both patterns and ran axe
against them:
<label> wrapping an input plus nested text spans:
no runtime violation. The rule cannot see text nested two levels
deep; the control is correctly labelled.CardTitle (<h3 {...props} /> taking content via children):
no runtime violation. A static rule cannot know children exist.<h3 />: is caught (empty-heading) — so the
engine is not merely permissive.Three rules are therefore disabled in .oxlintrc.json with that
evidence behind them: label-has-associated-control and
heading-has-content (false positives on this codebase’s legitimate
patterns, both covered properly by axe at runtime) and
prefer-tag-over-role (a style preference — role="status" is valid
ARIA, not a defect).
13 findings remain as warnings and are real, pre-existing issues now
visible rather than silently absent: no-redundant-roles (5),
control-has-associated-label (3), no-static-element-interactions (2),
media-has-caption (2), no-autofocus (1). They are deliberately not
fixed in this batch — they pre-date it, and absorbing them silently
would hide what enabling the plugin found. npm run lint still exits 0.
| File | Why |
|---|---|
frontend/.oxlintrc.json |
jsx-a11y plugin enabled; three rules off with the evidence above |
frontend/package.json, package-lock.json |
axe-core@4.14.0, devDependencies only |
frontend/src/test/axe.ts (new) |
The matcher, plus an explicit statement of what jsdom cannot check |
frontend/src/components/ui/accessibility.test.tsx (new) |
8 tests across Button, Card, Dialog, ChatMessage |
| Check | Result |
|---|---|
npx vitest run accessibility.test.tsx |
8 passed |
npm run test |
1158 passed, 89 files (was 1150 / 88) |
npx tsc --noEmit |
Clean |
npm run lint |
Exit 0; 13 a11y warnings now visible |
npm run build |
Succeeds |
Non-vacuity is proven, not assumed: one test renders an icon-only
button with no accessible name and asserts axe reports button-name. If
axe ever stopped running, that test fails rather than silently passing.
No production dependency added. axe-core is unreachable from the app
entry point — only accessibility.test.tsx and src/test/axe.ts import
it, so Vite cannot bundle it. (frontend/dist is read-blocked under
CLAUDE.md §12, so this is established by source reachability, which is
what determines bundling, rather than by grepping the artefact.)
Status: CORE COMPLETE, NOT WIRED. Row 79 moves
Needs decision / Missing → Core / Partial.
Baseline commit: cf0781a.
No user can reach this yet.
agent/translation.pyis built, tested and proven against the real model, but there is no API field and no UI control. It is the “built, not wired” stateCLAUDE.md§1 recognises, and it is recorded as Partial rather than Complete for exactly that reason.
Your condition was to preserve numbers, signs, units, currency, dates, identifiers, citations, source references and SQL — and to defer if those invariants could not be demonstrated.
A model asked to translate free text will eventually localise a decimal separator, round a figure or drop a citation. No prompt makes that a guarantee. So the model is never shown the parts that must not change:
The guarantee is not “the model behaved”. It is “a translation that
failed to preserve the invariants never reaches the caller”.
translate_answer has exactly two outcomes, by construction.
Against llama3.1:8b (local, no new provider, no cost), French, 32.0 s:
Les revenus ont atteint $1,234.56 sur 2026-10-17, en augmentation de 12.5% par rapport à l’année précédente. La colonne propriétaire est [restricted] pour votre rôle. Voir the catalogue pour la définition du métrique.
All five protected spans intact; prose genuinely translated; and
[restricted] was not translated — a translated mask could read as
content rather than as a withheld value.
Caught by tests:
[\d,]* swallowed a sentence comma — “In 2026,
revenue” captured 2026,, so the same figure in two sentences
produced different spans and verification rejected a faithful
translation. Now (?:,\d{3})*.\s?%? captured a trailing space unconditionally, making spans
whitespace-sensitive. Now (?:\s?%)?.Not caught by tests, found only by the live call: rag.llm.call_ollama
takes max_tokens as a required positional, which my call omitted.
Every unit test passed because the fakes had the wrong arity too. A
mocked suite cannot catch a signature mismatch with the real collaborator
— the live run is what found it, and the fakes now match the real
signature.
[restricted] is a protected span, so a mask can never be translated
away.agent/input_guard.py, which refuses a
user’s request to translate arbitrary text. That would route around
the governed answer path; this is a presentation transform of our own
governed output. Worth stating because the two look similar.| Check | Result |
|---|---|
pytest tests/test_translation.py |
34 passed |
Live translation, llama3.1:8b, fr |
Translated, all invariants intact, 32.0 s |
ruff / black |
Clean |
Coverage includes: numbers, signs, percentages, currency in three symbols, dates, inline and fenced SQL, markdown citations, the governance mask, a figure legitimately moved by word order (accepted), and five distinct ways a figure can drift (all rejected), plus model error, empty response, unsupported locale, and all four non-English locales.
32 seconds per translation on this hardware. That settles the design question: translation must be on demand, never automatic per answer — the same conclusion the SQL explainer reached for the same reason.
Wiring needs an optional response field or a small endpoint, an on-demand control in the answer actions, and i18n ×5. The original must stay available for comparison, which the two-outcome contract already guarantees server-side.
DimProduct) is not
protected and could be translated. Wrapping identifiers in backticks
upstream would close this; recorded rather than hidden.Status: COMPLETE. Audit status for row 45 moves Partial → Complete
(row 45 is Optional, not Core, so the Core tallies in the audit’s §1
are unchanged). Baseline commit: 4bb46fd.
Numbering. This is the plan’s Batch 3 (§4 of
ai-capability-implementation-plan.md). It is logged as Batch 4 because this log numbers by execution order and row 79’s translation work took the Batch 3 slot here first. Same work, two schemes — recorded rather than silently renumbered.
agent/llm_client.py had read Ollama’s own prompt_eval_count/
eval_count on every call since long before this batch — and then threw
them away into a log line. An operator could see which model a request
was routed to (model_routing’s GET /metrics) and how long each
LangGraph stage took (GET /metrics/performance), but nothing anywhere
said what the models actually consumed.
_log_ollama_timing is the one point all seven of this module’s
client.chat calls already funnel through — which is why its own
docstring puts the circuit breaker’s success signal there. The token
rollup goes in the same place, for the same reason: a future eighth
call site is counted without anyone remembering to add it.
The model name is read from the response, not threaded in from the call
sites, so not one of the seven callers changed. It is also the more
correct source: the name recorded is what the server actually served,
which can differ from what this app asked for (an alias, or a
per-request AskRequest.model override).
A structural test parses this module’s own AST and asserts
len(client.chat calls) == len(_log_ollama_timing calls). The failure
mode it guards is someone adding a chat call and forgetting the funnel
line — which no behavioural test of the existing seven would catch.
Token counts are a measure of a tenant’s own usage volume, so they are
partitioned per tenant exactly as latency and status mixes already are
(PerformanceMetrics’ own docstring explains why: this codebase has no
platform-admin-versus-tenant-admin split inside the tenant-scoped
route, so admin-gating alone would let one tenant’s admin read another’s
numbers).
The tenant comes from security.audit_log’s _tenant_id contextvar via
get_audit_tenant_id() — already bound by run_agent/run_orchestrated
on the worker side of /ask’s thread-pool boundary, which is
precisely where a contextvar survives (that module’s docstring records
why it is not bound in the middleware). No signature changed, no
process-global state was mutated, and CLAUDE.md §4.6 holds.
observability/llm_timing_capture.py already parses these exact numbers
out of the log line, and its module docstring claims it “backs the
API/observability layer’s per-request LlmCallTiming list”. Nothing in
api/ imports it — eval/runner.py is its only caller, so that claim
is stale.
It is also unusable here. It works by attaching a handler to the
agent.llm_client logger and forcing that logger’s level, both
process-wide for the duration of the with block. Under concurrent
/ask requests every active capture would see every other request’s
timing lines, so tokens would be cross-attributed between tenants,
and the save/restore of the logger level would race. Correct for the
single-threaded benchmark runner it was written for; a tenant-isolation
defect if reused on the request path. Recorded here so the next session
does not reach for it.
The one risk the plan named for this batch. The LLM runs locally, so this
deployment has no per-token price; a cost column would be an invented
number presented as an observed fact, which CLAUDE.md §4.4 forbids.
Three tests pin its absence — one on the snapshot’s keys, one on the HTTP
response’s keys, and one on the rendered panel (no currency amount, and
no cost column). The prose disclosure is allowed to use the word
“price”, which is what the first version of the frontend assertion got
wrong: it matched my own disclaimer and failed. Narrowed to a currency
amount plus a column-header check.
CLAUDE.md §4.8)model_routing.get_route_metrics() keeps owning “which model was chosen
and did the route work”, including its total_cost_units — an abstract
tier weight, not money. This rollup owns “what the models consumed”.
Neither duplicates the other, and the usage rollup works whether or not
ENABLE_MODEL_ROUTING is on (the routing route 404s when it is off).
| File | Why |
|---|---|
observability/metrics.py |
+ModelUsageSummary, +record_llm_call, llm_usage on MetricsSnapshot, max_models bound. Cumulative, not windowed — like the existing cache counters, and for the same stated reason |
agent/llm_client.py |
+_get_model_name; one record_llm_call in the existing funnel. No call site touched; the benchmark-pinned prompts (CLAUDE.md §12) are untouched |
api/schemas.py |
+ModelUsageOut; llm_usage: list[...] = [] — additive and defaulted, so the frozen model stays backward compatible (§6.3) |
api/main.py, api/platform_admin.py |
Both existing metrics routes pass the new field through. No new route, no new permission |
frontend/src/lib/types.ts |
+ModelUsageOut; llm_usage optional, so an older backend that omits it still renders |
frontend/src/pages/PlatformAdmin.tsx |
A token-usage table in the existing UsageSection |
frontend/src/pages/TenantAdmin.tsx |
Token totals inside the card already titled “Recent AI usage”, which until now showed only latency |
tests/test_observability_metrics.py |
+TestLlmUsageRollup, 13 tests |
tests/test_llm_client_usage_rollup.py (new) |
9 tests — the funnel, both response shapes, the guards, tenant attribution |
tests/test_api_platform_admin.py |
+TestLlmUsageRollupOverHttp, 3 tests incl. the cross-tenant non-leak |
frontend/.../PlatformAdmin.test.tsx, TenantAdmin.test.tsx |
3 tests |
These two admin pages use plain English, not i18n keys, so no locale files changed — following the surrounding convention (§6.1.4) rather than introducing a sixth pattern into pages that have none.
record_llm_call incremented the call counter and then the token
counters in place. A non-numeric count raised after the call counter
had already moved, and the except swallowed it — leaving a phantom
zero-token call that a reader could not tell apart from a real call
that consumed nothing. Now both counts are coerced before the window is
touched, so an unusable value records nothing at all. Negative counts are
rejected the same way.
This is also why a response with no counts at all records nothing rather than a zero: “nothing measured” must not read as “measured zero”.
| Check | Result |
|---|---|
pytest tests/test_observability_metrics.py |
24 passed (13 new) |
pytest tests/test_llm_client_usage_rollup.py |
9 passed |
pytest tests/test_api_platform_admin.py |
24 passed (3 new) |
pytest (full suite) |
7274 passed, 11 deselected, exit 0, 8m15s. Reconciles exactly: 7215 after Batch 1, + 34 from row 79’s translation tests, + this batch’s 25 = 7274. No regression |
npx vitest run (full) |
1161 passed, 89 files (was 1158 — exactly the 3 new) |
npx tsc --noEmit -p tsconfig.app.json |
Clean, exit 0 |
npm run lint |
Exit 0; warnings only, all in files this batch did not touch |
ruff check / black --check on changed files |
Clean (3 files needed black; reformatted, then re-verified) |
mypy on the four touched production modules |
3 errors, none in a file this batch touched — agent/sql_validator.py:839 (blamed to 933cfff, Batch 1) and db/schema_introspection.py:376 (blamed to 25073964, 2026-10-04). Both reproduce with this batch’s changes absent from the invocation |
Four guards proven non-vacuous by mutation, re-run after black
reformatted the files (a formatter can silently invalidate a
text-matching mutation and fake the proof). Each mutation asserts it
actually applied, and each was caught:
| Mutation | Caught by |
|---|---|
Drop record_llm_call from the funnel |
test_llm_client_usage_rollup.py |
| Attribute every call to the default tenant | TestTenantAttribution |
| Record a phantom zero-token call | TestLlmUsageRollup |
Ignore the max_models bound |
TestLlmUsageRollup |
CLAUDE.md §5.6).GET /metrics/performance must not
see another tenant’s model in llm_usage.max_models, LRU-evicted), the
same defense-in-depth posture as the tenant-window bound.CLAUDE.md §13). A
multi-worker deployment has one rollup per worker, so these are not
deployment-wide totals. Stated in both panels’ own prose.calls is not a request count.Row 79’s wiring (the translation module is still built-not-wired),
Word/Excel export (decision 4), the paid media providers (decision 5),
and the two pre-existing mypy findings above — all left alone rather
than folded into unrelated work.