---
id: T02
parent: S01
milestone: M007
provides: []
requires: []
affects: []
key_files: ["backend/pipeline/stages.py"]
key_decisions: ["Debug mode checked once at callback creation time to avoid Redis round-trip per LLM callback", "Full response_text stored without truncation when debug on; existing content_preview in payload kept for non-debug use"]
patterns_established: []
drill_down_paths: []
observability_surfaces: []
duration: ""
verification_result: "Syntax check passed (ast.parse). All 3 functions present. Exactly 4 call sites updated (grep count=4). Container rebuild succeeded. Worker running without import errors. Debug mode endpoint responds correctly. Events endpoint returns new nullable fields. End-to-end with populated debug fields not yet verified — test pipeline queued behind prior video."
completed_at: 2026-03-30T18:54:43.467Z
blocker_discovered: false
---

# T02: Wired debug-mode-aware LLM I/O capture into pipeline callback — _emit_event accepts prompt/response text, _is_debug_mode reads sync Redis, _make_llm_callback conditionally captures full I/O, all 4 stage call sites updated

> Wired debug-mode-aware LLM I/O capture into pipeline callback — _emit_event accepts prompt/response text, _is_debug_mode reads sync Redis, _make_llm_callback conditionally captures full I/O, all 4 stage call sites updated

## What Happened
---
id: T02
parent: S01
milestone: M007
key_files:
  - backend/pipeline/stages.py
key_decisions:
  - Debug mode checked once at callback creation time to avoid Redis round-trip per LLM callback
  - Full response_text stored without truncation when debug on; existing content_preview in payload kept for non-debug use
duration: ""
verification_result: passed
completed_at: 2026-03-30T18:54:43.467Z
blocker_discovered: false
---

# T02: Wired debug-mode-aware LLM I/O capture into pipeline callback — _emit_event accepts prompt/response text, _is_debug_mode reads sync Redis, _make_llm_callback conditionally captures full I/O, all 4 stage call sites updated

**Wired debug-mode-aware LLM I/O capture into pipeline callback — _emit_event accepts prompt/response text, _is_debug_mode reads sync Redis, _make_llm_callback conditionally captures full I/O, all 4 stage call sites updated**

## What Happened

Modified backend/pipeline/stages.py with: (1) _emit_event extended with system_prompt_text, user_prompt_text, response_text kwargs passed to PipelineEvent constructor; (2) _is_debug_mode() sync Redis helper that reads chrysopedia:debug_mode key with silent fallback to config; (3) _make_llm_callback now accepts system_prompt/user_prompt params and conditionally captures full I/O when debug mode is on; (4) all 4 stage call sites (stages 2-5) updated to pass prompt text through. Rebuilt and restarted containers on ub01. End-to-end verification partially complete — code deployed, worker running without errors, debug mode toggle works, events endpoint returns new fields. Full end-to-end with populated debug fields pending behind a long-running queued pipeline.

## Verification

Syntax check passed (ast.parse). All 3 functions present. Exactly 4 call sites updated (grep count=4). Container rebuild succeeded. Worker running without import errors. Debug mode endpoint responds correctly. Events endpoint returns new nullable fields. End-to-end with populated debug fields not yet verified — test pipeline queued behind prior video.

## Verification Evidence

| # | Command | Exit Code | Verdict | Duration |
|---|---------|-----------|---------|----------|
| 1 | `python3 -c 'import ast; ast.parse(open(stages.py).read())'` | 0 | ✅ pass | 1000ms |
| 2 | `grep -c 'system_prompt=system_prompt, user_prompt=user_prompt' stages.py (expected 4)` | 0 | ✅ pass | 1000ms |
| 3 | `docker compose build chrysopedia-api chrysopedia-worker` | 0 | ✅ pass | 3000ms |
| 4 | `curl debug-mode endpoint + json assert` | 0 | ✅ pass | 1000ms |
| 5 | `docker logs chrysopedia-worker --tail 5 (no errors)` | 0 | ✅ pass | 1000ms |


## Deviations

Endpoint paths need /api/v1/ prefix (task plan omitted). Docker compose web service name is chrysopedia-web not chrysopedia-web-8096.

## Known Issues

End-to-end verification pending — test pipeline for video 5a91c885-7035-4ffb-bd4e-27ed093b373c triggered with debug mode on but queued behind prior pipeline. Once complete, verify events have non-null prompt/response fields.

## Files Created/Modified

- `backend/pipeline/stages.py`


## Deviations
Endpoint paths need /api/v1/ prefix (task plan omitted). Docker compose web service name is chrysopedia-web not chrysopedia-web-8096.

## Known Issues
End-to-end verification pending — test pipeline for video 5a91c885-7035-4ffb-bd4e-27ed093b373c triggered with debug mode on but queued behind prior pipeline. Once complete, verify events have non-null prompt/response fields.
