adaptergate 0.5.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. adaptergate-0.5.1/LICENSE +189 -0
  2. adaptergate-0.5.1/NOTICE +53 -0
  3. adaptergate-0.5.1/PKG-INFO +437 -0
  4. adaptergate-0.5.1/README.md +396 -0
  5. adaptergate-0.5.1/pyproject.toml +68 -0
  6. adaptergate-0.5.1/setup.cfg +4 -0
  7. adaptergate-0.5.1/src/adaptergate/__init__.py +5 -0
  8. adaptergate-0.5.1/src/adaptergate/cli.py +588 -0
  9. adaptergate-0.5.1/src/adaptergate/core/__init__.py +0 -0
  10. adaptergate-0.5.1/src/adaptergate/core/procl.py +479 -0
  11. adaptergate-0.5.1/src/adaptergate/data/seed_recipes.jsonl +7 -0
  12. adaptergate-0.5.1/src/adaptergate/eval/__init__.py +0 -0
  13. adaptergate-0.5.1/src/adaptergate/eval/bird_eval.py +292 -0
  14. adaptergate-0.5.1/src/adaptergate/examples/__init__.py +0 -0
  15. adaptergate-0.5.1/src/adaptergate/examples/mock_scorer.py +98 -0
  16. adaptergate-0.5.1/src/adaptergate/gating/__init__.py +40 -0
  17. adaptergate-0.5.1/src/adaptergate/gating/cluster.py +119 -0
  18. adaptergate-0.5.1/src/adaptergate/gating/holdout_eval.py +153 -0
  19. adaptergate-0.5.1/src/adaptergate/gating/regression_gate.py +474 -0
  20. adaptergate-0.5.1/src/adaptergate/gating/replay_buffer.py +105 -0
  21. adaptergate-0.5.1/src/adaptergate/observability/__init__.py +0 -0
  22. adaptergate-0.5.1/src/adaptergate/observability/silent_collapse.py +334 -0
  23. adaptergate-0.5.1/src/adaptergate/recipes/__init__.py +33 -0
  24. adaptergate-0.5.1/src/adaptergate/recipes/models.py +151 -0
  25. adaptergate-0.5.1/src/adaptergate/recipes/recommend.py +142 -0
  26. adaptergate-0.5.1/src/adaptergate/recipes/store.py +100 -0
  27. adaptergate-0.5.1/src/adaptergate/serving/__init__.py +0 -0
  28. adaptergate-0.5.1/src/adaptergate/serving/qwen_backend.py +148 -0
  29. adaptergate-0.5.1/src/adaptergate.egg-info/PKG-INFO +437 -0
  30. adaptergate-0.5.1/src/adaptergate.egg-info/SOURCES.txt +41 -0
  31. adaptergate-0.5.1/src/adaptergate.egg-info/dependency_links.txt +1 -0
  32. adaptergate-0.5.1/src/adaptergate.egg-info/entry_points.txt +2 -0
  33. adaptergate-0.5.1/src/adaptergate.egg-info/requires.txt +26 -0
  34. adaptergate-0.5.1/src/adaptergate.egg-info/top_level.txt +1 -0
  35. adaptergate-0.5.1/tests/test_bird_eval.py +120 -0
  36. adaptergate-0.5.1/tests/test_cluster.py +157 -0
  37. adaptergate-0.5.1/tests/test_holdout_eval.py +111 -0
  38. adaptergate-0.5.1/tests/test_recipes.py +279 -0
  39. adaptergate-0.5.1/tests/test_regression_gate.py +194 -0
  40. adaptergate-0.5.1/tests/test_replay_buffer.py +86 -0
  41. adaptergate-0.5.1/tests/test_slice_attribution.py +193 -0
  42. adaptergate-0.5.1/tests/test_slice_attribution_robustness.py +101 -0
  43. adaptergate-0.5.1/tests/test_v04_retention.py +176 -0
