how-to deployeradministrator

Runbook: the look at the document check

In plain language. The portal can show an applicant a document note before sending. A note says that an uploaded file may not be the document that a question asks for. No applicant sees a note until staff test the check on real filings. That test is a look.

The operator runs the look on the server. An officer judges each note. If the look passes the bar, the operator adds one line to a setting. The portal then shows notes for that procedure in that language.

Spec: docs/specs/2026-10-06-applicant-document-check.md, sections 4.3, 4.4 and 6. Command: python3 -m opengov.eapproval.document_check.look. Scope: every deployment that runs a decision model.

Words used here (glosses in docs/reference/plain-vocabulary.md):

  • decision model: a model that writes no text. It picks one option from a list.
  • document note: a line that the portal shows the applicant before sending. It never blocks, and no officer sees it.
  • look: a test of the document check on filings that the agency accepted. It covers one procedure in one language.
  • measured model: a model name that the project tested on real documents. The two measured names are clef and clef-flash.
  • model copy: one installed package of a model. Its digest is a code that names that exact copy of the model.
  • fingerprint of the document texts: a code of 16 characters. It changes when a label or a description of a document changes.
  • document check list: the setting OPENGOV_DOCUMENT_CHECK_LIST. It names the procedures and languages that show notes.
  • right note and wrong note: the verdict of the officer on one note.

1. Set the model

The operator sets three settings. They are environment variables of the opengov service. docker-compose.yml and docker-stack.yml pass them to that service, and each one is empty by default. The worker does not get them, because it never checks a document.

SettingValue
OPENGOV_DECISION_MODEL_ADDRESSThe address of the model server, such as http://model.internal:11434
OPENGOV_DECISION_MODEL_NAMEclef or clef-flash
OPENGOV_DOCUMENT_CHECK_LISTEmpty for the first look. Section 6 tells you how to fill it

Do these steps:

  1. Write the bare model name: clef or clef-flash.
  2. Do not write clef:latest. That name is not a measured name, so no check is available.
  3. Use an address inside the deployment. No code can prove that the address is inside.
  4. Keep the three settings in a file under version control. The history records each change.
  5. On Compose, write the three values in the .env file beside docker-compose.yml.
  6. On a Swarm stack, export the three values in the shell that runs docker stack deploy.
  7. Apply each change of a setting (see “Apply a change” below).

Apply a change. On Compose, run docker compose up -d opengov. The command makes a new container with the new values. A docker compose restart keeps the old values. On a Swarm stack, run docker stack deploy -c docker-stack.yml opengov-prod again. For example:

set -a; . ./.env; set +a
docker stack deploy -c docker-stack.yml opengov-prod

A new container is necessary. Each process of the application keeps one model client. That client reads the address and the name once, when the process starts. A change of OPENGOV_DECISION_MODEL_ADDRESS or OPENGOV_DECISION_MODEL_NAME has no effect until you apply it.

What the health report says

/health has a row named “the document check before sending”. The row blocks nothing. A dead model costs the applicant a note, never a send. With no address or no name, the row is not in the report.

What the row saysWhat it meansWhat to do
the decision model does not answerThe model server did not answer in time, or the connection failedStart the model server. Check the address
the model is not a measured one: no check is availableThe name is not clef or clef-flash. No request goes to the addressWrite a measured name. Apply the change
the model copy is not a measured one: Repeat the look before you trust the notes.The name is a measured name, but the installed copy has a different digestRepeat the look for each listed procedure (section 7)
the decision model address is not a valid addressThe address is not an http or https addressCorrect the address. Apply the change
the decision model address answers, but it does not serve that modelThe server answers, but it has no model with that nameInstall the model on the server, or correct the name

A copy that is not measured. The row then reads “down”. The notes stay on for each listed procedure. The row is a warning to the operator. It does not switch the notes off.

The lock of the picture process

Before the model reads a document, a separate process draws its first page. On Linux, that process locks itself before it reads the file. After the lock, the process can open no file, make no network connection and start no program. A host that cannot give the lock gets no picture, and each document reads “not checked”.

Test the lock in the container of the app. On Compose:

docker compose exec opengov python3 -m opengov.platform.page_picture_selftest

On a Swarm stack, find the container with docker ps, then run the same command with docker exec <container>. Each check prints one line. The exit code is 0 when no check failed.

The option --strict makes each “note” a failure. A “note” is a check that the self-test could not do on this host. Use --strict in the container of the app, as the build of the image does:

docker compose exec opengov python3 -m opengov.platform.page_picture_selftest --strict

When the host refuses the lock, the first check names the cause and the error number of the kernel. For example:

