refactor(okf): typed FrontmatterError, yaml kept behind okf.py, enable ruff BLE - #1163
Merged
Merged
Conversation
…and keep yaml behind okf.py
…typed-error # Conflicts: # src/openkos/mcp/server.py
…typed-error # Conflicts: # src/openkos/cli/main.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
model/okf.pyis now the only module that knows what a frontmatter parse failure looks like.okf.load_frontmatterraises a typedokf.FrontmatterError(aValueErrorsubclass, so existingexcept ValueErrorsites keep working) for every parser failure:yaml.YAMLError, the library's ownValueErroron impossible dates, and the other errors the YAML stack can raise. The parser error is chained as__cause__. Addstry_load_frontmatter,parse_frontmatter_fragment,okf_version_is_currentandrewrite_okf_version.except Exceptionthat only guarded a frontmatter parse now catchesokf.FrontmatterError(orValueErrorwhere the same try also callsdecode_relations, or(OSError, ValueError)where it also reads the file). Each site keeps its skip / fail-closed / preserve / raise behaviour.bundle/source_titles.py,bundle/ledger.pyandapplication/doctor.pyno longer importyaml. Theokf_versionregex rewrite moved intookf.rewrite_okf_version;cli/main.pyandapplication/repair.pyuseokf.okf_version_is_current.BLEis enabled. The remaining broad catches (advisory caches, LLM and backend calls, probes, worker-thread forwarding) carry# noqa: BLE001 -- <reason>.evals/**has a per-file ignore for probe harnesses.Related issue
Closes #1144
Type of change
refactor— no behavior changechore/ci— tooling, build, or CIHow was this tested?
tests/unit/model/test_okf_frontmatter_error.pyfailed with 13 failures (AttributeError: module 'openkos.model.okf' has no attribute 'FrontmatterError'and the new helpers) before the implementation.tests/unit/test_frontmatter_catch_narrowing.py: one site per class (skip:scan_source_titles; preserve:parse_provenance_entry; fail closed:_reread_sensitivity_blocked) proves a malformed file still degrades the same way and that an unrelatedRuntimeErrornow propagates. Mutatingscan_source_titlesback toexcept Exceptionfails the propagation test.RuntimeError/ValueError; they now raiseokf.FrontmatterError, which is what a parse failure is.uv run ruff check .,uv run ruff format --check .,uv run mypy .clean; full suiteuv run pytest -q -p no:cacheprovider: 7833 passed, 2 skipped, after mergingorigin/main.Checklist
AGENTS.md).Notes for reviewers
---block, and frontmatter that is a list or scalar, still yield empty metadata from the library rather than an error (no spec asks otherwise). Only a block that is present and unparseable raises.config.pystill importsyaml: it parsesopenkos.yaml, not OKF frontmatter, so it is outside this seam.query,retrieval/answer,volatility_typing,edge_typing,revisions,contradiction) a crash is still closed, but it is a crash rather than a silentconfidential/empty result.bundle/references.pyandbundle/relations.pycatchValueError(coversFrontmatterErroranddecode_relations's shape error).