Open Factory Flooropen source

Guides

The Open Factory Floor app

On this page

See your factory: what it is, and what it is doing now. One command, on your own machine.

python3 -m factory.app --repo OWNER/REPO

Run it from a clone of Open Factory Floor at the version you use, with its one dependency installed (as in step 2 of the setup guide), signed in with gh (the GitHub command line). It starts a small web server that only this machine can reach, and opens the page in your browser. --port gives another port than 8787, and --no-open leaves the browser alone.

Without --repo it takes GITHUB_REPOSITORY, or the origin of the checkout it is started in. The project needs a factory.yml on its default branch.

#What you see

The factory, drawn as a factory. People know what one looks like, so the page shows one.

On the floorWhat it is
Funnels at the top leftThe hoppers: where work comes in. Each of yours holds its requests as outlined crates, with a count; a green valve opens by itself (an agent may start on these), an amber one waits for a person. The last funnel is the pull-request hopper, the front door for finished work: every project has it, and the number on it is the pull requests open now
The beltOne wide conveyor, the same width everywhere work travels: through the front door, down the right side, back along, and down the left side to each release line. A change is a crate with its number on it (#12), riding in the belt. A number of five digits or more is written without the #, at the size of a four-digit one, so that it can still be read; point at any crate and it says its number in full
The stations on the beltThe belt runs through each: its name above, a window, and what it does below. Built here, then the tests, then the review. A station pulls work off the belt into its window, holds it a moment, gives it a tick or a cross, and sends it on
The loop over the topThe rework loop: a change that fails its tests or its review goes up and over, back to where it was built
The dashed boxes under stationsHolding bays, where work stops and waits: sent back and waiting to be reworked (under "built here"); needs a person's review (under the review; where the factory file names no review station, a change that needs a person waits in a bay under the tests); held for a person (under each line's gate; a line with no gate station has the bay too, under its last station, because the release gate holds every release on such a line for a person). A line's bay always stops short of "completed", whatever stations the line names and in whatever order
"No release", the last machine on the main beltWhere accepted work is finished when no release line carries it: a document, a test, a setting. The station takes it in, ticks it as done, and it carries straight on down the right side into "completed". Work a release line carries rides past. Its count is the changes the kept history shows needed no release: no release carried them, and every line that was already releasing has decided a release since they were accepted, without them. Where the history cannot say (a change accepted before a line's releases were first on record, or with no release decided since), it is counted apart, under it: "2 more, release not known"
A round turntable on the beltA place where the belt divides and each piece of work is sent one way or the other: at the right side (done, or round to a release line), and on the left side where each release line begins (onto this line, or on down to the next line or the bin). Click one to see what goes which way
The skip at the bottom left, under the left-hand beltThe bin: what is waiting for a person to decide. A crate bound for it carries a small bin marker, rides past the front door's stations, round and down the left side past the turntable where each release line begins, and drops in. It never enters a line or reaches a gate
"Merge", the machine after the review, and the green bay under itWhere a change that has passed is accepted. Work that has passed everything waits in the bay for a person to merge it (the factory does not merge by itself; a change merged the moment it passed never sits there); then the station takes it in, ticks it, and sends it on to its line
The red bay hanging under "completed"A release that went out and was then undone, or failed part-way. It is not binned: it drops out of the bottom of the box and waits there for a person
Each release lineLabelled "release line" with the name the project's factory file gives it, and under the belt the paths whose changes it takes. The belt carries on through that line's stations, whatever the project's factory file names them (staging, gate, shipping, evaluate; or only a gate). Each takes the work in and ticks it. The gate has a bar across the belt: down and red when a release is held, lifted and green when the line is flowing. Accepted work waits on the line for its next release
A thin strip where a release line would beA quiet line, folded. On a floor of several lines, a line with nothing on it is drawn as one strip: its belt carries on, and a label lying on the belt says the line's name, the paths it takes, and what the page knows of it ("quiet · 12 completed · last release 3 days ago"). A line folds only when the page knows it is quiet: no accepted work waiting for its release, nothing in its stations or its bays, and its newest run not held, undone, failed, or stopped before the gate. A line an open alert is stopping is drawn open, because it needs a person. So is a line the page could not read: its releases, or whether an alert is stopping it. No strip says "quiet" of such a line (a line whose releases are not followed says that, and before the first reading every strip says "still reading"). What it last released is in "completed", and does not keep it open. Its lamp stands in "completed" beside those crates. Click the strip, or press Enter or Space on it, and the line opens; the small arrow beside an open line's name folds it again. A line with anything on it is always open, whatever you chose
"Completed", the box at the rightWhere finished work ends up: every release line runs into it from the left, and work that needed no release drops into it from above. Beside each line: how many changes it has released, and a lamp (green when flowing, amber when held, red when stopped or undone). A change that two lines both carry is counted once, on the line that released it first, which is the box its crate is in

Quiet lines are folded, so that a calm floor is one picture. The first time you see a floor, every line with nothing on it is folded and every line with something on it is open. The lines you open stay open: the page remembers them in this browser, for each project, and forgets a line the factory file no longer names. "Open every line" and "Fold the quiet lines", beside the colour key, do it for all of them at once. A floor of one line is never folded, and has none of this. Folding and opening happen at once, with no animation.

A crate's colour says how it is doing: plain for on its way, amber for needs a person, red for sent back or failing, green for passed. The key under the drawing says so.

Who is looking. The top of the page names the GitHub account the app is reading as, and what GitHub lets that account do on this project (admin, may change it, may read it).

What it costs. "Cost", at the top beside "Read again", opens a window that says what the factory cost to run over the last seven days (the cost report): what the machine minutes and the model calls are worth, a table by kind of work (each workflow), a table by how each change ended (merged, in the bin, closed, still open), tables by release line and by hopper when the factory file has them, and the changes that cost most. The figures are at list price and are not a bill, and the window says so. Working it out asks GitHub several hundred questions, so it is done only when you press "Cost", never as part of a reading, and the answer is kept for an hour: the window says how old it is. While it is being worked out (a few minutes on a busy project) the window says so, and fills in when it is ready; you can close it and come back. At the bottom, "How it has moved" shows a short history: one small summary for each day a report was made, the last ninety, kept with the history below. Everybody who can see the floor can see the cost.

Deciding from the page. Started as usual, the app only looks. Started with --decide, it lets a person GitHub allows to write to the project do six things from the floor:

WhereThe buttonWhat it does on GitHub
The gate, or its holding bay, when a release is held for a person"Release these N changes"Starts that line's release by hand: the same as running the line's release workflow on the releasing branch and typing "release" (the release gate). The word goes into the workflow's input called release, or the one the line names with release_input in the factory file. It releases everything waiting on that line
A change in the green bay under "merge" (passed, waiting for a person)"Merge this change"Merges it, the same as pressing GitHub's own merge button, and only at the version the page read: GitHub refuses if it has changed since, or if the project's own rules are not met. The kind of merge is the one the factory file asks for (merge: commit, squash or rebase), and the window says which before you confirm. If the project does not allow that kind on GitHub, the app says so and sends nothing: it never merges another way than the file asks. A file that asks for none gets a merge commit where the project allows one, otherwise the kind it does allow
The same change, or one waiting for a person's review"Send back…"Asks for your reason (what needs altering), then posts it on the change as a review that found something, in your name. The change goes round the rework loop to whoever built it; the builder reads your reason. The record says it is a person's decision and not a review of the code. Not offered for a version the review station has let through without a review (a send-back would not hold it): reject that to the bin. It is what the station last said of the version that counts: one let through at first and reviewed after all, because the rules changed under it, can be sent back. A status somebody set by hand under the gate's name is not the station's word, and changes nothing here
The same"Reject: send to the bin…"Asks for your reason, then gives the change the bin's label and posts your reason. It leaves the line and sits in the bin until a person decides; it is not closed, and cannot be merged from the app while it is there
A request or a change that a person put in the bin"Take out of the bin"Removes the bin's label. A change goes back onto the line where it stood; a request goes back to its hopper. Not for what the factory put there itself
A request waiting in a hopper whose valve is amber"Give the go-ahead"Adds the project's go-ahead label (builder.go) to the request, so the builder may start on it (hoppers)

Pressing the button sends nothing. It shows what will happen in plain words: the line, each change by number and title, why the gate held it, and the account it will be done as. "Yes" can be pressed once; the page then says what GitHub answered. It is one request to GitHub, sent once and never tried again by itself.

The app has no powers of its own. Each is done with your own GitHub access, so GitHub decides whether you may, and its record names you: a release run you started, a label you added. The factory already takes those as a person's decision. The buttons show only for someone GitHub lets write, on a project that is not archived; if one showed wrongly, GitHub would still refuse. On an archived project the top of the page says "this project is archived: nobody can change it" in place of what you may do there, whatever standing GitHub still shows you with, and the app refuses every decision in those words. The app also notes what you decided in the history it keeps, so the replay says who.

After you decide, the page watches for it. It has GitHub read again by itself, a reading and then a rest, until what you decided shows on the floor (the release is no longer held; the request may start) or twelve minutes have passed, and says which. The first of those readings is made at once, even when a reading had failed a moment before you decided; if it fails too, the next waits a minute, as a watch does after any failed reading, so that a GitHub that is failing is not asked over and over. This is the only time the page reads GitHub without a press; each reading asks GitHub only what changed.

Someone who may only read sees the same panels with no button and a line saying who can decide.

When a place holds more than it can draw (a hopper, a bay, the bin, a queue), its last place says how many more there are: "+4". Click the place to see them all.

Click anything (a crate, a funnel, a machine, a gate, the bin, "completed") and a window opens over the floor: what it is, what is there now, and what has happened there, newest first with its date and time, eight at a time with "Older" and "Newer". For a machine that is what it ticked and crossed; for a gate, what it held and let go; for "completed", each release; for a hopper, what arrived and left.

Click one of those and the window shows what it was about: the change (its title, author, where it stands, what its review said, a link to it on GitHub, and everything that has happened to it), the request, or the release and what it carried. It opens over the window you were in, a little down and to the left, and that one is still there underneath: "Close", Escape or a click outside closes the one on top and shows it again. Any window can be dragged aside by its top bar, to see what is under it. However many are open, each lies lower than all those under it, so every one's top bar and "Close" stay clear; when the pile is taller than the browser window, it scrolls.

Play the history. Press play once and the whole kept history runs through by itself, as work going through the stations.

  • A new change drops out of the pull-request hopper (or, when the builder made it from a request, out of a hopper an agent may start from), rides into "built here", gets its tick, and rides on to the tests, where it is pulled into the station's window.
  • The tests give it a tick, and it rides on into the review; or a cross, and it leaves by the top of the station, goes up and over the rework loop, and drops into the holding bay under "built here".
  • When it is reworked it comes up into "built here" again, gets its tick, and sets off for the tests once more.
  • The review does the same: a tick sends it on to the green bay under "merge", where it waits to be accepted; a cross sends it round the loop. When it is merged, the merge station takes it in, ticks it, and sends it on.
  • Accepted, it rides on from the merge. If no release line carries it, the "no release" station takes it in and ticks it as done, and it carries straight on down the right side into "completed". If one does, it rides past that station, is turned back along the return belt at the turntable, goes down the left side, and at that line's turntable onto the line, where it waits for the release.
  • At a release it goes through the line's stations in turn, each pulling it in and ticking it. At the gate, a held release gets a hold mark and drops into the holding bay; one that goes out carries on through the stations after the gate to "completed".
  • A release that is undone after going out really did go out first: it is ticked through its stations and reaches "completed", and when the watch undoes it (often minutes later) it gets a cross and drops into the red bay underneath, where it waits for a person. One that fails part-way is crossed at the station that failed, when that could be named, and goes to the same bay.

A folded line opens for the step that happens on it, so the replay never hides anything: when a change is accepted onto it, when one of its releases is held, goes out, is stopped, fails or is undone, and when something that was on it leaves. It folds again at the next step that leaves it with nothing on it, unless you opened it yourself. A line whose releases the last reading could not give stays open at every step. An alert open now, and how a line's newest run ended, are of now: the replay shows each step's own lamps, and folds by the step. Which lines are open depends on the step alone, never on how you came to it: stepping back shows exactly what stepping forward showed. When a line opens or folds above the part you are watching, the page holds that part where it was on the screen.

Nothing jumps across the floor. (Where waiting crates close up after one has left, a crate that moves up a row goes out of sight and comes in at its new place, so that none is ever drawn over another.) Choose a speed (slow to very fast), drag the slider, or move one step at a time; "Back to now" returns to the present. A request arrives in its hopper, and one sent to the bin drops out onto the belt and rides round to it. A release that a station stopped before the gate (a trial run that failed, say) is ticked at the stations before, crossed at that one, and stays in its window until a later release takes it on.

The history, to read. Under the drawing every step is written out in words, oldest first, with its time: "#20 “Add Fahrenheit to Kelvin” was sent back by review, by the automatic reviewer." The step being played is highlighted, and clicking any line sets the floor down as it was then.

The history is kept. Each reading looks back a week and adds what it finds to a file on your machine (~/.cache/factory/OWNER__REPO.history.json, readable by you alone), so the history grows longer than a week the longer you use the app, and keeps what GitHub forgets, such as a request that was in the bin and then left. It begins a week before the first time you opened the app; when exactly a request left its hopper is known only to the nearest reading. Delete the file and you lose the steps older than a week, nothing else.

It fits the window. The line is laid out to the width there is, and laid out again when the window changes. A floor that is only a little too tall for the window is drawn smaller so that all of it shows, with the colour key and the play bar under it (in a narrow window both wrap onto more lines, and the floor is given the room that is left). A floor of many lines with work on them, or a window too short for that, keeps the floor's size and scrolls (quiet lines are folded, so a calm floor of many lines is short). While the history is shown, the floor's size is judged by the lines the history is ever on, so that it does not change as lines open and fold from step to step. While the history plays, a floor that scrolls brings the part each step is about into view, unless you untick "follow the action": the main belt with its stations and bays, or the release line a release is on. It moves only when that part is not all in view, and a change being accepted does not move it. Below about 900 pixels wide the whole drawing shrinks to fit. Words on the drawing are shortened where a narrow window leaves them less room ("holding for a person" becomes "holding"), never cut off mid-word where a shorter wording fits. In the play bar a step's sentence takes two lines at most; point at it, or read the history below, for all of it.

The building is drawn at once, from the factory file. The floor is shown at once too, from the last reading that was kept (the top of the page says when it was made), while GitHub is read behind it; the newer reading replaces it when it is ready, unless you are watching the history, when it waits until you are back at "now" (a line above the floor says it has come, without moving the floor, and goes when "Back to now" shows it). While its tab is not in front the page asks nothing; it asks once when you come back to it, and takes up a reading that landed meanwhile. Only the very first reading, and "Read again", make you wait: up to a minute on a busy project. The page reads GitHub when it opens, when you press "Read again", and for up to twelve minutes after you decide something; otherwise not by itself (why).

#A change that clashes

A change that has passed everything can still clash with what was merged after it was made. GitHub then cannot merge it. The floor asks GitHub about each passed change, and shows one that clashes among those waiting to be reworked, not among those waiting for a person to merge: its window says why, offers no merge, and still offers sending it back or rejecting it. Where GitHub has not worked it out yet, the change stays where it was.

#Signing in with GitHub

Started as usual, the app uses the GitHub access already on your machine. Started with --sign-in CLIENT_ID, it has no access of its own: each person signs in with GitHub on the page, and the app shows them the factory, and does what they decide, with their access.

python3 -m factory.app --repo OWNER/REPO --sign-in Iv23...
  • How it goes. The page shows a short code and a link to github.com. You type the code there and approve; the page notices and shows the floor. "Sign out" ends it. There is no password and no secret anywhere: this is GitHub's device flow.
  • With one click, on a hosted copy that has been set up for it. The page shows one button, "Sign in with GitHub", and no code: such a copy signs nobody in by a code. It takes you to github.com to approve (the first time; after that GitHub remembers), and brings you straight back to the floor. If anything stops it (you said no on GitHub, it took more than ten minutes, GitHub does not let you in to the project) a page says which, in words, with a button to try again. Hosting says how a copy is set up for it.
  • What CLIENT_ID is. The public client id of a GitHub App you register once (Settings, Developer settings, GitHub Apps) with "Enable Device Flow" ticked, no webhook, and repository permissions for contents, pull requests, issues and actions (read and write) and checks, commit statuses and metadata (read). It is not a secret. No client secret or private key is used by the app.
  • What a signed-in person can reach. Only what both they and the GitHub App can. To decide anything, or to read a private project, the App must be installed on the repository (its settings, Install App; no private key is needed for that, whatever its settings page suggests). A public project can be read without installing it.
  • Whose is what. Each person has their own reading, kept in memory only and never handed to anyone else. Their token is held in memory by the server while they are signed in, is never written to disk or a log, and never reaches the page. The refresh token that comes with it is held the same way, and kept nowhere else, with one exception: a hosted copy that was told to keep people signed in across a restart also keeps the refresh token, and only that, outside its memory, locked by AWS KMS. GitHub's token lasts eight hours; the server renews it by itself, so a sign-in lasts up to a week (twelve hours where the GitHub App's tokens do not expire). If GitHub will not renew it, the page says the sign-in has ended and asks you to sign in again. On a hosted copy, if GitHub no longer lets you in to any project there, you are signed out and the page says so. The session is a cookie the page's script cannot read.
  • What the token is good for. It is that person's access to every repository the GitHub App is installed on that they can reach, not only this project. The server uses it for this project alone. Restarting the server signs everybody out, unless it is a hosted copy told to keep sign-ins. At most 200 people can be signed in or signing in at once.
  • For a team. Started like this the server still answers only on 127.0.0.1, for the machine it runs on. Hosting the app for a team puts one copy at a web address, and lets in only the people GitHub lets write to the project.

