Repository navigation
Commit 14332f2
Fix Foundry Local agent reliability + telemetry pipeline
The /api/command endpoint was reliably returning RUN_ERROR for all chats
because of three stacked Foundry Local + agent-framework bugs. This
commit fixes all three plus a telemetry pipeline bug discovered during
verification, plus two minor production papercuts found along the way.
## Streaming wrapper (agent.py)
Added _NormalizingChatClient._inner_get_response that translates AG-UI's
forced stream=True into a non-streaming Foundry call, then synthesizes
a single ChatCompletionChunk so the rest of agent-framework sees what
it expects. Foundry-Local#422 makes streaming unreliable inside the
long-running uvicorn process; non-streaming works.
Also strips AG-UI's auto-injected "Current state of the application:"
system message before sending to Foundry. With 200+ todos this message
is 75k+ chars and blows the 32k context window of qwen2.5-coder-0.5b.
## Smoke test (main.py)
Added _smoke_test_inference that probes the FULL agent payload (live
_build_instructions() + serialized ALL_TOOLS) before declaring a model
switch successful. Catches Foundry NPU runtime crashes (#506) at switch
time so users see a clear rollback instead of the server dying on the
first chat. _commit_switch now snapshots prior state and restores on
failure. Persists target_model.id (full ID, not alias) so switches
survive restart and don't bounce back to broken NPU defaults.
## EP-aware startup (agent.py)
Captures EpDownloadResult and filters cached models by registered
execution providers. CPU + WebGPU are always considered registered.
Without this, cached[0] auto-selection lands on a NPU model when
VitisAI EP failed to register, leaving the agent unusable.
## Idempotent telemetry init (telemetry.py)
Uvicorn imports main.py twice (worker + main process). OpenTelemetry
refuses to replace the active TracerProvider, but the old code still
mutated the module-level _ui_span_exporter on every call — leaving it
pointing at an orphaned exporter that never received spans. Added an
_otel_initialized guard so init_otel() is no-op on subsequent calls.
This restored ai.response, flow, and http.request events in the Stats
panel along with token counts.
## App config timezone shadow (app_config.py)
The local timezone() function shadowed the datetime.timezone import,
breaking app_config.set() with "'function' object has no attribute
'utc'". Imported datetime.timezone as _tz instead.
## Launch script Get-FileHash fallback (launch.ps1)
On rare PS 5.1 configurations Microsoft.PowerShell.Utility isn't
auto-imported when launch.ps1 runs via the taskbean:// protocol
handler, surfacing a confusing red error. Added a manual SHA256
fallback so dep-stamp gating still works silently.
## Testing
- 17 new unit tests in app/agent/test_phase0_fixes.py covering all
five fixes including edge cases (size guard on state-context filter,
smoke test rollback, persist-on-success, clear-on-failure).
- Full Python suite: 113/113 (test_phase0_fixes + test_agui_refactor
+ test_version_endpoint + test_fs_endpoints + test_projects_api
+ test_usage_scanners).
- CLI suite: 149/149.
- Manual E2E verified end-to-end through the UI: chat works, tasks
created, ai.response/flow/http.request spans appear in the Stats
panel with token counts and durations.
## Known limitation: NPU + agent payloads
NPU runtimes (VitisAI, QNN) reliably crash Foundry on requests
containing the full system prompt + 10-tool definition list. This is
Foundry-Local#506 and is out of taskbean's control. The smoke test
catches this at switch time and rolls back with an actionable error
message ("Foundry closed the connection ... NPU models are
particularly prone to this — see Foundry-Local#506") rather than
letting the real chat take down the server. CPU and GPU paths are
unaffected.
## Documentation
Updated .github/copilot-instructions.md with the Playwright MCP
recovery procedure (use configure-copilot agent to restart the MCP
server, then click the bridge extension to reconnect).
References:
- microsoft/foundry-local#422 (streaming bug)
- microsoft/foundry-local#506 (NPU + tools)
- microsoft/foundry-local#558 (VitisAI EP)
- microsoft/agent-framework#4084 (multi-modal content)
Co-authored-by: Copilot <[email protected]>1 parent 1da3503 commit 14332f2
7 files changed
Lines changed: 964 additions & 13 deletions
File tree
- .github
- app
- agent
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
306 | 306 | | |
307 | 307 | | |
308 | 308 | | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
309 | 332 | | |
310 | 333 | | |
311 | 334 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
63 | 75 | | |
64 | 76 | | |
65 | 77 | | |
| |||
109 | 121 | | |
110 | 122 | | |
111 | 123 | | |
| 124 | + | |
112 | 125 | | |
113 | 126 | | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
114 | 138 | | |
115 | 139 | | |
116 | 140 | | |
| |||
140 | 164 | | |
141 | 165 | | |
142 | 166 | | |
143 | | - | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
144 | 173 | | |
145 | 174 | | |
146 | 175 | | |
147 | | - | |
148 | | - | |
149 | | - | |
| 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 | + | |
150 | 204 | | |
151 | 205 | | |
152 | 206 | | |
| |||
229 | 283 | | |
230 | 284 | | |
231 | 285 | | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
232 | 298 | | |
233 | 299 | | |
234 | 300 | | |
| |||
268 | 334 | | |
269 | 335 | | |
270 | 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 | + | |
271 | 495 | | |
272 | 496 | | |
273 | 497 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
109 | | - | |
| 109 | + | |
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
| |||
0 commit comments