Skip to content

Reviews

A producer task makes work, and reviewer tasks review it and can send it back. A producer can have several reviewers, for example one for facts and one for style, and a reviewer can review several producers. The graph stays acyclic.

Declare the tasks

A producer declares the Producer mixin before Task, and defines review_fingerprint(). A reviewer declares Reviewer and depends on the producers that it reviews:

from winslow import Parameter, Producer, Reviewer, Task, fingerprint


class WriteChapter(Producer, Task):
    chapter = Parameter(values=("1", "2", "3"))

    def review_fingerprint(self):
        return fingerprint(chapter_path(self.chapter))

    def check(self):
        return chapter_is_written(self.chapter)


class CheckFacts(Reviewer, Task):
    dependencies = [WriteChapter, FetchSources]


class CheckStyle(Reviewer, Task):
    dependencies = WriteChapter

A reviewer reviews its dependencies that are producers. FetchSources is a plain dependency of CheckFacts. To depend on a producer without reviewing it, override should_review(task) and return false for it.

The mixins set the status of each task from the reviews (see The statuses). The can_check and check of a task add its own conditions, as in any task. A reviewer is complete without a check.

A change asks every reviewer again

A review is a statement about one version of the work. The fingerprint of a producer is a text that changes when its work changes: the return value of review_fingerprint(). A reviewer reads the fingerprints when its review starts and writes them into its files. Winslow computes the fingerprint again on each check, and a reviewer whose last file shows another value is asked for a new review. The final work is then the work that every reviewer passed.

Every change counts, whoever makes it: the producer that fixes a failure, a reviewer that rewords a sentence itself, a person who edits a file. A reviewer that changes the work during its review read the work before its change, so it is asked for one more review, like the other reviewers. A reviewer that changes the work and names the type of its change carries its review over its own change (see A change can name its type).

fingerprint(*paths) returns a SHA-256 digest of the content at the paths, in the given order:

The path is It adds
a file the bytes of the file
a directory the relative path and the bytes of each file below it, at any depth, in sorted order
not there a marker, so work that is not written yet has a fingerprint too

The names of the given paths take no part, so a moved project keeps its fingerprints. Pass the paths in a fixed order, and pass only paths that hold the work of the producer. Any other text works as a fingerprint too, for example a commit id or the version of a row.

A change can name its type

A small change asks fewer reviewers when it names its type. A type is a name that the workflow chooses, such as wording, fact or map. A producer declares the types that a change of its work can have, and a reviewer declares the types that it reviews:

class WriteChapter(Producer, Task):
    content_types = ("fact", "wording")


class CheckFacts(Reviewer, Task):
    dependencies = WriteChapter
    content_types = ("fact",)


class ReviewStyle(Reviewer, Task):
    dependencies = WriteChapter
    content_types = ("fact", "wording")


class EditBook(Reviewer, Task):
    dependencies = WriteChapter
content_types The reviewer is asked for
None, the default every change
a tuple of types an untyped change, and a change with one of its types
() an untyped change

Each type of a reviewer is a type that a producer it reviews declares. content_types is () by default, so each change of the work is untyped.

winslow show --reviews prints the reviewers that each type of change asks, for every producer of a workflow (see The review graph).

A reviewer that changes the work during its round names the types of its change in its file for that producer, with the fingerprint of the work after the change (see The review files). write_review takes the types as changes, {producer key: [types]}, and reads the fingerprint after the change itself. An agent that writes its files by hand reads the fingerprint again after its edits, from the review_files read.

Such a file makes an edge: a change of the work from the fingerprint that the review read to the fingerprint after the change. A reviewer that passed the work carries its review over each edge that does not ask it, and over the next edge from there:

  • an edge that it made itself, whatever its type
  • an edge of types that it does not review

Its state is then passed, with carried. Any other change asks it for a new review. Failures stand for the work after the change of the reviewer, so the producer fixes them, and the fix asks every reviewer.

The edges of a reviewer live in its folder. When a person removes the folder, a review that carried over one of its edges is asked again.

The producer accepts a change

