Skip to content

fix(notebook): handle plain-string outputs in _extract_output - #604

Closed
wallidsaydi-creator wants to merge 1 commit into
coderamp-labs:mainfrom
wallidsaydi-creator:fix/notebook-string-form-output
Closed

fix(notebook): handle plain-string outputs in _extract_output#604
wallidsaydi-creator wants to merge 1 commit into
coderamp-labs:mainfrom
wallidsaydi-creator:fix/notebook-string-form-output

Conversation

@wallidsaydi-creator

Copy link
Copy Markdown

Summary

Converts the fix offered in #603 into a reviewable PR.

process_notebook corrupts cell outputs into one-character-per-line garbage whenever an output stores its text as a plain string rather than a list of strings — which the nbformat v4 schema explicitly allows for both stream.text and output.data["text/plain"] (the schema permits string | array of strings for multiline vs single-line storage).

A normal output like hello world currently renders as:

# Output:
#   h
#   e
#   l
#   l
#   o
#    
#   w
#   o
#   r
#   l
#   d

burning tokens and destroying readability for any notebook produced by a tool that serializes single-line outputs as strings (common in programmatic notebook generation and some exporter paths).

Root cause

_extract_output in src/gitingest/utils/notebook.py returned the raw value. The caller (_process_cell) then does raw_lines += _extract_output(output) — when the value is a str, list.__iadd__ iterates characters, and each character becomes its own # -prefixed line. cell["source"] in the same file already handles both forms correctly, so _extract_output was the only unguarded site.

Fix

Coerce the string form via splitlines() in both branches. This also restores correct rendering for multi-line string-form outputs, matching the list-form behavior line-for-line.

Verification

  • Reproduced on stock main (4e259a0): string-form stream + execute_result outputs explode into per-character lines (regression test fails with the exact signature below).
  • With the fix: both render as # hello world / # 42 on single lines; multi-line string form splits correctly.
  • New regression test test_process_notebook_string_form_output in tests/test_notebook_utils.py — proven RED on stock (stash control) and GREEN with the patch.
  • Full local suite: 152 passed (151 stock + this test). The only failures anywhere are 3 pre-existing network-dependent bitbucket cases in test_git_host_agnostic.py that fail identically on unpatched stock (verified via stash control).
  • ruff check parity with stock (no new findings; the 2 CPY001 copyright notices are pre-existing on both trees).

Fixes #603


Context: I run FreshContext — a $5 pack that keeps AI coding agents off stale docs and deprecated patterns. Recently credited in llm-docs-builder v1.0.0 for a similar LLM-pipeline correctness fix, and have a merged fix in cloudflare-docs#32985.

nbformat v4 allows stream.text and output.data['text/plain'] as either a
list of strings or a plain string. _extract_output returned the raw
value, and the caller's list += iterated characters, exploding every
string-form output into one-character-per-line garbage in the LLM-facing
digest. Coerce string form via splitlines(), which also renders
multi-line string outputs line-for-line like the list form.

Fixes #603
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 29, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-08-29T20:06:41.209850Z aa2c3a4 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@wallidsaydi-creator wallidsaydi-creator closed this by deleting the head repository Sep 5, 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.

Notebook outputs stored as plain strings (schema-valid) explode into one character per line in digest

1 participant