Source: https://sopops.dev/docs/sessions-and-review

# Sessions, review and models

## Sessions and checks

A session is one call or chat, in one JSON format ([API reference](https://sopops.dev/docs/api/sessions.md)).

- **Post it** to `/v1/workspaces/{ws}/sessions` with an `ingest` token, or stream it to `/v1/workspaces/{ws}/sessions/open`, `/v1/workspaces/{ws}/sessions/{platform}/{external_id}/events` and `/v1/workspaces/{ws}/sessions/{platform}/{external_id}/close`.
- **A stream** idle for `SOPOPS_SESSION_IDLE_MINUTES` closes as incomplete.
- **Resending is safe.** Sessions are keyed by platform and session id.
- **Past sessions** come in from a file ([example](https://github.com/sopops-dev/sopops/blob/main/examples/import-sessions)):

```sh
sopops import sessions.jsonl --workspace prod
```

The **Sessions** page lists sessions as they arrive, each with its transcript, tool calls and result per procedure, with quotes highlighted. Each new or changed session goes through these steps:

1. **Normalize** turns and tool calls.
2. **Route**: which procedures in its release applied, and which ended early.
3. **Check**: a decision per rule, the reviewer model on flagged ones, a status per rule with quotes, the goal, required tool steps.
4. **Result** per procedure and session: deviated, partial, followed or not measurable ([how](https://sopops.dev/docs/api/checks-and-review.md#sop-checks)).
5. **Patterns**: findings join their rule's pattern ([below](#patterns-review-and-suggestions)).

This runs inside sopops by default. With `HATCHET_CLIENT_TOKEN` it runs on [Hatchet](https://hatchet.run) in `sopops worker`: one run per session version, fair share per workspace, per-model rate limits, a daily recluster. `docker compose --profile hatchet up` starts hatchet-lite ([docker-compose.yml](https://github.com/sopops-dev/sopops/blob/main/docker-compose.yml)).

Live UI updates work from any process on Postgres, only from the sopops process on SQLite.

**Insights** compares sessions checked, followed and needing attention against the same length of time just before ([definitions](https://sopops.dev/docs/api/insights.md)). Every number links to its sessions.

- A trend with release markers.
- A scoreboard per procedure, with its rule ladder and rule pages.
- **Release compare**: two releases rule by rule, with 95% intervals.
- **Report**, which reads like a hand-written call review.

## Patterns, review and suggestions

**Patterns.** Each rule with findings is a pattern, named by the reviewer model ("Didn't read the order back") or by the rule's words without one. At 8 findings it splits into named patterns ("Told the caller a dish is safe") that new findings join. Themes group them by call phase. Names and ids stay stable across reclusters ([how](https://sopops.dev/docs/api/checks-and-review.md#patterns-and-themes)).

**SOP-first review.** Patterns opens with one row per SOP. The Home and sidebar counts use the same queue. A behavior needs evidence on five distinct calls within that SOP and its clustering window, or a confirmed recurrence after a fix. Ten subsequent measurable calls in the SOP without an occurrence move it to Quiet. All SOPs includes quiet and low-volume behaviors. Expand a behavior to inspect its source patterns and an example call. A verdict applies to the displayed sources in that SOP. New sources require their own review. View individual patterns opens the original queue, including patterns awaiting grouping.

**Grouped review.** Patterns → Grouped queue opens a workspace-wide queue of corrections. Each card links to the rules and flows that produced its evidence, their example calls and their proposed SOP edits. Grouping compares the required behavior and its conditions. A single call counts once on a card even when several rules flag it.

- Five distinct affected calls bring a correction into Needs review. Smaller groups are available under Low volume. The displayed call count uses the workspace’s finding window.
- Record fix saves a dated review note on the card. A later affected call reopens the same card.
- Quiet shows corrections where every affected procedure has had at least ten measurable calls since the last occurrence.
- Grouping runs with rule clustering. The daily pass also picks up existing patterns and retries incomplete groups. Group now processes pending patterns on demand.

**Source pattern review.** Patterns → Needs review shows one pattern at a time as a card; the others are one line each (`j` and `k` move). The card labels what it's about: the **procedure**, what the **SOP says**, the **order** of the steps for an out-of-order pattern (at most three, the full order on the pattern's page), and one **example** linked to its session, with the rest folded under it. The model's summary is on the pattern's page ("Read more").

The verdict is two questions, answered by keys:

| Answer | Verdict | Then |
|---|---|---|
| Is this a problem? `1` Yes, then is the SOP step right? `1` Yes, the agent should follow it | Real mistake | Findings count. sopops drafts a clearer, more specific step. |
| … `1` Yes, then `2` No, the step is wrong | SOP is wrong | sopops drafts a new version of the step. |
| `2` No, it's fine here | Acceptable | Findings suppressed: kept, but out of every Insights number. sopops drafts an exception into the step. |
| `3` sopops got it wrong | Checker is wrong | Nothing changes in the SOP. Findings suppressed, kept as calibration labels and training data, and listed on Fine tune. |

Every fix is an edit to the SOP, drafted for you to review: nothing changes the agent directly. `n` adds a note to any answer: it's kept with the verdict, given to the model that drafts the edit, and exported with the training data. A verdict waits 6 seconds before it's saved, so `u` can undo it.

You can mark one finding wrong. A judged pattern exports its sessions as regression cases (JSON Lines).

**Corrections.** On a session, any rule can get its right status:

| Control | On | What it does |
|---|---|---|
| Wrong? | A finding | Right or wrong, then "What actually happened?" with the rule's statuses (you can skip it). A wrong finding is suppressed. |
| Wrong status | Any rule | Pick the status it should have. On a finding, a status that isn't a finding suppresses it, like Wrong?. |
| Checker missed this | A done step or an ok never rule | Pick the failure the checker missed (skipped, out of order, violated). |

A corrected rule shows the status, who gave it and when. A missed mistake doesn't add a finding: the session's result, its patterns and Insights keep what the checker found, so a correction never changes a number without showing it. Every correction is a calibration label. The latest call on a rule wins, and it outlives a re-check.

**Fine tune.** Review → Fine tune collects data for tuning sopops to your calls; its first collection point is **Checker spot checks**, one table with the patterns marked Checker is wrong on Patterns and spot checks. Spot checks ask about rules the checker passed, one batch at a time (25 by default, `PUT /v1/workspaces/{ws}/spot-checks/settings`), so the work doesn't grow with call volume. A batch is spread across procedures and agents, and takes close calls and decisions the reviewer model changed first. Items are grouped by call, so one transcript answers all its rules; procedure and agent filters show, and rule, dates and why it was picked are under More filters. The rule you're on is a card (procedure and step, what the checker said, the evidence, why sopops picked it) with two questions: was the checker right (`1` yes, `2` no), and after no, what actually happened, from the statuses that kind of rule can have. `n` adds a note, kept with the answer and the training data; `j` and `k` move. A finished batch shows what you found and offers "Give me N more"; nothing is drawn twice, and an item left unanswered for 7 days expires quietly. Answers are labels, like corrections.

| State | When |
|---|---|
| needs review | No verdict, or a recluster changed it. |
| open | Real mistake or wrong SOP, unfixed. |
| fixing | Fix applied, or a pull request open or merged. Waits for the release to go live with 10 sessions. |
| fixed | No findings in 10 sessions on that release or later. |
| regressed | A finding came back on sessions that ran the fix. Requeued. |
| closed | Acceptable, or checker wrong. |

A merged pull request moves the pattern on. A closed one reopens it.

**Reworded rules.** sop gives changed rule text a new id, and every applied suggestion rewords one. On publish, sopops links each reworded rule to the one it replaced: by the suggestion that made the edit, else by wording at the same position, then anywhere in the procedure ([API reference](https://sopops.dev/docs/api/checks-and-review.md#rule-lineage)).

- The rule keeps its pattern, verdicts, state and history.
- Sessions keep the wording they ran.
- Insights shows "reworded in release 4", with earlier wordings on hover.
- Link or unlink a wrong match by hand on the rule's Insights page.

**Suggestions.** The reviewer proposes the smallest edit that settles the verdict. sopops compiles it with sop (one retry) and shows how each agent's instructions change ([details](https://sopops.dev/docs/api/checks-and-review.md#review-and-suggestions)).

- Apply saves a draft, or opens a pull request if a GitHub repository is connected.
- If the procedure changed since, edits on different lines merge when the result compiles.
- Overlaps show the conflict and block applying.
- **Rewrite against the current text** redoes the edit on the current file, keeping later changes.

## Models

Each model call is a typed [DSPy](https://dspy.ai) signature ([`signatures.py`](https://github.com/sopops-dev/sopops/blob/main/src/sopops_server/ai/signatures.py)). Each result records its model and instructions version. You bring your own keys.

| Role | What it does |
|---|---|
| `SOPOPS_MODEL_FAST` | Decides: routing, rule checks, pattern assignment. |
| `SOPOPS_MODEL_REASONING` | Reviews flagged or uncertain rules, splits rules into checks, names and clusters patterns and themes, writes suggestions. |

Use strings like `anthropic/claude-haiku-4-5` or `anthropic/claude-sonnet-5-5`, with the provider's usual key variable (`ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, ...). One model can fill both roles. Any DSPy provider works, or an OpenAI-compatible endpoint (`SOPOPS_LLM_API_BASE`) for local models. With neither role set, sessions are stored unchecked.

| Topic | What to know |
|---|---|
| **Jev** | With `pip install 'sopops-server[jev]'` and a TypeSafe key, TypeSafe's [Jev](https://docs.typesafe.ai) answers decisions instead of the fast model: calibrated probabilities, faster and much cheaper. The reviewer still reviews. Setup asks for a key. A deployment with a model gateway can serve Jev (or another system-1 classifier) from there instead (`SOPOPS_SYSTEM1_URL`), keeping the key in the gateway. |
| **A team's own keys** | The environment variables are the deployment's defaults. In setup, and later in Settings under Checks, a team adds its own TypeSafe key, picks Anthropic, OpenAI, Google or any other LiteLLM provider, pastes a key (or uses the deployment's) and picks the two models from those the key can use. Each key and model is tried before it's saved, stored encrypted with `SOPOPS_SECRET_KEY`, and never shown again. Anything a team doesn't set uses the default. |
| **Check modes** | `decide` (default) sends flagged decisions to the reviewer. `review` has it judge every rule. `SOPOPS_CHECK_REVIEW=off` lets decisions stand. |
| **Tracing** | An extension can register a listener (`sopops_server.ai.tracing.add_listener(after, before)`) that sees each model call, decisions included: workspace, session, procedure and rules, purpose, signature, inputs, outputs and reasoning, model, instructions version, tokens, latency, any error, and a run id shared by one session's check. `before` can add request headers to calls to a hosted model gateway (`sopops/...` models) only. The web app and `sopops worker` both load extensions. None is registered by default, and a failing one never stops a check. |
| **Spend** | Each call records tokens and estimated cost by purpose and session (prices: `SOPOPS_MODEL_PRICES`). See Results → Insights → Model spend, and each session page ([API reference](https://sopops.dev/docs/api/insights.md#model-spend)). Text sent to models isn't stored. |

**Calibration.** sopops fits decision thresholds per workspace from labeled sessions (verdicts, overrides, corrections and spot checks; checker-wrong labels are negative, missed mistakes count as failures). Defaults apply until then; `SOPOPS_DECISIONS` overrides them.

```sh
sopops calibrate --workspace WS [--procedure P] [--dry-run]   # or POST /v1/workspaces/{ws}/calibrate
```

It reports each threshold before and after. A procedure needs at least 5 labeled sessions and a rule with 3 labeled failures. It only widens the review band.