FAILED  this host gives the lock: cause filter (the kernel refused the filter: errno 1)

When the host refuses the lock, the process ends before it reads the document. The log of the app then has this line, with the same cause code: page picture failed: sandbox not available, cause <code>.

The line alone does not prove that the host refused the lock. A hostile document can get control of the process after the lock. The process can then end in the same way and name a cause too. The document reads “not checked” in each case. Run the self-test. It proves that the host gives the lock, or it names the cause.

A host can mount /proc with the option hidepid. Such a host hides the locked process from its own user, and the lock still works there. Two checks of the self-test then read “note”, because the self-test cannot look at the process. The plain command then ends with exit code 0, and the command with --strict ends with exit code 1. Run the self-test in the container of the app. The container runtime mounts /proc there without that option.

Cause codeWhat it meansWhat to do
filterThe host refused the filter of the lock. The filter is the system call seccompUse the default seccomp profile of the container runtime. A profile of your own must permit seccomp
privilegesThe host refused the promise that the process never gets more rights. The system call is prctlA seccomp profile of your own must permit prctl
dumpThe host refused the switch that forbids a memory dump of the process. The system call is prctlA seccomp profile of your own must permit prctl
landlockThe kernel has Landlock, which removes the file rights of the process. The host refused to apply itA seccomp profile of your own must permit landlock_create_ruleset and landlock_restrict_self
cpu_typeThe lock has a list of system calls for the CPU types x86_64 and aarch64 only. The host has a different CPU type, or the Python of the app is not a 64-bit programRun the app on a host with one of the two CPU types, with a 64-bit Python
otherAn error that the lock did not expectRun the self-test and report its output
unknownThe process ended with no lock, and named no causeRun the self-test and report its output

One more line of the log is about the lock:

What the log saysWhat it meansWhat to do
page picture failed: a call outside the listThe process made a system call that the lock does not permit. The kernel stopped the processFor one document, do nothing. For each document, run the self-test and report its output

The row picture_lock of the health report

The app runs the self-test of the lock one time, in the background, after it starts. The run uses strict rules: a “note” is a failure. /health shows the result in the row “the lock of the picture process for the document check” (picture_lock).

The row shows on each deployment, also when the operator names no decision model. The lock is a property of the image and the host. The row blocks nobody. A row that is not “up” sets degraded, and status stays “ok”.

StateWhat it meansWhat to do
upThe self-test passed in this processNothing
unknownThe self-test has not finished. The error says “has not finished yet” in the first 5 minutes after the start, and “did not finish” after thatWait 5 minutes after the start. If the row stays “unknown”, read the log of the app for the lines that contain picture lock self-test
downOne or more checks failed, or the self-test stopped with an error, or the host is not LinuxRead the log of the app for the failed checks, as the table below says. Run the self-test by hand, as this section says

A “down” row gives the number of failed checks and the pointer to this section. For example: 2 of 21 checks failed. See docs/runbooks/document-check-look.md, section 1.

The row names no check and holds no detail, because /health is public. The name of a failed check tells a stranger which defence is open. The names and the details are in the log of the app. Search the log for these texts:

Text in the logWhat it means
picture lock self-test: FAILED: <name>: <detail>One check failed. The line gives its name and its detail
picture lock self-test: note: <name>: <detail>One check could not run on this host. The rules of the app count it as a failure
picture lock self-test raised: <error>The self-test stopped with an error. The line gives the error
picture lock self-test did not run: the lock exists on Linux onlyThe host is not Linux

The app runs the self-test in a thread. A thread that runs cannot be cancelled. So a stop of the app in the first seconds after a start can wait for the self-test to end. The wait is about 10 seconds. A child process that hangs adds at most 30 seconds for each such child. Nothing is lost.

On a laptop with macOS, the row reads “down” with the error “the lock exists on Linux only”. This is normal for a development stack.

The post-deploy smoke of the sandbox reads this row (docs/runbooks/post-deploy-smoke.md). The smoke fails when the row reads “down”.

The limit of checks

One signed-in applicant can start 12 checks in one minute. The limit applies to each process. With 4 processes, one applicant can start up to 48 checks in one minute.


2. The four steps of a look

Before the first look, the country decides if its own rules allow this use. The look makes the model read documents of filings that applicants sent before the check existed. Those applicants were not told of this use. The documents stay inside the deployment.

  1. Set the model. Do section 1. For a new procedure, keep its line out of the list.
  2. Run the look. The command reads the newest accepted filings of one procedure in one language. It asks the model the same question as the portal does.
  3. Judge each note. An officer opens each filing in the notes file. The officer gives each note one of the four choices of section 3.
  4. Add the line. Do this step only if the look passes the bar (section 4 or 5). Add the list line to the setting (section 6).

