Skip to content

fix(sources): page interrupted cursor recovery reads - #5603

Merged
Sinity merged 1 commit into
masterfrom
fix/2w2mr-cursor-read-frame
Sep 27, 2026
Merged

Sinity merged 1 commit into
masterfrom
fix/2w2mr-cursor-read-frame

Conversation

@Sinity

@Sinity Sinity commented Sep 27, 2026

Copy link
Copy Markdown
Owner

Summary

Bound interrupted-ingest cursor recovery reads through the declared source-tier read profile. The recovery query now pages its input paths in batches of 500 and retries a complete buffered page once after frame expiry.

Problem

On fresh origin/master (1ad0f4a), the literal sqlite3.connect(...mode=ro...) census has 32 calls in polylogue/, including 22 in polylogue/sources/live/. The interrupted cursor recovery query used an unprofiled source.db connection, which could keep a WAL read snapshot open beyond the background-read bound.

Solution

CursorStore._rewind_interrupted_unparsed_cursors() now uses a query-only ReadFrame for the source tier. It buffers each bounded path page before updating its result set, rebinds and replays the full page once if expiry occurs mid-stream, and lets a repeated expiry remain a typed refusal. The existing missing-source return and SQLite-error diagnostic remain intact. Synthetic tests cover committed WAL visibility, expiry before stream exhaustion, and a missing source tier.

This converts one literal read call: the remaining census is 31 calls repo-wide and 21 in sources/live/. devtools schema closure polylogue/sources/live/cursor.py reports IN; land before a fresh archive rebuild starts.

Verification

  • devtools test tests/unit/sources/test_live_cursor_read_profile.py — PASSED exit=0 (3 tests), receipt .cache/verify/runs/20260927T050626Z-focused-test-1063431-35a2710b/run.json.
  • devtools verify --quick — PASSED exit=0 (static gates), receipt .cache/verify/runs/20260927T050735Z-quick-1066939-e3f41338/run.json.
  • No affected or full suite was run.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 27, 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-09-27T05:15:05.024748Z 47ca405 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.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 47ca4059eb

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread polylogue/sources/live/cursor.py Resolved
@Sinity
Sinity merged commit 3c4eb95 into master Sep 27, 2026
2 checks passed
@Sinity
Sinity deleted the fix/2w2mr-cursor-read-frame branch September 27, 2026 05:21
Sinity added a commit that referenced this pull request Sep 28, 2026
…#5682)

## Summary

Second intake pass (stacked on #5643).

- Every ChatGPT mapping node now goes through the scratch carrier. That
includes tool chains, multimodal parts, reasoning timings,
code-interpreter runs and authorship evidence, not only text nodes.
- A decoded value too large for one SQLite cell is refused as a counted
conservation gap, never truncated.
- Live, retained-replay and cold-build publication of one raw now
produce identical rows.
- Remaining SQLite connections are closed, and intake readers are
migrated onto the profiled factories.
- Seven old, unanswered Codex P1 findings from earlier PRs are fixed
here or dismissed with evidence.

## Problem

- **ChatGPT collecting fallback:** any node outside a narrow text-only
shape sent the whole mapping back through the collecting parser.
Normalized messages, attachments and events then grew with the
conversation.
- **Oversized values:** nothing bounded a single giant scalar, and the
ChatGPT parser capped sandbox-link attachments at 512 per message,
dropping the rest.
- **Route characterization:** the route test pinned a "delta" that was
an artefact of acquiring the retained raw without the revision identity
live intake assigns.
- **Connection leaks:** spool connections used `with
sqlite3.connect(...)`, which commits but never closes.
- **Stale test fixtures:** three tests failed on master against stale
fixtures:
  - one patched a helper that no longer exists;
  - one used a fake with an out-of-date signature;
  - one expected pre-fresh-v1 migration behaviour.

## Solution

- **One ChatGPT normalization, two stores.** `chatgpt.parse(...,
spill=)` collects messages into a `MessageEntries` store. It is a list
for the collecting parser and scratch for preparation. Ordering, parent
resolution, the active leaf and generation-timing ownership are written
once and read through the store. Declared sibling order is answered from
the spilled `children` rows. The old text-only fast path is deleted.
- **Physical value limit.** `polylogue.sources.value_bounds` reads
`SQLITE_LIMIT_LENGTH` from the linked SQLite.
- The ijson member normalizer, bundle records and ChatGPT keys refuse
any value whose UTF-8 encoding exceeds it, with
`ValueBoundRefusedError`.
- Source conservation types that refusal as `value_bound_refused`, a
counted warning.
- The sandbox attachment cap and the Gemini sidecar size caps are
removed; attachments spill to scratch instead.
- **Route equality.** The characterization test acquires the retained
raw under live's revision identity and asserts identical source and
index rows across all three routes.
- **Connections.** A `spool_connection` context closes spool databases.
The live batch, watcher, batch observability and raw-retention readers
use `open_readonly_connection`, and sibling tiers use
`attach_readonly_database`.
- **Old P1 findings:**
- #5610: a browser-capture envelope that also carries a mapping keeps
the capture route.
- #4720: a Gemini sidecar that is still being written, or is shorter
than the inline envelope, becomes debt and does not replace the
envelope. Claude Code also leaves the path-independent parse cache, for
the same sidecar reason as Gemini CLI.
- #4850: the sibling tool-id index composes the full revision plus its
appended tails.
- #5603: interrupted attempts stay `running` until the rewind read has
succeeded.
- #5630: a resumed completed ingest decodes the nested
`historical_receipt`.
- #5250 and #5630 (abandoned manifests): already fixed on master.
Evidence is in the review thread replies.
  - #5557: deferred to the location-binding change in daemon config.

## Verification

- `devtools test` over 14 files (prepared JSONL, the ChatGPT parser,
source conservation, route characterization, live watcher/append/batch,
raw retention, daemon ingest idempotency, Gemini sidecars, cursor
recovery, machine receipts, reviewed defects, route interpretation): 741
passed, 1 failed. The one failure is the Gemini oversize-sidecar
expectation that changed with the cap removal. It is fixed and its rerun
is below.
- `devtools gate mypy`, `layering`, `patterns` and `schema-closure` pass
locally; the cursor-recovery test file was rerun on the final head.
- Hosted quick gate on this head.

## Schema closure

This moves the derived schema identity, so it must land before the
rebuild. `decoder_json.py`, `prepared_jsonl.py`,
`prepared_message_sink.py`, the live batch/watcher/observability modules
and `raw_retention.py` are in the closure. The baseline grows by one
module, `polylogue/sources/value_bounds.py`, because the decoder now
imports the storable-value limit from it.

## Residuals

- behu4 shapes that still load whole objects, all code-ready with no
decision pending:
- Claude AI `chat_messages` (the evidence graph in
`normalize_chat_messages`);
  - Drive and chunked prompts;
  - Hermes ATIF and OTel;
  - the Grok fallback.
- The Claude Code tool-result sidecar join keeps its 64 MiB-per-file and
256 MiB-aggregate caps.
- Storing values above SQLite's cell limit is an undecided future
question, not committed work.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_013Vn4qhKjhyaVBG4aPiqNW4

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
@Sinity

Sinity commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

  • 70.F071 / P1: fixed-already at the checked revision: The interrupted-attempt handler reads and rewinds the affected paths before changing attempt status. polylogue/sources/live/cursor.py:582 returns without marking attempts interrupted when rewind fails, and exhausted ReadFrameExpiredError retries propagate at line 651 while the original running obligation remains discoverable.

Only the rows listed above are dispositioned. Held findings remain open.

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