Skip to content

LLM triage: propose tasks from dumps and a review queue - #10

Merged
rooty-bot merged 2 commits into
mainfrom
claude/3-llm-triage-propose-tasks-from-dumps-and
Nov 30, 2026
Merged

rooty-bot merged 2 commits into
mainfrom
claude/3-llm-triage-propose-tasks-from-dumps-and

Conversation

@rooty-bot

Copy link
Copy Markdown
Collaborator

Summary

  • LLM client (src/lib/server/llm.ts): OpenAI-compatible POST {LLM_BASE_URL}/chat/completions. It reads LLM_BASE_URL (default http://ollama:11434/v1), LLM_MODEL and an optional LLM_API_KEY (sent as a bearer token). It has a timeout and gives distinct, readable errors for timeout, unreachable server, HTTP error (with a short body excerpt) and non-chat responses. The API key never appears in messages.
  • Triage (src/lib/server/triage.ts): a strict system prompt asks for a JSON [{title, notes, project?, due?}] array. Parsing is defensive: it strips code fences and <think> tags, unwraps {tasks: [...]}, and validates with zod (trimmed title; blank fields become null; an invalid or non-ISO due becomes null). On invalid JSON or the wrong shape it retries once, telling the model what was wrong.
  • Review queue (/review): pending proposals grouped by dump. You can edit then accept, accept, reject, ask the LLM again, or reject the rest and mark triaged. Triage all new dumps processes every untriaged dump and reports failures per dump.
    • Accepting is atomic and idempotent, so a double submit makes one task.
    • A dump becomes triaged once none of its proposals are pending.
  • Tasks (/tasks): list with a done toggle (todo ↔ done, bumps updated_at) and a project filter.
  • Never auto-accept: nothing becomes a task without a human accepting it.

Decisions the issue didn't specify

  • LLM_MODEL defaults to llama3.2, so the bundled Ollama works without extra config. I also added LLM_TIMEOUT_SECONDS (default 120). All four variables are in the README table and in docker-compose.yml.
  • Migration 003_triage.sql adds three things:
    • a proposals table, deleted with its dump;
    • a tasks.project column (the existing table only had category_id);
    • a dumps.proposed_at column marking "sent to the LLM, awaiting review".
  • If the LLM proposes nothing for a dump, the dump stays in the review queue until a human marks it triaged or retries. A model that wrongly returns [] can't silently drop a dump.
  • A retry swaps the pending proposals only after the LLM succeeds; a failed retry keeps the old ones. Saving proposals claims the dump atomically, so two tabs triaging at once don't create duplicates.
  • Triage all skips a dump the LLM errors on, and stops after two LLM errors in a row (e.g. the endpoint is down).
  • zod was added as a runtime dependency.

How it was tested

  • Vitest, with the LLM mocked at the fetch level as an OpenAI-compatible server:
    • valid JSON → 1 call
    • fenced JSON → 1 call
    • garbage then valid → 2 calls, and the retry message explains the error
    • wrong shape then valid → 2 calls
    • garbage twice → 2 calls, then TriageError; no proposals are stored and the dump stays new
  • Client tests cover the request shape, the bearer key, the HTTP error, unreachable and timeout messages, and non-chat responses.
  • DB tests cover accept (with edits, idempotent), reject, dismiss, claim/replace, cascade on delete, and task ordering, filter and toggle.
  • Route tests drive the /review and /tasks form actions end to end with a stubbed global fetch, including a failed retry that keeps existing proposals.
  • npm run lint, npm run check, npm test (68 tests) and npm run build all pass locally.
  • I also ran the production build against a tiny fake LLM server: create dump → triage all → edit and accept → the task shows on /tasks with its project filter, and the dump shows triaged in the inbox.

Closes #3

🤖 Generated with Claude Code

rooty-bot and others added 2 commits November 30, 2026 12:36
- OpenAI-compatible chat client (LLM_BASE_URL, LLM_MODEL, LLM_API_KEY,
  LLM_TIMEOUT_SECONDS) with a timeout and clear error messages.
- Triage: strict JSON system prompt, defensive parsing (code fences,
  <think> tags, {tasks: [...]} wrapper) validated with zod, one retry
  that explains what was wrong.
- Proposals table: nothing becomes a task until a human accepts it.
  Accepting is atomic and idempotent; a dump is triaged once all its
  proposals are reviewed. Empty results stay in the queue.
- Review page: triage all new dumps, edit/accept/reject, retry, dismiss.
- Tasks page: list with done toggle and project filter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Retry only replaces a dump's pending proposals after the LLM succeeds.
- Saving proposals claims the dump atomically, so concurrent triage runs
  or a dump deleted mid-call cannot duplicate or crash.
- Triage-all skips a dump the LLM errors on and only stops after two
  LLM errors in a row.
- Pass LLM_TIMEOUT_SECONDS through docker compose.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rooty-bot

Copy link
Copy Markdown
Collaborator Author

Thanks for this, it's a careful and well-scoped PR. I checked it against #3 point by point:

Scope vs. issue #3

  • ✅ OpenAI-compatible client (llm.ts): LLM_BASE_URL defaults to http://ollama:11434/v1, and LLM_MODEL and an optional LLM_API_KEY sent as a bearer token are supported. It uses AbortSignal.timeout and gives separate, readable errors for timeout, unreachable server, HTTP status (with a 200-char excerpt), non-JSON and non-chat responses. The key never appears in error text.
  • ✅ Triage (triage.ts): a strict system prompt, extractJson strips fences and <think> tags, and zod validates the result. It retries exactly once and tells the model what was wrong. A second failure throws TriageError and stores nothing.
  • ✅ Review page: proposals are grouped by dump, with edit+accept, accept, reject and "Triage all new dumps". Accepting creates a task, and the dump becomes triaged once nothing is pending.
  • ✅ Tasks page: done toggle and project filter.
  • ✅ Never auto-accept: tasks are only created in acceptProposal, which a human form action triggers.

Tests: All four cases the issue requires are in triage.spec.ts: valid JSON, fenced JSON, garbage then valid, and garbage twice. They are mocked at the fetch/chat level and also assert the number of calls. On top of that there are client, DB and route-level tests. Locally I get npm test 68/68, and lint, prettier and svelte-check all report 0 errors. CI (test + docker) is green.

Correctness/security

  • All SQL is parameterised. The only interpolations are constant column lists and NOW, and the replace flag only switches a fixed clause.
  • Accept and reject are atomic, using UPDATE … WHERE status='pending' RETURNING, so a double submit is harmless. The saveProposals claim prevents duplicate proposals across tabs, and a failed retry keeps the existing proposals.
  • No {@html}. Dump and LLM text is rendered escaped. Form input goes back through proposalSchema, with length limits and a real-date check on due.
  • No disabled lint/type checks, and no skipped or .only tests.

Non-blocking nits (fine for a follow-up):

  1. dismissDump calls setDumpStatus(…, 'triaged') without checking that the dump is still new. A crafted or stale POST could move an archived dump to triaged. Adding AND status = 'new' (or checking first) would close that.
  2. proposed_at is never cleared. If a dump is later set back to new from the inbox, it lands in the review queue with no proposals, and "Triage all" skips it. "Ask the LLM again" still recovers it, so this is minor, but resetting proposed_at when the status goes back to new would be more intuitive.
  3. The review page shows LLM_BASE_URL in the UI. That's fine for a self-hosted app, but if someone puts credentials in the URL (https://user:pass@…), they'd be shown on the page. Stripping userinfo before display would be a cheap safeguard.

Nice work overall. Approving from my side.

-- OpenSourcerer (Rootshift review)

@rooty-bot
rooty-bot merged commit 4741e0a into main Nov 30, 2026
2 checks passed
@rooty-bot
rooty-bot deleted the claude/3-llm-triage-propose-tasks-from-dumps-and branch November 30, 2026 11:49
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.

LLM triage: propose tasks from dumps and a review queue

1 participant