Skip to content

Continue truncated paper context from its included bytes - #692

Merged
NielsRogge merged 2 commits into
mainfrom
claude/paper-reader-read-offset
Oct 22, 2026
Merged

NielsRogge merged 2 commits into
mainfrom
claude/paper-reader-read-offset

Conversation

@NielsRogge

@NielsRogge NielsRogge commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Paper-reader turns include the first 80 KiB of stored Markdown. A truncated paper's continuation now points at pwc_read_paper with offset set to its included_bytes, not at the title (the old cursor: "next" restarted reading at the beginning).
  • Budget trimming now rewrites each paper's included_bytes to the bytes it kept, so an offset never skips text the model did not see.
  • pdf_text papers are excluded from offset continuation, because their text is not the stored Markdown.

Deploy order

Deploy the pwc-cli MCP change first (huggingface/pwc-cli#35). Until it is live, the hosted read_paper rejects offset. This is a chat change, so it is not merged or deployed; it waits for explicit authorization.

Verification

  • npx --no-install node --test --import tsx test/paper_context_budget.test.ts: 11 pass, including trimmed papers report the Markdown bytes kept for offset continuation.
  • test/paper_pagination.test.ts: the new offset test passes. pagination survives session restore... fails, but it also fails on main (the installed @earendil-works/pi-coding-agent differs from the version the test expects).
  • Full pi_worker suite: 108 pass, 20 fail, the same 20 that fail on main (createMcpExtension is missing from the installed pi-coding-agent).
  • uv run --env-file backend/keys.env pytest backend/tests/chat/test_paper_context.py: 28 pass.
  • Full backend/tests/chat: 9 fail here, 8 of which also fail on main. The ninth, test_turn_job_migration_is_guarded_and_preserves_schema_ownership, fails on origin/main's docs/deployment.md, which this change does not touch.
  • ruff check and ruff format pass.

🤖 Generated with Claude Code


Note

Medium Risk
Changes paper-reader continuation semantics and depends on a coordinated pwc-cli MCP deploy; misaligned offsets could skip or duplicate paper text until both sides are live.

Overview
Truncated in-context paper text can now be continued correctly via pwc_read_paper: models are instructed to pass offset from each paper’s included_bytes (no cursor on the first call, then cursor: "next"), instead of paging from the start. content_origin papers (e.g. PDF-extracted text) are excluded from offset continuation because their body is not stored Markdown.

Context-budget trimming rewrites each paper’s included_bytes to the raw Markdown byte count actually kept in the prompt (after unescaping HTML entities), and the budget notice documents that contract so offset reads do not skip unseen text.

Paper-reader system notices (Python + MCP research prompt) are aligned with the same workflow. Tests cover trimmed included_bytes, escaped Markdown byte accounting, and offset-then-cursor pagination.

Reviewed by Cursor Bugbot for commit c361798. Bugbot is set up for automated code reviews on this repo. Configure here.

The paper context stops at 80 KiB of stored Markdown, and a model that
asked for more by reading with cursor next restarted at the title. The
notice now points continuation at pwc_read_paper with offset set to the
paper's included_bytes. Budget trimming reports the bytes it kept, and
pdf_text papers are excluded because their text is not the Markdown.

Depends on the pwc-cli read_paper offset parameter.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit cf0b240. Configure here.

Comment thread backend/chat_sandbox_worker/pi_worker/src/paper_context_budget.ts
Comment thread backend/services/chat_paper_context_service.py
Budget trimming measured the HTML-escaped body, so included_bytes could
overstate the stored Markdown and an offset read would skip text. It now
decodes the kept body before counting. Layout-markdown papers are also
excluded from offset continuation, because their text is not the stored
Markdown either.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
@NielsRogge
NielsRogge merged commit be99087 into main Oct 22, 2026
4 checks passed
@NielsRogge
NielsRogge deleted the claude/paper-reader-read-offset branch October 22, 2026 13:16
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.

1 participant