Run the look

Run the command in a container of the opengov service. The command uses the settings of that container. On Compose:

docker compose exec opengov python3 -m opengov.eapproval.document_check.look \
  --procedure-id 8f2c1c1e-0a5e-4a3c-9c53-3f1d0f6b7a11 \
  --language en \
  --count 20 \
  --out /tmp/look-notes.csv \
  --operator-id <your account id>

On a Swarm stack, the container has a name that Swarm gives. Do these steps:

  1. Find the node of the task: docker service ps opengov-prod_opengov.
  2. Connect to that node.
  3. Find the container: docker ps -q -f name=opengov-prod_opengov.
  4. Run the same command with docker exec <container> in place of docker compose exec opengov.
ParameterWhat it is
--procedure-idThe id of the procedure
--languageThe language of the labels and of the filings, such as en, fr or ar
--countThe most filings to read. The default is 20
--outThe notes file. The command writes it. The folder must exist
--operator-idYour account id. The audit log records it as you give it

The command does these things, in this order:

  1. It checks that the virus check answers. If the virus check does not answer, or you switched it off, it stops.
  2. It reads the copy of the model. If the model does not answer, it stops.
  3. It opens the notes file. If it cannot open the file, it stops.
  4. It writes one entry in the audit log. The entry names you, the procedure, the language, the count, the model copy and the fingerprint of the document texts.
  5. It reads the filings that the agency accepted (status registered), newest first.
  6. It checks the newest top-level file of each document question, one at a time. Before each file, it proves the virus check again when the last proof is older than 30 seconds.
  7. It writes one line in the notes file for each note.

A filing with no language counts as the default language of the deployment. A label that names no kind, such as “Pdf 1”, gets no question. The look does not count it.

What the command prints

The terminal shows counts only. It never shows a filing reference.

Filings: 20
Documents: 64
Notes: 3
Not checked: 1
Fingerprint of the document texts: 3f9c0a17b2d4e851
List line: 8f2c1c1e-0a5e-4a3c-9c53-3f1d0f6b7a11:en:3f9c0a17b2d4e851

A look of fewer than 5 filings prints no list line, because no such look can pass the bar (section 5). The last line then reads:

List line: none (fewer than 5 filings; see the runbook, section 5)
  • Filings counts the filings that the look read.
  • Documents counts the documents that the look tried to check. It includes a document that stopped before a model call, such as a missing file.
  • Not checked counts the documents that the look could not check. A file that is missing, or that the virus scan now refuses, is one. The log names the file id. For a folder look, it names the manifest row. A document is also not checked when the virus check stops answering during the look. The log line for such a document has the code virus_check_no_answer.
  • List line is the entry for the document check list. It shows from 5 filings only. It does not show when the virus check did not answer for one document or more. The line then says for how many documents it did not answer.

A look cut short by the virus check. A document can be “not checked” because the virus check did not answer during the look. Such a look is not a full look, so the command prints no list line. The last line then reads:

List line: none (the virus check did not answer for 2 of the documents; repeat the look; see the runbook, section 2)

The number is the count of documents without an answer. There are three situations. The virus check gives an error, or its proof is old. A scan lasts longer than the time limit of the check. The operator switches the virus check off during the look.

Open the health report and read the row “the virus check on uploaded documents”. Repeat the look when that row shows the virus check as healthy.

A file that the virus check refuses as infected does not cut a look short. The scanner answered for that file. The look keeps its list line.

Where the log goes. The look does not write to the log file of the server. It writes its warnings and errors to your terminal (standard error). Keep the terminal output if you need the file ids.

The command stops with exit code 1 and one line that starts with Look failed:. The line names the cause. Correct the cause and run the look again. A look that stops before step 4 writes no audit entry.

The notes file

The file has one line for each note: reference_number,slot_label,picked_option. The slot label is the label of the question. The picked option is the option that the model chose. A folder look adds the column file (section 9).

The file names filings. Only its owner can read it. Give it only to the officer who judges the notes.

  1. Copy the file out of the container: docker compose cp opengov:/tmp/look-notes.csv ./look-notes.csv.
  2. Give the copy to the officer.
  3. When the record of section 8 is complete, delete the file in the container: docker compose exec opengov python3 -c "import os; os.remove('/tmp/look-notes.csv')".
  4. Delete the copy outside the container: rm ./look-notes.csv.

On a Swarm stack, run these commands on the node of the task. Write the id of the container in place of <container>.

docker cp <container>:/tmp/look-notes.csv ./look-notes.csv
docker exec <container> python3 -c "import os; os.remove('/tmp/look-notes.csv')"
rm ./look-notes.csv

