Skip to content

Stream certified native context within caller resource budgets - #110

Merged
unbraind merged 12 commits into
mainfrom
feat/bounded-read-sessions
Oct 23, 2026
Merged

unbraind merged 12 commits into
mainfrom
feat/bounded-read-sessions

Conversation

@unbraind

@unbraind unbraind commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

Native hosts can now pull certified tracker context through a typed Rust session with caller resource admission, cooperative cancellation and compact CLI frames. Previously, embedders owned corpus lifetime and resource controls themselves.

The v1 session freezes a private disk-backed copy, strictly decodes all items with the core duplicate checker, then reuses Workspace::list_page and its JSON/TOON codecs. Registry reads stay in the snapshot; cursors retain the original tracker identity. Admission covers source, indexes, clock storage and page rendering. Exhaustion, explicit cancellation, failure and drop attempt snapshot cleanup. Cleanup failures terminate delivery without certifying an undelivered page and require host scratch-storage recovery. pm-rust read-session emits compact JSON frames or TOON documents, with typed refusal codes and remedies. README, the resource contract and a runnable Rust host document the surface.

Review correction: optional schema lookup falls back only on NotFound; other errors preserve the canonical source path, kind and raw OS code before admission can certify completion. Unix regressions retain the regular-file schema-parent refusal. Separate Windows checks exercise canonical default-registry behavior, and portable invalid-filename SDK/CLI checks exercise actual I/O refusal on every platform, including original-source diagnostics and snapshot cleanup.

The memory ceiling is an admission ledger; measured RSS is separate. Hard process-wide RSS enforcement belongs to the embedding host's OS limits. Cancellation is cooperative at copy/query boundaries. Snapshot capture validates individually read files rather than promising an atomic transaction across concurrent source writers. Completion certifies brief projected context and preserves field-omission receipts.

Acceptance criterion Evidence
Large synthetic tracker respects its declared ceiling 10,000 items, 10 pages; 381,185,760 admitted bytes and 43,652 KiB peak RSS under a 536,870,912-byte ceiling
Cancellation releases resources SDK peer cancellation before/after real queries, explicit cancellation, CLI marker cancellation, terminal failure, successful completion and drop regressions; snapshot removal verified; real cleanup-error regressions keep undelivered pages uncertified
Wire results remain oracle-conformant Both trackers pass real SDK whole-corpus certification; all identities and 11 canonical CLI JSON page payloads match, normalizing indentation only; existing byte-exact differential gates retained
Typed SDK, compact CLI, refusals and documentation Exported native session types; JSON frames/TOON documents; stable refusal codes and remedies; README, contract and runnable example
Works without Git or Node in the native host Real non-git initialized trackers; native CLI runs with neither executable on PATH

These resource observations are retained from the identified pre-review binary; the schema lookup correction has its own focused regression and CI evidence. Measured using Rust 1.90.0 and the unoptimized native binary on a contended development host. These are individual observations, not latency guarantees. Every native source copy was read-only; authoritative source hashes remained unchanged.

Dataset Items Pages Source bytes Admission bytes Peak RSS (KiB) Wall (ms) Output bytes
SDK-generated tracker 10,000 10 1,959,611 381,185,760 43,652 131,120 988,986
Public pm-rust tracker copy 78 1 757,075 131,681,424 13,824 782 12,549

The public tracker comes from commit 5862034d9618aba23ee909d7a9f9bbdd1b78e252. Its unchanged source SHA-256 is f498f5527c1203481d01f42a473082756e48a173bc5b8dea54b222e8dfb536c2. The measured binary SHA-256, checked before and after validation, is b521fc24870ac80b095e3f417af765e58c0a50a616b455b04b8b0c7e430bfa71. No generated trackers, raw output, cache or executable files are committed.

Ten independent behavioral reverts compiled and failed their targeted regression: admission charging, snapshot binding, registry isolation, cancellation cleanup, omission-only result refusal, clock-storage accounting, duplicate-file remedies, final cleanup ordering, output-cursor continuation and schema lookup refusal. All functions were restored before passing validation.

Focused correction validation:

  • Five pm-linked commands passed: 17 session SDK tests, 7 CLI session tests and 3 supporting tests (27 cases, zero failed/ignored after retry).
  • Four current-round behavioral reverts compiled and failed with exit 101: Unix schema-parent SDK/CLI refusal and portable invalid-filename SDK/CLI refusal. Only the old optional lookup behavior in Workspace::read_session was restored; the exact fixed source was restored afterward. Revert receipts are in the feature item.
  • Strict all-target/all-feature Clippy, formatting, private rustdoc, changelog regeneration/check and isolated CI-style tracker health passed locally. Windows CI caught two Windows-only docstring formatting issues; both are corrected without changing assertions or executable logic.
  • One linked CLI attempt encountered bundle_integrity_torn_install during an oracle reinstall and passed after installation completed. The local full release gate was stopped under heavy host load after 334 library, 35 CLI-unit and branch-merge tests passed; that attempt is incomplete gate evidence.
  • The historical tracker chain advisories remain separately tracked by pm-rust-b4yl; CI check-only health does not certify those older chains. Append-only history prefixes were preserved.
  • Reproduction and resource boundaries: bounded read sessions.

