---
name: HITL feedback
type: architecture-map-page
slice: 02-tauri-runtime
last_verified: 2026/05/09
---

# `commands::feedback`

> **Where you are:** [Architecture map](../../README.md) → [Tauri runtime](../README.md) → [Commands](README.md) → Feedback

**Plain English summary.** Phase 2: thumbs + correction capture on AI-generated output (microsteps from a task decomposition, task lines extracted from a transcript, or LLM cleanup). The captured rows feed a few-shot loop: subsequent prompts are conditioned on the user's preferred style by injecting the (input, preferred-output) pairs as exemplars.

## At a glance

- Path: `src-tauri/src/commands/feedback.rs`.
- LOC: 110.
- Tauri commands exposed:
  - `record_feedback(state, input: RecordFeedbackInput) -> Result<i64, String>` — returns the new row id.
  - `list_feedback_examples_cmd(state, target_type, limit, min_rating, profile_id) -> Result<Vec<FeedbackDto>, String>`.
- Events emitted: none.
- Depends on: `lumotia_storage::{record_feedback, list_feedback_examples, FeedbackRow, FeedbackTargetType, RecordFeedbackParams}`.
- Called from frontend at: dictation result panel (thumb up/down + correction-text on cleanup); Tasks page (thumb on extracted tasks and decomposed microsteps).

## What's in here

### `RecordFeedbackInput` (`src-tauri/src/commands/feedback.rs:15`)

Frontend-supplied shape:

- `targetType`: `"microstep" | "task_extraction" | "cleanup"`. Parsed via `FeedbackTargetType::parse`.
- `targetId`: optional surface-specific id (subtask id, task id, transcript id).
- `rating`: `-1` (thumbs down), `0` (correction, neutral), `+1` (thumbs up).
- `originalText`: the AI-generated text the user is rating.
- `correctedText`: the user's preferred text (when they corrected it).
- `contextJson`: freeform JSON used by the prompt builder later to reconstruct the (input, preferred-output) pair.
- `profileId`: scopes the row.

### `FeedbackDto` (`:38`)

camelCase mirror of `FeedbackRow`. Note `rating` widens to `i64` in the DTO (storage uses `i64`).

### `parse_target_type` (`:68`)

Wraps `FeedbackTargetType::parse(raw)`, returning `"unknown feedback target_type: <raw>"` on miss.

### `record_feedback` (`:73`)

`parse_target_type` then `db_record_feedback`. Returns the row id.

### `list_feedback_examples_cmd` (`:95`)

Clamps `limit` to `[1, 64]`, defaults 8. Clamps `min_rating` to `[-1, 1]`, default 0. Calls `db_list_feedback_examples`. Returns `FeedbackDto`s. Used by the `commands::tasks` few-shot exemplar pull and would be used by the equivalent in `commands::llm` if/when cleanup gets its own exemplar path.

## Data flow

```
dictation result thumbs-up -> invoke('record_feedback', { targetType: 'cleanup', rating: +1, originalText, correctedText, contextJson, profileId })
                            -> lumotia_storage::record_feedback -> row id

decomposition thumbs-down + correction -> record_feedback({ targetType: 'microstep', rating: 0, originalText, correctedText: "user's preferred wording", contextJson: {parent_text}, profileId })

next decompose call -> list_feedback_examples_cmd('microstep', 5, 0, profile_id)
                    -> [FeedbackDto, ...] -> few-shot exemplars
```

## Watch-outs

- **No `ensure_main_window` guard.** Tasks float and History viewer secondary windows can also fire feedback. Intentional. If you ever want to lock down feedback writes, this is where to add the guard.
- **`contextJson` is freeform.** Storage stores the raw string. `commands::tasks::to_llm_examples` parses it and skips rows that are malformed. Bad data therefore degrades gracefully but doesn't surface to the user. The `eprintln!` in `to_llm_examples` is the only visibility.
- **`min_rating` clamp is `[-1, 1]`.** Pass `1` to get only thumbs-up examples, `0` for thumbs-up + corrections, `-1` for everything. The default of `0` is what `commands::tasks` picks.
- **No deduplication.** A user thumbs-upping the same output twice creates two rows. The exemplar trim in `commands::tasks` does not dedupe by `originalText`. If two identical exemplars steal slots, that's just lost prompt budget.

## See also

- [Tasks](tasks.md) — the consumer of `list_feedback_examples_cmd`.
- [LLM](llm.md) — the cleanup path that produces the text that thumbs-up/down feedback rates.
- [Profiles](profiles.md) — `profileId` is the scoping key.
