Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Use the object ID shown under **Enterprise applications** in Microsoft Entra, no

## Daily reminder

A scheduled cloud flow, **MedTrack – Daily Reminder**, checks once a day at local midnight and posts one message in Microsoft Teams, as a chat from the Flow bot (shown as "Workflows"). With Teams on your phone, that is a notification:
A scheduled cloud flow, **MedTrack – Daily Reminder**, checks once a day just after local midnight (00:05) and posts one message in Microsoft Teams, as a chat from the Flow bot (shown as "Workflows"). With Teams on your phone, that is a notification:

- **Due today** — every Active Medication due that day. Injections count from the last dose; everything else follows its fixed schedule.
- **Follow-ups** — a Medication whose intake was missed, on the 1st, 3rd, 5th and 7th day afterwards. Logging it as Taken or Skipped stops the follow-ups.
Expand Down Expand Up @@ -133,7 +133,7 @@ Earlier versions of this feature sent email, first through the Mail connector an

- **Teams holds back phone notifications while you are active in Teams on a computer.** The message is in the chat either way.
- **A failed check notifies nobody.** Power Automate sends failure notices to the flow's owner, and the owner is a service principal. The record of each day is a row in the **Reminder Run** table (`ppa_reminderrun`) — outcome Sent, Nothing To Send or Failed, with the step that failed — and the flow's run history. A day with no row at all means the flow could not reach Dataverse.
- **At most one message a day.** A second run on the same day stops at the Reminder Run row. A failed run is retried on the hour until 03:00 local time.
- **At most one message a day.** A second run on the same day stops at the Reminder Run row. A failed run is retried every hour, at five past, until 03:05 local time.
- **Testing by hand works only in the first four hours of the local day.** The flow's Run button obeys the same time gate as the schedule.

---
Expand Down
2 changes: 1 addition & 1 deletion solution/src/Other/Solution.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<LocalizedName description="MedTrack Solution" languagecode="1033" />
</LocalizedNames>
<Descriptions />
<Version>1.0.0.4</Version>
<Version>1.0.0.5</Version>
<Managed>0</Managed>
<Publisher>
<UniqueName>PowerPlatformAdvocates</UniqueName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"recurrence": {
"frequency": "Hour",
"interval": 1,
"startTime": "2026-01-01T00:00:00Z"
"startTime": "2026-01-01T00:05:00Z"
},
"conditions": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ FR-014 to FR-027 and User Stories 2 and 3. The rules it applies are in

| Setting | Value |
|---|---|
| Type | Recurrence, every 1 hour, at minute 0 |
| Type | Recurrence, every 1 hour, at minute 5 (`startTime` `2026-01-01T00:05:00Z`) |
| Trigger condition | local hour, from `convertFromUtc(utcNow(), <time zone>, 'HH')`, is 0, 1, 2 or 3 |
| Concurrency | 1 (no parallel runs) |

Normal night: the 00:00 run does the work and the 01:00–03:00 runs stop at step 3.
Normal night: the 00:05 run does the work and the 01:05–03:05 runs stop at step 3.

The trigger is kept off the hour boundary on purpose. A Recurrence trigger can fire a
fraction of a second early; at minute 0 that made the midnight check read the local hour
as 23 and skip itself (research R5).

## Steps

Expand Down
2 changes: 1 addition & 1 deletion specs/004-schedule-page-reminders/data-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ No column ever holds the reminder address.
- `Started`, `Sent` and `Nothing To Send` all end a later run immediately.
- A row stuck at `Started` means a run was interrupted after it may have sent. It is not
retried, which keeps the guarantee at "never two messages" rather than "always one".
- Retries stop after the 03:00 local run (research R5); the row then stays `Failed`.
- Retries stop after the 03:05 local run (research R5); the row then stays `Failed`.

### Validation rules

Expand Down
4 changes: 2 additions & 2 deletions specs/004-schedule-page-reminders/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ Then:
Leave the flow on for one night with at least one seeded Medication due the next day.