#Several floors

A hosted copy can show several projects. You sign in once.

  • With one floor open to you, the page looks as it always has. The project's name is beside the title.
  • With more than one, the project's name is a chooser. It is as wide as the name chosen, so its arrow stays beside the name. Choose another floor there and the page goes to it. It loads afresh as it goes, so nothing of the floor you left (its replay, its open windows, its cost) comes with you.
  • The address says which floor (…/#example/site), so a link opens the right one, and the browser remembers the last one you chose. A link to a floor that is not open to you opens one that is, and says so.
  • You see only the floors GitHub lets you in to. If your access to the one you are looking at is taken away, the page says so and moves to another of yours.
  • With none open to you, nobody is signed in. At the door, the page says GitHub does not let that account in, and names it: change accounts on github.com first if it is the wrong one. If your access to every floor is taken away while you are signed in, you are signed out, and the sign-in card says why. If GitHub cannot be asked just then, you stay signed in and the page says GitHub could not be asked.

#What it does and does not do

  • Started as usual it looks, and changes nothing. Only when started with --decide does it have buttons, and then five: merge a change that has passed, send one back or to the bin with a reason, release what a gate holds, and give a request the go-ahead (above). Each is done on GitHub as you, after you confirm it.
  • It runs for you alone. The server listens on this machine only (127.0.0.1) and reads GitHub with the access you already have: GITHUB_TOKEN if it is set, otherwise the one gh is signed in with. The token stays in the server; the page never sees it.
  • It keeps what GitHub said, on your machine, so that asking again is nearly free (below). The file is in your own cache directory (~/.cache/factory/), readable by you alone, and holds what GitHub said about the project: for a private repository that is private text. Your token is never kept. Delete the file whenever you like; it is only a cache.
  • It shows one project. A hosted copy can show several.

Titles and review notes are other people's words. The page shows them as text, exactly as written.

#GitHub's hourly allowance

GitHub gives each login 5,000 requests an hour, shared by everything that login does. One reading of a busy project is several hundred. Without care, a few people reading a few times would use it all, and then nothing else they do on GitHub works until the hour is up.

So the app pays for each answer once:

  • It keeps every answer with GitHub's tag for it, and next time asks only "has this changed?". GitHub answers "not modified" when it has not, and does not count that against the allowance. A reading of a project where little has changed costs little: only what changed is paid for.
  • The kept answers survive a restart, so the first reading after one is cheap too.
  • It reads when it opens and when you press "Read again", and for up to twelve minutes after you decide something, to show it coming through. Otherwise never by itself. The cost report, which asks far more, is worked out only when you press "Cost", and is then kept for an hour. With --decide it also writes, only when you press and confirm. Between readings it hands out what it has for five minutes.
  • It will not spend the last tenth of the allowance. When it is that low, the page says so and when it refills. It still asks whether things changed, which is free when they have not.
  • The page says what each reading cost and how much of the hour's allowance was left after it, beside the reading's time at the top. That is what GitHub said when that reading of that floor ended, not a figure for now: a reading is shown again for five minutes, and whatever else your login has asked GitHub since (a reading of another floor, a cost report, anything outside the app) has used more. Two floors read one after the other show two different figures for that reason.

Several people each running the app on their own machine each use their own allowance, and each pays only for what changed. A server shared by a team reads once for everybody who looks: that is one of the reasons to host it, when hosting is built.

#What to know

  • A line's releases are followed only when the line names its workflow in the factory file, and only for releases the factory's own gate decided. A project that releases with its own tooling sees "no release seen yet" on that line.
  • "Releases by itself" is what the factory file says the gate may do. Where a project's own tooling still decides releases, the factory file is a restatement of it.
  • A reading takes a while on a busy project (about 11 seconds for a week of some forty changes), behind the scenes. A change that has been read at least an hour after it was merged or closed, and has not been touched since, is not asked about again; what is open, what ended lately, the release runs and the hoppers are. Nothing is missed by that: a test result that ends after its change was merged or closed is left out of the record whenever it is read (the record), so asking again later would find nothing new. The release runs are asked about while the changes are being read, not after them (the eleven seconds were measured before that). You see the last reading meanwhile.
  • The numbers on the hoppers and the bin are today's, also while the history plays.

#What comes next

This is the start of a larger design: for people who are allowed, deciding from the app (giving a go-ahead, releasing what is held). The same app can be hosted for a team. The API says how it is put together.

This guide is docs/APP.md in the repository, and this page is made from it. Something wrong or unclear? Open an issue or send a pull request. Next: How is the factory getting on?.