feat(P01-04-03,P01-04-04): wire store into pipeline + per-session cost logging

server/cost.py — derive_cost() counts LLM input/output tokens (gemma4 +
deepseek-v4-flash), Deepgram audio minutes, Cartesia/Piper characters;
derives estimated cents from scenarios/cost_rates.yaml. No enforced ceiling
(D-012 pilot). CostBreakdown dataclass carries the breakdown dict stored in
sessions.cost_breakdown_json. Per G-005: v0.1 logged costs are pilot-config
(Ollama tier + cloud), NOT at-scale /learner economics — that requires
self-hosted gemma4:e4b + Piper (post-pilot).

server/session_recorder.py — SessionRecorder wires the SQLite store into the
pipeline lifecycle: start() creates a session row, log_turn() writes turns
with ASR/TTS text + latency + accumulates cost inputs, set_branch_path(),
end() derives cost + writes outcome + debrief + updates progress. No auth —
learner_id is the hardcoded learner-1 (D-007).

7 tests pass (derive_cost basic/piper-zero/breakdown-dict, load_rates yaml,
no-enforced-ceiling, recorder full lifecycle with DB assertions, progress
updated).

---ci---
phase: 1
milestone: v0.1
plan: 04
task: 04-03,04-04
status: execute
persona: backend-engineer,data-engineer
requirements:
  covered: [REQ-STATE-01, REQ-NFR-COST-01]
---/ci---
This commit is contained in:
Praxis CI
2026-08-01 13:16:00 +00:00
parent 73b583342b
commit 376fddf18e
4 changed files with 373 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
# Praxis v0.1 cost rates — per-unit pricing for the cost logging (D-012, REQ-NFR-COST-01).
# v0.1 logs actual per-session cost; no enforced ceiling (pilot).
# Per G-005: these are pilot-config rates (Ollama tier + cloud), NOT at-scale
# per-learner unit economics — the $3/learner target requires self-hosted
# gemma4:e4b + Piper (post-pilot).
# LLM role-play (gemma4:cloud) — Ollama tier (Pro plan amortized, pilot estimate).
gemma4_cloud_per_1k_tokens_cents: 0.5
# Debrief + classifier (deepseek-v4-flash:cloud) — Ollama tier.
deepseek_v4_flash_per_1k_tokens_cents: 1.0
# ASR (Deepgram Nova-3 streaming) — $0.0043/min → 0.43 cents/min.
deepgram_per_audio_minute_cents: 0.43
# TTS (Cartesia Sonic cloud) — per-char pricing (pilot estimate).
cartesia_per_1k_chars_cents: 3.0
# TTS (Piper self-hosted) — open-weights, $0 marginal cost.
piper_per_1k_chars_cents: 0.0