-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.html
More file actions
690 lines (690 loc) · 45.7 KB
/
README.html
File metadata and controls
690 lines (690 loc) · 45.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>README</title>
<style>
/* Default styles provided by pandoc.
** See https://pandoc.org/MANUAL.html#variables-for-html for config info.
*/
html {
color: #1a1a1a;
background-color: #fdfdfd;
}
body {
margin: 0 auto;
max-width: 36em;
padding-left: 50px;
padding-right: 50px;
padding-top: 50px;
padding-bottom: 50px;
hyphens: auto;
overflow-wrap: break-word;
text-rendering: optimizeLegibility;
font-kerning: normal;
}
@media (max-width: 600px) {
body {
font-size: 0.9em;
padding: 12px;
}
h1 {
font-size: 1.8em;
}
}
@media print {
html {
background-color: white;
}
body {
background-color: transparent;
color: black;
font-size: 12pt;
}
p, h2, h3 {
orphans: 3;
widows: 3;
}
h2, h3, h4 {
page-break-after: avoid;
}
}
p {
margin: 1em 0;
}
a {
color: #1a1a1a;
}
a:visited {
color: #1a1a1a;
}
img {
max-width: 100%;
}
svg {
height: auto;
max-width: 100%;
}
h1, h2, h3, h4, h5, h6 {
margin-top: 1.4em;
}
h5, h6 {
font-size: 1em;
font-style: italic;
}
h6 {
font-weight: normal;
}
ol, ul {
padding-left: 1.7em;
margin-top: 1em;
}
li > ol, li > ul {
margin-top: 0;
}
blockquote {
margin: 1em 0 1em 1.7em;
padding-left: 1em;
border-left: 2px solid #e6e6e6;
color: #606060;
}
code {
font-family: Menlo, Monaco, Consolas, 'Lucida Console', monospace;
font-size: 85%;
margin: 0;
hyphens: manual;
}
pre {
margin: 1em 0;
overflow: auto;
}
pre code {
padding: 0;
overflow: visible;
overflow-wrap: normal;
}
.sourceCode {
background-color: transparent;
overflow: visible;
}
hr {
border: none;
border-top: 1px solid #1a1a1a;
height: 1px;
margin: 1em 0;
}
table {
margin: 1em 0;
border-collapse: collapse;
width: 100%;
overflow-x: auto;
display: block;
font-variant-numeric: lining-nums tabular-nums;
}
table caption {
margin-bottom: 0.75em;
}
tbody {
margin-top: 0.5em;
border-top: 1px solid #1a1a1a;
border-bottom: 1px solid #1a1a1a;
}
th {
border-top: 1px solid #1a1a1a;
padding: 0.25em 0.5em 0.25em 0.5em;
}
td {
padding: 0.125em 0.5em 0.25em 0.5em;
}
header {
margin-bottom: 4em;
text-align: center;
}
#TOC li {
list-style: none;
}
#TOC ul {
padding-left: 1.3em;
}
#TOC > ul {
padding-left: 0;
}
#TOC a:not(:hover) {
text-decoration: none;
}
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
/* The extra [class] is a hack that increases specificity enough to
override a similar rule in reveal.js */
ul.task-list[class]{list-style: none;}
ul.task-list li input[type="checkbox"] {
font-size: inherit;
width: 0.8em;
margin: 0 0.8em 0.2em -1.6em;
vertical-align: middle;
}
.display.math{display: block; text-align: center; margin: 0.5rem auto;}
/* CSS for syntax highlighting */
html { -webkit-text-size-adjust: 100%; }
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { color: #008000; } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { color: #008000; font-weight: bold; } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>
</head>
<body>
<header id="title-block-header">
<h1 class="title">README</h1>
</header>
<h1 id="llmprovider-module">LLMProvider Module</h1>
<p><code>digital.vasic.llmprovider</code> is a generic, reusable Go
module providing LLM provider abstractions and utilities. It defines the
core <code>LLMProvider</code> interface and common patterns for building
LLM provider implementations, including circuit breakers, health
monitoring, retry logic, and lazy loading.</p>
<h2 id="features">Features</h2>
<ul>
<li><strong>LLMProvider Interface</strong>: Unified interface for all
LLM providers with <code>Complete</code>, <code>CompleteStream</code>,
<code>HealthCheck</code>, <code>GetCapabilities</code>,
<code>ValidateConfig</code></li>
<li><strong>Circuit Breaker</strong>: Fault tolerance pattern with
closed/open/half-open states to prevent cascading failures</li>
<li><strong>Health Monitor</strong>: Configurable health tracking with
thresholds, intervals, and status transitions (healthy, degraded,
unhealthy, unknown)</li>
<li><strong>Retry Logic</strong>: Exponential backoff with jitter, HTTP
status code detection, and context cancellation support</li>
<li><strong>Lazy Provider</strong>: Lazy initialization pattern with
deferred provider creation and optional event bus integration</li>
<li><strong>Thread-Safe</strong>: All components designed for concurrent
use with proper synchronization</li>
<li><strong>Minimal Dependencies</strong>: Only depends on
<code>digital.vasic.models</code> and
<code>github.com/sirupsen/logrus</code></li>
</ul>
<h2 id="installation">Installation</h2>
<div class="sourceCode" id="cb1"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="ex">go</span> get digital.vasic/llmprovider</span></code></pre></div>
<h2 id="quick-start">Quick Start</h2>
<div class="sourceCode" id="cb2"><pre class="sourceCode go"><code class="sourceCode go"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="kw">package</span> main</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a><span class="kw">import</span> <span class="op">(</span></span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a> <span class="st">"context"</span></span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a> <span class="st">"digital.vasic.llmprovider"</span></span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a> <span class="st">"digital.vasic.models"</span></span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a> <span class="st">"fmt"</span></span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a><span class="op">)</span></span>
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-10"><a href="#cb2-10" aria-hidden="true" tabindex="-1"></a><span class="co">// Example provider implementation</span></span>
<span id="cb2-11"><a href="#cb2-11" aria-hidden="true" tabindex="-1"></a><span class="kw">type</span> MyProvider <span class="kw">struct</span> <span class="op">{</span></span>
<span id="cb2-12"><a href="#cb2-12" aria-hidden="true" tabindex="-1"></a> llmprovider<span class="op">.</span>LLMProvider</span>
<span id="cb2-13"><a href="#cb2-13" aria-hidden="true" tabindex="-1"></a> name <span class="dt">string</span></span>
<span id="cb2-14"><a href="#cb2-14" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span>
<span id="cb2-15"><a href="#cb2-15" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-16"><a href="#cb2-16" aria-hidden="true" tabindex="-1"></a><span class="kw">func</span> <span class="op">(</span>p <span class="op">*</span>MyProvider<span class="op">)</span> Complete<span class="op">(</span>ctx context<span class="op">.</span>Context<span class="op">,</span> req <span class="op">*</span>models<span class="op">.</span>LLMRequest<span class="op">)</span> <span class="op">(*</span>models<span class="op">.</span>LLMResponse<span class="op">,</span> <span class="dt">error</span><span class="op">)</span> <span class="op">{</span></span>
<span id="cb2-17"><a href="#cb2-17" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> <span class="op">&</span>models<span class="op">.</span>LLMResponse<span class="op">{</span></span>
<span id="cb2-18"><a href="#cb2-18" aria-hidden="true" tabindex="-1"></a> ID<span class="op">:</span> <span class="st">"resp_123"</span><span class="op">,</span></span>
<span id="cb2-19"><a href="#cb2-19" aria-hidden="true" tabindex="-1"></a> RequestID<span class="op">:</span> req<span class="op">.</span>ID<span class="op">,</span></span>
<span id="cb2-20"><a href="#cb2-20" aria-hidden="true" tabindex="-1"></a> ProviderID<span class="op">:</span> p<span class="op">.</span>name<span class="op">,</span></span>
<span id="cb2-21"><a href="#cb2-21" aria-hidden="true" tabindex="-1"></a> Content<span class="op">:</span> <span class="st">"Response from "</span> <span class="op">+</span> p<span class="op">.</span>name<span class="op">,</span></span>
<span id="cb2-22"><a href="#cb2-22" aria-hidden="true" tabindex="-1"></a> <span class="op">},</span> <span class="ot">nil</span></span>
<span id="cb2-23"><a href="#cb2-23" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span>
<span id="cb2-24"><a href="#cb2-24" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-25"><a href="#cb2-25" aria-hidden="true" tabindex="-1"></a><span class="kw">func</span> <span class="op">(</span>p <span class="op">*</span>MyProvider<span class="op">)</span> CompleteStream<span class="op">(</span>ctx context<span class="op">.</span>Context<span class="op">,</span> req <span class="op">*</span>models<span class="op">.</span>LLMRequest<span class="op">)</span> <span class="op">(<-</span><span class="kw">chan</span> <span class="op">*</span>models<span class="op">.</span>LLMResponse<span class="op">,</span> <span class="dt">error</span><span class="op">)</span> <span class="op">{</span></span>
<span id="cb2-26"><a href="#cb2-26" aria-hidden="true" tabindex="-1"></a> ch <span class="op">:=</span> <span class="bu">make</span><span class="op">(</span><span class="kw">chan</span> <span class="op">*</span>models<span class="op">.</span>LLMResponse<span class="op">,</span> <span class="dv">1</span><span class="op">)</span></span>
<span id="cb2-27"><a href="#cb2-27" aria-hidden="true" tabindex="-1"></a> ch <span class="op"><-</span> <span class="op">&</span>models<span class="op">.</span>LLMResponse<span class="op">{</span></span>
<span id="cb2-28"><a href="#cb2-28" aria-hidden="true" tabindex="-1"></a> ID<span class="op">:</span> <span class="st">"resp_123"</span><span class="op">,</span></span>
<span id="cb2-29"><a href="#cb2-29" aria-hidden="true" tabindex="-1"></a> RequestID<span class="op">:</span> req<span class="op">.</span>ID<span class="op">,</span></span>
<span id="cb2-30"><a href="#cb2-30" aria-hidden="true" tabindex="-1"></a> ProviderID<span class="op">:</span> p<span class="op">.</span>name<span class="op">,</span></span>
<span id="cb2-31"><a href="#cb2-31" aria-hidden="true" tabindex="-1"></a> Content<span class="op">:</span> <span class="st">"Stream response from "</span> <span class="op">+</span> p<span class="op">.</span>name<span class="op">,</span></span>
<span id="cb2-32"><a href="#cb2-32" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span>
<span id="cb2-33"><a href="#cb2-33" aria-hidden="true" tabindex="-1"></a> <span class="bu">close</span><span class="op">(</span>ch<span class="op">)</span></span>
<span id="cb2-34"><a href="#cb2-34" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> ch<span class="op">,</span> <span class="ot">nil</span></span>
<span id="cb2-35"><a href="#cb2-35" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span>
<span id="cb2-36"><a href="#cb2-36" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-37"><a href="#cb2-37" aria-hidden="true" tabindex="-1"></a><span class="kw">func</span> <span class="op">(</span>p <span class="op">*</span>MyProvider<span class="op">)</span> HealthCheck<span class="op">()</span> <span class="dt">error</span> <span class="op">{</span></span>
<span id="cb2-38"><a href="#cb2-38" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> <span class="ot">nil</span> <span class="co">// Always healthy for example</span></span>
<span id="cb2-39"><a href="#cb2-39" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span>
<span id="cb2-40"><a href="#cb2-40" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-41"><a href="#cb2-41" aria-hidden="true" tabindex="-1"></a><span class="kw">func</span> <span class="op">(</span>p <span class="op">*</span>MyProvider<span class="op">)</span> GetCapabilities<span class="op">()</span> <span class="op">*</span>models<span class="op">.</span>ProviderCapabilities <span class="op">{</span></span>
<span id="cb2-42"><a href="#cb2-42" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> <span class="op">&</span>models<span class="op">.</span>ProviderCapabilities<span class="op">{</span></span>
<span id="cb2-43"><a href="#cb2-43" aria-hidden="true" tabindex="-1"></a> Name<span class="op">:</span> p<span class="op">.</span>name<span class="op">,</span></span>
<span id="cb2-44"><a href="#cb2-44" aria-hidden="true" tabindex="-1"></a> SupportsStream<span class="op">:</span> <span class="ot">true</span><span class="op">,</span></span>
<span id="cb2-45"><a href="#cb2-45" aria-hidden="true" tabindex="-1"></a> SupportsTools<span class="op">:</span> <span class="ot">false</span><span class="op">,</span></span>
<span id="cb2-46"><a href="#cb2-46" aria-hidden="true" tabindex="-1"></a> SupportsVision<span class="op">:</span> <span class="ot">false</span><span class="op">,</span></span>
<span id="cb2-47"><a href="#cb2-47" aria-hidden="true" tabindex="-1"></a> MaxConcurrency<span class="op">:</span> <span class="dv">10</span><span class="op">,</span></span>
<span id="cb2-48"><a href="#cb2-48" aria-hidden="true" tabindex="-1"></a> MaxTokens<span class="op">:</span> <span class="dv">4096</span><span class="op">,</span></span>
<span id="cb2-49"><a href="#cb2-49" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span>
<span id="cb2-50"><a href="#cb2-50" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span>
<span id="cb2-51"><a href="#cb2-51" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-52"><a href="#cb2-52" aria-hidden="true" tabindex="-1"></a><span class="kw">func</span> <span class="op">(</span>p <span class="op">*</span>MyProvider<span class="op">)</span> ValidateConfig<span class="op">(</span>config <span class="kw">map</span><span class="op">[</span><span class="dt">string</span><span class="op">]</span><span class="kw">interface</span><span class="op">{})</span> <span class="op">(</span><span class="dt">bool</span><span class="op">,</span> <span class="op">[]</span><span class="dt">string</span><span class="op">)</span> <span class="op">{</span></span>
<span id="cb2-53"><a href="#cb2-53" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> <span class="ot">true</span><span class="op">,</span> <span class="ot">nil</span></span>
<span id="cb2-54"><a href="#cb2-54" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span>
<span id="cb2-55"><a href="#cb2-55" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-56"><a href="#cb2-56" aria-hidden="true" tabindex="-1"></a><span class="kw">func</span> main<span class="op">()</span> <span class="op">{</span></span>
<span id="cb2-57"><a href="#cb2-57" aria-hidden="true" tabindex="-1"></a> <span class="co">// Create a provider</span></span>
<span id="cb2-58"><a href="#cb2-58" aria-hidden="true" tabindex="-1"></a> provider <span class="op">:=</span> <span class="op">&</span>MyProvider<span class="op">{</span>name<span class="op">:</span> <span class="st">"my-provider"</span><span class="op">}</span></span>
<span id="cb2-59"><a href="#cb2-59" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb2-60"><a href="#cb2-60" aria-hidden="true" tabindex="-1"></a> <span class="co">// Wrap with circuit breaker</span></span>
<span id="cb2-61"><a href="#cb2-61" aria-hidden="true" tabindex="-1"></a> cb <span class="op">:=</span> llmprovider<span class="op">.</span>NewDefaultCircuitBreaker<span class="op">(</span><span class="st">"my-provider"</span><span class="op">,</span> provider<span class="op">)</span></span>
<span id="cb2-62"><a href="#cb2-62" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb2-63"><a href="#cb2-63" aria-hidden="true" tabindex="-1"></a> <span class="co">// Create a request</span></span>
<span id="cb2-64"><a href="#cb2-64" aria-hidden="true" tabindex="-1"></a> req <span class="op">:=</span> <span class="op">&</span>models<span class="op">.</span>LLMRequest<span class="op">{</span></span>
<span id="cb2-65"><a href="#cb2-65" aria-hidden="true" tabindex="-1"></a> ID<span class="op">:</span> <span class="st">"req_123"</span><span class="op">,</span></span>
<span id="cb2-66"><a href="#cb2-66" aria-hidden="true" tabindex="-1"></a> SessionID<span class="op">:</span> <span class="st">"sess_456"</span><span class="op">,</span></span>
<span id="cb2-67"><a href="#cb2-67" aria-hidden="true" tabindex="-1"></a> Prompt<span class="op">:</span> <span class="st">"Hello, world!"</span><span class="op">,</span></span>
<span id="cb2-68"><a href="#cb2-68" aria-hidden="true" tabindex="-1"></a> ModelParams<span class="op">:</span> models<span class="op">.</span>ModelParameters<span class="op">{</span></span>
<span id="cb2-69"><a href="#cb2-69" aria-hidden="true" tabindex="-1"></a> Model<span class="op">:</span> <span class="st">"my-model"</span><span class="op">,</span></span>
<span id="cb2-70"><a href="#cb2-70" aria-hidden="true" tabindex="-1"></a> Temperature<span class="op">:</span> <span class="fl">0.7</span><span class="op">,</span></span>
<span id="cb2-71"><a href="#cb2-71" aria-hidden="true" tabindex="-1"></a> MaxTokens<span class="op">:</span> <span class="dv">100</span><span class="op">,</span></span>
<span id="cb2-72"><a href="#cb2-72" aria-hidden="true" tabindex="-1"></a> <span class="op">},</span></span>
<span id="cb2-73"><a href="#cb2-73" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span>
<span id="cb2-74"><a href="#cb2-74" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb2-75"><a href="#cb2-75" aria-hidden="true" tabindex="-1"></a> <span class="co">// Use the provider</span></span>
<span id="cb2-76"><a href="#cb2-76" aria-hidden="true" tabindex="-1"></a> resp<span class="op">,</span> err <span class="op">:=</span> cb<span class="op">.</span>Complete<span class="op">(</span>context<span class="op">.</span>Background<span class="op">(),</span> req<span class="op">)</span></span>
<span id="cb2-77"><a href="#cb2-77" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> err <span class="op">!=</span> <span class="ot">nil</span> <span class="op">{</span></span>
<span id="cb2-78"><a href="#cb2-78" aria-hidden="true" tabindex="-1"></a> fmt<span class="op">.</span>Printf<span class="op">(</span><span class="st">"Error: %v</span><span class="ch">\n</span><span class="st">"</span><span class="op">,</span> err<span class="op">)</span></span>
<span id="cb2-79"><a href="#cb2-79" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span></span>
<span id="cb2-80"><a href="#cb2-80" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span>
<span id="cb2-81"><a href="#cb2-81" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb2-82"><a href="#cb2-82" aria-hidden="true" tabindex="-1"></a> fmt<span class="op">.</span>Printf<span class="op">(</span><span class="st">"Response: %s</span><span class="ch">\n</span><span class="st">"</span><span class="op">,</span> resp<span class="op">.</span>Content<span class="op">)</span></span>
<span id="cb2-83"><a href="#cb2-83" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
<h2 id="core-components">Core Components</h2>
<h3 id="llmprovider-interface">LLMProvider Interface</h3>
<p>The foundational interface that all LLM provider implementations must
satisfy:</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode go"><code class="sourceCode go"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="kw">type</span> LLMProvider <span class="kw">interface</span> <span class="op">{</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a> Complete<span class="op">(</span>ctx context<span class="op">.</span>Context<span class="op">,</span> req <span class="op">*</span>models<span class="op">.</span>LLMRequest<span class="op">)</span> <span class="op">(*</span>models<span class="op">.</span>LLMResponse<span class="op">,</span> <span class="dt">error</span><span class="op">)</span></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a> CompleteStream<span class="op">(</span>ctx context<span class="op">.</span>Context<span class="op">,</span> req <span class="op">*</span>models<span class="op">.</span>LLMRequest<span class="op">)</span> <span class="op">(<-</span><span class="kw">chan</span> <span class="op">*</span>models<span class="op">.</span>LLMResponse<span class="op">,</span> <span class="dt">error</span><span class="op">)</span></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a> HealthCheck<span class="op">()</span> <span class="dt">error</span></span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a> GetCapabilities<span class="op">()</span> <span class="op">*</span>models<span class="op">.</span>ProviderCapabilities</span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a> ValidateConfig<span class="op">(</span>config <span class="kw">map</span><span class="op">[</span><span class="dt">string</span><span class="op">]</span><span class="kw">interface</span><span class="op">{})</span> <span class="op">(</span><span class="dt">bool</span><span class="op">,</span> <span class="op">[]</span><span class="dt">string</span><span class="op">)</span></span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
<h3 id="circuit-breaker">Circuit Breaker</h3>
<p>Prevents cascading failures when providers are unhealthy:</p>
<ul>
<li><strong>Closed</strong>: Normal operation, requests pass
through</li>
<li><strong>Open</strong>: Provider is failing, requests are
short-circuited with error</li>
<li><strong>Half-Open</strong>: Testing if provider has recovered
(single request allowed)</li>
<li>Configurable failure thresholds, timeouts, and reset intervals</li>
</ul>
<div class="sourceCode" id="cb4"><pre class="sourceCode go"><code class="sourceCode go"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a>cb <span class="op">:=</span> llmprovider<span class="op">.</span>NewDefaultCircuitBreaker<span class="op">(</span><span class="st">"provider-name"</span><span class="op">,</span> provider<span class="op">)</span></span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a>cb<span class="op">.</span>WithFailureThreshold<span class="op">(</span><span class="dv">5</span><span class="op">)</span></span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a>cb<span class="op">.</span>WithOpenStateTimeout<span class="op">(</span><span class="dv">30</span> <span class="op">*</span> time<span class="op">.</span>Second<span class="op">)</span></span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a><span class="co">// Use the circuit breaker as an LLMProvider</span></span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a>resp<span class="op">,</span> err <span class="op">:=</span> cb<span class="op">.</span>Complete<span class="op">(</span>ctx<span class="op">,</span> req<span class="op">)</span></span></code></pre></div>
<h3 id="health-monitor">Health Monitor</h3>
<p>Tracks provider health with configurable thresholds and
intervals:</p>
<ul>
<li><strong>Healthy</strong>: Provider responding normally</li>
<li><strong>Degraded</strong>: Performance issues but still
operational</li>
<li><strong>Unhealthy</strong>: Provider failing consistently</li>
<li><strong>Unknown</strong>: Insufficient data to determine health</li>
<li>Supports listeners for health status changes</li>
</ul>
<div class="sourceCode" id="cb5"><pre class="sourceCode go"><code class="sourceCode go"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a>monitor <span class="op">:=</span> llmprovider<span class="op">.</span>NewHealthMonitor<span class="op">(</span><span class="st">"provider-name"</span><span class="op">,</span> provider<span class="op">)</span></span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a>monitor<span class="op">.</span>WithCheckInterval<span class="op">(</span><span class="dv">10</span> <span class="op">*</span> time<span class="op">.</span>Second<span class="op">)</span></span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a>monitor<span class="op">.</span>WithFailureThreshold<span class="op">(</span><span class="dv">3</span><span class="op">)</span></span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a>health <span class="op">:=</span> monitor<span class="op">.</span>GetHealthStatus<span class="op">()</span></span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span> health <span class="op">==</span> llmprovider<span class="op">.</span>HealthStatusHealthy <span class="op">{</span></span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a> <span class="co">// Provider is healthy</span></span>
<span id="cb5-8"><a href="#cb5-8" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
<h3 id="retry-logic">Retry Logic</h3>
<p>Configurable retry with exponential backoff and jitter:</p>
<ul>
<li>Exponential backoff with configurable multiplier</li>
<li>Jitter to prevent thundering herd problems</li>
<li>HTTP status code detection (429, 500, 502, 503, 504)</li>
<li>Context cancellation support</li>
<li>Max attempts and max backoff duration</li>
</ul>
<div class="sourceCode" id="cb6"><pre class="sourceCode go"><code class="sourceCode go"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a>retry <span class="op">:=</span> llmprovider<span class="op">.</span>NewRetryConfig<span class="op">()</span></span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a>retry<span class="op">.</span>WithMaxAttempts<span class="op">(</span><span class="dv">3</span><span class="op">)</span></span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a>retry<span class="op">.</span>WithBackoffMultiplier<span class="op">(</span><span class="fl">2.0</span><span class="op">)</span></span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a>retry<span class="op">.</span>WithMaxBackoff<span class="op">(</span><span class="dv">60</span> <span class="op">*</span> time<span class="op">.</span>Second<span class="op">)</span></span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true" tabindex="-1"></a>err <span class="op">:=</span> retry<span class="op">.</span>Execute<span class="op">(</span>ctx<span class="op">,</span> <span class="kw">func</span><span class="op">()</span> <span class="dt">error</span> <span class="op">{</span></span>
<span id="cb6-7"><a href="#cb6-7" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> provider<span class="op">.</span>HealthCheck<span class="op">()</span></span>
<span id="cb6-8"><a href="#cb6-8" aria-hidden="true" tabindex="-1"></a><span class="op">})</span></span></code></pre></div>
<h3 id="lazy-provider">Lazy Provider</h3>
<p>Lazy initialization pattern for expensive provider setup:</p>
<ul>
<li>Deferred provider initialization until first use</li>
<li>Configurable timeout and retry attempts</li>
<li>Optional event bus integration for provider lifecycle events</li>
<li>Thread-safe initialization using <code>sync.Once</code></li>
</ul>
<div class="sourceCode" id="cb7"><pre class="sourceCode go"><code class="sourceCode go"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a>factory <span class="op">:=</span> <span class="kw">func</span><span class="op">()</span> <span class="op">(</span>llmprovider<span class="op">.</span>LLMProvider<span class="op">,</span> <span class="dt">error</span><span class="op">)</span> <span class="op">{</span></span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> <span class="op">&</span>MyProvider<span class="op">{</span>name<span class="op">:</span> <span class="st">"lazy-provider"</span><span class="op">},</span> <span class="ot">nil</span></span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true" tabindex="-1"></a>lazy <span class="op">:=</span> llmprovider<span class="op">.</span>NewLazyProvider<span class="op">(</span><span class="st">"lazy-provider"</span><span class="op">,</span> factory<span class="op">)</span></span>
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true" tabindex="-1"></a>lazy<span class="op">.</span>WithTimeout<span class="op">(</span><span class="dv">30</span> <span class="op">*</span> time<span class="op">.</span>Second<span class="op">)</span></span>
<span id="cb7-7"><a href="#cb7-7" aria-hidden="true" tabindex="-1"></a>lazy<span class="op">.</span>WithInitAttempts<span class="op">(</span><span class="dv">3</span><span class="op">)</span></span>
<span id="cb7-8"><a href="#cb7-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-9"><a href="#cb7-9" aria-hidden="true" tabindex="-1"></a><span class="co">// Provider is initialized on first use</span></span>
<span id="cb7-10"><a href="#cb7-10" aria-hidden="true" tabindex="-1"></a>resp<span class="op">,</span> err <span class="op">:=</span> lazy<span class="op">.</span>Complete<span class="op">(</span>ctx<span class="op">,</span> req<span class="op">)</span></span></code></pre></div>
<h2 id="configuration">Configuration</h2>
<h3 id="circuit-breaker-configuration">Circuit Breaker
Configuration</h3>
<table>
<thead>
<tr>
<th>Parameter</th>
<th>Default</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>FailureThreshold</code></td>
<td>5</td>
<td>Number of consecutive failures before opening circuit</td>
</tr>
<tr>
<td><code>OpenStateTimeout</code></td>
<td>30s</td>
<td>How long circuit stays open before moving to half-open</td>
</tr>
<tr>
<td><code>HalfOpenSuccessThreshold</code></td>
<td>3</td>
<td>Number of consecutive successes needed to close circuit</td>
</tr>
<tr>
<td><code>Timeout</code></td>
<td>30s</td>
<td>Request timeout</td>
</tr>
</tbody>
</table>
<h3 id="health-monitor-configuration">Health Monitor Configuration</h3>
<table>
<thead>
<tr>
<th>Parameter</th>
<th>Default</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>CheckInterval</code></td>
<td>30s</td>
<td>How often to perform health checks</td>
</tr>
<tr>
<td><code>FailureThreshold</code></td>
<td>3</td>
<td>Consecutive failures before marking unhealthy</td>
</tr>
<tr>
<td><code>SuccessThreshold</code></td>
<td>2</td>
<td>Consecutive successes needed to become healthy</td>
</tr>
<tr>
<td><code>DegradedThreshold</code></td>
<td>0.8</td>
<td>Performance threshold for degraded state (0-1)</td>
</tr>
</tbody>
</table>
<h3 id="retry-configuration">Retry Configuration</h3>
<table>
<thead>
<tr>
<th>Parameter</th>
<th>Default</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>MaxAttempts</code></td>
<td>3</td>
<td>Maximum number of retry attempts</td>
</tr>
<tr>
<td><code>BackoffMultiplier</code></td>
<td>2.0</td>
<td>Exponential backoff multiplier</td>
</tr>
<tr>
<td><code>InitialBackoff</code></td>
<td>1s</td>
<td>Initial backoff duration</td>
</tr>
<tr>
<td><code>MaxBackoff</code></td>
<td>60s</td>
<td>Maximum backoff duration</td>
</tr>
<tr>
<td><code>Jitter</code></td>
<td>0.1</td>
<td>Jitter factor (0-1)</td>
</tr>
</tbody>
</table>
<h2 id="thread-safety">Thread Safety</h2>
<p>All components are designed for concurrent use:</p>
<ul>
<li><code>CircuitBreaker</code> uses <code>sync.RWMutex</code> for
thread-safe state management</li>
<li><code>HealthMonitor</code> uses atomic operations for status
updates</li>
<li><code>CircuitBreakerManager</code> is thread-safe for concurrent
provider management</li>
<li><code>RetryConfig</code> is immutable after creation</li>
<li><code>LazyProvider</code> uses <code>sync.Once</code> for
thread-safe lazy initialization</li>
</ul>
<h2 id="dependencies">Dependencies</h2>
<ul>
<li><code>digital.vasic.models</code> - For <code>LLMRequest</code>,
<code>LLMResponse</code>, <code>ProviderCapabilities</code> types</li>
<li><code>github.com/sirupsen/logrus</code> - For structured logging in
circuit breaker</li>
<li>Go standard library: <code>context</code>, <code>sync</code>,
<code>time</code>, <code>net/http</code>, etc.</li>
</ul>
<h2 id="development">Development</h2>
<h3 id="building-and-testing">Building and Testing</h3>
<div class="sourceCode" id="cb8"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Build</span></span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a><span class="ex">go</span> build ./...</span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a><span class="co"># Run all tests</span></span>
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true" tabindex="-1"></a><span class="ex">go</span> test ./...</span>
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb8-7"><a href="#cb8-7" aria-hidden="true" tabindex="-1"></a><span class="co"># Run tests with race detection</span></span>
<span id="cb8-8"><a href="#cb8-8" aria-hidden="true" tabindex="-1"></a><span class="ex">go</span> test ./... <span class="at">-race</span></span>
<span id="cb8-9"><a href="#cb8-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb8-10"><a href="#cb8-10" aria-hidden="true" tabindex="-1"></a><span class="co"># Format code</span></span>
<span id="cb8-11"><a href="#cb8-11" aria-hidden="true" tabindex="-1"></a><span class="ex">gofmt</span> <span class="at">-w</span> .</span>
<span id="cb8-12"><a href="#cb8-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb8-13"><a href="#cb8-13" aria-hidden="true" tabindex="-1"></a><span class="co"># Vet code</span></span>
<span id="cb8-14"><a href="#cb8-14" aria-hidden="true" tabindex="-1"></a><span class="ex">go</span> vet ./...</span>
<span id="cb8-15"><a href="#cb8-15" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb8-16"><a href="#cb8-16" aria-hidden="true" tabindex="-1"></a><span class="co"># Check dependencies</span></span>
<span id="cb8-17"><a href="#cb8-17" aria-hidden="true" tabindex="-1"></a><span class="ex">go</span> mod tidy</span>
<span id="cb8-18"><a href="#cb8-18" aria-hidden="true" tabindex="-1"></a><span class="ex">go</span> mod verify</span></code></pre></div>
<h3 id="adding-new-features">Adding New Features</h3>
<ol type="1">
<li>Keep the <code>LLMProvider</code> interface stable - changes break
all implementations</li>
<li>Add new configuration options with sensible defaults</li>
<li>Ensure thread safety for all exported methods</li>
<li>Add comprehensive test coverage</li>
<li>Update documentation in <code>README.md</code> and
<code>CLAUDE.md</code></li>
</ol>
<h2 id="anti-bluff-guarantees-round-276">Anti-Bluff Guarantees
(round-276)</h2>
<p>LLMProvider ships with a layered defence against the failure mode the
constitution captures verbatim:</p>
<blockquote>
<p>Verbatim 2026-05-19 operator mandate (preserved per CONST-049
§11.4.17): <em>"all existing tests and Challenges do work in anti-bluff
manner - they MUST confirm that all tested codebase really works as
expected! We had been in position that all tests do execute with success
and all Challenges as well, but in reality the most of the features does
not work and can't be used! This MUST NOT be the case and execution of
tests and Challenges MUST guarantee the quality, the completition and
full usability by end users of the product!"</em></p>
</blockquote>
<p>The layers, top to bottom:</p>
<ol type="1">
<li><strong>Unit + race</strong>:
<code>GOMAXPROCS=2 go test -count=1 -race -p 1 ./...</code> covers every
<code>pkg/</code> package plus the new <code>challenges/runner/</code>
package. Mocks are permitted ONLY here (CONST-050(A)).</li>
<li><strong>Per-locale Challenge runner</strong>
(<code>challenges/runner/main.go</code>): real
<code>circuit.CircuitBreaker</code> + real
<code>health.HealthMonitor</code> + real <code>retry.RetryConfig</code>
exercised across 5 locale fixtures (<code>en</code>, <code>sr</code>,
<code>de</code>, <code>ja</code>, <code>es</code>). 23 invariants per
run; each carries the actual runtime value in the PASS line.</li>
<li><strong>Paired-mutation Challenge</strong>
(<code>challenges/llmprovider_describe_challenge.sh</code>): wraps the
runner with <code>LLMPROVIDER_MUTATE_RUNNER=1</code>, asserts the runner
DETECTS the planted invariant flip, exits 99 to signal "mutation
correctly observed" (CONST-050(A) §1.1).</li>
<li><strong>Domain-level Challenges</strong>
(<code>challenges/scripts/*.sh</code>): chaos, DDoS, scaling, stress,
UI, UX — env-gated to avoid bluffing when no target endpoint is
configured (<code>SKIP-OK:</code> markers per §11.4.6).</li>
<li><strong>Test-coverage ledger</strong>
(<code>docs/test-coverage.md</code>): every public symbol of
<code>pkg/circuit</code>, <code>pkg/health</code>,
<code>pkg/retry</code>, <code>pkg/provider</code>,
<code>pkg/models</code> traced to the test + Challenge that proves it
works.</li>
</ol>
<h3 id="quick-verification">Quick verification</h3>
<div class="sourceCode" id="cb9"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Layer 1: race-detector clean across every package</span></span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a><span class="va">GOMAXPROCS</span><span class="op">=</span>2 <span class="ex">go</span> test <span class="at">-count</span><span class="op">=</span>1 <span class="at">-race</span> <span class="at">-p</span> 1 ./...</span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb9-4"><a href="#cb9-4" aria-hidden="true" tabindex="-1"></a><span class="co"># Layer 2: per-locale runner (exit 0 on success)</span></span>
<span id="cb9-5"><a href="#cb9-5" aria-hidden="true" tabindex="-1"></a><span class="ex">go</span> run ./challenges/runner/</span>
<span id="cb9-6"><a href="#cb9-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb9-7"><a href="#cb9-7" aria-hidden="true" tabindex="-1"></a><span class="co"># Layer 3: paired-mutation Challenge (exit 0 normal, 99 mutate)</span></span>
<span id="cb9-8"><a href="#cb9-8" aria-hidden="true" tabindex="-1"></a><span class="ex">./challenges/llmprovider_describe_challenge.sh</span> normal</span>
<span id="cb9-9"><a href="#cb9-9" aria-hidden="true" tabindex="-1"></a><span class="ex">./challenges/llmprovider_describe_challenge.sh</span> mutate</span>
<span id="cb9-10"><a href="#cb9-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb9-11"><a href="#cb9-11" aria-hidden="true" tabindex="-1"></a><span class="co"># Layer 4: domain Challenges (env-gated; SKIP-OK without target)</span></span>
<span id="cb9-12"><a href="#cb9-12" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> c <span class="kw">in</span> challenges/scripts/<span class="pp">*</span>.sh<span class="kw">;</span> <span class="cf">do</span> <span class="fu">bash</span> <span class="st">"</span><span class="va">$c</span><span class="st">"</span> <span class="kw">||</span> <span class="fu">true</span><span class="kw">;</span> <span class="cf">done</span></span></code></pre></div>
<h3 id="what-is-not-bluffed">What is NOT bluffed</h3>
<ul>
<li>The runner uses <code>circuit.NewCircuitBreaker</code> (real) +
<code>health.NewHealthMonitor</code> (real) +
<code>retry.CalculateBackoff</code> (real) — no in-process stub circuit
/ monitor / backoff.</li>
<li>The <code>controllableProvider</code> used to drive the breaker is
the smallest concrete LLMProvider satisfying the package interface and
exists ONLY to flip-flop induced failures so the real breaker observes
them. Its failure flag is atomic so probes never race.</li>
<li>Every PASS line includes the runtime value
(<code>isOpen=true shortCircuited=true err=...</code>), so a regression
that broke the state machine would surface in the diff, not just in the
exit code.</li>
<li>The mutation hook is checked by
<code>TestRun_MutationDetected</code> — if a future edit silently
removes the mutation logic, the test fails. This is the §1.1 "paired
mutation" requirement.</li>
<li>Fixtures are plain YAML in <code>challenges/fixtures/</code>; they
MUST agree with the real config defaults
(<code>FailureThreshold=3</code>, initial state <code>closed</code>,
initial health <code>unknown</code>). Mismatch → runner FAIL → Challenge
exit 1.</li>
</ul>
<h3 id="cascade-const-047--const-051a">Cascade (CONST-047 /
CONST-051(A))</h3>
<p>This anti-bluff stack mirrors the pattern in sibling submodules
LeakHub (round 266), MCP_Module (round 267), Models (round 268),
Ouroborous (round 269), Planning (round 270), conversation (round 271),
DebateOrchestrator (round 272), HelixSpecifier (round 273), and is
bumped as part of every meta-repo close-out round.</p>
<h2 id="license">License</h2>
<p>This module is part of the HelixAgent project. See root project for
license details.</p>
<h2 id="contributing">Contributing</h2>
<p>See <code>AGENTS.md</code> for agent coordination guidelines and
<code>CLAUDE.md</code> for AI assistant instructions.</p>
</body>
</html>