**Expect**: a Reminder Run for the new day with outcome Sent, created within 15 minutes of
local midnight, and exactly one message. Runs at 01:00–03:00 either do not appear or end at
the guard.
local midnight (the check runs at 00:05), and exactly one message. Runs at 01:05–03:05
either do not appear or end at the guard.

## Definition of done for this feature

Expand Down
29 changes: 24 additions & 5 deletions specs/004-schedule-page-reminders/research.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,16 @@ bounded page.

## R5. How the daily check is triggered at local midnight

**Decision**: A Recurrence trigger that fires every hour, with a trigger condition that
lets it run only when the local hour is 0 to 3. Local time comes from a Text environment
**Decision**: A Recurrence trigger that fires every hour, at five past, with a trigger
condition that lets it run only when the local hour is 0 to 3. Local time comes from a Text environment
variable, `ppa_ReminderTimeZone` (a Windows time zone name, default `UTC`). The first run
after local midnight does the work; later runs that night exit at the idempotency guard
(R6) unless the earlier attempt failed, in which case they retry.

**Rationale**:
- Daylight saving is handled by `convertFromUtc`, not by trigger arithmetic. A zone whose
clocks jump at midnight skips hour 0 entirely on that day; the hour-1 run covers it.
- A transient outage at 00:00 is retried at 01:00, 02:00 and 03:00 without owner action
- A transient outage at 00:05 is retried at 01:05, 02:05 and 03:05 without owner action
(FR-021: a failure must not prevent the check from running).
- The time zone is configuration, not a literal in a public repository (CLAUDE.md:
environment variables for configuration).
Expand Down Expand Up @@ -186,8 +186,27 @@ Verified way to test at any time of day, with no design change:
This is an open point for the owner: keep the gate and test this way, or change the gate.
quickstart.md sections E to G assume a manual test simply runs.

**Found in production (2026-10-07) — the trigger must not sit on the hour boundary.**
The trigger first ran at minute 0 (`startTime` `2026-01-01T00:00:00Z`). A Recurrence
trigger does not fire exactly on time: of 24 hourly evaluations in production, 7 started
before the hour, by up to 0.4 s. The trigger condition reads `utcNow()` at that moment,
so an early midnight evaluation saw the previous hour:

| Evaluation (UTC) | Eastern local time | `HH` | Result |
|---|---|---|---|
| 2026-10-07T03:59:59.597Z | 23:59:59 | `23` | not fired — no run at midnight |
| 2026-10-06T04:59:59.607Z | 00:59:59 | `00` | fired — the 01:00 run did the work |
| 2026-10-06T08:00:00.588Z | 04:00:00 | `04` | not fired |

No reminder was lost, because the next hourly run did the work, but it arrived an hour
late, outside SC-006. The trigger now starts at five past the hour (`startTime`
`2026-01-01T00:05:00Z`), far enough from the boundary that the hour cannot be read
wrong, and still inside SC-006's 15 minutes. Padding the condition (for example
`addSeconds(utcNow(), 30)`) was rejected: it would let the early run start, and the
`Today` step reads `utcNow()` the same way, so it could take yesterday's date.

**Alternatives considered**:
- *Daily Recurrence at 00:00 with a literal `timeZone`* — simplest, but the zone would be
- *Daily Recurrence at local midnight with a literal `timeZone`* — simplest, but the zone would be
duplicated (trigger and in-flow date maths), hard-coded, and there is no retry.
- *Every 15 minutes* — supports half-hour-offset zones exactly, at the cost of a noisy run
history. Not needed for the owner's zone; recorded as a known limitation (R13).
Expand Down Expand Up @@ -618,7 +637,7 @@ read. A tooltip — unusable on touch screens.

## R13. Known limitations accepted

- **Half-hour-offset time zones**: with an hourly trigger the check runs at 00:30 local in
- **Half-hour-offset time zones**: with an hourly trigger the check runs at 00:35 local in
such zones, outside SC-006's 15-minute target. Not the owner's zone. Moving to a
30-minute trigger fixes it if ever needed.
Comment on lines +640 to 642
- **One owner per environment**: the `ppa_ReminderRun` alternate key is the day alone, so
Expand Down
2 changes: 1 addition & 1 deletion specs/004-schedule-page-reminders/tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ says "email", read "reminder message". What that changed in the task list:
### Cloud flow for User Story 2

