- SUMMARY.md with 25 tests, 2 task commits, 1 deviation - STATE.md: plan 5/14, 4 completed, clock decisions recorded - ROADMAP.md: 4/14 plans complete in Phase 1 - REQUIREMENTS.md: CLOCK-01 through CLOCK-09 marked complete Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
6.8 KiB
6.8 KiB
| phase | plan | subsystem | tags | requires | provides | affects | tech-stack | key-files | key-decisions | patterns-established | requirements-completed | duration | completed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 01-tournament-engine | 04 | api |
|
|
|
|
|
|
|
|
|
8min | 2026-03-01 |
Phase 1 Plan 04: Clock Engine Summary
Server-authoritative tournament clock with state machine, drift-free 100ms ticker, configurable warnings, multi-tournament registry, REST API, and DB persistence -- verified with 25 unit tests
Performance
- Duration: 8 min
- Started: 2026-03-01T02:48:21Z
- Completed: 2026-03-01T02:56:31Z
- Tasks: 2
- Files modified: 12
Accomplishments
- Complete clock state machine (stopped/running/paused) with all transitions and guard conditions
- Drift-free ticker using Go monotonic clock at 100ms resolution with adaptive broadcast rate
- Multi-tournament clock registry with independent engines and per-engine ticker goroutines
- Full REST API with role-based access (floor+ for mutations, any auth for reads)
- Configurable warning thresholds (default 60s/30s/10s) with WebSocket events
- Clock state persisted to DB on every meaningful state change for crash recovery
- Hand-for-hand mode support (clock pauses, per-table deduction via seating engine)
- Overtime handling (repeat last level or stop -- configurable)
Task Commits
Each task was committed atomically:
- Task D1: Clock engine state machine and ticker -
9ce05f6(feat) - Task D2: Warnings, API routes, tests, and server wiring -
ae90d9b(feat)
Files Created/Modified
internal/clock/engine.go- ClockEngine state machine, Level/Warning/Snapshot structs, all operationsinternal/clock/ticker.go- StartTicker with 100ms resolution and adaptive broadcast rateinternal/clock/registry.go- Thread-safe ClockRegistry managing multiple enginesinternal/clock/warnings.go- Warning system documentation (logic in engine.go)internal/clock/engine_test.go- 16 tests: state machine, countdown, auto-advance, pause/resume, jump, rewind, hand-for-hand, snapshot, overtime, crash recoveryinternal/clock/warnings_test.go- 5 tests: threshold detection, no re-emit, reset on level change, defaults, custominternal/clock/registry_test.go- 4 tests: get/create, get, remove, shutdowninternal/server/routes/clock.go- 8 API endpoints with DB integration and role-based accessinternal/server/server.go- Clock registry wired into server constructor and route registrationcmd/leaf/main.go- Clock registry created during startup, shutdown on exitcmd/leaf/main_test.go- Test setup updated with clock registry parameterinternal/auth/pin.go- Fix missing crypto/rand import (auto-fix)
Decisions Made
- Clock ticker uses single 100ms timer with broadcast gating rather than two separate tickers (simpler, same result)
- Crash recovery always restores as paused -- safer than auto-resuming with potentially stale remaining time
- Overtime defaults to repeat mode (most common in poker tournaments)
- State change callback runs in a goroutine to prevent DB latency from blocking the clock ticker
- AuditRecorder is an interface (not direct import) to avoid circular dependency between clock and audit packages
Deviations from Plan
Auto-fixed Issues
1. [Rule 3 - Blocking] Missing crypto/rand import in auth/pin.go
- Found during: Task D2 (compiling routes package which depends on auth)
- Issue: internal/auth/pin.go uses
rand.Readbut was missingcrypto/randimport, preventing compilation of the routes package - Fix: Added
"crypto/rand"to the import block - Files modified: internal/auth/pin.go
- Verification:
go build ./...passes,go vet ./...passes - Committed in:
ae90d9b(Task D2 commit)
Total deviations: 1 auto-fixed (1 blocking) Impact on plan: Single missing import in a dependency. No scope creep.
Issues Encountered
None
User Setup Required
None - no external service configuration required.
Next Phase Readiness
- Clock engine fully operational for all tournament clock requirements
- API endpoints ready for frontend integration (Plan K/L)
- Clock registry supports multi-tournament operation (MULTI-01)
- Warning events ready for display views (Phase 2)
- DB persistence ensures clock survives server restart
Self-Check: PASSED
All 8 created files verified present. Both commit hashes (9ce05f6, ae90d9b) found in git log. SUMMARY.md exists at expected path.
Phase: 01-tournament-engine Completed: 2026-03-01