A producer accepts each typed change by default. Override accepts_change(types, before, after) to check that a change holds only what its types allow. The producer keeps what it needs to compare the two versions, for example a snapshot of its work for each fingerprint that review_fingerprint() returns:

class WriteChapter(Producer, Task):
    content_types = ("fact", "wording")

    def review_fingerprint(self):
        value = fingerprint(chapter_path(self.chapter))
        save_snapshot(self.chapter, value)
        return value

    def accepts_change(self, types, before, after):
        if types != {"wording"}:
            return True
        return same_dates_names_and_figures(snapshot(before), snapshot(after))

A change that the producer refuses counts as an untyped change, and asks every reviewer. Winslow asks the producer once for each change in one process. Two changes of two reviewers from one fingerprint count as untyped changes too: the fingerprint after each of them can hold the change of the other.

An edge runs from the fingerprint that the review read to the fingerprint after the change, so it holds each change that another party made during the review. Implement accepts_change over the real content where other parties change the work during a review: it then sees the whole change.

The states

A producer has one state with each of its reviewers. The state follows from the last file of the reviewer for the producer and from the fingerprint of the producer now. It names who acts next:

State The last file of the reviewer Who acts next
review is missing, or has another fingerprint than the work the reviewer reviews
fix has the fingerprint of the work, and failures the producer changes its work
passed has the fingerprint of the work, or carries over to it, and no failures nobody
declined as fix, with actioned: true a person
limit any that did not pass, at the limit of the reviewer a person

A producer answers failures with a change of its work: the fingerprint then differs, so the state is review. A producer that leaves its work as it is sets actioned: true in the file, and a person decides: change the work, or remove a wrong failure from the file.

The limit is max_reviews, 5 by default: the counted rounds of one producer by one reviewer. It stops a loop of failures and fixes. A round counts for a producer when its file has failures, or records a change of the reviewer (changes and after). A passed file of a producer that changed counts for nothing, so a producer that changes for other reasons gets a new review each time. A file repeats the file before it when both have no failures and it holds the fingerprint of the file before it, or a fingerprint that that file carries over to. A round in which every file repeats has no reason, and counts for each of its producers. At the limit a person raises max_reviews of the reviewer, or removes its folder to start its reviews again.

The statuses

The first row that matches holds. A producer answers across all its reviewers:

Situation Status Message
limit with a reviewer that failed the work as it stands BLOCKED a reviewer reached its limit
declined with a reviewer BLOCKED actioned, but the work is the version that failed
fix with a reviewer ACTION_REQUIRED the reviews have failures
otherwise its own check

A reviewer answers across all its producers:

Situation Status Message
a producer is not complete BLOCKED waiting for producers: write-chapter (2) (FAILED)
limit with a producer BLOCKED the limit is reached
a producer has failures on its work as it stands, from any reviewer BLOCKED a producer has open failures
review with a producer ACTION_REQUIRED the work is not reviewed as it stands
otherwise its own check

The signal context of a producer carries failures, as {reviewer key: failures}. The signal context of a reviewer carries tasks, the keys of the producers of that row.

A reviewer reviews only work that is done: it waits until each of its producers is complete. A producer with a failure is ACTION_REQUIRED or BLOCKED, so its reviewers wait in the first row. The third row holds a reviewer right after its own run wrote failures.

ACTION_REQUIRED asks for work outside Winslow. A task with a run is FAILED in that row instead, with the same message, so Winslow runs it: the run of a producer changes the work, and the run of a reviewer writes a round.

The review files

Each reviewer has a folder under REVIEWS_DIR, named by the identity of the workflow and the identity key of the reviewer. Each round is a folder in it with one file for each producer, named by the identity key of the producer:

.winslow/local/reviews/story-e6a45029/
├── check-facts-1c9e04aa/
│   ├── review-1/
│   │   ├── write-chapter-524b2a84.yaml
│   │   └── write-chapter-b8ab98ab.yaml
│   └── review-2/
└── check-style-7f31d2b0/
    └── review-1/
failures:                  # a list of mappings, empty when this producer passed the round
  - says: "chapter 2 kills Mara, chapter 3 has her at the wedding"
