#622

feat(core): shared readings for fetches made of many requests

Openwiiiimmwants to merge intofrom

Fixes OPS-284 · Part of OPS-282

Summary

tc::readings gains what the GitHub and Linear widgets need before they share readings across panes. There, one fetch is many requests and can take minutes; in agent-usage it is one request.

share(cache, "github-actions", caps, on, now)    // open/keep/drop the widget's own store
follow(cache)                                    // every 5 s: did another pane write?
let k = key(cache, "gha.runs", 1, &[host, repo], &[token]);   // token → SHA-256, registered as secret
if gate(cache, "core").is_some() → show "next ask in …"
match take(cache, &k, Policy::new(ttl, 45.0)) {
  Serve(v)              → draw v
  Waiting { by, have }  → draw have; "pane by asking now"   (never blocks)
  Fetch(mut t)          → for each page { t.renew(); request }
                          t.publish(v)  |  t.refuse(why, reset)  |  drop → lease released
}
sharing_rows(cache, &[provenance(cache, &k, now)…], now, width)   // or "not sharing readings: why"

Fixes to the OPS-274 code found while speccing OPS-282:

BeforeAfter
One 90 s lease for every readingLease per claim, renewed per request, capped at MAX_LEASE (300 s)
One busy timeout stops sharing for 10 minBusy = "not this pass"
A store of another version is deleted while other panes have it openLeft alone; this pane goes on alone and says why
A file replaced under its name goes unnoticedreplaced() → share() reopens
Reading stamped when the fetch startedStamped when the answer arrived (the deferred #639 review comment)
A too-large or token-carrying reading silently not sharedPublish::{TooLarge, HeldSecret}, kept as unshared and shown
One size cap and a 24 h retentionCaps { max_pages, max_value, forget_after } per widget

sharing_rows() draws "not sharing readings: " in the same place as the freshness line, as decided on OPS-282.

agent-usage keeps its blocking cached path, file, schema and keys.

Evidence

  • 16 new tests. They cover:
    • publishing and serving across panes with the right provenance
    • never waiting on another pane, and a dropped ticket releasing its lease
    • refusal-with-reset and gate/shut shared across panes
    • key fingerprinting and secret registration
    • a busy store (BEGIN EXCLUSIVE held by another connection) not stopping sharing
    • stamping when the answer arrives
    • lease renewal and takeover after one request
    • another version's store left with its rows intact
    • a replaced file detected
    • the size cap and retention per widget
    • provenance rows fitting every width from 12 to 120
  • cargo test passes on Linux, all 30 suites including check.rs. Not built on a Mac locally; the hosted macos job is the check.
  • New docs/shared-readings.md, plus a paragraph in wiki/making-a-widget.md and docs/internals.md.

Merge Danger

Door: two-way

Blast Radius: agent-usage

The only user today is agent-usage. Two changes apply to it:

  • A busy store no longer stops sharing.
  • Readings are stamped when the answer arrives.

One more case changes for it: a store written by another version is no longer reset. Today VERSION is 1 everywhere, so nothing changes in practice. Older builds still distrust a lease more than 180 s ahead, so a new lease past 180 s (only new widgets, never agent-usage) could be taken over by them. That can only happen in a widget an older build doesn't run.


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Activity

78
linear-code[bot]13d ago
coderabbitai[bot]13d ago

Summary by CodeRabbit

  • New Features
    • Panes can share readings, reducing duplicate requests and keeping displayed data consistent.
    • Shared reads support configurable freshness, renewable fetch leases and rate-limit handling across panes.
    • Reading status can show its source, age, staleness, active fetches and sharing state.
  • Improvements
    • Temporary store contention no longer automatically disables sharing; readings can be fetched locally or awaited.
    • Shared data supports configurable size and retention limits and avoids sharing oversized or secret-bearing readings.
    • Incompatible or replaced stores are handled without deleting existing data.
  • Documentation
    • Added guidance on shared readings, rate limits and multi-pane widget behaviour.

Walkthrough

The change adds configurable shared-reading storage and lease-based coordination between panes. It adds APIs for fetching, publishing, sharing refusals and reporting provenance. Busy-store handling and fetch timestamps are updated. Tests and documentation cover the new behaviour.

Changes

Shared readings

Layer / File(s)Summary
Configurable store and leases
core/src/readings/store.rs, core/src/readings/lease.rs
The store supports per-widget limits, bounded lease claims and renewal, and distinct publication outcomes. It preserves stores with incompatible versions and detects file replacement. Tests cover limits, leases, version handling and publication results.
Pane coordination and reading status
core/src/readings.rs
The readings API adds store management, stable keys, fetch tickets, shared rate-limit gates and provenance reporting. Busy-store errors do not disable sharing in the covered operations. Fetch timestamps are recorded after completion. Tests cover coordination, refusals and provenance.
Shared-readings documentation
docs/internals.md, docs/shared-readings.md, wiki/making-a-widget.md
The documentation describes the shared-readings APIs, pane behaviour, store compatibility and the share_readings setting.

Estimated code review effort: 4 (Complex) | ~50 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Pane
  participant ReadingsTake
  participant Store
  participant Ticket
  Pane->>ReadingsTake: request reading
  ReadingsTake->>Store: check reading and claim lease
  Store-->>ReadingsTake: return reading or claim result
  ReadingsTake-->>Pane: return reading, waiting state, or fetch ticket
  Pane->>Ticket: publish value or refusal
  Ticket->>Store: publish shared result

Possibly related PRs

  • stealth-factory/opscope#639: Moves the agent-usage shared-readings store into tc::readings, the module extended by this change.
  • stealth-factory/opscope#619: Introduces agent-usage shared-reading leases and refusal backoff, which this change generalises in tc::readings.
Merge Risk: Low · up to a5407

In rare clock-skew cases a pane's late answer may not be shared with other panes, and that pane keeps its local reading. The shared-readings change is otherwise mergeable, and this edge case could be fixed before or after merge.

Security architecture risk: Minimal · up to a5407

The inspected changes preserve existing file-creation controls, bound abandoned leases, and strengthen takeover and version handling. No introduced or worsened risk materially affecting security, failure containment, rollback, or ownership was established.

Retained concerns No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The inspected sharing domain is a widget store on one machine. A fetched value published under a reading key can influence other panes consuming that key. These APIs establish local coordination, not a new remotely authenticated service or additional credential authority.

Trust Boundaries and Controls

  • observed — The new key helper escapes plain-part separators, incorporates a 128-bit SHA-256 fingerprint of supplied secret parts, and registers those secrets for persistence filtering. Publication checks both current and last-good values; publication and annotation reject registered tokens of at least eight bytes in literal or JSON-escaped form. This is a bounded leakage check, not general sensitive-data detection.

Resilience and Maintainability Implications

  • inferred — Size-pressure cleanup still clears leases and readings in place, as it did at the comparison base; the head additionally preserves active gate rows. Consequently, leases provide best-effort fetch deduplication rather than an exactly-once execution guarantee. This pre-existing cleanup behavior was not retained as an introduced security concern.
Pre-merge checks: 4

Check nameStatusExplanation
Title checkThe title names the main change: shared readings for fetches made of many requests, in the core crate. It matches the changeset's new tc::readings sharing API, leases, and publish/refuse flow. It is s…
Description checkThe description explains the purpose of the new tc::readings APIs, gives a usage example, lists fixes against the earlier OPS-274 code, and lists tests, docs, and merge risk. It matches the changeset …
Linked Issues checkCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes checkCheck skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: shared readings for fetches made of many requests, in the core crate. It matches the changeset's new tc::readings sharing API, leases, and publish/refuse flow. It is specific and single-sentence in conventional-commit form.

Full details: Description check

Explanation

The description explains the purpose of the new tc::readings APIs, gives a usage example, lists fixes against the earlier OPS-274 code, and lists tests, docs, and merge risk. It matches the changeset closely.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
Simplify code

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit checks the reading store,
One pane fetches; others wait no more.
A lease renews beneath the moon,
A ticket shares the answer soon.
Refusals rest until reset time,
And provenance records the line.

chatgpt-codex-connector[bot]12d ago
Codex Review Summary: ✅ Completed

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

ReviewStatusCommitReview trigger
📝 Code Review✅ Completed 2026-11-16T11:09:07.986970Za540715New commits
ℹ️ 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[bot]reviewed12d ago
chatgpt-codex-connector[bot]12d ago

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: be8eaa5796

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

chatgpt-codex-connector[bot]reviewed12d ago
chatgpt-codex-connector[bot]reviewed12d ago
coderabbitai[bot]reviewed12d ago
coderabbitai[bot]reviewed12d ago
coderabbitai[bot]reviewed12d ago
wiiiimmreviewed12d ago
wiiiimmreviewed12d ago
coderabbitai[bot]approved changes12d ago
chatgpt-codex-connector[bot]reviewed12d ago
wiiiimmreviewed12d ago
coderabbitai[bot]approved changes12d ago