-
Notifications
You must be signed in to change notification settings - Fork 0
supply: replay deterministic File change pages from opaque cursors #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
117 changes: 117 additions & 0 deletions
117
docs/decisions/0054-acknowledge-file-change-pages-before-cursor-advance.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| --- | ||
| name: adr-0054-acknowledge-file-change-pages-before-cursor-advance | ||
| version: "1.0.0" | ||
| description: > | ||
| Activate bounded File readChanges while keeping provider proposals distinct | ||
| from Control-accepted acquisition checkpoints. | ||
| --- | ||
|
|
||
| # 0054. Acknowledge File change pages before cursor advance | ||
|
|
||
| - Status: accepted | ||
| - Date: 2026-07-25 | ||
| - Refines: ADR-0012, ADR-0043, ADR-0044 | ||
|
|
||
| ## Context | ||
|
|
||
| Issue #81 activates the first File `readChanges` carrier. A shallow filesystem | ||
| scan can deterministically propose an ordered page, but observing files does not | ||
| prove that ContextControl durably accepted every envelope. Returning the same | ||
| cursor type before and after commit would let callers continue a scan while the | ||
| acquisition checkpoint still points at the previous accepted page. | ||
|
|
||
| The provider page also has no delivery audience. Creating publishable import | ||
| jobs during page acceptance would invent FileSourceAccess authority and conflate | ||
| acquisition progress with Runtime visibility. | ||
|
|
||
| ## Decision | ||
|
|
||
| The active File capability advances from immutable v2 to immutable v3 only | ||
| through ContextControl. V3 activates bounded `describeCapabilities`, | ||
| `readChanges`, cursor semantics, checkpoint semantics, and the provider | ||
| checkpoint operation. `discover`, `authorizeAndProject`, deletion execution, | ||
| freshness, and consistency guarantees remain unavailable. | ||
|
|
||
| `InitialScan` observes only shallow regular Markdown files under the anchored | ||
| logical root. It orders names by UTF-8 bytes, does not follow symlinks, and emits | ||
| content-free change envelopes containing canonical path, content digest, byte | ||
| length, change kind, Organization, Source, SourceVersion, and scan binding. | ||
| Before returning success, the Provider re-lists the anchored root and | ||
| revalidates every observed file identity; a changed directory membership or | ||
| file identity closes as retryable-unavailable rather than signing a mixed | ||
| snapshot. The database path constraint accepts the exact shallow Markdown | ||
| filename domain owned by `FileImportPath`, including the minimal `.md` name. | ||
|
|
||
| The provider signs the canonical whole page and returns a | ||
| `PendingChangeCursor`. ContextControl verifies that page proof, then a narrow | ||
| SECURITY DEFINER transaction requires the same active v3 SourceVersion, exact | ||
| predecessor page, and complete bounded change array. That transaction appends | ||
| the immutable page, every immutable change envelope, and one entry in the | ||
| existing acquisition-checkpoint sequence. Exact replay returns the same receipt; | ||
| out-of-order, changed, foreign, disabled, or stale acceptance returns nothing. | ||
|
|
||
| Only after the transaction commits does the PostgreSQL Control adapter wrap the | ||
| pending provider cursor in a separately authenticated `ChangeCursor` bound to | ||
| the accepted page digest, checkpoint reference, and global acquisition sequence. | ||
| Provider pages and Control checkpoints use opposite Ed25519 key directions: each | ||
| consumer holds only the other boundary's public verification key, never its | ||
| private signing authority. The provider accepts only this post-commit cursor | ||
| form for continuation. Keys are injected composition contracts; page and cursor | ||
| values remain opaque and redacted from representations. | ||
|
|
||
| Every initial source state receives an opaque scan epoch derived from the | ||
| canonical state plus the current Control-read durable scan head. It is stable | ||
| across Provider restarts while bytes and durable head remain unchanged, but | ||
| advances whenever the observed state changes relative to that head. Every | ||
| continuation page carries that epoch plus its preceding accepted page, | ||
| checkpoint, and sequence. A new epoch also carries the immediately superseded | ||
| epoch so Control can atomically replace the current scan; it cannot name any | ||
| older epoch. Control exposes this head only through the trusted Source progress | ||
| read model, and the caller must recompose `FileChangeSource` from that value | ||
| before Provider I/O. The acceptance transaction compares these bindings with | ||
| the latest accepted File change page for the Source, not merely the latest page | ||
| within one content-derived scan. Re-presenting the same durable state is exact | ||
| replay rather than a new checkpoint; a stale initial page cannot regress a | ||
| newer completed scan. This globally monotonic rule remains crash-safe across | ||
| Provider restart and rejects stale continuation cursors, including ABA source | ||
| state reversion. | ||
|
|
||
| Provider-page checkpoints carry no publish outcome and therefore do not create | ||
| gaps in the publication-bearing watermark prefix. Runtime has no privileges on | ||
| page, change, or checkpoint tables and does not consult them as authorization. | ||
| Page acceptance creates no acquisition job, WorkerLease, Revision, candidate, | ||
| Resource policy, or publish watermark. Later scheduling must establish an | ||
| existing File import audience and WorkerLease lineage explicitly. | ||
|
|
||
| ## Rationale | ||
|
|
||
| Acknowledging a signed whole page before issuing its continuation cursor makes | ||
| the durable checkpoint—not Provider process memory—the source of truth. A full | ||
| shallow rescan on each request deliberately preserves restart-safe snapshot | ||
| validation; caching or incremental watching would introduce new invalidation | ||
| and recovery semantics that this fixed point has not proven. Separate signing | ||
| directions and a private cursor-payload encoder also keep page proposal and | ||
| checkpoint minting authority from becoming a shared public API. | ||
|
|
||
| ## Consequences | ||
|
|
||
| - A filesystem observation cannot advance the durable cursor by itself. | ||
| - Provider verification cannot mint a Control checkpoint, and Control | ||
| verification cannot mint a Provider page. | ||
| - An old scan cannot resume after a newer scan becomes current, including ABA | ||
| source-state reversion. | ||
| - Whole-page replay is idempotent, while partial insertion cannot commit. | ||
| - Cross-Organization, SourceVersion change, and source disable fail closed. | ||
| - Manual v3 File imports remain available and keep their existing audience/job | ||
| path; provider changes do not inherit that audience implicitly. | ||
| - Recursive scanning, watching, deletion execution, automatic scheduling, | ||
| retries, dead-letter handling, and full resync remain inactive. | ||
| - Downgrade is refused after any accepted provider page because deleting or | ||
| renumbering acquisition history would violate opaque monotonic checkpoints. | ||
|
|
||
| ## Revisit trigger | ||
|
|
||
| Revisit before automatic scheduling, deletion execution, checkpoint compaction, | ||
| key rotation, recursive discovery, or full resync. Any revision must preserve | ||
| post-commit cursor issuance, exact tenant/source/version lineage, whole-page | ||
| atomicity, replay idempotency, and Runtime independence. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| """Canonical codecs shared by opaque internal protocol values.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import base64 | ||
| import binascii | ||
|
|
||
|
|
||
| def encode_base64url(value: bytes) -> str: | ||
| """Encode canonical unpadded base64url.""" | ||
|
|
||
| return base64.urlsafe_b64encode(value).rstrip(b"=").decode("ascii") | ||
|
|
||
|
|
||
| def decode_base64url(value: str) -> bytes: | ||
| """Decode only canonical unpadded base64url.""" | ||
|
|
||
| alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_" | ||
| if not value or any(character not in alphabet for character in value): | ||
| raise ValueError("invalid base64url") | ||
| try: | ||
| decoded = base64.b64decode( | ||
| value + "=" * (-len(value) % 4), | ||
| altchars=b"-_", | ||
| validate=True, | ||
| ) | ||
| except (binascii.Error, ValueError): | ||
| raise ValueError("invalid base64url") from None | ||
| if encode_base64url(decoded) != value: | ||
| raise ValueError("noncanonical base64url") | ||
| return decoded |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.