# AutoProtocol manual recovery rerun after web-session loss

Use this reference when AutoProtocol/Streamlit has already uploaded media into `input/`, the web session or service was restarted, and the user asks to continue or implement next steps without re-uploading.

## Trigger

- A long AutoProtocol transcription/protocol run was interrupted after upload.
- The web app was restarted to apply a fix, losing Streamlit UI session state.
- Uploaded media still exists under the project `input/` directory.
- The user asks to continue with the next steps rather than manually re-uploading.

## Pattern

1. **Inspect existing inputs before asking the user to re-upload.**
   - Prefer the newest relevant `.mp4`/`.m4a`/audio file over generated `_extracted.wav` siblings unless the recovery target is explicitly STT-only.
   - Avoid printing transcript contents or meeting-sensitive raw text in chat.
2. **Verify the service and repo state if relevant.**
   - `systemctl --user is-active autoprotocol-webapp.service`
   - `bash scripts/status-webapp.sh`
   - `git status --short`
3. **Run the same production pipeline from a project-local CLI snippet.**
   - Call `process_direct(media)` for STT/diarization.
   - Immediately call `export_to_word(transcript, media.name)` to preserve the raw transcript.
   - Then call `generate_protocol_with_llm(...)` and `save_llm_to_word(...)` for the final protocol.
4. **Use a tracked background process for long recordings.**
   - Use `terminal(background=True, notify_on_complete=True)` or equivalent process tracking.
   - Tee logs into ignored project logs, e.g. `logs/autoprotocol_manual_YYYYMMDD_HHMMSS.log`.
5. **On completion, verify output files by path/size and deliver only the `.docx` artefacts or paths.**
   - Do not paste raw transcripts or protocol text unless explicitly requested.

## Example recovery command

```bash
set -euo pipefail
mkdir -p logs
LOG="logs/autoprotocol_manual_$(date +%Y%m%d_%H%M%S).log"
MEDIA="input/<uploaded-meeting-recording>.mp4"
{
  echo "START $(date -Is)"
  echo "INPUT $MEDIA"
  .venv/bin/python - <<'PY'
from pathlib import Path
from autoprotocol import process_direct, export_to_word
from llm_processor import generate_protocol_with_llm, save_llm_to_word

media = Path("input/<uploaded-meeting-recording>.mp4")
print(f"processing={media.resolve()} size={media.stat().st_size}")
transcript = process_direct(str(media))
transcript_path = export_to_word(transcript, media.name)
print(f"transcript_docx={transcript_path}")
protocol = generate_protocol_with_llm(transcript, "bauprojekt", "", "")
protocol_path = save_llm_to_word(protocol, media.name)
print(f"protocol_docx={protocol_path}")
PY
  echo "END $(date -Is)"
} 2>&1 | tee "$LOG"
```

## Reporting

Report that the recovery run is active, include the process/session id if available, and say that files will be delivered after completion. Keep the message short; the important evidence is the tracked process and final artefacts, not a speculative success claim.
