Skip to content

fix(agent): faster purchasing run, clean rationale, no silent hangs#5

Open
eugnmueller-87 wants to merge 1 commit into
mainfrom
fix/agent-run-ux
Open

fix(agent): faster purchasing run, clean rationale, no silent hangs#5
eugnmueller-87 wants to merge 1 commit into
mainfrom
fix/agent-run-ux

Conversation

@eugnmueller-87

Copy link
Copy Markdown
Owner

Fixes three issues you spotted on the weekly purchasing screen.

1. The run was slow (~60s+) — now parallel

It made one LLM call per product, serially. Split the copilot's sourcing call into signal-gather (DB, main thread) + the LLM call (pure network), so the network calls fire in a thread pool — N round-trips collapse into ~one. recommend_sourcing stays the single mockable seam (accepts pre-gathered signals); all copilot mocks updated. Decisions are unchanged — only wall-clock.

2. Debug text leaked into the cards

Rationale showed the raw [trigger] {evidence dict} | net_need=N | bundle_tier=X | prefix. The audit log keeps the full string; the UI now shows only the human rationale (cleanRationale).

3. Silent hangs

api() gains an optional timeout (AbortController); the run (90s) and insights (60s) use it and show an error + Retry instead of spinning forever when an LLM call stalls.

Note on the original 'can't place escalated items'

That was the €50k escalate threshold — already fixed in the merged PR #4 (€150k → these become propose/approvable). This PR is the other three issues.

Verification

  • 310 tests pass (the parallelization caught + fixed 12 mock-signature regressions across 4 test files), ruff clean, frontend syntax clean.

Demo-first.

Three UX/perf fixes for the weekly purchasing screen:

1. Parallelize the run. It made one LLM call PER product, serially (~60s+).
   Split the copilot's sourcing call into signal-gather (DB, main thread) and
   the LLM call (pure network) so the network calls fire in a thread pool —
   collapsing N round-trips into ~one. The public recommend_sourcing stays the
   single mockable seam (now accepts pre-gathered signals); all copilot mocks
   updated to match. Decisions are unchanged — only the wall-clock.

2. Strip the debug prefix from rationale. Cards showed the raw
   "[trigger] {evidence} | net_need=N | bundle_tier=X |" justification. The
   audit log keeps the full string; the UI now shows only the human rationale.

3. No more silent hangs. api() gains an optional timeout (AbortController);
   the run (90s) and insights (60s) use it and show an error+Retry instead of
   spinning forever when an LLM call stalls.

Tests: 310 pass, ruff clean, frontend syntax clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant