Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3af2fa8
docs: refresh project state and remove the scaffold report
ukez15 Oct 26, 2026
93ee405
docs: draft ATLAS + GOTCHA brief for practice mode in the overlay
ukez15 Oct 26, 2026
e9293fe
Merge remote-tracking branch 'origin/main-z36vk7' into main-z36vk7
ukez15 Oct 26, 2026
c7e0f89
feat(practice): run mock interviews in the overlay
ukez15 Oct 26, 2026
46486b4
fix(desktop): start the bundled backend in its own folder
ukez15 Oct 26, 2026
fde7363
Merge branch 'issue/75-backend-working-folder' into main-z36vk7
ukez15 Oct 26, 2026
fdb743f
fix(ui): allow the backend events WebSocket in the CSP
ukez15 Oct 26, 2026
76a1211
feat(practice): show the scored answer and auto-scroll the overlay
ukez15 Oct 26, 2026
0e98586
docs: draft brief for practice-mode latency and stale speech
ukez15 Oct 26, 2026
780549b
feat(practice): only transcribe a mock interview while a question is …
ukez15 Oct 26, 2026
cc38685
test(audio): drop a redundant null-forgiving operator
ukez15 Oct 26, 2026
306c086
test: move the capture gate test doubles to the shared test namespace
ukez15 Oct 26, 2026
1a52257
fix(audio): restart the stream clock when a stream ends
ukez15 Oct 26, 2026
f0b94b1
perf(practice): read at most 2,000 document characters when asking a …
claude Oct 27, 2026
d67de8f
Merge remote-tracking branch 'origin/main' into main-z36vk7
claude Oct 27, 2026
883a7a8
feat(practice): show the next question word by word as it is written
claude Oct 27, 2026
26db87b
fix(practice): limit question documents for the local model only
claude Oct 27, 2026
1a2dcc0
feat(practice): wait up to 5 s for the last words before scoring
claude Oct 27, 2026
c687df8
docs: brief for practice on cloud models (awaiting approval)
claude Oct 27, 2026
e67b4bf
docs: review notes for practice in the overlay and practice latency
claude Oct 27, 2026
aaace84
docs: plan for the owner's second practice test (awaiting approval)
claude Oct 27, 2026
209398e
fix(practice): score after 6 s without voice, and show every word tha…
claude Oct 27, 2026
9f3ebb6
fix(practice): say the mic is paused until the question is complete
claude Oct 29, 2026
504b869
fix(desktop): end the live session when the app quits
claude Oct 29, 2026
9e8ef08
feat(practice): stream the score and feedback as they are written
claude Oct 29, 2026
855d45b
docs: brief for a larger speech model in Settings (awaiting approval)
claude Oct 29, 2026
ec41186
test(practice): read the first score part without a one-pass loop
claude Oct 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions docs/atlas-gotcha/practice-cloud-models.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Practice on cloud models — ATLAS + GOTCHA brief

Status: **awaiting the owner's approval**, issue #82.
Permanent rules: `GOTCHA-PROJECT.md` and `CLAUDE.md`.

## User story

As a user who picked a cloud model in Settings, I want mock interviews to use it too, so questions
and scores come from the model I chose, not only from the local one.

- GIVEN I chose a cloud model (Anthropic, OpenAI or Google) and saved its key, WHEN I start a mock
interview and ask for a question, THEN the question and the score come from that model.
- GIVEN the key is missing or rejected, WHEN I ask for a question, THEN I see the provider's message
(for example "Add your Anthropic API key in Settings.") and nothing falls back silently.
- GIVEN a cloud model, WHEN a question is written, THEN it gets the full 6,000-character document
budget. The 2,000 limit stays for the local model only.
- GIVEN I left the model on Ollama (the default), WHEN I practise, THEN nothing changes and nothing
leaves my machine.

---

## ATLAS