- [X] T030 [US2] Spike research R5 in dev: a throwaway solution flow with an hourly Recurrence trigger whose trigger condition reads `ppa_ReminderTimeZone` through `convertFromUtc(utcNow(), <env var>, 'HH')`. Record in `specs/004-schedule-page-reminders/research.md` R5 whether it saves and fires; if it does not, record that the hour check moves to the first action and ends the run as Cancelled. Delete the throwaway flow
- [X] T031 [US2] In dev, inside `MedTrackSolution`, create the flow "MedTrack – Daily Reminder" per `contracts/reminder-flow.contract.md`: hourly Recurrence at minute 0, the local-hour 0–3 gate from T030, concurrency 1; then steps 1–3: local `today` from `ppa_ReminderTimeZone`, `WhoAmI`, and the guard (create `ppa_reminderrun` with `ppa_name = today`, outcome Started, attempts 1, counts 0; on duplicate key read the row — outcome Failed → set Started and attempts + 1 and continue, anything else → end the run)
- [X] T031 [US2] In dev, inside `MedTrackSolution`, create the flow "MedTrack – Daily Reminder" per `contracts/reminder-flow.contract.md`: hourly Recurrence at minute 0 (moved to minute 5 on 2026-10-07, see research R5), the local-hour 0–3 gate from T030, concurrency 1; then steps 1–3: local `today` from `ppa_ReminderTimeZone`, `WhoAmI`, and the guard (create `ppa_reminderrun` with `ppa_name = today`, outcome Started, attempts 1, counts 0; on duplicate key read the row — outcome Failed → set Started and attempts + 1 and continue, anything else → end the run)
- [X] T032 [US2] Add steps 4–6 to the flow: validate `ppa_ReminderRecipientEmail` (failure step name `ValidateRecipient`); list Medications with `statecode eq 0`, `ppa_isactive eq true`, `ppa_frequency ne 894250003`, `_ownerid_value eq <WhoAmI user>` and only the columns in data-model.md §1; for each, read the latest Taken and latest Skipped log (`top 1`, `ppa_loggedat le utcNow()`, newest first) and apply Steps 1–3 of `contracts/schedule-rules.contract.md` to decide **due today** (rolling for Injection with a Taken or Skipped log, fixed otherwise). Use the date text of `ppa_startdate` as-is, never shifted through a time zone
- [X] T033 [US2] Add steps 7–9 and the failure path: nothing due → outcome Nothing To Send; otherwise one Office 365 Outlook "Send an email (V2)" (first built with Mail "Send an email notification (V3)", which this tenant refuses — research R7) with Secure Inputs and Secure Outputs on, subject `MedTrack: <n> due today`, HTML section "Due today" ordered by Reminder Time then name, each line `<name> — <dosage> — <Reminder Time or "no reminder time">`, injections adding `Last taken <date> · <site>` or `Not yet taken`; then outcome Sent with `ppa_DueCount`, `ppa_Summary` (`Due: …` / `Follow-up: –`). Wrap steps 4–9 in a scope whose failure handler sets outcome Failed and `ppa_ErrorStep` = `<step name> (<status code>)` only — no raw error text — and ends the run Failed; a failure after the send succeeded leaves the outcome as Started
- [X] T034 [US2] In dev run `pwsh scripts/reminder/seed-reminder-scenarios.ps1`, test the flow manually, then `pwsh scripts/reminder/assert-reminder-run.ps1 -ExpectOutcome Sent -ExpectDue S01,S03,S04,S12,S17,S18,S25,S27,S29`; fix the flow until it passes and one email with the nine due rows arrives. Check the send action's inputs are hidden in run history (the seeded run passed with the email version, whose messages the owner's mail provider then refused; delivery was confirmed by the owner with the Teams version — research R7, R10)
Expand Down
Loading