Skip to content

Fence selected document refresh with durable leases - #1310

Draft
zlareb1 wants to merge 16 commits into
feat/mcp-worker-live-controlfrom
feat/mcp-worker-refresh-on-live
Draft

zlareb1 wants to merge 16 commits into
feat/mcp-worker-live-controlfrom
feat/mcp-worker-refresh-on-live

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Related: #1302
Related: #1190

Changelog category

Not for changelog

Changelog entry

None. This change adds the storage and lease contract for selected document refresh. It does not expose a refresh operation.

Why

Scheduled refresh and Sync now need to admit the same bounded work without depending on a running agent session. Postgres owns the schedule cursor, exact selected task, and lease. A reissued lease changes the fence without changing the task identity. Repeated completion can be recognized under current authority without publishing the work twice.

Scope and risk

Add additive Postgres storage for the selected refresh queue, schedule and one manual offer per source. An authority transaction admits at most one unfinished batch of 64 selected items and retains at most 128 queue entries. Expired receipts for new queue entries may be removed without touching document or source history. A manual offer binds its exact owner, destination, generations and selected identities; retry returns its accepted job, and an expired or changed offer cannot enqueue again. A prior document version is unchanged only when its accepted raw digest and scoped revision agree.

The queue stores no upstream tokens or document bodies. Hosted fixtures cover partitioned claims, rollback of a staged checkpoint, cancellation fencing, and replay and expiry of a manual offer. They do not exercise a document write. An authenticated worker transport, scheduler, public Sync now operation, stored copy acceptance and access still need separate changes.

Compatibility, rollout and rollback

  • Wire: none. No new public operation, input or default.
  • Operator steps: none. The migrations are additive; no backfill or reindex. Keep the queue inactive while any running eraser does not recognize these tables.
  • Rollback: additive tables and their rows remain. Nothing in this change deletes existing sources, credentials or stored copies.

Tests

  • Focused planner, claim, receipt, and store checks passed. The latest admission and offer checks passed 21 tests. Ruff, format and diff checks passed on changed refresh source and fixtures. The worker separately decoded the actual synthetic claim bytes; that is a local format check, not a transport test.
  • The normal hosted PostgreSQL storage matrix includes the two refresh fixtures. This draft is stacked on the live prerequisite; the normal hosted workflow does not start against that feature branch. The fresh independent review at bd3e79cad2aa8901acd1c6e945b3096227e8092e is pending.

AI assistance in the code

AI-generated (Codex). Focused tests were run on the rebased code; database behavior is still subject to hosted qualification.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • Full required hosted checks and independent source review passed at this head.
  • The new migrations are additive and do not modify previous migrations.
  • There are no changes to public op schemas, settings or plugin payloads.
  • The architecture page distinguishes the storage contract from the inactive runtime.
  • Commits are signed off.

Signed-off-by: zlareb1 <[email protected]>
(cherry picked from commit 43642ce)
Signed-off-by: zlareb1 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
(cherry picked from commit 91307a575ba422e9902a92908e38064f2fcfac22)
Signed-off-by: zlareb1 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
(cherry picked from commit 4b79adb68ab6b676765bd23b2a93b8fb5467be45)
Signed-off-by: zlareb1 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
(cherry picked from commit 363b42d009ecb211c80241b8f3a86f92bb263afe)
Signed-off-by: zlareb1 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
(cherry picked from commit 28af9cbea128f7c9df850d606a5da3f094d2d6d7)
Signed-off-by: zlareb1 <[email protected]>
@vercel

vercel Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
loom-docs Ready Ready Preview Nov 24, 2026 1:33pm UTC

Request Review

@zlareb1

zlareb1 commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Independent review of 2dd4cf4d776c8f53f86315bb9536a884efecde81 against 15ac4a2e3757edf91e1d6474ef650068e93571f9 covered all 16 changed paths and requests changes.

  1. pg_worker_refresh.lock_current and checkpoint accept an autocommit connection. They must require the authority transaction that validates and settles the lease.
  2. Per-document keys do not preserve manual request idempotency after a selection or binding change. Bind the original request to a durable manifest or refuse the replay.
  3. A 64-document batch limit does not bound pending work or terminal metadata. Admission needs a durable source bound and the receipt retention rule must preserve the replay contract.
  4. Terminal replay does not compare the storage destination supplied by its authority callback. Use one canonical destination or check both.
  5. Keep one replay contract, matching the terminal Postgres row. Explicit deletion remains deferred until there is a checked store transition with authoritative evidence.