Full CI evidence: run 40012181308 passed all 10 jobs for e52dc73c6fd59bdfecf4eee4574748aace08eaaa. All four full release aggregates passed: Linux npm and Linux Bun each ran 625 tests twice; macOS npm ran 614 tests twice; Windows npm ran 608 tests twice. Every run had zero failed or ignored tests. Each aggregate measured 100 percent lines, functions, regions and branches at unchanged thresholds and passed audit, changelog and CI-style tracker health. The three separate Rust jobs passed 625/614/608 cases, and all three latency jobs passed. npm and Bun invoke the same native just release-check gate. The local full attempt remains explicitly incomplete; full-gate evidence comes from CI.

Automated line review remains limited: Greptile's trial ended, CodeRabbit skipped automatic review, and Sourcery exhausted its review budget. These are missing review evidence.

Overlap was checked against CLI 2026.10.23 and sibling packages. Core complete-list certification, native pagination and latency work are reused; pm-context retains durable context-pack ownership and pm-web remains a complete-list consumer. This adds an embedding/resource contract without changing the pinned 2026.10.21 oracle or introducing a duplicate core query.

PM: bounded read sessions, native pagination, native latency. The feature remains in progress with its claim released for orchestrator verification.

Summary by Sourcery

Provide embedders with a resource-admitted native read session that streams certified tracker context safely and predictably.

New Features:

  • Add a typed Rust and CLI read-session interface for streaming certified context from immutable tracker snapshots under caller-specified resource limits.
  • Support compact JSON frames and TOON documents with stable refusal codes, cancellation controls, receipts, and recovery guidance.

Bug Fixes:

  • Preserve canonical schema lookup failures and operating-system diagnostics while limiting optional fallback to missing files.
  • Ensure cancellation, terminal failures, dropped sessions, and cleanup errors cannot certify undelivered pages and release private snapshot resources.

Enhancements:

  • Reuse canonical pagination, filtering, projection, cursor continuation, registry isolation, and output codecs while retaining original tracker query identity.
  • Document the bounded read-session embedding contract, resource accounting model, lifecycle guarantees, and runnable native host usage.

Build:

  • Expose npm and Bun aliases for the native release-check and run both runtimes in the CI release aggregate matrix.

CI:

  • Expand cross-platform regression coverage for session admission, cancellation, cleanup, source integrity, schema behavior, cursor continuation, and native hosts without Git or Node.

Documentation:

  • Add README guidance, a detailed bounded read-session contract, and a runnable Rust embedding example.

Tests:

  • Add SDK, CLI, cross-platform, resource-validation, oracle-conformance, and failure-boundary tests for bounded read sessions.

Chores:

  • Move tempfile to regular dependencies for the public session implementation.

@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: eae319a5-9dbf-4ca1-9cc8-04b76aa0f9ab
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai

sourcery-ai Bot commented Oct 23, 2026

Copy link
Copy Markdown

Reviewer's Guide

This PR introduces a native bounded read-session surface that freezes and certifies a private tracker snapshot, streams canonical paginated context under caller admission and cancellation controls, and exposes the behavior through SDK, CLI, documentation, examples, and validation tooling. Existing pagination and codecs remain the query/output implementation; lifecycle cleanup, typed refusals, oracle comparisons, RSS measurements, and npm/Bun release-gate coverage define the new integration boundaries.

Sequence diagram for the bounded native read session

sequenceDiagram
    actor Host
    participant Workspace
    participant Snapshot as PrivateSnapshot
    participant Session as ReadSession
    participant Reader as CanonicalListReader

    Host->>Workspace: read_session(limits, cancellation, timestamp)
    Workspace->>Snapshot: Capture and validate source files
    Snapshot-->>Workspace: Immutable snapshot and receipt
    Workspace-->>Host: ReadSession
    loop Pull pages
        Host->>Session: next_page()
        Session->>Reader: list_page()
        Reader-->>Session: Canonical paginated output
        Session-->>Host: SessionPage(output, receipt)
    end
    Session->>Snapshot: Remove on exhaustion, cancellation, failure, or drop
Loading

Flow diagram for read-session admission and cancellation

flowchart TD
    Start[Open read session] --> Check{Limits and cancellation valid?}
    Check -- No --> Refuse[Typed refusal and cleanup]
    Check -- Yes --> Capture[Copy and strictly validate files]
    Capture --> Budget{Admission ledger within ceiling?}
    Budget -- No --> Refuse
    Budget -- Yes --> Ready[Create certified snapshot]
    Ready --> Pull[next_page]
    Pull --> Boundary{Cancelled or query failed?}
    Boundary -- Yes --> Cleanup[Remove snapshot and terminate]
    Boundary -- No --> Page[Return canonical page and receipt]
    Page --> More{More pages?}
    More -- Yes --> Pull
    More -- No --> Cleanup
Loading

File-Level Changes