The image has no shell and no rm, so the delete in the container uses python3.


3. The four choices

The officer opens each filing in the notes file. The officer looks at the document of that question, and gives the note one of four choices.

ChoiceVerdict
A different document from the one asked forRight note
The picture cannot be readRight note
A cover page, or the content is not on this pageWrong note
The right document, with a note all the sameWrong note

The agency accepted each filing of a look. A right note shows a wrong document inside a decision that the agency already made. Nothing follows automatically. The agency decides.


4. The bar

A verdict needs 20 filings or more. Count the filings that have at least one wrong note. A filing with two wrong notes counts once. The look passes when that count is at or below the bar.

Filings in the lookFilings with a wrong note that the bar allowsA check at 1 in 10 passesA check at 1 in 4 passes
20268%9%
30365%4%
50562%1%
100832%0%

The bar keeps a check that is wrong 1 time in 20, 9 times in 10. A look of 20 stops a check that is wrong 1 time in 4, 9 times in 10. No look proves a rate of 1 in 20.

The look finds wrong notes only. It does not find a wrong document that got no note.


5. A procedure with fewer than 20 accepted filings

You can list such a procedure after a smaller look. All four conditions must be true:

  1. The look covers each accepted filing of that procedure in that language. Fewer than 20 exist.
  2. At least one accepted filing exists. With no accepted filing, do not list the procedure.
  3. The look is within its own bar. For 5 to 10 filings, 1 filing may have a wrong note. For 11 to 19 filings, 2 may.
  4. The country administrator agrees in writing. In a pilot that the team operates, the concept owner agrees.

The bar has no value for 1 to 4 filings. So condition 3 cannot be true, and you do not list the procedure. Repeat the look when the procedure has 5 accepted filings.

Repeat the look when the procedure reaches 20 accepted filings.


6. Add the line to the document check list

The list is the setting OPENGOV_DOCUMENT_CHECK_LIST. Commas separate its entries. Each entry is the list line of one look: procedure_id:language:fingerprint. The last part is the fingerprint of the document texts.

  1. Copy the list line that the command printed.
  2. Add the line to the setting. Put a comma between two entries.
  3. Commit the change to the file under version control.
  4. Apply the change (section 1, “Apply a change”).

An example with two entries:

OPENGOV_DOCUMENT_CHECK_LIST=8f2c1c1e-0a5e-4a3c-9c53-3f1d0f6b7a11:en:3f9c0a17b2d4e851,8f2c1c1e-0a5e-4a3c-9c53-3f1d0f6b7a11:fr:a07c55e1d9b3f264

A procedure shows notes in a language when three things are true:

  • the list has an entry for it,
  • the fingerprint of the document texts of its current published version is the one in that entry,
  • the model name is a measured name.

An empty list switches the notes off everywhere. To stop all notes in the country, make the list empty and apply the change. To stop one procedure, delete its entry.

The application ignores an entry that is not valid, and writes a warning in its log. The warning gives the position of the entry, counted from 1.


7. After a change

  • A new label or description of a document. The fingerprint of the document texts changes. So the notes stop for that procedure in that language. Run the look again. Then replace the old entry with the new list line.
  • A change of a fee or of a rule. The fingerprint of the document texts stays the same. The notes stay on.
  • A new copy of the model. The health row says that the copy is not a measured one. Repeat the look for each listed procedure.
  • A change of the model address or name. Apply the change (section 1).
  • New country languages. A change of the language list or of the default language can change the fingerprint of the document texts. That happens for a language in which a label has no text, because the label then shows another language. The notes for that language then stop until you repeat the look.

The cause of each wrong note tells the country what to change. A wrong note on each filing for one document points at the label of that document. The remedy is a description for the applicant on that document.


8. The record that the officer keeps

The officer keeps one record for each look. The record holds these items:

  • the procedure and the language,
  • the date of the look,
  • the list line and the model copy (the audit entry has both),
  • the count of filings and the count of notes,
  • the count of notes for each of the four choices of section 3,
  • the count of filings with a wrong note, and the bar,
  • the verdict: listed or not listed,
  • the name of the officer who judged.

The record never holds a filing reference. The references stay in the notes file only, and you delete that file when the record is complete (section 2, “The notes file”).

For a look of fewer than 20 filings, the record also names the person who agreed in writing (section 5).


9. A look on the filings of the old system

When to use it. A new country has no accepted filings in OpenGov. Its old system has them. The command can read files that the operator exported from the old system into a folder. The procedure is still an OpenGov procedure. So the labels and the fingerprint of the document texts are the ones that applicants will see.

