Commit 31605bd
committed
QVAC-18183 feat[api]: cancel capability + per-handler cancel scope + structured logging
Lands the three M3a framework primitives so subsequent handler migration
sub-PRs (M3b/M3c) have a single, declarative contract to slot into:
1. `PluginHandlerDefinition.cancel: { scope: "request" | "model" | "none"; hard?: boolean }`
- Added to `schemas/plugin.ts` (`PluginHandlerCancel`, `PluginHandlerCancelScope`)
+ runtime schema validation on `pluginHandlerDefinitionRuntimeSchema`.
- Declared on every built-in plugin manifest (llamacpp-completion,
llamacpp-embedding, whispercpp/parakeet-transcription, nmtcpp-translation,
onnx-tts/ocr, sdcpp-generation). The truth-table assignment is pinned by
`test/unit/plugin-cancel-capability.test.ts`.
2. `RequestRegistry.policy({ kind, oneAtATimePerModel })`:
- Admission control runs before scope/controller allocation in `begin(...)`.
Rejecting a request raises `RequestRejectedByPolicyError` (52420) carrying
`requestId`, `kind`, `modelId`, `reason` — re-exported from `@qvac/sdk` for
`instanceof` checks.
- The worker singleton installs `{ kind: "completion", oneAtATimePerModel: true }`
on first access, matching the llama.cpp addon's single-decode-loop reality.
3. Structured `[request-lifecycle]` emits at begin/cancel/end:
- Fixed log shape `requestId=<id> kind=<kind> modelId=<id|"-"> state=<state>` so
`grep "requestId=abc"` returns the full per-request story chronologically.
- `withRequestContext(logger, ctx)` extends the same prefix to handler-level
emits; threaded through `completion(...)` and into `KvCacheSession` so
KV-cache turn lifecycle shares the request's correlation tuple.
- Single-cancel-emit guard suppresses duplicate cancel lines when
`cancel({ requestId })` is invoked twice.
Verification (from `packages/sdk/`):
- `bun run lint` (eslint + tsc): clean.
- `bun run test:unit`: 49 files / all asserts pass, including the 4 M3a test
files (`plugin-cancel-capability` 7/7, `request-registry` 41/41,
`request-lifecycle-logging` 6/6, `with-request-context` 5/5).
Cursor rules updated alongside the code:
- `request-lifecycle-primitives.mdc`: cancel-capability declaration table,
concurrency-policy contract, structured-logging shape, error-codes table now
carries 52420.
- `docs/request-lifecycle-system.mdc`: migration-roadmap table reflects M3a
shipped; three new FAQ entries explain *why* each primitive was chosen;
implementation files table covers the new modules.
- `error-handling.mdc`: 52420 row added.
This PR is framework-only — no handler is migrated onto `registry.begin(...)` here
beyond the completion handler that landed in M2. Handler migrations follow in
M3b (inference handlers), M3c (non-inference / addon handlers), and M3d (CLI
cancel bridge + cancelHandler retirement).1 parent e2bc0e6 commit 31605bd
25 files changed
Lines changed: 1509 additions & 45 deletions
File tree
- .cursor/rules/sdk
- docs
- packages/sdk
- schemas
- server/bare
- plugins
- llamacpp-completion
- ops
- llamacpp-embedding
- nmtcpp-translation
- onnx-ocr
- onnx-tts
- parakeet-transcription
- sdcpp-generation
- whispercpp-transcription
- runtime
- test/unit
- runtime
- utils
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
| 183 | + | |
183 | 184 | | |
184 | 185 | | |
185 | 186 | | |
| |||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
156 | | - | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
157 | 161 | | |
158 | 162 | | |
| 163 | + | |
159 | 164 | | |
160 | 165 | | |
161 | 166 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
4 | 22 | | |
5 | 23 | | |
6 | 24 | | |
| |||
21 | 39 | | |
22 | 40 | | |
23 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
24 | 47 | | |
25 | 48 | | |
26 | 49 | | |
| |||
43 | 66 | | |
44 | 67 | | |
45 | 68 | | |
| 69 | + | |
| 70 | + | |
46 | 71 | | |
47 | 72 | | |
48 | 73 | | |
| |||
254 | 279 | | |
255 | 280 | | |
256 | 281 | | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
257 | 291 | | |
258 | 292 | | |
259 | 293 | | |
260 | 294 | | |
261 | 295 | | |
262 | 296 | | |
263 | 297 | | |
| 298 | + | |
264 | 299 | | |
265 | 300 | | |
266 | 301 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| |||
309 | 310 | | |
310 | 311 | | |
311 | 312 | | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
312 | 323 | | |
313 | 324 | | |
314 | 325 | | |
| |||
Lines changed: 14 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| |||
415 | 416 | | |
416 | 417 | | |
417 | 418 | | |
418 | | - | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
419 | 429 | | |
420 | 430 | | |
421 | 431 | | |
422 | 432 | | |
| 433 | + | |
423 | 434 | | |
424 | 435 | | |
425 | 436 | | |
| |||
470 | 481 | | |
471 | 482 | | |
472 | 483 | | |
473 | | - | |
| 484 | + | |
474 | 485 | | |
475 | 486 | | |
476 | 487 | | |
| |||
523 | 534 | | |
524 | 535 | | |
525 | 536 | | |
526 | | - | |
| 537 | + | |
527 | 538 | | |
528 | 539 | | |
529 | 540 | | |
| |||
Lines changed: 25 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
19 | 23 | | |
20 | 24 | | |
21 | 25 | | |
| |||
204 | 208 | | |
205 | 209 | | |
206 | 210 | | |
207 | | - | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
208 | 222 | | |
209 | 223 | | |
210 | 224 | | |
| |||
254 | 268 | | |
255 | 269 | | |
256 | 270 | | |
257 | | - | |
| 271 | + | |
258 | 272 | | |
259 | 273 | | |
260 | 274 | | |
| |||
297 | 311 | | |
298 | 312 | | |
299 | 313 | | |
300 | | - | |
| 314 | + | |
301 | 315 | | |
302 | 316 | | |
303 | 317 | | |
| |||
453 | 467 | | |
454 | 468 | | |
455 | 469 | | |
456 | | - | |
457 | | - | |
458 | | - | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
459 | 473 | | |
460 | 474 | | |
461 | 475 | | |
| |||
512 | 526 | | |
513 | 527 | | |
514 | 528 | | |
515 | | - | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
516 | 533 | | |
517 | 534 | | |
518 | 535 | | |
| |||
Lines changed: 11 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
34 | 37 | | |
| 38 | + | |
35 | 39 | | |
36 | 40 | | |
37 | 41 | | |
| |||
96 | 100 | | |
97 | 101 | | |
98 | 102 | | |
| 103 | + | |
99 | 104 | | |
100 | 105 | | |
101 | 106 | | |
| |||
141 | 146 | | |
142 | 147 | | |
143 | 148 | | |
| 149 | + | |
| 150 | + | |
144 | 151 | | |
145 | 152 | | |
146 | 153 | | |
| |||
151 | 158 | | |
152 | 159 | | |
153 | 160 | | |
154 | | - | |
| 161 | + | |
155 | 162 | | |
156 | 163 | | |
157 | 164 | | |
| |||
210 | 217 | | |
211 | 218 | | |
212 | 219 | | |
| 220 | + | |
213 | 221 | | |
214 | 222 | | |
215 | 223 | | |
| |||
220 | 228 | | |
221 | 229 | | |
222 | 230 | | |
| 231 | + | |
223 | 232 | | |
224 | 233 | | |
225 | 234 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
113 | 116 | | |
114 | 117 | | |
115 | 118 | | |
| |||
0 commit comments