Skip to content

Preserve YAML layout when adding OpenAI endpoints - #1865

Merged
simonw merged 1 commit into
simonw:mainfrom
wsj040303:fix/endpoint-yaml-layout-1864
Nov 11, 2026
Merged

simonw merged 1 commit into
simonw:mainfrom
wsj040303:fix/endpoint-yaml-layout-1864

Conversation

@wsj040303

Copy link
Copy Markdown
Contributor

Adding an endpoint to an indented block list wrote the new entry at column zero, leaving extra-openai-models.yaml unparseable. Appending after an explicit ... document end marker caused the same failure, so subsequent model-loading commands stopped working.

Preserve the block list's indentation and insert new entries before its document end marker. Read indentation from the block-start token so sequence tags and anchors work too. Existing records, comments and quoting are preserved.

Regression tests cover zero/two/four-space indentation, missing final newlines, trailing comments, document end markers, tagged/anchored lists, empty explicit documents, and repeated additions followed by model loading.

Validation on Linux / Python 3.13:

  • Existing endpoint baseline: 21 passed; new regressions against the original code: 11 failed, 23 passed.
  • Fixed endpoint tests: 34 passed. Full pytest -q: 1,413 passed.
  • Original CLI reproduction and document-end variant: llm models and endpoint list --json fail before the fix and succeed afterwards.
  • Black, Ruff, mypy, Cog documentation checks, package build, and tests/test-llm-load-plugins.sh all passed.

Fixes #1864

@millionbillions

Copy link
Copy Markdown

Code Review Bot — PR #1865

0 patch(es) generated for simonw/llm.

llm/default_plugins/openai_models.py [LOW]

Fault: FATAL: Error code: 401 - Incorrect API key provided: sk-proj-*******************************************************************************************************************************************
Quality score: 0/5 —

tests/test_openai_endpoint_add.py [LOW]

Fault: FATAL: Error code: 401 - Incorrect API key provided: sk-proj-*******************************************************************************************************************************************
Quality score: 0/5 —


Generated by CodeReviewBot — GraphRAG-powered code analysis

@chrikrah chrikrah left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wsj040303 From my perspective this can be merged. It matches the indent it finds, which answers the question in #1864, and the repro from that issue now loads both models:

# git archive f605dcf673 (base 39d3254), Python 3.13.5, llm.__file__ from the export
$ llm openai endpoint add http://localhost:11434/v1 -m qwen3 --id local-b && llm models
  (base, list indented by 2) -> yaml.parser.ParserError: expected '<document start>', but found '<block sequence start>'
  (head, list indented by 2) -> OpenAI Chat: local-a, OpenAI Chat: local-b
  (base, list ending in ...) -> the same ParserError
  (head, list ending in ...) -> both models, `...` still the last line
$ pytest -q tests/test_openai_endpoint_add.py
  (head) -> 34 passed
  (head, openai_models.py from 39d3254) -> 11 failed, 23 passed
$ pytest -q
  (head) -> 1413 passed
  (base) -> 1400 passed
# _append_extra_model at head, reloaded with yaml.safe_load: a comment line above the list, `---` above an
# indented list and a model_name of "a\n\nb" all come back intact
# not run: Windows

@simonw

simonw commented Nov 11, 2026

Copy link
Copy Markdown
Owner

Thanks for this!

@simonw
simonw merged commit e3c6eaf into simonw:main Nov 11, 2026
17 checks passed
simonw added a commit that referenced this pull request Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

llm openai endpoint add writes unparseable YAML when the existing list is indented

4 participants