Change Details Files
Adds a native, pull-based read-session API that snapshots and validates tracker data before serving canonical context pages.
  • Introduces caller-configurable memory, page, and output limits with a conservative admission ledger.
  • Copies supported tracker files into a private temporary snapshot, validates item decoding and unique IDs, and records a SHA-256 receipt.
  • Reuses existing list pagination and JSON/TOON rendering while preserving query identity and continuation cursors.
  • Cleans up snapshot storage on exhaustion, cancellation, failure, and drop; exposes cooperative SDK cancellation and typed refusals.
src/read_session.rs
src/lib.rs
src/workspace.rs
Cargo.toml
tests/support/read_session_unit.rs
Exposes the bounded session through a native CLI and documents its embedding, integrity, accounting, and cancellation contract.
  • Adds read-session JSON-frame and TOON output modes with page and token controls.
  • Supports marker-file cancellation and structured refusal output with exit code 2.
  • Provides a runnable native host example and documents admission-versus-RSS semantics, non-atomic source capture, lifecycle guarantees, and recovery remedies.
src/main.rs
examples/read_session.rs
README.md
docs/BOUNDED_READ_SESSIONS.md
Adds contract, behavioral, and independent validation coverage for session correctness and lifecycle boundaries.
  • Compares native pages and identities against the existing SDK oracle for synthetic and public tracker copies.
  • Tests pagination continuations, immutable source behavior, duplicate and invalid items, unsupported files, source drift, cancellation, cleanup, and refusal codes.
  • Adds a runnable measurement harness for elapsed time, output, admission usage, source hashes, and child peak RSS.
tests/read_session_contract.rs
scripts/read-session-validate.mts
.agents/pm/features/pm-rust-bounded-read-sessions.toon
.agents/pm/history/pm-rust-bounded-read-sessions.jsonl
Makes the unchanged native release aggregate available through both npm and Bun CI entrypoints.
  • Adds private package scripts delegating to just release-check.
  • Expands the release matrix to run npm on existing platforms and Bun on Ubuntu.
  • Adds a release-pipeline contract test confirming both runtimes invoke the same aggregate gate.
package.json
package-lock.json
.github/workflows/ci.yml
justfile
tests/release_pipeline_contract.rs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@unbraind
unbraind marked this pull request as ready for review October 23, 2026 15:44
@sourcery-ai

sourcery-ai Bot commented Oct 23, 2026

Copy link
Copy Markdown

Sorry @unbraind, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 17 hours and 51 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@greptile-apps greptile-apps 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.

Your trial has ended. Reactivate Greptile to resume code reviews.

@greptile-apps greptile-apps 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.

Your trial has ended. Reactivate Greptile to resume code reviews.

@greptile-apps greptile-apps 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.

Your trial has ended. Reactivate Greptile to resume code reviews.

@greptile-apps greptile-apps 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.

Your trial has ended. Reactivate Greptile to resume code reviews.

@greptile-apps greptile-apps 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.

Your trial has ended. Reactivate Greptile to resume code reviews.

@greptile-apps greptile-apps 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.

Your trial has ended. Reactivate Greptile to resume code reviews.

@greptile-apps greptile-apps 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.

Your trial has ended. Reactivate Greptile to resume code reviews.

@unbraind unbraind left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Orchestrator review (built-in Claude review agent, verified by the orchestrator; bots are not waited for since 2026-10-22):

VERDICT: MERGE
FINDINGS:

  • [non-blocking] src/read_session.rs:430 — Lossy filename conversion gives identical snapshot hashes for distinct Unix filenames such as tasks/\x80.toon and tasks/\x81.toon with identical contents — reject non-UTF-8 filenames or hash their exact bytes to preserve the certificate’s filename guarantee.
    SUMMARY: The PR adds resource-admitted native snapshot sessions with cancellation, pagination, and CLI framing. Tests extensively cover lifecycle and failure paths but omit filename-hash collisions; I reviewed them without running them.
    STOP.

Retain Bun aggregate setup and Linux crash-corpus dependencies. Preserve exact native filename bytes in snapshot digests and cover invalid UTF-8 filenames and parent directories with a behavioral revert proof. Regenerate the changelog and retain gate evidence in the tracker.

@greptile-apps greptile-apps 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.

Your trial has ended. Reactivate Greptile to resume code reviews.

@greptile-apps greptile-apps 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.

Your trial has ended. Reactivate Greptile to resume code reviews.

@unbraind unbraind left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Orchestrator check of the merge-main delta: the only conflict was .github/workflows/ci.yml (Bun setup from main + Linux strace for the crash harness, both kept); changelog regenerated byte-identical; CI 10/10 + CodeQL green at 1c37108. The non-blocking review finding (lossy non-UTF-8 filename hashing, #112) is fixed with Linux filesystem and portable Unix digest regressions that fail on revert (exit 101). Final review verdict MERGE stands.

@unbraind
unbraind merged commit ec39af2 into main Oct 23, 2026
27 of 28 checks passed
@unbraind
unbraind deleted the feat/bounded-read-sessions branch October 23, 2026 22:54
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