@@ -0,0 +1,189 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Support. While redistributing the Work or
166
+ Derivative Works thereof, You may accept support, warranty, indemnity,
167
+ or other liability obligations and/or rights consistent with this
168
+ License. However, in accepting such obligations, You may act only
169
+ on Your own behalf and on Your sole responsibility, not on behalf
170
+ of any other Contributor, and only if You agree to indemnify,
171
+ defend, and hold each Contributor harmless for any liability
172
+ incurred by, or claims asserted against, such Contributor by reason
173
+ of your accepting any such warranty or support.
174
+
175
+ END OF TERMS AND CONDITIONS
176
+
177
+ Copyright 2026 Kazdov
178
+
179
+ Licensed under the Apache License, Version 2.0 (the "License");
180
+ you may not use this file except in compliance with the License.
181
+ You may obtain a copy of the License at
182
+
183
+ http://www.apache.org/licenses/LICENSE-2.0
184
+
185
+ Unless required by applicable law or agreed to in writing, software
186
+ distributed under the License is distributed on an "AS IS" BASIS,
187
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
188
+ implied. See the License for the specific language governing permissions
189
+ and limitations under the License.
@@ -0,0 +1,53 @@
1
+ adaptergate
2
+ Copyright (c) 2026
3
+ Licensed under the Apache License, Version 2.0.
4
+
5
+ This product builds upon the following research and software. All upstream
6
+ work is credited to its authors; this project's contribution is its
7
+ original implementation, integration, and the regression-gating system.
8
+
9
+ ============================================================================
10
+ PAPERS (algorithmic foundations)
11
+ ============================================================================
12
+
13
+ ProCL — arXiv 2605.13162
14
+ "Continual Fine-Tuning of LLMs via Program Memory"
15
+ Used in: src/adaptergate/core/procl.py
16
+ Our contribution: independent re-implementation from the paper, bug fixes
17
+ (composition cross-terms, dtype handling, autograd reset), production
18
+ integration. The algorithm is credited to the paper authors.
19
+
20
+ Silent Collapse — arXiv 2605.14588
21
+ "Silent Collapse in Recursive Learning Systems"
22
+ Used in: src/adaptergate/observability/silent_collapse.py
23
+ Our contribution: independent re-implementation of the MTR framework.
24
+ The drift signature (H_g/H_0 < 0.5 with PPL_g/PPL_0 ≈ 1) is credited
25
+ to the paper authors.
26
+
27
+ Online-LoRA — arXiv 2411.05663
28
+ "Online-LoRA: Task-free Online Continual Learning via LoRA"
29
+ Concepts of online distribution-shift detection informed our
30
+ regression-gating design.
31
+
32
+ PreFT — arXiv 2605.14217
33
+ "Prefill-only Finetuning for Efficient Inference"
34
+ Referenced as a future integration once code is publicly released
35
+ by the authors. Not currently integrated.
36
+
37
+ N-LoRA / O-LoRA — arXiv 2408.06133, arXiv 2310.14152
38
+ Orthogonal LoRA subspace work, referenced in the regression-gating
39
+ literature review.
40
+
41
+ ============================================================================
42
+ SOFTWARE
43
+ ============================================================================
44
+
45
+ vLLM — https://github.com/vllm-project/vllm — Apache License 2.0
46
+ Used as serving backbone via its public Python API.
47
+ No source modifications are distributed in this repository.
48
+
49
+ bitsandbytes — Apache License 2.0
50
+ Used for 4-bit quantization.
51
+
52
+ transformers, peft, accelerate (HuggingFace) — Apache License 2.0
53
+ torch — BSD-3-Clause
@@ -0,0 +1,437 @@
1
+ Metadata-Version: 2.4
2
+ Name: adaptergate
3
+ Version: 0.5.1
4
+ Summary: CI gate for per-tenant LoRA adapters that update online. Slice-level reject explain. Serving-stack agnostic.
5
+ Author: Kazdov
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/OriginalKazdov/adaptergate
8
+ Project-URL: Repository, https://github.com/OriginalKazdov/adaptergate
9
+ Keywords: llm,lora,regression,continual-learning,fine-tuning,evaluation
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Requires-Python: >=3.11
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ License-File: NOTICE
18
+ Requires-Dist: typer>=0.12
19
+ Requires-Dist: pydantic>=2.9.0
20
+ Requires-Dist: rich
21
+ Provides-Extra: ml
22
+ Requires-Dist: torch>=2.5.0; extra == "ml"
23
+ Requires-Dist: transformers>=4.45.0; extra == "ml"
24
+ Requires-Dist: peft>=0.13.0; extra == "ml"
25
+ Requires-Dist: accelerate>=1.0.0; extra == "ml"
26
+ Requires-Dist: bitsandbytes; extra == "ml"
27
+ Requires-Dist: sentencepiece; extra == "ml"
28
+ Requires-Dist: protobuf; extra == "ml"
29
+ Requires-Dist: numpy; extra == "ml"
30
+ Requires-Dist: pandas; extra == "ml"
31
+ Requires-Dist: tqdm; extra == "ml"
32
+ Provides-Extra: serve
33
+ Requires-Dist: vllm; extra == "serve"
34
+ Provides-Extra: sql-example
35
+ Requires-Dist: sqlglot>=25.0.0; extra == "sql-example"
36
+ Provides-Extra: dev
37
+ Requires-Dist: pytest; extra == "dev"
38
+ Requires-Dist: ruff; extra == "dev"
39
+ Requires-Dist: ipython; extra == "dev"
40
+ Dynamic: license-file
41
+
42
+ # adaptergate
43
+
44
+ **CI gate for per-tenant LoRA adapters that update online.**
45
+
46
+ When a customer-specific LoRA adapter is about to be promoted to production,
47
+ `adaptergate gate` evaluates the candidate against a per-tenant held-out set
48
+ and refuses to promote it if aggregate quality drops more than ε. Rejected
49
+ adapters go to a replay buffer for later analysis. CI-friendly exit codes.
50
+ Serving-stack agnostic: you supply a scorer callable, we supply the gate.
51
+
52
+ When your held-out queries carry slice tags (intent, language, difficulty,
53
+ whatever) and natural-language text, adaptergate doesn't just say "score
54
+ dropped." It tells you **which behavioral slice broke**, **shows you the
55
+ failing query IDs**, and **describes what the failing queries have in
56
+ common** — the line your on-call PM screenshots into Slack at 2am.
57
+
58
+ ```
59
+ $ adaptergate gate \
60
+ --tenant acme \
61
+ --candidate adapter_v19 \
62
+ --baseline adapter_v18 \
63
+ --holdout data/acme_holdout.jsonl \
64
+ --scorer my_eval:score
65
+ ─────────────────────────────────── REJECTED ───────────────────────────────────
66
+ Tenant: acme
67
+ Candidate: adapter_v19
68
+ Baseline: adapter_v18
69
+ Score: 0.924 → 0.353 (Δ=-0.571, ε=0.02)
70
+ Held-out: n=25
71
+ Reason: REJECTED: aggregate 0.924 → 0.353 (Δ=-0.571) over n=25.
72
+ Drop exceeds ε=0.02.
73
+
74
+ DRIVER SLICE: intent=billing_dispute 0.946 → 0.113 (Δ=-0.834, 10/10 regressed)
75
+ Pattern: all 10 failing queries contain: "order_id", "refund"
76
+ Failing query IDs: billing_1, billing_2, billing_3, billing_4, billing_5 + 5 more
77
+
78
+ Slice breakdown (most-regressed first):
79
+ -0.834 10/10 regressed intent=billing_dispute
80
+ -0.396 15/15 regressed intent=order_status
81
+
82
+ 25 unique queries regressed (slice n_regressed values may sum higher when
83
+ queries belong to multiple slices)
84
+ $ echo $?
85
+ 1
86
+ ```
87
+
88
+ That `Pattern: ...` line is N-gram frequency analysis — no LLM, no extra
89
+ dependencies, no cloud calls. Just the common words across failing queries.
90
+ Slack-paste-friendly by design.
91
+
92
+ ---
93
+
94
+ ## Why it exists
95
+
96
+ > *91% of production LLMs experience silent behavioral drift within 90 days.
97
+ > Detection lag from onset to first user complaint: 14-18 days.*
98
+ > — InsightFinder, 2026
99
+
100
+ The dominant failure mode for teams serving per-customer fine-tuned LLMs is
101
+ **silent regression on online updates**: a sub-skill (e.g. `JOIN-with-aggregate`
102
+ accuracy) collapses from 91% to 64% while the aggregate eval stays green at
103
+ 87%, and you only find out when a customer Slacks support two weeks later.
104
+
105
+ ### Where adaptergate sits in the landscape
106
+
107
+ Generic LLM eval CIs ([Braintrust](https://www.braintrust.dev/),
108
+ [DeepEval](https://deepeval.com/), [LangSmith](https://www.langchain.com/langsmith),
109
+ [Promptfoo](https://www.promptfoo.dev/), [W&B Registry](https://wandb.ai/site/automations/))
110
+ all support pre-deploy CI gating with non-zero exit on regression. They're
111
+ built for the case where the artifact under test is a **prompt or chain
112
+ commit**, scored against a single fixed dataset.
113
+
114
+ Runtime guardrails ([Galileo Luna-2](https://galileo.ai/luna-2),
115
+ [Arize](https://arize.com/), [Langfuse](https://langfuse.com/)) catch failures
116
+ after the model has shipped.
117
+
118
+ adaptergate is for the workflow those tools aren't built for:
119
+
120
+ - **Per-tenant scoping** — each customer has its own held-out set; regression
121
+ is measured against that customer's queries, not a shared benchmark.
122
+ - **Online update cadence** — every accepted user query may trigger a new
123
+ adapter version, not a quarterly retrain.
124
+ - **LoRA-adapter aware** — the artifact under test is a binary adapter, not
125
+ a prompt commit.
126
+ - **Replay buffer for rejected updates** — rejects don't disappear; they're
127
+ preserved with the full gate decision for later analysis or downstream
128
+ repair logic.
129
+
130
+ Closest neighbors:
131
+
132
+ - [Predibase / LoRAX](https://github.com/predibase/lorax) — per-tenant LoRA
133
+ *serving* and continuous fine-tuning, no CI gate primitive.
134
+ - [Baseten rank-1 LoRA continual learning](https://www.baseten.co/research/write-small-learn-forever/)
135
+ — same problem shape (shadow replica, ring buffer for rollback) but it's
136
+ research infrastructure, not a product, and has no per-tenant eval gate.
137
+
138
+ ### What we measured
139
+
140
+ Reference run on Qwen 2.5 Coder 14B (4-bit, RTX 4090) with ProCL multi-LoRA
141
+ slots on BIRD-SQL `student_club`:
142
+
143
+ | | Before update | After update | Δ |
144
+ |---|---|---|---|
145
+ | `student_club` memorize set | 55.7% | 82.3% | **+26.6pp** |
146
+ | Held-out other DBs (forgetting check) | 45.0% | 55.0% | **+10.0pp** |
147
+
148
+ Zero catastrophic forgetting. The gate fires when this property breaks —
149
+ the moment a candidate update would have damaged the held-out other-DBs
150
+ score, it gets blocked.
151
+
152
+ ---
153
+
154
+ ## Install
155
+
156
+ ```bash
157
+ pip install adaptergate
158
+ ```
159
+
160
+ Core install is lightweight (typer + pydantic + rich). The gate doesn't
161
+ require torch, transformers, or any specific serving stack.
162
+
163
+ For the BIRD-SQL example or ProCL/Silent Collapse reference implementations:
164
+
165
+ ```bash
166
+ pip install "adaptergate[ml]" # adds torch/transformers/peft/bitsandbytes
167
+ pip install "adaptergate[sql-example]" # adds sqlglot for the BIRD-SQL demo
168
+ ```
169
+
170
+ ---
171
+
172
+ ## Quickstart
173
+
174
+ ### 1. Write a scorer
175
+
176
+ A scorer is any Python callable `(adapter_id: str, query: dict) -> float`
177
+ returning a score in `[0.0, 1.0]`. You almost certainly already have one
178
+ for your eval suite — wire it up.
179
+
180
+ ```python
181
+ # my_eval.py
182
+ def score(adapter_id: str, query: dict) -> float:
183
+ output = run_adapter(adapter_id, query["prompt"])
184
+ return float(matches_gold(output, query["gold"]))
185
+ ```
186
+
187
+ ### 2. Seed a held-out set
188
+
189
+ ```bash
190
+ adaptergate holdout add \
191
+ --tenant acme \
192
+ --holdout data/acme_holdout.jsonl \
193
+ '{"question_id": "q1", "prompt": "...", "gold": "..."}'
194
+ # ... add at least 20 queries (configurable)
195
+ ```
196
+
197
+ ### 3. Run the gate
198
+
199
+ ```bash
200
+ adaptergate gate \
201
+ --tenant acme \
202
+ --candidate adapter_v18 \
203
+ --baseline adapter_v17 \
204
+ --holdout data/acme_holdout.jsonl \
205
+ --scorer my_eval:score \
206
+ --epsilon 0.02 \
207
+ --audit-log data/audit.jsonl \
208
+ --replay-path data/rejected.jsonl
209
+ ```
210
+
211
+ Exit code 0 = accepted (safe to promote). 1 = rejected. Use this in your
212
+ deploy script.
213
+
214
+ ### 4. Try without writing any code
215
+
216
+ ```bash
217
+ # 30 fake queries
218
+ for i in $(seq 1 30); do
219
+ adaptergate holdout add --tenant demo --holdout demo.jsonl \
220
+ "{\"question_id\": \"q$i\"}"
221
+ done
222
+
223
+ adaptergate gate \
224
+ --tenant demo \
225
+ --candidate adapter_good_v18 \
226
+ --baseline adapter_bad_v17 \
227
+ --holdout demo.jsonl \
228
+ --scorer adaptergate.examples.mock_scorer:score
229
+ ```
230
+
231
+ ---
232
+
233
+ ## How the gate decides
234
+
235
+ ```
236
+ accepted = (score_candidate - score_baseline) >= -epsilon
237
+ ```
238
+
239
+ That's the headline rule. The gate runs the scorer against the held-out set
240
+ for both the candidate and the baseline, takes the average delta, and
241
+ compares to `epsilon` (default `0.02` = 2pp tolerance).
242
+
243
+ ### Modes
244
+
245
+ - **Default (aggregate):** Reject if average drop > ε.
246
+ - **`--strict`:** Also reject if any single query that scored 1.0 on baseline
247
+ now scores less. Catches regression-via-averaging.
248
+ - **`--no-require-calibration`:** Allow promotion of a first adapter when no
249
+ baseline exists. Useful for bootstrapping a new tenant.
250
+
251
+ ### Per-query breakdown
252
+
253
+ Every `GateDecision` includes `per_query`: a list of
254
+ `{query_id, score_baseline, score_candidate, delta}` records. Use it to
255
+ surface *which* queries regressed, not just *how much*.
256
+
257
+ ```python
258
+ decision = gate.evaluate(...)
259
+ for q in decision.regressions:
260
+ print(q["query_id"], q["delta"])
261
+ ```
262
+
263
+ ---
264
+
265
+ ## Recipe library — the answer to "what now?"
266
+
267
+ When the gate rejects with a driver slice, adaptergate can recommend
268
+ paper-derived intervention recipes ranked by **empirical efficacy across
269
+ prior applications**. Generic eval frameworks tell you *what* failed;
270
+ adaptergate v0.5+ tells you *what to do*, citing the paper each recipe
271
+ came from.
272
+
273
+ ```bash
274
+ # Seed your recipe library from the bundled 7-recipe starter
275
+ adaptergate recipes seed --recipes data/recipes.jsonl
276
+
277
+ # After a gate rejects (audit log captures the decision)
278
+ adaptergate recommend-cmd \
279
+ --decision data/audit.jsonl \
280
+ --recipes data/recipes.jsonl \
281
+ --top-k 3
282
+ ```
283
+
284
+ ```
285
+ Recipes for driver slice: intent=billing_dispute
286
+
287
+ 1. ProCL slot rebalance for the driver slice [no prior applications]
288
+ id: procl_slot_rebalance_v1
289
+ intervention: slot_rebalance
290
+ source: arXiv 2605.13162
291
+ Allocate a new ProCL program slot dedicated to the driver-slice queries...
292
+
293
+ 2. Online-LoRA learning rate decay [no prior applications]
294
+ id: online_lora_lr_decay_v1
295
+ source: arXiv 2411.05663
296
+ Reduce the LoRA learning rate and re-run training...
297
+ ```
298
+
299
+ The compounding mechanic, scope-honest:
300
+
301
+ - **Within a single store**: every recipe application you log via
302
+ ``RecipeStore.add_application()`` strengthens the recommender's ranking
303
+ for that store. Recipes with positive empirical efficacy outrank fresh
304
+ entries. This works today.
305
+ - **Across tenants in a single store**: applications carry an anonymized
306
+ ``tenant_hash``; queries that aggregate across tenants ("recipe X has
307
+ worked for N other tenants on this slice signature") will land in v0.6.
308
+ - **Across organizations** (your store vs. some other team's store): NOT
309
+ shipped. There is no centralized recipe-application service. Your
310
+ ``applications.jsonl`` stays on your disk.
311
+
312
+ Seven seed recipes ship with the package: ProCL slot rebalance,
313
+ Online-LoRA LR decay, N-LoRA orthogonalization, Silent Collapse
314
+ trust-throttle, StableEdit localized patch (all paper-cited), plus
315
+ two heuristic recipes (replay-buffer prune, LoRA rank reduction —
316
+ explicitly tagged in the seed file as ``"(heuristic)"`` since they're
317
+ common practice rather than paper-cited). Load via
318
+ ``adaptergate recipes seed --recipes data/recipes.jsonl``.
319
+
320
+ ---
321
+
322
+ ## CI integration & output formats
323
+
324
+ ```bash
325
+ # Human-readable CLI output (default)
326
+ adaptergate gate --tenant acme --candidate v19 --baseline v18 \
327
+ --holdout data/acme.jsonl --scorer my_eval:score
328
+
329
+ # Structured JSON for piping into your own tooling
330
+ adaptergate gate ... --format json
331
+
332
+ # GitHub-flavored Markdown for PR comments
333
+ adaptergate gate ... --format pr-comment | gh pr comment "$PR" --body-file -
334
+
335
+ # Configurable failing-ID preview
336
+ adaptergate gate ... --show-failures 20
337
+
338
+ # Detect stale held-out sets
339
+ adaptergate gate ... --staleness-threshold-days 14
340
+ ```
341
+
342
+ The CLI surfaces three kinds of warnings on stderr (so they survive
343
+ ``--format json`` piping):
344
+
345
+ - **Malformed slices** — when a query's ``slices`` field is a string
346
+ instead of a list (common typo).
347
+ - **Suspected duplicate slice tags** — when two slice tags look alike
348
+ (e.g. ``"billing_dispute"`` and ``"intent=billing_dispute"``), reported
349
+ via ``GateDecision.suspected_duplicate_slices``.
350
+ - **Held-out staleness** — when your held-out set hasn't been refreshed
351
+ in N days. Stops you from misreading eval-set drift as adapter drift.
352
+
353
+ ---
354
+
355
+ ## What's in the box (v0.5)
356
+
357
+ ```
358
+ adaptergate/
359
+ ├── gating/
360
+ │ ├── regression_gate.py # RegressionGate + GateConfig + GateDecision + SliceAttribution
361
+ │ ├── holdout_eval.py # HoldoutSet — per-tenant queries, JSONL-backed, staleness check
362
+ │ ├── replay_buffer.py # ReplayBuffer — rejected updates with full decision
363
+ │ └── cluster.py # find_pattern() — N-gram failure pattern detection
364
+ ├── recipes/
365
+ │ ├── models.py # Recipe + RecipeApplication + RecipeRecommendation
366
+ │ ├── store.py # RecipeStore — JSONL-backed library + application log
367
+ │ └── recommend.py # recommend(decision, store) — efficacy-ranked picks
368
+ ├── data/
369
+ │ └── seed_recipes.jsonl # 7 seed recipes derived from May-2026 CL literature
370
+ ├── cli.py # `adaptergate` entry point
371
+ └── examples/
372
+ └── mock_scorer.py # deterministic mock for trying things out
373
+ ```
374
+
375
+ Tests: 92 unit tests across the gating subsystem, cluster, robustness,
376
+ recipes, and BIRD-SQL eval primitives. Run with `pytest`. Ruff-clean.
377
+
378
+ ### Scope
379
+
380
+ **In:** per-tenant gate, slice-level attribution, driver slice, failing
381
+ query IDs, N-gram pattern of failing queries, replay buffer, audit log,
382
+ CI exit codes.
383
+
384
+ **NOT in (yet):** LLM-generated cause hypothesis, automatic counterfactual
385
+ training data, recipe library for repairs, multi-base-model orchestration,
386
+ hosted dashboard. See **Roadmap** below — these are deliberate omissions.
387
+
388
+ ### Built on (cited, not invented)
389
+
390
+ adaptergate implements ideas from published research. See [NOTICE](./NOTICE)
391
+ for full attribution.
392
+
393
+ - **ProCL** — arXiv 2605.13162 — program-memory LoRA slot architecture
394
+ - **Silent Collapse / MTR** — arXiv 2605.14588 — drift detection framework
395
+ - **Online-LoRA** — arXiv 2411.05663 — task-free online LoRA updates
396
+ - **N-LoRA / O-LoRA** — arXiv 2408.06133, arXiv 2310.14152 — orthogonal subspaces
397
+
398
+ Our contribution: independent production implementations + the per-tenant
399
+ gating layer + slice-level attribution + N-gram failure-pattern detection +
400
+ audit log + replay buffer + CLI.
401
+
402
+ ---
403
+
404
+ ## Roadmap
405
+
406
+ **v0.1** — basic regression gate (✅ shipped)
407
+ **v0.2** — slice-level attribution + driver slice + failing IDs (✅ shipped)
408
+ **v0.3** — N-gram failure pattern + robustness fixes (✅ shipped)
409
+ **v0.4** — `--format json/pr-comment`, `--show-failures N`, duplicate-slice
410
+ detection, holdout staleness check (✅ shipped)
411
+ **v0.5** — **recipe library** + `observed_efficacy` + `recommend()` API +
412
+ 7 seeded paper-derived recipes (✅ this release — the moat substrate)
413
+
414
+ **v0.5.x / v0.6**:
415
+ - Automated radar.db → recipe ingestion (LLM-extracted typed recipes from
416
+ newly-published CL papers, with manual review queue)
417
+ - Cross-tenant pattern matching ("this regression style failed at N other
418
+ tenants") — emerges naturally as the application corpus grows
419
+ - Diff view (`adaptergate review --query X`) — needs scorer-contract change
420
+ - Baseline drift handling — gate currently assumes baseline is ground
421
+ truth, wrong for online-updating adapters
422
+ - GitHub PR comment action (wrap `--format pr-comment` in a reusable action)
423
+
424
+ ---
425
+
426
+ ## Status
427
+
428
+ **v0.5 — early but production-tested.** 92 tests, ruff clean, wheel built
429
+ clean. API may change before v1.0; the gate decision schema carries a
430
+ `schema_version` field so audit-log consumers can handle older records.
431
+ Issues and PRs welcome.
432
+
433
+ ---
434
+
435
+ ## License
436
+
437
+ Apache 2.0. See [LICENSE](./LICENSE) and [NOTICE](./NOTICE).