Skip to content

fix: read the current markdown body in get - #754

Draft
sb123sb123 wants to merge 2 commits into
pyrite-wiki:devfrom
sb123sb123:fix/753-get-body-preserved
Draft

sb123sb123 wants to merge 2 commits into
pyrite-wiki:devfrom
sb123sb123:fix/753-get-body-preserved

Conversation

@sb123sb123

@sb123sb123 sb123sb123 commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

pyrite get --format json now reads the current Markdown body and raw-byte SHA-256 for the selected entry, even when the index is stale. Passing that body to pyrite update --body-file leaves the file unchanged.

Scope: the file-backed refresh is opt-in and used by CLI get; REST, MCP, and other KBService reads keep their established normalized-body behavior.

Validation:

  • Ruff check, Ruff format, and git diff check pass on Windows.
  • Focused Windows run: 145 passed; two path-separator assertions and 11 SQLite teardown errors are Windows-specific. The new round-trip regression and core-test selector pass.
  • The first hosted run exposed the side effects of refreshing every KBService caller. The follow-up commit narrows the refresh to CLI get; hosted CI is rerunning on this head.

Fixes pyrite-wiki#753

Signed-off-by: sb123sb123 <152394158+sb123sb123@users.noreply.github.com>
Signed-off-by: sb123sb123 <152394158+sb123sb123@users.noreply.github.com>
@markramm

markramm commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

Automated review (Pyrite conductor, an AI agent) of head 034aeba. The maintainer decides; this is input only.

Thanks, @sb123sb123. The fix does stop the reported loss: with a stale index, the ### QC section now survives get → update --body-file, and the regression test fails without the change. Four things should change before this merges.

  1. Use the one splitter. refactor: one frontmatter splitter, every reader uses it #744 has merged split_frontmatter (pyrite/storage/frontmatter.py) as the single frontmatter splitter. _body_from_entry_file adds a third rule (line.strip(" \t") == "---") that disagrees with it. For example, ---\nid: n1\ntitle: T\n--- # end\n\nIntro kept?\n\n---\n\nTail.\n returns Tail.\n, so a get → update round trip would delete "Intro kept?". Please rebase on dev and take the body span from split_frontmatter.
  2. One meaning of "the entry's body". The file read is behind a CLI-only flag, so REST (endpoints/entries.py) and MCP (mcp_server.py) still return the index body, and the same round trip loses data there. ADR-0042 decision 9 says a single-entry read reads the file, for every surface. Please move the read into get_entry itself rather than behind read_current_body.
  3. One read, one version. Take title, tags and the other fields from the same file read as body and content_hash. Today a stale index can return old frontmatter beside a fresh body and a hash of the new file.
  4. Claim only what holds. update rewrites the whole file, so "leaves the file unchanged" is false for files with CRLF, a BOM, no final newline, YAML comments or extra trailing blank lines. Byte-identical body writes come with B6 (B6 write path: phases, acceptance and footprint (spike result) #730, apply()). Please narrow the changelog to "get returns the file's current body". Add round-trip tests built from hand-written bytes for those file shapes, not from to_markdown(). Assert body equality for get, and file equality only where it actually holds.

Smaller: an entry added since the last sync still gives NOT_FOUND. find_file scans the whole KB when the id is not the filename.

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.

kb get returns a body missing a section; a get → update --body-file round trip deletes it

2 participants