Recent feature flag changes have broken `store_counts.py` script
After today's deployment, our statistics gathering script began failing. This appears to be due to the recent feature flag changes (#12984):
Traceback (most recent call last):
File "/openlibrary/scripts/store_counts.py", line 16, in <module>
sys.exit(stats.main(*sys.argv[1:]))
~~~~~~~~~~^^^^^^^^^^^^^^^
File "/openlibrary/openlibrary/admin/stats.py", line 134, in main
setup_ol_config(openlibrary_config)
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
File "/openlibrary/openlibrary/admin/stats.py", line 117, in setup_ol_config
infogami._setup()
~~~~~~~~~~~~~~~^^
File "/openlibrary/infogami/__init__.py", line 63, in _setup
delegate._load()
~~~~~~~~~~~~~~^^
File "/openlibrary/infogami/utils/delegate.py", line 203, in _load
__import__(plugin.module + '.code', globals(), locals(), ['plugins'])
~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/openlibrary/openlibrary/code.py", line 74, in <module>
setup()
~~~~~^^
File "/openlibrary/openlibrary/code.py", line 25, in setup
import openlibrary.plugins.openlibrary.code # noqa: I001 registers endpoints
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/openlibrary/openlibrary/plugins/openlibrary/code.py", line 27, in <module>
from openlibrary.core.features import features as ol_features
File "/openlibrary/openlibrary/core/features.py", line 75, in <module>
features: Features = _load_features()
~~~~~~~~~~~~~~^^
File "/openlibrary/openlibrary/core/features.py", line 72, in _load_features
return Features.from_yaml(path)
~~~~~~~~~~~~~~~~~~^^^^^^
File "/openlibrary/openlibrary/core/features.py", line 48, in from_yaml
data = yaml.safe_load(Path(path).read_text()) or {}
~~~~~~~~~~~~~~~~~~~~^^
File "/usr/local/lib/python3.14/pathlib/__init__.py", line 787, in read_text
with self.open(mode='r', encoding=encoding, errors=errors, newline=newline) as f:
~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.14/pathlib/__init__.py", line 771, in open
return io.open(self, mode, buffering, encoding, errors, newline)
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
PermissionError: [Errno 13] Permission denied: 'conf/openlibrary.yml'
Other scripts/functionality may also be broken.
⚠️ Contributors, this issue will be ready to work on once:
- [ ] Triage — maintainers will add
Priority: *andLead: @*to replaceNeeds: TriageandNeeds: Lead
Context
Root cause traced to openlibrary/core/features.py (added in #12984, commit dac833d73):
def _load_features() -> Features:
path = os.environ.get("OL_CONFIG", "conf/openlibrary.yml")
return Features.from_yaml(path)
features: Features = _load_features() # runs at import time
- This module-level singleton executes at import time, as a side effect of
infogami._setup()loading theopenlibrary.plugins.openlibraryplugin (openlibrary/plugins/openlibrary/code.pyimportsopenlibrary.core.features). store_counts.py→openlibrary/admin/stats.py:setup_ol_config()callsinfogami.load_config(openlibrary_config_file)with an explicit config path passed as a CLI argument (sys.argv[2]), then callsinfogami._setup(). The newfeatures.pymodule completely ignores that explicit path — it only readsOL_CONFIGfrom the environment or falls back to the relative path"conf/openlibrary.yml".- If the script runs from a cwd other than the repo root, or in an environment where
OL_CONFIGisn't exported,Path("conf/openlibrary.yml").read_text()raises exactly the kind of error seen in the traceback. Cron jobs commonly run with a minimal environment that does not inherit a container's docker-composeenvironment:block — thecron-jobsservice (compose.production.yaml:157,docker/ol-cron-start.sh) loads its crontab from the privateolsystemrepo (/etc/cron.d/openlibrary.ol_home0), which isn't visible from here, so I can't confirm whetherOL_CONFIGis set there. Flagging as an open question rather than asserting it. - The parent epic (#12946) explicitly settled: "Does the new system need environment-aware overrides? No... The
OL_FEATURES_YAML_PATHenv var is sufficient." The merged PR usedOL_CONFIGinstead, and didn't account for CLI-script invocation —grep -rln "_setup()\|delegate._load\|infogami.load_config"showsstore_counts.py,oldump.py,solr_updater.py,manage-imports.py, andaffiliate_server.pyall trigger the same infogami plugin-loading path and are equally exposed in theory. - #12984's testing section only covers the web container (
stats-headerHTTP header,?debugparam) — no test exercised a standalone CLI script, which is how this slipped through.
Issue Assessment
Open questions
- Does the private
olsystemcrontab exportOL_CONFIGfor cron-invoked jobs, or is that the actual gap? - Are
oldump.py,solr_updater.py,manage-imports.py,affiliate_server.pyalso affected in production, or onlystore_counts.py? - Should
features.pyaccept an explicit config path (mirroringinfogami.load_config()'s argument) instead of only reading env/relative-default, or should the module-level load be made lazy so it runs after the caller has setOL_CONFIG?
Action items
- [x] Confirm in
olsystemwhether cron jobs haveOL_CONFIGset (Answer: No, they do not.) - [ ] Decide on fix direction: pass config path explicitly vs. lazy-load
featuresvs. always requireOL_CONFIGto be set process-wide (including for cron)
Full triage checklist (maintainers / Richy)
- [x] Triage — correct labels applied or removed
- [x] Problem / opportunity — problem is clear, audience identified, actionable
- [x] Scope — issue is well-scoped; does not try to do too many things
- [x] Justification — reasoning and impact stated; sufficient for leads to prioritize
- [ ] Success & testing criteria — not stated in issue; proposed above
- [ ] Proposal & breakdown — no fix proposal yet; root cause identified above
- [x] If bug: environment & repro steps — full traceback with commit context provided
- [x] Risks, concerns, open questions — identified and surfaced above
- [x] Richy context — relevant code, commits, PRs reviewed; no duplicate issue found
- [ ] References — no screenshots/designs needed for this bug
[!NOTE] This comment was automatically generated by Richy, via PAM, Open Library's Project AI Manager, on behalf of @mekarpeles. Richy is designed to provide status visibility, perform basic project management functions and relevant codebase research, and provide actionable feedback so contributors aren't left waiting.
OL_CONFIG is not set for cron jobs.
update_stale_work_references.py is failing with the same error.