Decide first. The country decides if its own rules allow this use, as section 2 says. The applicants of the old system were not told of this use. The files stay inside the deployment. The look keeps no copy of a file. It writes the notes file only.

Export the files

The operator exports the files from the old system into a folder on the host. Follow these rules:

  1. Take accepted filings only.
  2. Take the newest filings.
  3. Take at least 20 filings when they exist. If fewer exist, section 5 applies.

The opengov container reads the folder, so copy the folder into the container. On Compose:

docker compose cp <host folder> opengov:/tmp/old-system-export

On a Swarm stack, run the copy on the node of the task. Write the id of the container in place of <container>:

docker cp <host folder> <container>:/tmp/old-system-export

The application does not run as the user that owns the copy. So each folder needs read and search permission for all users, and each file needs read permission for all users. If not, the look reports the folder as not a folder, or the file as not checked. Set the permissions on the host before the copy:

chmod -R a+rX <host folder>

Before a new copy, delete the old folder in the container (see “Delete” below). A second copy into a folder that exists puts the new folder inside the old one. The look then reads the old manifest.

Write the manifest

The folder holds a file named manifest.csv. The first line is exactly this header: reference,field_name,file. Each other line is one file.

ColumnWhat it is
referenceThe reference of the filing in the old system
field_nameThe form key of the requirement in the OpenGov procedure
fileThe path of the file inside the folder

Save the manifest as UTF-8 text with commas. In Excel, choose “CSV UTF-8”. The command compares a reference exactly, so R1 and r1 are two filings. Write each reference the same way in each row.

An example of three rows:

reference,field_name,file
2024-00117,cr12,2024-00117/cr12.pdf
2024-00117,pin,2024-00117/pin.pdf
2024-00122,cr12,2024-00122/cr12.pdf

The command skips a row with a field_name that is not a document question of the procedure. It prints the count of skipped rows. It skips a document in a table row too.

Run the command

Run it in a container of the opengov service, as section 2 says. Add --from-folder and --accepted-in-old-system. Do not add --count.

docker compose exec opengov python3 -m opengov.eapproval.document_check.look \
  --procedure-id 8f2c1c1e-0a5e-4a3c-9c53-3f1d0f6b7a11 \
  --language en \
  --from-folder /tmp/old-system-export \
  --accepted-in-old-system \
  --out /tmp/look-notes.csv \
  --operator-id <your account id>

What the flag says. With the flag, you state that the old system accepted each filing in the folder. The audit log records your statement with your account id. The command cannot check it. Without --from-folder, the command refuses the flag.

What the command refuses

The command stops before the audit entry and before any call to the model when one of these is true:

  • The folder is not a folder, or manifest.csv is missing or cannot be read.
  • The first line of the manifest is not the exact header.
  • The manifest has no row of data.
  • A row has an empty reference, field_name or file.
  • A file path is absolute, or it leaves the folder. A symbolic link that points out of the folder is a path that leaves it.
  • Two rows have the same reference and the same field_name.
  • The manifest is not a plain file, is not UTF-8 text with commas, or has more than 100,000 data rows.
  • You gave --from-folder without --accepted-in-old-system, or with --count.
  • The virus check does not answer, or you switched it off. A time without a time zone in OPENGOV_VIRUS_SCAN_OFF_UNTIL also stops the look.

A message about a row gives the number of its line in the manifest. No message gives a reference or a file path.

Read the output

The output has the same counts as section 2 and one more line, Skipped rows.

  • A filing is one reference that has at least one row for a document question.
  • A file that is missing, that is not a regular file, or that cannot be read counts as not checked. So does a file that is larger than the upload limit of the deployment.
  • The log names the number of the manifest row and a code. It never names a reference or a file.
  • A document that the virus check leaves unchecked has a rule in section 2: repeat the look when the virus check is healthy.

The bar is the one of sections 4 and 5. The notes file is the one of section 2. The officer opens each filing in the OLD system to judge a note.

The notes file of a folder look has a fourth column, file. Its value is the file cell of the manifest row, as you wrote it. Two documents can have the same label. The officer uses the value to open the right file in the old system.

Delete

When the record of section 8 is complete, the operator deletes the notes file (section 2, “The notes file”). The operator also deletes the folder in the container. The copy does not belong to the user that the application runs as, so the delete runs as the root user (-u 0). On Compose:

docker compose exec -u 0 opengov python3 -c "import shutil; shutil.rmtree('/tmp/old-system-export')"

On a Swarm stack, run docker exec -u 0 <container> with the same python3 -c command. The image has no shell and no rm, so the delete uses python3. Last, the operator deletes the copy of the folder on the host.