Capstone: Pila 1.2 · lesson 9 of 9
Ideas in this lesson
A1.2.17.4: a patch release
BPost-mortem7.9: what happened, why, and what changes
CRetrospective9.7: specific, owned actions

Look back

Last updated

Monday morning, the first week after the release. Ate Cora texts: four babies due a vaccine today missed their appointment, and none of their mothers got a reminder. The feature passed every test. In this lesson you'll find out why, fix it with a regression test, release the fix, write a blameless post-mortem, and run the retrospective that closes the capstone.

By the end of this lesson you can

  • Reproduce a bug reported from the field with a failing test, and fix it
  • Release a fix as a patch version
  • Write a blameless post-mortem and a retrospective with actions that change things

The report

Monday, 10:30. A text from Ate Cora:

From Ate Cora
TimeMessage
10:30“Four babies due today didn’t come. I phoned two of the mothers: neither got a reminder. The ones due Thursday and Friday last week all came. Is something wrong with Pila?”

It's a bug from the field: corrective maintenance (lesson 8.1), the first of Pila's 1.2 line. Open an issue for it with what Ate Cora said, label it bug, and put it at the top of the board.

Thursday’s and Friday’s mothers got reminders; Monday’s didn’t. What’s the first thing to suspect?
How the reference does it pila/jobs.py
"""When Pila's scheduled jobs run, such as the nightly reset of each queue."""

from datetime import date

# The health centres are open Monday to Friday, so the jobs run on those days.
JOB_DAYS = {0, 1, 2, 3, 4}  # date.weekday(): Monday is 0, Sunday is 6


def runs_on(day: date) -> bool:
    """Whether the scheduled jobs run on this day."""
    return day.weekday() in JOB_DAYS

Reproduce it

Before changing anything, write a test that shows the bug in your code, and watch it fail. The reference used a Friday and the following Monday:

Terminal
def test_mondays_vaccines_are_reminded_on_friday():
    assert [r.due for r in book_with(NEXT_MONDAY).due_for(FRIDAY)] == [NEXT_MONDAY]


(.venv) $ python -m pytest -q
FAILED tests/test_reminders.py::test_mondays_vaccines_are_reminded_on_friday
    assert [] == [datetime.date(2027, 3, 15)]
1 failed, 38 passed

If yours already handled weekends, well done: you caught what the reference team missed. Write the test anyway, to keep it that way, and read on: the post-mortem is still worth writing about how close it came.

Fix it, and release 1.2.1

There's more than one fix. The reference weighed two, and recorded its choice as a decision:

How the reference does it docs/adr/0002-remind-on-the-last-job-day-before.md
# 2. Remind on the last job day before the vaccine

Status: accepted (replaces the first version of #50, after bug #57)

## Context

Reminders are sent by the scheduled job, which runs only Monday to Friday (`jobs.py`). Version 1.2.0 sent each reminder exactly one day before the vaccine. Vaccines due on Monday would have been reminded on Sunday, when no job runs, so they were never reminded.

## Options

1. Run the reminder job every day, including weekends.
2. On each job day, remind for every vaccine due up to and including the next job day.

## Decision

Option 2. On Monday to Thursday it sends the reminders for the next day, as before. On Friday it sends Saturday's, Sunday's and Monday's.

Option 1 would mean the scheduled jobs running on days nobody at the health centres is working, so nobody would be there to notice if they failed.

## Consequences

- Monday's vaccines are reminded three days early, on Friday. The text says the day, such as "Monday 15 March", so it's still clear.
- If the job days change, for example for a holiday, the reminders follow without another change.

Here's its fixed due_for, with the helper it needed:

How the reference does it pila/reminders.py, lines 22–27
def next_job_day(today: date) -> date:
    """The next day after today when the scheduled jobs run."""
    day = today + timedelta(days=1)
    while not runs_on(day):
        day += timedelta(days=1)
    return day
How the reference does it pila/reminders.py, lines 64–75
    def due_for(self, today: date) -> list[Reminder]:
        """The reminders to send today.

        Every vaccine due after today, up to and including the next day the jobs
        run. On a Friday that's Saturday, Sunday and Monday: no job runs at the
        weekend to send Monday's reminders (#57).
        """
        if not runs_on(today):
            return []
        last = next_job_day(today)
        return [r for r in self.reminders if today < r.due <= last and r.phone not in self.stopped]

Fix yours on a branch, with the regression test. Add tests for the other edges too: Tuesday's vaccines aren't sent on Friday, and nothing is sent at the weekend. Then release, as in C.8, but smaller:

What’s the version of this release?

Add a Fixed entry to the changelog, tag v1.2.1, and publish it. Text Ate Cora too: what was wrong, that it's fixed, and that her staff might phone next Monday's mothers, just in case.

The post-mortem

Four babies missed a vaccine. Write a blameless post-mortem (lesson 7.9): what happened, how the system let it happen, and what will change. Save it as docs/postmortem-<issue>.md.

Post-mortemKept in this browser only
  • Says who was affected (not yet)
  • Says for how long, or how many (not yet)
  • At least four moments (not yet)
  • Times or days (not yet)
  • At least two causes (not yet)
  • About weekends or job days (not yet)
  • About the tests (not yet)
  • Blameless: no one is blamed (done)
  • At least two actions (not yet)
  • Each has an owner or a date (not yet)
Write each part until its checks pass.
Ate Cora mentioned in the very first interview that Monday is the big vaccination day. What does the post-mortem do with that?

The retrospective

Last, look back over the whole capstone, as the team would at the end of a sprint (lesson 9.7). Compare your sprint plan from C.4 with what really happened.

RetrospectiveKept in this browser only
  • At least two (not yet)
  • At least two (not yet)
  • At least one action (not yet)
  • Not “try harder” or “be more careful” (done)
Write each part until its checks pass.

What you’ve built

Look at your repository. It has:

  • Requirements: stories with testable criteria, as issues on a board.
  • Design: a design document, decision records and a threat model.
  • Code: a feature built in small, reviewed pull requests, each linked to its issue.
  • Tests: unit tests, acceptance tests for every criterion, and regression tests for every bug.
  • A pipeline that checks every change, with its badge on the front page.
  • Two releases, tagged, with a changelog and notes for the people who use it.
  • A post-mortem and a retrospective that turn a failure into changes.

That's every phase of the life cycle, done once, for real. It's also exactly the kind of work you can show (lesson 9.8). Put a short paragraph at the top of the README saying what you did, and the repository is a portfolio piece.

Check what you learned

The feature passed every test and still failed in the field. What does that show?
Which retrospective action is most likely to change something?

Sources

Every claim on this page comes from these sources: the standard, the founding text of a method, a study, or the official record of a project, from the body that publishes it. Industry reports are labelled as such.

All sources for Simple Software Development