# openloops.closer

The one module that writes to GitHub: a manual task closes on its passing check.

ADR-015 §4. Everything else in openloops reads. This module may, for one issue at a
time, post **one comment**, **close** the issue, and add or remove the `attempted`
label, and only when all four conditions hold ([`refusal()`](#openloops.closer.refusal)):

1. the issue is open;
2. it carries the `manual-task` label;
3. its repository’s owner is one the person configured as trusted
   (`OPENLOOPS_CLOSE_OWNERS`; unset means the `gh` login alone, so a client’s or a
   team’s tracker is never written to unless named);
4. it was filed under the person’s own `gh` login.

A close needs a **passing check**: a read-only command (`write_effect` finds nothing)
whose exit status is 0. The check is the issue’s `**Verify:**` field, or one the owner
approved with a run plan (ADR-018). A report alone (“I ran it”) never closes; a model’s
reading of an output never closes. With no check, nothing is closed: only the person’s
own tap does that. A run with no check is still reported in one comment.

Every comment ends with a hidden marker carrying the attempt id, so a retry never posts
twice. Comments say what ran and what the check returned; they never carry command
output, and their text goes through [`openloops.egress.scrub()`](openloops.egress.html.md#openloops.egress.scrub) first (an issue in a
public repository is public).

Nothing in the core imports this module: `import openloops` still reaches no network
and writes nothing. Its callers are the run-plan executor ([`openloops.runbook_run`](openloops.runbook_run.html.md#module-openloops.runbook_run))
and, later, `ol do` (ADR-015 §2).

Two seams (ADR-015’s table): `gh=` reads, `(args, *, input=None) -> (status, stdout)`;
`deliver=` writes, a [`Deliver`](#openloops.closer.Deliver) (default [`GhDeliver`](#openloops.closer.GhDeliver), the `gh` CLI the
person already authenticated; a spool or the board store can take its place).

Outcomes use the run vocabulary: `done` (it ran as expected), `failed` (it ran and
did not), `check-only` (nothing ran). ADR-015 §1’s `blocked` and `needs-owner` are
reports that close nothing; a caller maps them to `failed` with its own note.

### Functions

| [`read_issue`](#openloops.closer.read_issue)(ref, \*[, gh])                       | The issue's state, labels, author and body, plus its comments' last lines.         |
|--------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------|
| [`refusal`](#openloops.closer.refusal)(issue, \*, owners, login)               | Why this module must not write to *issue*, or `""`.                                |
| [`report`](#openloops.closer.report)(ref, \*, attempt[, ran, ran_label, ...]) | Report an outcome for one manual task; close it only if its check passes.          |
| [`trusted_owners`](#openloops.closer.trusted_owners)(\*[, gh, environ])               | Whose trackers this module may write to: `OPENLOOPS_CLOSE_OWNERS`, else the login. |
| [`who`](#openloops.closer.who)(\*[, gh])                                   | `(trusted owners, login)`, resolved once; a run passes them to every report.       |

### Classes

| [`Deliver`](#openloops.closer.Deliver)(\*args, \*\*kwargs)   | Where this module's writes go.                                                                          |
|--------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| [`GhDeliver`](#openloops.closer.GhDeliver)([gh])               | The default [`Deliver`](#openloops.closer.Deliver): the `gh` CLI, one call per write. |

### *class* openloops.closer.Deliver(\*args, \*\*kwargs)

Bases: [`Protocol`](https://docs.python.org/3/library/typing.html#typing.Protocol)

Where this module’s writes go. Each returns `(ok, detail)`.

### *class* openloops.closer.GhDeliver(gh=<function \_gh_cli>)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

The default [`Deliver`](#openloops.closer.Deliver): the `gh` CLI, one call per write.

### openloops.closer.read_issue(ref, \*, gh=<function \_gh_cli>)

The issue’s state, labels, author and body, plus its comments’ last lines.

Only each comment’s last line is read (where the marker lives), never whole
comments: they are other people’s text.

* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any)]

### openloops.closer.refusal(issue, , owners, login)

Why this module must not write to *issue*, or `""`. The four conditions.

```pycon
>>> ok = {'ref': 'me/r#1', 'state': 'OPEN', 'labels': [{'name': 'manual-task'}],
...       'author': {'login': 'me'}}
>>> refusal(ok, owners=('me',), login='me')
''
>>> refusal({**ok, 'state': 'CLOSED'}, owners=('me',), login='me')
'the issue is not open'
>>> refusal(ok, owners=('client',), login='me')
"owner 'me' is not one this module may write to (OPENLOOPS_CLOSE_OWNERS)"
>>> refusal({**ok, 'author': {'login': 'someone'}}, owners=('me',), login='me')
"filed by 'someone', not by the person's own login 'me'"
```

* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

### openloops.closer.report(ref, \*, attempt, ran='', ran_label='', outcome='done', check=None, check_source='', gh=<function \_gh_cli>, deliver=None, run_check=<function default_run_check>, owners=None, login=None, dry_run=False)

Report an outcome for one manual task; close it only if its check passes.

`outcome` is `done`, `failed` or `check-only` (nothing ran; the check is run to
see whether it is already done). `ran` is a one-line description of what ran (it is
scrubbed before it is posted); `ran_label` names it without its text (`"step s3 of
run plan p (ab12cd34)"`), and is what a comment on a repository that is not private
says instead of the command and the check. `check` overrides the issue’s own `**Verify:**`
command; `check_source` says where it came from (`"run plan <hash8>"`).

Returns `{ref, action, reason, check, check_status, commented}` where `action` is
one of `closed`, `attempted`, `open` (nothing ran and the check fails: nothing
written), `no-check` (reported in a comment when something ran; never closed) or
`refused` (a condition failed: nothing written). `dry_run` decides as usual and
writes nothing.

* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any)]

### openloops.closer.trusted_owners(\*, gh=<function \_gh_cli>, environ=environ({'SHELL': '/bin/bash', 'SELENIUM_JAR_PATH': '/usr/share/java/selenium-server.jar', 'GITHUB_WORKSPACE': '/home/runner/work/openloops/openloops', 'JAVA_HOME_11_X64': '/usr/lib/jvm/temurin-11-jdk-amd64', 'JAVA_HOME_25_X64': '/usr/lib/jvm/temurin-25-jdk-amd64', 'PROJECT_NAME': 'openloops', 'PKG_CONFIG_PATH': '/opt/hostedtoolcache/Python/3.12.16/x64/lib/pkgconfig', 'GITHUB_PATH': '/home/runner/work/_temp/_runner_file_commands/add_path_2485f815-8cd2-453b-97e4-edc6b2b96920', 'GITHUB_ACTION': '_\_i2mint_epythet', 'JAVA_HOME': '/usr/lib/jvm/temurin-25-jdk-amd64', 'GITHUB_RUN_NUMBER': '257', 'RUNNER_NAME': 'GitHub Actions 1000076090', 'GRADLE_HOME': '/usr/share/gradle-9.9.2', 'GITHUB_REPOSITORY_OWNER_ID': '1906276', 'ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE': '/opt/actionarchivecache', 'XDG_CONFIG_HOME': '/home/runner/.config', 'Python_ROOT_DIR': '/opt/hostedtoolcache/Python/3.12.16/x64', 'MEMORY_PRESSURE_WRITE': 'c29tZSAyMDAwMDAgMjAwMDAwMAA=', 'DOTNET_SKIP_FIRST_TIME_EXPERIENCE': '1', 'ANT_HOME': '/usr/share/ant', 'GITHUB_TRIGGERING_ACTOR': 'thorwhalen', 'pythonLocation': '/opt/hostedtoolcache/Python/3.12.16/x64', 'GITHUB_REF_TYPE': 'branch', 'HOMEBREW_CLEANUP_PERIODIC_FULL_DAYS': '3650', 'ACTIONS_RUNNER_RETURN_JOB_RESULT_FOR_HOSTED': '1', 'ANDROID_NDK': '/usr/local/lib/android/sdk/ndk/27.3.13750724', 'BOOTSTRAP_HASKELL_NONINTERACTIVE': '1', 'PWD': '/home/runner/work/openloops/openloops', 'PIPX_BIN_DIR': '/opt/pipx_bin', 'LOGNAME': 'runner', 'GITHUB_ARTIFACTS_LIST': '/home/runner/work/_temp/_runner_file_commands/artifacts_list_2485f815-8cd2-453b-97e4-edc6b2b96920', 'GITHUB_REPOSITORY_ID': '1346350581', 'GITHUB_ACTIONS': 'true', 'USE_BAZEL_FALLBACK_VERSION': 'silent:', 'ANDROID_NDK_LATEST_HOME': '/usr/local/lib/android/sdk/ndk/30.0.16248370', 'SYSTEMD_EXEC_PID': '2136', 'GITHUB_SHA': '091b60c3937152b52e2b66e13157b52eb53f8f0c', 'GITHUB_WORKFLOW_REF': 'thorwhalen/openloops/.github/workflows/ci.yml@refs/heads/main', 'POWERSHELL_DISTRIBUTION_CHANNEL': 'GitHub-Actions-Linux', 'RUNNER_ENVIRONMENT': 'github-hosted', 'DOTNET_MULTILEVEL_LOOKUP': '0', 'GOROOT_1_27_X64': '/opt/hostedtoolcache/go/1.27.4/x64', 'GITHUB_REF': 'refs/heads/main', 'RUNNER_OS': 'Linux', 'GITHUB_REF_PROTECTED': 'false', 'HOME': '/home/runner', 'GITHUB_API_URL': 'https://api.github.com', 'LANG': 'C.UTF-8', 'GOROOT_1_25_X64': '/opt/hostedtoolcache/go/1.25.14/x64', 'RUNNER_TRACKING_ID': 'github_5bd64462-ecc2-4b6c-a4ef-ec03ca75fc68', 'RUNNER_ARCH': 'X64', 'MEMORY_PRESSURE_WATCH': '/sys/fs/cgroup/system.slice/hosted-compute-agent.service/memory.pressure', 'RUNNER_TEMP': '/home/runner/work/_temp', 'GITHUB_STATE': '/home/runner/work/_temp/_runner_file_commands/save_state_2485f815-8cd2-453b-97e4-edc6b2b96920', 'EDGEWEBDRIVER': '/usr/local/share/edge_driver', 'JAVA_HOME_21_X64': '/usr/lib/jvm/temurin-21-jdk-amd64', 'GITHUB_ENV': '/home/runner/work/_temp/_runner_file_commands/set_env_2485f815-8cd2-453b-97e4-edc6b2b96920', 'GITHUB_EVENT_PATH': '/home/runner/work/_temp/_github_workflow/event.json', 'INVOCATION_ID': '0829efb1d2ef4e2a84a00b4802818fd7', 'GITHUB_EVENT_NAME': 'push', 'GITHUB_RUN_ID': '46425419446', 'JAVA_HOME_17_X64': '/usr/lib/jvm/temurin-17-jdk-amd64', 'ANDROID_NDK_HOME': '/usr/local/lib/android/sdk/ndk/27.3.13750724', 'GITHUB_STEP_SUMMARY': '/home/runner/work/_temp/_runner_file_commands/step_summary_2485f815-8cd2-453b-97e4-edc6b2b96920', 'HOMEBREW_NO_AUTO_UPDATE': '1', 'GITHUB_ACTOR': 'thorwhalen', 'NVM_DIR': '/home/runner/.nvm', 'GITHUB_RUN_ATTEMPT': '1', 'ANDROID_HOME': '/usr/local/lib/android/sdk', 'GITHUB_GRAPHQL_URL': 'https://api.github.com/graphql', 'ACCEPT_EULA': 'Y', 'USER': 'runner', 'PSModulePath': '/root/.local/share/powershell/Modules:/usr/local/share/powershell/Modules:/opt/microsoft/powershell/7/Modules:/usr/share/az_15.6.1', 'GITHUB_ACTION_PATH': '/home/runner/work/_actions/i2mint/epythet/master/actions/publish-github-pages', 'GITHUB_SERVER_URL': 'https://github.com', 'PIPX_HOME': '/opt/pipx', 'GECKOWEBDRIVER': '/usr/local/share/gecko_driver', 'CHROMEWEBDRIVER': '/usr/local/share/chromedriver-linux64', 'SHLVL': '1', 'ANDROID_SDK_ROOT': '/usr/local/lib/android/sdk', 'VCPKG_INSTALLATION_ROOT': '/usr/local/share/vcpkg', 'GITHUB_ACTOR_ID': '1906276', 'ACTIONS_ORCHESTRATION_ID': '16f5d376-a23b-831e-bce8-75ea392c4529.ci.github-pages._\_default', 'RUNNER_TOOL_CACHE': '/opt/hostedtoolcache', 'ImageVersion': '20261122.9.1', 'Python3_ROOT_DIR': '/opt/hostedtoolcache/Python/3.12.16/x64', 'DOTNET_NOLOGO': '1', 'GITHUB_ARTIFACTS': '/home/runner/work/_temp/_runner_file_commands/artifacts_2485f815-8cd2-453b-97e4-edc6b2b96920', 'GITHUB_WORKFLOW_SHA': '091b60c3937152b52e2b66e13157b52eb53f8f0c', 'GITHUB_REF_NAME': 'main', 'GITHUB_JOB': 'github-pages', 'LD_LIBRARY_PATH': '/opt/hostedtoolcache/Python/3.12.16/x64/lib', 'XDG_RUNTIME_DIR': '/run/user/1001', 'AZURE_EXTENSION_DIR': '/opt/az/azcliextensions', 'GOROOT_1_26_X64': '/opt/hostedtoolcache/go/1.26.11/x64', 'GITHUB_REPOSITORY': 'thorwhalen/openloops', 'Python2_ROOT_DIR': '/opt/hostedtoolcache/Python/3.12.16/x64', 'CHROME_BIN': '/usr/bin/google-chrome', 'ANDROID_NDK_ROOT': '/usr/local/lib/android/sdk/ndk/27.3.13750724', 'GITHUB_RETENTION_DAYS': '90', 'JOURNAL_STREAM': '10:16381', 'RUNNER_WORKSPACE': '/home/runner/work/openloops', 'GITHUB_ACTION_REPOSITORY': '', 'HCA_CLOUD_PROVIDER': 'aws', 'PATH': '/opt/hostedtoolcache/Python/3.12.16/x64/bin:/opt/hostedtoolcache/Python/3.12.16/x64:/snap/bin:/home/runner/.local/bin:/opt/pipx_bin:/home/runner/.cargo/bin:/home/runner/.config/composer/vendor/bin:/usr/local/.ghcup/bin:/home/runner/.dotnet/tools:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin', 'GITHUB_BASE_REF': '', 'GHCUP_INSTALL_BASE_PREFIX': '/usr/local', 'CI': 'true', 'SWIFT_PATH': '/usr/share/swift/usr/bin', 'ImageOS': 'ubuntu26', 'GITHUB_REPOSITORY_OWNER': 'thorwhalen', 'GITHUB_HEAD_REF': '', 'GITHUB_ACTION_REF': '', 'ENABLE_RUNNER_TRACING': 'true', 'GITHUB_WORKFLOW': 'Continuous Integration', 'DEBIAN_FRONTEND': 'noninteractive', 'GITHUB_OUTPUT': '/home/runner/work/_temp/_runner_file_commands/set_output_2485f815-8cd2-453b-97e4-edc6b2b96920', 'AGENT_TOOLSDIRECTORY': '/opt/hostedtoolcache', '_': '/opt/hostedtoolcache/Python/3.12.16/x64/bin/epythet', 'EPYTHET_PROJECT_DIR': '/home/runner/work/openloops/openloops', 'EPYTHET_OVERRIDES': '{"api_generator": "autosummary", "ignore": ["tests/", "scrap/", "examples/"]}', 'EPYTHET_BUILD_INFO': '{"schema_version": 1, "built_at": "2026-11-30T13:10:50Z", "package": {"name": "openloops", "version": "0.1.58", "display_name": "openloops", "source": "pyproject.toml"}, "git": {"available": true, "commit": "091b60c3937152b52e2b66e13157b52eb53f8f0c", "short_commit": "091b60c", "branch": "main", "tags": [], "dirty": false, "remote_url": "https://github.com/thorwhalen/openloops", "commit_url": "https://github.com/thorwhalen/openloops/commit/091b60c3937152b52e2b66e13157b52eb53f8f0c", "error": null}, "ci": {"provider": "github", "repository": "thorwhalen/openloops", "sha": "091b60c3937152b52e2b66e13157b52eb53f8f0c", "sha_in_history": true, "ref": "refs/heads/main", "ref_name": "main", "run_id": "46425419446", "run_url": "https://github.com/thorwhalen/openloops/actions/runs/46425419446", "server_url": "https://github.com"}, "tools": {"epythet": "0.2.25", "sphinx": "9.1.1", "docutils": "0.22.4", "python": "3.12.16"}, "config": {"theme": "auto", "html_theme": "pydata_sphinx_theme", "accent": "#006d67", "mode": "auto", "api_generator": "autosummary", "ignore": ["tests/", "scrap/", "examples/"], "agent_outputs": true, "aggregates": ["md"], "ai_artifacts": true, "provenance": true, "docs_dir": "docsrc"}, "site": {"modules_documented": null, "objects_documented": null}, "pypi": {"checked": true, "latest": "0.1.59", "relation": "behind", "error": null}, "reproduce": "git clone https://github.com/thorwhalen/openloops && cd openloops\\\\ngit checkout 091b60c3937152b52e2b66e13157b52eb53f8f0c\\\\npip install \\\\"epythet==0.2.25\\\\"\\\\nepythet quickstart . --ignore tests/ scrap/ examples/", "warnings": [], "alignment": {"aligned": false, "notes": ["The documented version (0.1.58) is behind the latest release on PyPI (0.1.59): \`pip install openloops\` gives newer code than these docs describe."]}}', 'DOCUTILSCONFIG': '/home/runner/work/openloops/openloops/docsrc/docutils.conf'}))

Whose trackers this module may write to: `OPENLOOPS_CLOSE_OWNERS`, else the login.

```pycon
>>> trusted_owners(environ={'OPENLOOPS_CLOSE_OWNERS': 'acme, widgets'})
('acme', 'widgets')
>>> trusted_owners(gh=lambda args, **kw: (0, 'me\n'), environ={})
('me',)
```

* **Return type:**
  [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`...`](https://docs.python.org/3/builtins/constants.html#Ellipsis)]

### openloops.closer.who(\*, gh=<function \_gh_cli>)

`(trusted owners, login)`, resolved once; a run passes them to every report.

* **Return type:**
  [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`...`](https://docs.python.org/3/builtins/constants.html#Ellipsis)], [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]
