fix: prevent duplicate scheduled clockins and repair Bark notifications #7

Merged
YingmoY merged 1 commit from codex into main 2026-06-08 11:06:07 +08:00
YingmoY commented 2026-06-08 11:04:44 +08:00 (Migrated from github.com)

Motivation

  • Prevent duplicate clock-ins caused by overlapping triggers (cron, calibration, startup recovery) for the same user and date.
  • Ensure startup-recovery work is handled by the scheduler path so the same dedupe logic applies.
  • Fix Bark notification failures when using GET/path-based delivery with characters that break URL encoding.

Description

  • Add scheduler deduplication by introducing runDate and dedupeKey to scheduled tasks and maintain an in-memory pendingRuns map with reserveScheduledRun/releaseScheduledRun guarded by runDedupeMu.
  • Stop enqueueing duplicate scheduled jobs by checking the dedupe key at submitScheduledRun, and release the dedupe entry when the run finishes or is aborted.
  • Route startup_recovery through the scheduler queue (use submitScheduledRun) instead of executing immediately to reuse dedupe logic.
  • Add a persistent guard in the execution path (executeClockinRunForDate) to skip runs when a successful scheduled run for the same run_date already exists and return a skipped status.
  • Change Bark delivery to use the JSON /push API with POST, validate device_key, support a default Bark server URL, and surface Bark API error codes/messages.
  • Add tests: internal/server/scheduler_test.go (queue dedupe and skip-on-existing-success) and internal/server/notification_test.go (Bark JSON payload), and make internal/core/service_test.go self-contained by writing a temp config.json.

Testing

  • Ran go test ./... and all package tests passed; the added tests exercise scheduler dedupe and Bark JSON behavior. (success)
  • Ran go build ./... to verify the project compiles after changes. (success)

Codex Task

### Motivation - Prevent duplicate clock-ins caused by overlapping triggers (cron, calibration, startup recovery) for the same user and date. - Ensure startup-recovery work is handled by the scheduler path so the same dedupe logic applies. - Fix Bark notification failures when using GET/path-based delivery with characters that break URL encoding. ### Description - Add scheduler deduplication by introducing `runDate` and `dedupeKey` to scheduled tasks and maintain an in-memory `pendingRuns` map with `reserveScheduledRun`/`releaseScheduledRun` guarded by `runDedupeMu`. - Stop enqueueing duplicate scheduled jobs by checking the dedupe key at `submitScheduledRun`, and release the dedupe entry when the run finishes or is aborted. - Route `startup_recovery` through the scheduler queue (use `submitScheduledRun`) instead of executing immediately to reuse dedupe logic. - Add a persistent guard in the execution path (`executeClockinRunForDate`) to skip runs when a successful scheduled run for the same `run_date` already exists and return a `skipped` status. - Change Bark delivery to use the JSON `/push` API with `POST`, validate `device_key`, support a default Bark server URL, and surface Bark API error codes/messages. - Add tests: `internal/server/scheduler_test.go` (queue dedupe and skip-on-existing-success) and `internal/server/notification_test.go` (Bark JSON payload), and make `internal/core/service_test.go` self-contained by writing a temp `config.json`. ### Testing - Ran `go test ./...` and all package tests passed; the added tests exercise scheduler dedupe and Bark JSON behavior. (success) - Ran `go build ./...` to verify the project compiles after changes. (success) ------ [Codex Task](https://chatgpt.com/codex/cloud/tasks/task_e_6a262ddced94832f8f3a04211d0b5d5d)
copilot-pull-request-reviewer[bot] (Migrated from github.com) reviewed 2026-06-08 11:07:29 +08:00
copilot-pull-request-reviewer[bot] (Migrated from github.com) left a comment

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Sign in to join this conversation.
No description provided.