### [A] Architect
- **Purpose:** practice follows the chat model chosen in Settings, as live answers already do.
- **Constraints:** zero-cost by default: Ollama stays the default, cloud is opt-in BYOK. Keys stay in
the OS keychain and reach the backend only through the existing per-session hand-off (#30), held in
memory and cleared when the session ends. Clean Architecture: `PracticeService` talks to
`ILlmProviderResolver` and `ISessionKeyStore` only.
- **Already in place:** starting a session already hands the chosen chat provider's key to the backend
(`start-live.ts`), so the overlay needs no change. `AnswerGenerator` already picks provider, model
and key this way. The budget rule `QuestionDocumentBudgetFor(provider)` is already in PR #79.
- **Privacy:** with a cloud model, practice sends that provider the selected document excerpts, the
questions already asked, and the text of the spoken answer (never audio). That's what live answers
already send, and it only happens once the user has chosen a cloud model.
- **Out of scope:** a separate model choice for practice, speech-to-text changes, new providers.

### [T] Trace
1. The user starts a mock interview → the app hands the chosen provider's key to the session (today).
2. **Next question** → `PracticeService.NextAsync` reads the owner's chat provider and model, the same
way `AnswerGenerator` does.
3. The session's key for that provider goes into the `LlmRequest`; the provider streams the question.
4. **Done answering** → the score uses the same provider, model and key.
5. A missing or rejected key → the provider's message as the stream's `error` event (question) or the
existing 503 with that message (score). The question stays answerable after a scoring failure, as today.

### [L] Link
| From | To | Method | Contract | Failure mode |
|---|---|---|---|---|
| PracticeService | IUserPreferencesRepository | owner's `LlmProvider` / `LlmModel` | unchanged | none set → configured default (Ollama) |
| PracticeService | ISessionKeyStore | `TryGet(session, provider)` | unchanged | no key → the provider's "Add your key" message |
| PracticeService | ILlmProviderResolver | `Resolve(provider)` | unchanged | unknown provider → as live answers today |
| UI | API | `practice/next`, `practice/finish` | unchanged | provider message shown inline, retry allowed |

### [A] Assemble
1. Tests first (Application unit tests; one API test with a fake cloud provider).
2. Move the provider/model/key choice out of `AnswerGenerator` into one shared helper, so live answers and
practice can't disagree (question 3).
3. `PracticeService` uses it for both the question and the score; drop "Ollama only in this wave".
4. Checks → "What we adjusted" → PR.

### [S] Stress-test
- **Zero cost:** with no preference set, the provider is Ollama and the request carries no key (test).
- **Security:** the key never appears in logs, events, errors or the saved attempt (test on the saved
attempt and the error text).
- **Failure:** a key added in Settings after the session started isn't in the session yet → "Add your
key" until the session is restarted. Same as live answers today.

---

## GOTCHA

=== GOALS ===
- Practice uses the owner's chosen chat provider and model, with the session's key.
- No silent fallback; Ollama-default behaviour unchanged.
- Coverage of at least 75% per package; CI green.

=== ORCHESTRATION ===
1. Failing tests. 2. Shared provider choice. 3. PracticeService. 4. Checks → review → PR.

=== TOOLS ===
.NET 10, xunit v3, FluentAssertions 7.2.2. No new packages. No UI change.

=== CONTEXT ===
BYOK cloud providers from #30 (`CloudLlmProviderBase`, `InMemorySessionKeyStore`). Backend tests run in
CI only (the .NET SDK download is blocked in cloud sessions).

=== HEURISTICS ===
DO: reuse the live-answer choice of provider, model and key (yes/no). Keep Ollama the default (yes/no).
DON'T: fall back to another provider without telling the user (yes/no). Log or store the key (yes/no).

=== ARGS ===
- Question document budget: 2,000 for Ollama, 6,000 for cloud (`QuestionDocumentBudgetFor`, already in #79).

---

## Open questions for the owner

1. **Which model does practice use?** **Recommended:** the same chat model chosen in Settings for live
answers. Or add a separate "Practice model" setting (more UI, more to keep in sync).
2. **Missing or rejected key:** **Recommended:** show the provider's message and stop, with no fallback
to Ollama. Or quietly fall back to Ollama (but then the user can't tell which model scored them).
3. **Share the choice with live answers:** **Recommended:** move it into one helper used by both, so a
fix to one applies to both. It touches `AnswerGenerator` too, but its behaviour stays the same.
4. **Show which model is in use in the overlay?** **Recommended: not now.** Live answers don't show it
either; it could be a follow-up for both.
5. **Delivery:** **Recommended:** a separate PR after #79 is merged, on branch `issue/82-practice-cloud-models`,
so #79 can be tested and released on its own.
222 changes: 222 additions & 0 deletions docs/atlas-gotcha/practice-latency.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
# Practice mode latency and stale speech — ATLAS + GOTCHA brief

Status: **approved by the owner with the recommendations (2026-10-26)**, issue #78, PR #79.
Permanent rules: `GOTCHA-PROJECT.md` and `CLAUDE.md`. Builds on `practice-overlay.md` (#74).

## What the owner saw (2026-10-26, test installer 76a1211)

1. "Next question" takes too long.
2. Words said ~30 s earlier, before the question had appeared, showed up as the answer.

## Why

- Mic audio is transcribed all the time, including while the model writes the next question or scores
an answer. Whisper (`ggml-small.en`) and Ollama share the CPU, so each slows the other, and the
transcription backlog grows. The live-answer benchmark (#24) gave 0.9 s P95 to first token on the
same machine with the same 6,000-character document context. That points to CPU contention, not
prompt size.
- `PracticeAnswerCollector` and `PracticePanel` accept every Candidate segment that *arrives* after
the question is asked. A segment that was *spoken* before the question but transcribed late counts as
the answer. Segments already carry `startMs`, their position in the audio stream (frames × 100 ms),
so "spoken before the question" can be told apart from "transcribed late".
- `PracticeService.NextAsync` waits for the whole reply before showing anything, although
`OllamaLlmProvider` already streams.

## User story

As a candidate in a mock interview, I want the next question to appear quickly and only what I say
after it to count as my answer, so that practice feels like a real interview.

- GIVEN a question is being generated or an answer scored, WHEN I talk, THEN none of it is
transcribed or counted.
- GIVEN the question is shown, WHEN I answer, THEN only speech that started after the question
appeared is shown and scored, however late transcription delivers it.
- GIVEN I click Next question, WHEN the model starts writing, THEN I see the question appear word by
word (question 2).

---

## ATLAS

### [A] Architect
- **Purpose:** stop stale speech counting as the answer, and cut question latency by not running
Whisper and Ollama at the same time in mock interviews.
- **Constraints:** zero-cost and local only. Live-interview and Sales/general sessions must not change:
they keep transcribing all the time. Clean Architecture: the gate is an Application interface. The
Deepgram path (off by default) honours the same rule.
- **Out of scope:** Whisper model choice (Settings already has the download; a smaller model is a
separate decision), GPU support, document budget changes for scoring and live answers, text-to-speech, and pre-generating the next
question (it would compete with Whisper while the user answers).

### [T] Trace
1. The user clicks **Next question** → `POST practice/next`.
2. `PracticeService.NextAsync` builds the prompt and streams Ollama's reply (question 2).
3. When the question is complete, `PracticeAnswerCollector.Open(sessionId, question, fromMs)` records
`fromMs`, the session's current mic-stream position from the audio sink. **The gate opens.**
4. Mic frames now reach the speech buffer and Whisper. Before step 3 they were dropped on arrival.
5. Each Candidate segment with `startMs >= fromMs` is added to the answer and shown. Earlier ones are
ignored by both the collector and the panel; the API returns `answerFromMs` with the question.
6. **Done answering** or 4 s of silence → `Take` → **the gate closes** → scoring runs with the CPU free.
7. A scoring failure → `Restore` re-opens the gate with the same `fromMs`, so the user can carry on.

### [L] Link
| From | To | Method | Contract | Failure mode |
|---|---|---|---|---|
| TranscriptionSink / DeepgramStreamingSink | New `IAudioCaptureGate` (Application) | in-process | `bool Accepts(sessionId, speaker)` | Sessions that aren't mock interviews: always true |
| PracticeAnswerCollector | IAudioCaptureGate | implements it | open question ⇒ accept Candidate | No open question ⇒ drop |
| PracticeAnswerCollector | Audio sink | in-process | `long PositionMs(sessionId, speaker)` | No stream yet ⇒ 0 |
| `POST practice/next` | UI | SSE, as approved in question 2: `delta` events, then `done` carrying `{question, answerFromMs}`, or `error` | adds `answerFromMs` | Checks before the stream (404/400/409) as today; a model failure mid-stream is an `error` event, not a 503 |
| PracticePanel | Events WS | existing | filters `startMs < answerFromMs` | — |

### [A] Assemble
1. Tests first: the gate drops mock-interview Candidate frames with no question open and passes them
with one open; the collector ignores segments with `startMs < fromMs`; other modes are unaffected;
the panel ignores early segments; `Restore` keeps `fromMs`.
2. Application: `IAudioCaptureGate`, plus collector changes (`fromMs`, gate state).
3. Audio sinks: check the gate per frame; expose the mic-stream position.
4. API: `answerFromMs` on the question response (plus streaming if question 2 says yes).
5. UI: the panel filters by `answerFromMs` (plus word-by-word question if question 2 says yes).
6. `dotnet test` (cloud CI, since the .NET SDK can't download here) and the UI checks, then
"What we adjusted", a PR, and a fresh test installer.

### [S] Stress-test
- **Load:** while a question is generated or scored, Whisper work for the session drops to zero.
- **Data integrity:** speech spanning the moment the question appears starts before `fromMs`, so it's
dropped. The cost is at most the first ~0.6 s pause-segment.
- **Failure:** scoring fails → `Restore` → the gate re-opens and answering continues.
- **Regression:** live interviews and auto-answer are unchanged; that's covered by tests.

---

## GOTCHA

=== GOALS ===
- In mock interviews, speech that started before the question appeared is never shown or scored.
- No mic transcription runs in a mock interview while no question is open.
- Other session modes transcribe exactly as today.
- Coverage of at least 75% per package; CI green.

=== ORCHESTRATION ===
1. Failing tests (Application, Api, UI). 2. Gate interface plus collector. 3. Sinks: gate and position.
4. API field (and streaming if approved). 5. UI filter (and streaming if approved).
6. Checks → review → PR → installer.

=== TOOLS ===
.NET 10, xunit v3, FluentAssertions 7.2.2, React 19.3.1, Vitest 5.0.5. No new packages.

=== CONTEXT ===
Clean Architecture: the gate interface lives in Application; the sinks depend on it. Ollama and
Whisper are both local and CPU-bound on the owner's laptop. Cloud sessions can't run .NET locally
(`dot.net` is blocked), so backend tests run in CI.

=== HEURISTICS ===
DO: drop frames at the sink, before buffering (yes/no). Keep live-interview behaviour byte-for-byte
unchanged (yes/no). Use stream position (`startMs`), not wall-clock time (yes/no).
DON'T: transcribe and then discard (it wastes the CPU we're trying to free) (yes/no). Change VAD
thresholds or the Whisper model (yes/no).

=== ARGS ===
- Frame length 100 ms (existing `VadOptions.FrameMs`); silence auto-finish 4,000 ms (existing).
- New response field `answerFromMs` (long, ms of mic stream) — name to confirm (question 3).

---

## Open questions for the owner

1. **Gate the mic between questions:** in mock interviews, only transcribe while a question is open.
**Recommended: yes.** It's the fix for both problems.
2. **Show the question word by word as it's written?** It feels faster, but it changes
`POST practice/next` to stream like live answers do. **Recommended: yes**, in the same PR. Or leave
it out and see whether the gate alone is fast enough.
3. **Name of the new field:** `answerFromMs`. **Recommended: OK.**
4. **"Done answering" right after you stop talking:** the last few words may still be in Whisper's
queue. Today they're lost; with the gate they'd be dropped too. Should the app wait for them, up to
a few seconds, before scoring? **Recommended: yes, up to 5 s,** as part of this work.
5. **To size the problem,** about how many seconds did "Next question" take, and were you talking
while it was working?

## Added after approval (2026-10-27)

6. **Document budget for question prompts.** The owner's Ollama stats (prompt read at about 41 tokens/s,
6 s cold load) showed that the prompt's up to 6,000 document characters (~1,500 tokens, ~37 s to read)
were the biggest cost behind the 90 s question. **Owner's decision: 2,000 characters for question
prompts only** (`PracticePromptBuilder.QuestionDocumentBudget`). Scoring and the live assistant keep
6,000.
7. **Local models only (owner, 2026-10-27).** The 2,000 limit applies only when the question runs on the
local model (Ollama). A cloud model gets the full 6,000 (`QuestionDocumentBudgetFor`). Practice runs on
Ollama only in this wave, so the cloud rule matters once practice gains cloud models.

---

## What we adjusted

- **Step 1's backend code came before its tests** (the mic gate and stream clock). That broke the tests-first
rule. The tests followed in the same PR, and three CI rounds caught what they found: a redundant `!`
(S8969), an ambiguous test double (CS0104), and the clock not restarting when a stream reconnects.
- **The stream clock restarts when a stream ends,** so a reconnected stream's times start at 0, as its
segment times always have. A reconnect while a question is open can therefore drop the rest of that
answer; you'd click Next question again. Not worth more code for a rare case.
- **Deepgram sessions aren't gated** and skip the 5 s wait: they use no local CPU, and gating would put
Deepgram's own clock out of step.
- **Skipping a question closes it at once,** so the mic rests while the next one is written. That wasn't in
the brief; it closes a gap the gate left.
- **The question stream's last event carries the result:** `done` holds `{question, answerFromMs}` (live
answers send an empty `done`). Live answers and practice share one relay, `LlmEventStream`, so a model
failure is an `error` event in both. A model failure on Next question is no longer a 503.
- **The 2,000 budget (question 6) and "local models only" (question 7)** were added after approval, from the
owner's Ollama stats.
- **Not verifiable in the cloud session:** the speed-up and the 5 s wait need the owner's check on Windows
with Ollama and the mic. The backend tests ran in CI only.

---

## Changes after the owner's second test (2026-10-27, test installer e67b4bf)

Status: **approved by the owner with the recommendations (2026-10-27)**: 6 s of no voice, drop noise labels in
every mode, and show the mic hint.

What the owner saw: questions now come quickly, word by word. But scoring started while they were still
answering (once after about 12 words). "(mumbles)" appeared as their answer, and words they'd said
(such as "microservices") only showed up after scoring.

Causes:
1. **Auto-finish counts gaps in text, not silence.** The overlay scores once 4 s pass without a new
Candidate segment. A segment only exists after a 0.6 s pause (or 15 s of non-stop talking), and Whisper
then needs a few seconds on the CPU, so a 4 s gap between segments is normal mid-answer.
2. **The overlay stops listening once scoring starts,** but the backend's 5 s last-words wait still adds
segments. They're scored without ever being shown.
3. **Whisper labels noise** as "(mumbles)", "[BLANK_AUDIO]", "(music)" and so on, and nothing filters them.
4. **The mic is muted while the question is written** (by design), but the overlay doesn't say so.

Proposed changes:
- **A. Silence means no voice.** The backend already knows from the voice detector when the candidate last
spoke. Once a question is open, if 6 s pass with no voice *and* everything said has been transcribed, it
sends one new session event (`practice.silence`), and the overlay scores. The 4 s text timer goes.
"Done answering" still works at any time, with its 5 s last-words wait.
- **B. Show every word that's scored.** The overlay keeps adding live lines while scoring, then shows the
exact scored text, as today.
- **C. Drop Whisper's noise labels.** A segment whose whole text is a bracketed label, like "(mumbles)" or
"[BLANK_AUDIO]", is discarded before it's saved or shown, in every mode.
- **D. Say when the mic listens.** While the question is being written, the overlay shows "The mic
listens once the question is complete."

Out of scope: the speech model's accuracy (model size, mic level). That's a separate issue if needed.

---

## Changes after the owner's third test (2026-10-29, test installer 209398e)

Status: **decided by the owner (2026-10-29).**

What the owner saw: much better. Questions take about 20 s (down from 90), the answer shows, and "Done
answering" works. But the mic line said "Listening" while the question was being written, and scoring takes
60–120 s. Transcription is weaker than paid models.

Decisions:
- **Mic line:** "Mic ⏸ Paused until the question is complete" while no question is open; it replaces the
separate hint line. A mic problem still shows as "Mic ✗ …".
- **Scoring:** stream the feedback word by word (the owner chose this alone; the document budget for
scoring stays 6,000). Scoring takes as long, but reading starts within seconds.
- **Speech quality:** a larger Whisper model as a Settings option goes to its own issue and brief (#85).
- **Also found:** a session left Live when the app closed couldn't be deleted. The desktop app now ends it
on quit (#84).
Loading
Loading