Spaces:
Running

ahmdelbaz28-ux commited on
Commit
0916f03
·
1 Parent(s): ce629f4

fix(chatbot): agent-architecture audit (layers 3/6/10) — routing noise, refs ownership, block coherence, rendering contract E2E, post-deploy live probe

Browse files

Skills applied: agent-architecture-audit + e2e-testing + systematic-debugging
(+ the ci-cd gates pattern), per the owner's token-burn minimization mandate.

AUDIT FINDINGS → FIXES (evidence-backed, code-first):
1. Layer 6 (routing discipline) — keyword hygiene: single generic words fired
whole domain cores on unrelated questions ('قاطع' lit saudi+schneider on a
generic breaker-vs-disconnector question; 'قصر' lit the Saadat pack on a
cables question; 'كود' lit cables on a SAUDI-code question; 'kva' lit ABB
on any load question; 'توليد/نقل/توزيع' lit Gilany on anything). Removed
the generic tokens from the keyword lists — the specific PHRASES keep
every intended contract (all skillnet tests green untouched).
2. Layer 6 (coherence) — forced co-selection: a dynamic RAG block can never
ride without its protocol block anymore (getSystemPrompt force-includes
saadat/cables/the exact refs skills when their context block is present).
3. Layer 3 (context routing) — refs ownership: when the cables layer is
active and no reference corpus matches, routeRefsQuery now returns an
EMPTY route → empty block, instead of falling back to searching 4
unrelated documents (wrong-file token burn the owner explicitly banned).
4. Layer 10 (rendering) — E2E contract: new chat-refs-citations.spec.ts
proves the price-table → documented bullets transform keeps every cell
verbatim (Product IDs/EGP prices), Latin IDs never bidi-mangled inside
RTL text, and the citation lines survive LAST in the bubble (DOM-order
assertions — innerText bidi reordering would false-fail).
5. CI/CD: deploy-hf.yml gains a live-probe job — waits for the Space to
reach RUNNING, runs scripts/chatbot-refs-live-proof.ts (deterministic
server-enforced citation contracts as HARD gates; model-variance price
formatting as SOFT warn per the flaky-test pattern; 1 retry), and
publishes the proof into the step summary (log-embedded — the security
contract pins every action ref to a verified SHA, so no artifact action).

MEASURED (scripts/audit_prompt_size.ts, before → after): generic thinking
prompt 31,818 → 29,264 chars (~−750 tokens); cables 39,078 → 35,385
(~−1,086 tokens); saadat 38,140 → 36,897. Static floor (21,036 chars ≈
6,187 tokens — persona/identity design) reported to the owner as a finding,
deliberately NOT cut.

Unit 1269 ✓ · E2E 42 ✓ · tsc/ultracheck/biome ✓

10 files changed +309 -39
Files changed (10)
.github/workflows/deploy-hf.yml+51
api/lib/chatbot-prompts.ts+32-12
api/lib/chatbot-refs.ts+11-7
api/lib/chatbot-skillnet.ts+21-18
scripts/audit_prompt_breakdown.tsAdded+20
scripts/audit_prompt_dup.tsAdded+24
scripts/audit_prompt_size.tsAdded+40
scripts/chatbot-refs-live-proof.ts+15-2
scripts/ui-test-server.mjs+21
tests/e2e/features/chat-refs-citations.spec.tsAdded+74