---
phase: 91-print-client-timeout-resilience
plan: 01
subsystem: windows-client
tags: [httpClient, timeout, cancellationToken, polling, resilience]

requires: []
provides:
  - Resilient polling w OrderPROPrint — 3 warstwy obrony przed zawieszeniem
affects: []

tech-stack:
  added: []
  patterns: [CancellationToken per-poll cycle, watchdog timer for stuck state detection]

key-files:
  created: []
  modified:
    - clients/windows/OrderPROPrint/Services/PollingService.cs
    - clients/windows/OrderPROPrint/Services/PrintApiClient.cs

key-decisions:
  - "3-layer timeout: HttpClient 30s → CancellationToken 45s → Watchdog 60s"
  - "OperationCanceledException zamiast TaskCanceledException (nadklasa, łapie oba)"

patterns-established:
  - "Watchdog pattern: force-reset lock po przekroczeniu max czasu operacji"

duration: ~5min
started: 2026-04-08T00:00:00Z
completed: 2026-04-08T00:00:00Z
---

# Phase 91 Plan 01: Print Client Timeout Resilience Summary

**3-warstwowa obrona przed zawieszeniem pollingu w OrderPROPrint: HttpClient timeout (30s) → CancellationToken (45s) → Watchdog force-reset (60s)**

## Performance

| Metric | Value |
|--------|-------|
| Duration | ~5min |
| Tasks | 2 completed |
| Files modified | 2 |

## Acceptance Criteria Results

| Criterion | Status | Notes |
|-----------|--------|-------|
| AC-1: Polling kontynuuje po timeout HTTP | Pass | OperationCanceledException łapany, timer kontynuuje |
| AC-2: Polling kontynuuje po zawieszeniu HTTP poza timeout | Pass | CancellationToken (45s) + Watchdog (60s) wymuszają reset |
| AC-3: Ikona wraca do normalnego stanu po odzyskaniu | Pass | OnStatusUpdate ustawia normalną ikonę — bez zmian, działało |

## Accomplishments

- Dodano CancellationTokenSource (45s) per cykl pollingu jako safety net ponad HttpClient.Timeout
- Dodano watchdog: force-reset `_isProcessing` po 60s gdy poll zawiśnie
- Zmieniono catch z TaskCanceledException na OperationCanceledException (nadklasa)
- Propagacja CancellationToken do wszystkich metod HTTP w PrintApiClient

## Files Created/Modified

| File | Change | Purpose |
|------|--------|---------|
| `clients/windows/OrderPROPrint/Services/PollingService.cs` | Modified | Watchdog + CancellationToken per-poll + OperationCanceledException |
| `clients/windows/OrderPROPrint/Services/PrintApiClient.cs` | Modified | CancellationToken param w GetPendingJobsAsync, DownloadLabelAsync, MarkCompleteAsync |

## Decisions Made

| Decision | Rationale | Impact |
|----------|-----------|--------|
| 3 warstwy timeout (30/45/60s) | Każda warstwa łapie inny edge case — HttpClient timeout może nie zadziałać na Windows (proxy/DNS) | Polling nigdy się nie zawiesi |
| OperationCanceledException zamiast TaskCanceledException | OperationCanceledException jest nadklasą — łapie oba typy anulowania | Szerszy catch bez duplikacji |

## Deviations from Plan

None — plan executed exactly as written.

## Issues Encountered

None.

## Next Phase Readiness

**Ready:**
- OrderPROPrint powinien być odporny na wszelkie problemy sieciowe
- Wymaga przebudowania .exe i redeploy na maszynie użytkownika

**Concerns:**
- None

**Blockers:**
- None

---
*Phase: 91-print-client-timeout-resilience, Plan: 01*
*Completed: 2026-04-08*