This is a static review of the refresh queue prerequisite only. The base is the live prerequisite, so the normal hosted CI workflow has not started for this stacked PR. No worker transport or knowledge writes are enabled. The reviewer could not independently verify the requested model identifier. I’ll address the findings in source, then request another review at the next head.

@zlareb1

zlareb1 commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

The independent review of bd3e79cad2aa8901acd1c6e945b3096227e8092e covered all 24 changed paths and requested changes. The new head ff93b84ed2d61a89f9aba4241c720b2108f7d3de addresses its five findings:

  • Admission fences and cancels unfinished rows for an obsolete assignment, retaining completed receipts and the bounded queue. Claim pages distinguish retired attempts from idle polls.
  • If an offer expires during staging, the batch rolls back and the observed time is recorded outside the savepoint. An earlier clock reading cannot reopen it.
  • The planner and Postgres accept the same cadence, from 300 to 86,400 seconds. Manual demand comes from the durable offer alone.

Terminal replay now reacquires the exact queue row only after source authorization. The hosted Postgres fixture covers reassignment, exhaustion, a clock rollback, and both interval boundaries. Local focused checks passed (97 tests), as did Ruff and git diff --check. The new whole-source review is running. This stack targets the live-read PR, so the normal hosted workflow has not run for it. It still has no authenticated worker API or document writes.

@zlareb1

zlareb1 commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

The independent review of ff93b84ed2d61a89f9aba4241c720b2108f7d3de covered all 24 changed paths and identified three flaws. At c7a7fe1b8ba17e9b887ff0b63870ae1da5c8e957, lease and receipt deadlines are tested after the row lock, claim fences come from a noncycling sequence and cannot be reused after pruning, and the allowed cadence accounts for the selection and a full day of receipts. Manual work can still defer a scheduled batch.

Focused checks passed (135 tests), as did Ruff and git diff --check. The hosted fixture now covers an actual row-lock wait across the deadline, prune and re-admission, and three full batches. Those cases need hosted execution. The new whole-source review is running, and the normal hosted workflow is not eligible while this PR is stacked on the live-read branch.

@zlareb1

zlareb1 commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

The independent source review of c7a7fe1b8ba17e9b887ff0b63870ae1da5c8e957 found a timing flaw and missing native evidence. Updated head 0b5e2dbe4df2e46026692c39edfc4c4817ae68f3 includes the latest live authorization base. Manual work uses the database wall-time sample for claim eligibility, independent of the monotone offer clock. The PostgreSQL fixture now covers claimability after a forward/backward adjustment, a committed terminal receipt with exact current authority, and full capacity with selective pruning that preserves a live batch and an unmarked row.

The remaining wall-clock behavior is explicit: an unreclaimed lease or unpruned receipt can reopen after a backward step. This draft stays disabled pending a qualified expiry policy. The re-run after recovery of the local resource floor passed 70 focused tests, Ruff and diff checks. Fresh independent review is running; no hosted database result exists yet for this stacked head.

@zlareb1

zlareb1 commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

7872efc55b674e620e53778f94af1df0003c8969 addresses the independent review. The Postgres fixture expires and reclaims the same unfinished row, checks the stable task key and incremented attempt, and independently refuses the stale fence and stale deadline without writing a receipt. The current lease commits the matching receipt. The architecture now distinguishes database filters from authenticated worker scope.

56 focused tests passed. The new Postgres fixture has not run locally. This draft is stacked; the required hosted suites still need to run against the eligible base. A fresh independent review of the entire change is in progress. This draft does not enable refresh or write a document.

@zlareb1

zlareb1 commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

a32c7130ff01d6fe9b478379d585b00285caf2b9 adds separate wrong-organization claim coverage and a Postgres erasure fixture. The latter waits for the real namespace lock, removes refresh-only metadata for one owner, and leaves another owner's queue, schedule, and admission rows in place. Refresh identifiers share the byte limit, and the architecture labels full transport qualification as a target.

96 focused tests passed. The Postgres fixtures await required hosted execution. The exact-head independent review stopped before a verdict due to disk exhaustion; a fresh review is running. This draft remains unqualified and disabled.

@zlareb1

zlareb1 commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

The independent review of all 24 changed paths at a32c7130ff01d6fe9b478379d585b00285caf2b9 found no blocking defect in the disabled storage path and confirmed the four earlier findings were corrected in source. One nonblocking cleanup remains: reuse the identifier bound in the stricter manual owner/actor checks.

Verdict: needs verification. Exact-head Postgres execution and the required hosted workflow are still pending. The queue remains disabled, with no approval to activate it or to merge without those checks.

This branch has not been deployed

No deployments
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