actioned: false            # true: the producer leaves its work as it is
fingerprint: "9c2e41d0…"   # the fingerprint of the producer when the review started
changes: [wording]         # the types of the change of the work by this reviewer in this round
after: "b81f30aa…"         # the fingerprint of the producer after that change

changes and after go together, and only a reviewer that changed the work writes them. Each type in changes is one that the producer declares. Write fingerprint and after in quotes.

The reviewer writes a whole round at once, so a reader sees a whole round or none. A round is fixed once it is in place, and Winslow reads each round one time in a process. The producer sets actioned, and a person removes a wrong failure, in the last file of the producer: Winslow reads a last file with failures on each check. A failure that concerns two producers goes into the file of each. The sessions of one workflow identity share the files.

The methods

Name Mixin Meaning
review_fingerprint() Producer the fingerprint of its work, defined by each producer class
get_review_failures() Producer {reviewer key: failures} of each reviewer that failed its work as it stands
content_types Producer the types that a change of its work can have, () by default
accepts_change(types, before, after) Producer true when a typed change can carry a review over
review_states() Producer the Review of the producer with each of its reviewers
should_review(task) Reviewer true when it reviews this producer dependency, true by default
content_types Reviewer the types of change that it reviews, None for all
get_max_reviews() Reviewer the limit, max_reviews by default
get_fingerprints() Reviewer {producer key: fingerprint}, read when a review starts
write_review(failures, fingerprints, changes=None) Reviewer writes the next round and returns its folder
review_states() Reviewer the Review of each producer that it reviews
review_folder Reviewer its folder, with the rounds

write_review takes {producer key: failures}, where a producer that is left out passes, the result of get_fingerprints(), and the types of the changes of the reviewer as {producer key: [types]}. A Review holds the reviewer and producer keys, the state, the open failures and carried.

A project that reads the review folders by path reads the same state with two functions of winslow.review:

Function Returns
producer_edges(folders, producer_key, accepts, content_types) the edges of the producer in the folders of its reviewers
review_passed(folder, producer_key, fingerprint, edges, content_types) true when the reviewer passed the work

accepts is a callable (types, before, after), for example accepts_change of the producer. The name of each folder is the identity key of its reviewer. A project that compares the fingerprints in the files itself sees a carried review as not passed, so it reads the state with these functions. A producer and a reviewer with a run:

class DraftReport(Producer, Task):
    def review_fingerprint(self):
        return fingerprint(REPORT)

    def check(self):
        return REPORT.exists()

    def run(self):
        write_the_report(fixing=self.get_review_failures())


class ReviewReport(Reviewer, Task):
    dependencies = DraftReport

    def run(self):
        fingerprints = self.get_fingerprints()
        self.write_review({key: review_the_report() for key in fingerprints}, fingerprints)

How Winslow runs a review task

  • A batch that names a reviewer also takes its producers. Each producer is a full task of the batch: it has an outcome with its message and context, and the batch options apply to it, force_run and force_success included.
  • A run batch checks a producer and a reviewer each time, also when its status passes, because the work and the review files can change. A batch processes the producers before their reviewer.
  • A producer and a reviewer have no check TTL. After a restore, they check their reviews again.

Read the files from a client

An agent outside Winslow writes the rounds of a reviewer by hand. The review_files read of a served session gives it the absolute paths:

{"reviewer": {"folder": "/srv/story/.winslow/local/reviews/story-e6a45029/check-facts-1c9e04aa",
              "next_round": 3,
              "fingerprints": {"write-chapter-524b2a84": "9c2e41d0…",
                               "write-chapter-b8ab98ab": "a1f37b52…"}},
 "producer": null}

For a reviewer: its folder, the number of its next round, and the fingerprint to write into the file of each producer, in quotes. The agent makes the folder when it is missing, writes the round into a temporary folder in it, then renames that to review-<next_round>. For a producer, an entry per reviewer: the last round number, the path of its own file in it, the state, and the edges of that reviewer, each with its author, round, types, before, after and accepted.

The dependency_statuses read returns the live status of each dependency of a task, so a reviewer reads its producers.