@loro-dev/roost 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +397 -0
- package/dist/codec.d.ts +66 -0
- package/dist/codec.js +275 -0
- package/dist/crypto.d.ts +21 -0
- package/dist/crypto.js +103 -0
- package/dist/durable-framing.d.ts +44 -0
- package/dist/durable-framing.js +207 -0
- package/dist/framing.d.ts +28 -0
- package/dist/framing.js +144 -0
- package/dist/history-publication.d.ts +58 -0
- package/dist/history-publication.js +234 -0
- package/dist/identity.d.ts +14 -0
- package/dist/identity.js +62 -0
- package/dist/inbox.d.ts +69 -0
- package/dist/inbox.js +262 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +6 -0
- package/dist/indexeddb.d.ts +38 -0
- package/dist/indexeddb.js +299 -0
- package/dist/json.d.ts +23 -0
- package/dist/json.js +221 -0
- package/dist/lody-history.d.ts +397 -0
- package/dist/lody-history.js +1559 -0
- package/dist/projection.d.ts +53 -0
- package/dist/projection.js +543 -0
- package/dist/replay.d.ts +63 -0
- package/dist/replay.js +201 -0
- package/dist/sender.d.ts +26 -0
- package/dist/sender.js +67 -0
- package/dist/store.d.ts +384 -0
- package/dist/store.js +1437 -0
- package/dist/sync/coverage.d.ts +276 -0
- package/dist/sync/coverage.js +1084 -0
- package/dist/sync/crypto.d.ts +64 -0
- package/dist/sync/crypto.js +155 -0
- package/dist/sync/execute.d.ts +142 -0
- package/dist/sync/execute.js +321 -0
- package/dist/sync/history.d.ts +214 -0
- package/dist/sync/history.js +786 -0
- package/dist/sync/index.d.ts +17 -0
- package/dist/sync/index.js +9 -0
- package/dist/sync/link.d.ts +192 -0
- package/dist/sync/link.js +663 -0
- package/dist/sync/mod.d.ts +24 -0
- package/dist/sync/mod.js +15 -0
- package/dist/sync/policy.d.ts +62 -0
- package/dist/sync/policy.js +128 -0
- package/dist/sync/registry.d.ts +129 -0
- package/dist/sync/registry.js +333 -0
- package/dist/sync/transport.d.ts +91 -0
- package/dist/sync/transport.js +162 -0
- package/dist/sync/work.d.ts +351 -0
- package/dist/sync/work.js +1344 -0
- package/package.json +47 -0
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import type { IndexedDbStorage } from '../indexeddb.js';
|
|
2
|
+
import type { Generation, RemoteId } from './registry.js';
|
|
3
|
+
import { CoverageStore } from './coverage.js';
|
|
4
|
+
import type { MarkResult } from './coverage.js';
|
|
5
|
+
/**
|
|
6
|
+
* Durable send tasks and discovery progress for remote sync (RS2-02), the
|
|
7
|
+
* IndexedDB mirror of src/sync/work.rs. A WorkStore persists, per remote
|
|
8
|
+
* target scope, the scheduler's intent to send specific stream operations:
|
|
9
|
+
* frozen task bytes, a dependency wait index, and the discovery cursor of the
|
|
10
|
+
* local enumeration. Semantics are fixed by the RS0-02 independent model: a
|
|
11
|
+
* `done` task never nets against re-discovered content (F1 — dedupe covers
|
|
12
|
+
* every status, and a conflicting fingerprint at an already-discovered
|
|
13
|
+
* position is a typed error, not a silent second task), an `acked_local` task
|
|
14
|
+
* must be re-confirmable after a crash (F2), an `inflight` task stays
|
|
15
|
+
* re-acquirable (F3), and `ready` means status `ready|inflight` with every
|
|
16
|
+
* dependency satisfied at operation precision (review finding C, with the
|
|
17
|
+
* L009/L010/L011 follow-ups): a same-turn predecessor must be *present* with
|
|
18
|
+
* its exact fingerprint, a cross-turn parent must be *closed* with a matching
|
|
19
|
+
* seal fingerprint, every direct parent of the task's turn must be closed,
|
|
20
|
+
* and same-turn transitive closure is proven incrementally by the per-turn
|
|
21
|
+
* prefix watermark (`[0x05]` record) — dep lists stay O(1 + parents) no
|
|
22
|
+
* matter how long the turn grows.
|
|
23
|
+
*
|
|
24
|
+
* Storage layout (private to this module, not a wire format) — byte-for-byte
|
|
25
|
+
* the Rust layout. All keys live in one KV space `rsync_work`. Every key
|
|
26
|
+
* embeds the full scope `(remote_id, generation, stream)` with the registry's
|
|
27
|
+
* full generation identity encoding (`gen_len[1] || gen[..] || source_tag[1]`),
|
|
28
|
+
* so equal bytes with different provenance never share a task and a superseded
|
|
29
|
+
* generation's tasks are physically unreachable from the new one (S6). Values
|
|
30
|
+
* are `[version byte] || serde_json` payloads with a fixed DTO field order
|
|
31
|
+
* (deterministic and identical to the Rust serde encoding); the leading
|
|
32
|
+
* version byte is authoritative and a mismatch is `unsupportedVersion`, never
|
|
33
|
+
* silently decoded.
|
|
34
|
+
*
|
|
35
|
+
* | Keys | Value |
|
|
36
|
+
* | --- | --- |
|
|
37
|
+
* | `[0x01] \|\| scope \|\| turn[16] \|\| seq[4 BE]` | task record: `task_seq` (monotonic per scope), fingerprint, deps, status, attempts, frozen bytes (`null` = bytes not fetched locally yet) |
|
|
38
|
+
* | `[0x02] \|\| scope \|\| dep_turn[16] \|\| dep_seq[4 BE]` | wait index: sorted, deduped list of tasks waiting on this dependency; maintained in the same transaction as task status changes |
|
|
39
|
+
* | `[0x03] \|\| scope \|\| "cursor"` | discovery state: `cursor` (last enumerated turn id, `null` = not started) and `enumerated_count` |
|
|
40
|
+
* | `[0x04] \|\| scope \|\| "taskseq"` | task sequence allocator `{next}` |
|
|
41
|
+
* | `[0x05] \|\| scope \|\| turn[16]` | same-turn prefix watermark `{upto}`: every seq in `0..=upto` is present on the target with the exact fingerprint its task record declared; advances one confirmed op per step, never regresses |
|
|
42
|
+
* | `[0x06] \|\| scope \|\| status_tag[1] \|\| task_seq[8 BE]` | status candidate index (RS2-04): one row per non-done task, value `turn[16] \|\| seq[4 BE]`; maintained in the same transaction as every status change |
|
|
43
|
+
* | `[0x07] \|\| scope \|\| "statusidx"` | status-index completeness marker; absent on pre-index scopes, which fall back to full task scans until `resume` rebuilds the index |
|
|
44
|
+
* | `[0x08] \|\| scope \|\| turn[16]` | open-turn record `{offered_upto}` (G009): one row per turn discovered before its seal; deleted in the same transaction that persists the turn's seal op |
|
|
45
|
+
* | `[0x09] \|\| scope \|\| "openidx"` | open-index completeness marker; absent on scopes written before open tracking existed |
|
|
46
|
+
* | `[0x0a] \|\| scope \|\| "events"` | local event checkpoint: version byte + u64 BE, committed with tasks after comparing the previous checkpoint |
|
|
47
|
+
* | `[0x0b] \|\| scope \|\| turn[16] \|\| seq[4 BE]` | empty value; ready/inflight candidate in dependency order |
|
|
48
|
+
* | `[0x0c] \|\| scope` | version byte; complete ordered candidate index, including atomic legacy rebuild |
|
|
49
|
+
*
|
|
50
|
+
* Transactions (T1/T2/T3), each a single IDB readwrite transaction (a throw
|
|
51
|
+
* aborts the native transaction, so a rejected step commits nothing):
|
|
52
|
+
* - T1 (`discoverBatch`): insert-if-absent task creation, wait-index
|
|
53
|
+
* maintenance, sequence allocation, open-turn tracking and the monotonic
|
|
54
|
+
* cursor advance commit atomically; a crash before commit loses nothing and
|
|
55
|
+
* the replay is idempotent.
|
|
56
|
+
* - T2 (`acquire`): the CAS to `inflight` and the attempt increment commit
|
|
57
|
+
* before any network send; the frozen bytes are returned to the caller. The
|
|
58
|
+
* same dependency gate as `ready` runs inside this transaction.
|
|
59
|
+
* - T3 (`ack`/`confirm`): compare-and-swap on the attempt token; `confirm`
|
|
60
|
+
* with the registry check enabled re-reads the registry's current
|
|
61
|
+
* generation *inside* its own write transaction (G009) and refuses the
|
|
62
|
+
* confirmation when it no longer matches the task's scope.
|
|
63
|
+
*
|
|
64
|
+
* Cross-module read coupling: the dependency gate runs through the coverage
|
|
65
|
+
* store's in-transaction readers (`presentExactIn`/`closedMatchesIn`), and
|
|
66
|
+
* `confirm` writes coverage through `markPresentIn` in the same transaction
|
|
67
|
+
* as the task completion (T3/T5). This store never writes coverage keys
|
|
68
|
+
* directly and never touches the network.
|
|
69
|
+
*/
|
|
70
|
+
/** KV space holding all work-store keys. */
|
|
71
|
+
export declare const WORK_SPACE = "rsync_work";
|
|
72
|
+
/** Current record encoding version. Version 2 binds dependencies to exact
|
|
73
|
+
* fingerprints and persists seal/parents for the atomic confirm (review
|
|
74
|
+
* finding C); version-1 records are refused as unsupported, never decoded. */
|
|
75
|
+
export declare const RECORD_VERSION = 2;
|
|
76
|
+
export declare const TASK_KEY_TAG = 1;
|
|
77
|
+
export declare const WAIT_KEY_TAG = 2;
|
|
78
|
+
export declare const CURSOR_KEY_TAG = 3;
|
|
79
|
+
/** Local event checkpoint, independent of Turn ID ordering. */
|
|
80
|
+
export declare const EVENT_CURSOR_KEY_TAG = 10;
|
|
81
|
+
/** Ready/inflight tasks ordered by Turn ID and seq, independent of arrival. */
|
|
82
|
+
export declare const ORDERED_CANDIDATE_TAG = 11;
|
|
83
|
+
export declare const ORDERED_CANDIDATE_MARKER_TAG = 12;
|
|
84
|
+
export declare const TASKSEQ_KEY_TAG = 4;
|
|
85
|
+
export declare const PREFIX_KEY_TAG = 5;
|
|
86
|
+
/** Per-status candidate index keys (RS2-04). */
|
|
87
|
+
export declare const STATUS_INDEX_KEY_TAG = 6;
|
|
88
|
+
export declare const STATUS_INDEX_MARKER_TAG = 7;
|
|
89
|
+
/** Open-turn record keys (G009). */
|
|
90
|
+
export declare const OPEN_TURN_KEY_TAG = 8;
|
|
91
|
+
export declare const OPEN_INDEX_MARKER_TAG = 9;
|
|
92
|
+
/** Maximum frozen bytes of one task's package. */
|
|
93
|
+
export declare const MAX_TASK_BYTES: number;
|
|
94
|
+
/** Maximum direct dependencies recorded on one task (cross-turn parent refs
|
|
95
|
+
* plus one same-turn predecessor — never the turn's length, L010). */
|
|
96
|
+
export declare const MAX_TASK_DEPS = 4096;
|
|
97
|
+
/** Maximum waiters tracked per dependency. */
|
|
98
|
+
export declare const MAX_WAITERS_PER_DEP: number;
|
|
99
|
+
/** Full scope of every work key: one remote target's send-queue view of one
|
|
100
|
+
* stream generation. Scopes are independent truths per target (S3) and per
|
|
101
|
+
* generation (S6). */
|
|
102
|
+
export type WorkScope = {
|
|
103
|
+
remote: RemoteId;
|
|
104
|
+
generation: Generation;
|
|
105
|
+
stream: string;
|
|
106
|
+
};
|
|
107
|
+
/** Lightweight task / dependency reference: one operation of one turn. */
|
|
108
|
+
export type TaskRef = {
|
|
109
|
+
turn: Uint8Array;
|
|
110
|
+
seq: number;
|
|
111
|
+
};
|
|
112
|
+
/** A direct dependency bound to exact content (review finding C). */
|
|
113
|
+
export type DepRef = {
|
|
114
|
+
turn: Uint8Array;
|
|
115
|
+
seq: number;
|
|
116
|
+
fingerprint: Uint8Array;
|
|
117
|
+
};
|
|
118
|
+
/** Lifecycle of one durable send task (serde snake_case strings, matching
|
|
119
|
+
* the Rust TaskStatus encoding). */
|
|
120
|
+
export type TaskStatus = 'pending_local' | 'ready' | 'inflight' | 'acked_local' | 'done';
|
|
121
|
+
/** One enumerated operation offered to `discoverBatch`. */
|
|
122
|
+
export type OpRef = {
|
|
123
|
+
turn: Uint8Array;
|
|
124
|
+
seq: number;
|
|
125
|
+
fingerprint: Uint8Array;
|
|
126
|
+
/** Direct dependencies, each bound to the exact dependency content by
|
|
127
|
+
* fingerprint: for seq > 0 exactly one same-turn dep (the direct
|
|
128
|
+
* predecessor) plus every cross-turn parent seal; any other same-turn dep
|
|
129
|
+
* shape is rejected at discovery. */
|
|
130
|
+
deps: DepRef[];
|
|
131
|
+
/** Whether this operation is its turn's seal (persisted so a crash
|
|
132
|
+
* between ack and confirm can still replay the coverage mark, F2). */
|
|
133
|
+
isSeal: boolean;
|
|
134
|
+
/** The turn's direct parents (seal-fingerprint refs), persisted for the
|
|
135
|
+
* confirm-time coverage closed check and for the ready/acquire gate. */
|
|
136
|
+
parents: {
|
|
137
|
+
turnId: Uint8Array;
|
|
138
|
+
sealFp: Uint8Array;
|
|
139
|
+
}[];
|
|
140
|
+
/** Declared size of the operation's package. */
|
|
141
|
+
bytesLen: number;
|
|
142
|
+
/** The package bytes, or null when the local copy still has to be fetched
|
|
143
|
+
* (`bytesLen` still bounds the future fetch). */
|
|
144
|
+
bytes: Uint8Array | null;
|
|
145
|
+
};
|
|
146
|
+
/** Observable state of one persisted task. */
|
|
147
|
+
export type TaskInfo = {
|
|
148
|
+
task: TaskRef;
|
|
149
|
+
/** Monotonic per-scope allocation order (creation sequence). */
|
|
150
|
+
taskSeq: number;
|
|
151
|
+
status: TaskStatus;
|
|
152
|
+
attempts: number;
|
|
153
|
+
fingerprint: Uint8Array;
|
|
154
|
+
deps: DepRef[];
|
|
155
|
+
/** Frozen package size, undefined while the task is `pending_local`. */
|
|
156
|
+
frozenBytes: number | undefined;
|
|
157
|
+
};
|
|
158
|
+
/** The frozen package handed to a sender by `acquire` (T2). */
|
|
159
|
+
export type AcquiredTask = {
|
|
160
|
+
token: AttemptToken;
|
|
161
|
+
fingerprint: Uint8Array;
|
|
162
|
+
deps: DepRef[];
|
|
163
|
+
bytes: Uint8Array;
|
|
164
|
+
/** Previously bound ciphertext, if any. When present the sender must
|
|
165
|
+
* append these bytes and must not encrypt `bytes` again. */
|
|
166
|
+
wire?: Uint8Array;
|
|
167
|
+
};
|
|
168
|
+
/** Attempt-scoped confirmation credential: an old token can never ack or
|
|
169
|
+
* confirm a newer attempt of the same task. */
|
|
170
|
+
export type AttemptToken = {
|
|
171
|
+
scope: WorkScope;
|
|
172
|
+
task: TaskRef;
|
|
173
|
+
attempt: number;
|
|
174
|
+
};
|
|
175
|
+
/** Result of one `discoverBatch` call (T1). */
|
|
176
|
+
export type DiscoverResult = {
|
|
177
|
+
/** One outcome per input op, in input order. */
|
|
178
|
+
outcomes: DiscoverOutcome[];
|
|
179
|
+
/** The cursor after this batch (monotonic: never below the stored one). */
|
|
180
|
+
cursor: Uint8Array | undefined;
|
|
181
|
+
/** Ops that became new tasks so far in this scope (duplicates excluded). */
|
|
182
|
+
enumeratedCount: number;
|
|
183
|
+
};
|
|
184
|
+
/** Per-op outcome of `discoverBatch`. */
|
|
185
|
+
export type DiscoverOutcome = {
|
|
186
|
+
kind: 'created';
|
|
187
|
+
task: TaskRef;
|
|
188
|
+
}
|
|
189
|
+
/** The op was already confirmed present on the target with this exact
|
|
190
|
+
* fingerprint, so a pre-completed task was persisted: status `done`, zero
|
|
191
|
+
* attempts, never sent (RS2-04). */
|
|
192
|
+
| {
|
|
193
|
+
kind: 'adopted';
|
|
194
|
+
task: TaskRef;
|
|
195
|
+
} | {
|
|
196
|
+
kind: 'duplicate';
|
|
197
|
+
};
|
|
198
|
+
/** What to replay after a restart, per `resume` (F2/F3). */
|
|
199
|
+
export type ResumePlan = {
|
|
200
|
+
/** `acked_local` tasks: confirm semantics must be replayed before the
|
|
201
|
+
* scheduler moves on (F2). Tokens carry the persisted attempts. */
|
|
202
|
+
confirm: AttemptToken[];
|
|
203
|
+
/** `inflight` tasks: eligible to be acquired again (F3). */
|
|
204
|
+
reacquire: TaskRef[];
|
|
205
|
+
};
|
|
206
|
+
/** Result of `confirm`: the completed task, the downstream tasks that were
|
|
207
|
+
* waiting on it in the wait index (wakeup hints), and the coverage mark
|
|
208
|
+
* committed atomically with the completion (T3/T5). */
|
|
209
|
+
export type ConfirmResult = {
|
|
210
|
+
task: TaskRef;
|
|
211
|
+
woke: TaskRef[];
|
|
212
|
+
coverage: MarkResult;
|
|
213
|
+
};
|
|
214
|
+
/** Persisted discovery position of one scope. */
|
|
215
|
+
export type DiscoveryState = {
|
|
216
|
+
cursor: Uint8Array | undefined;
|
|
217
|
+
enumeratedCount: number;
|
|
218
|
+
};
|
|
219
|
+
/** A turn discovered before its seal and still tracked for streaming growth
|
|
220
|
+
* (G009): every seq below `offeredUpto` was already offered to discovery. The
|
|
221
|
+
* row disappears once the turn's seal op is discovered. */
|
|
222
|
+
export type OpenTurn = {
|
|
223
|
+
turn: Uint8Array;
|
|
224
|
+
offeredUpto: number;
|
|
225
|
+
};
|
|
226
|
+
/** Errors returned by WorkStore. `code` mirrors the Rust WorkError variants;
|
|
227
|
+
* `cause` carries structured fields where the Rust variant has them. Native
|
|
228
|
+
* IDB failures propagate as DOMExceptions, as in the registry. */
|
|
229
|
+
export declare class WorkError extends Error {
|
|
230
|
+
readonly code: 'storage' | 'corrupt' | 'unsupportedVersion' | 'invalid' | 'notFound' | 'invalidTransition' | 'attemptMismatch' | 'unsatisfiedDeps' | 'contentConflict' | 'generationConflict' | 'registry' | 'coverage';
|
|
231
|
+
constructor(code: 'storage' | 'corrupt' | 'unsupportedVersion' | 'invalid' | 'notFound' | 'invalidTransition' | 'attemptMismatch' | 'unsatisfiedDeps' | 'contentConflict' | 'generationConflict' | 'registry' | 'coverage', message?: string, options?: ErrorOptions);
|
|
232
|
+
}
|
|
233
|
+
/** Task record key: `[TASK_KEY_TAG] || scope || turn[16] || seq[4 BE]`. */
|
|
234
|
+
export declare function taskKey(scope: WorkScope, task: TaskRef): Uint8Array;
|
|
235
|
+
/** Wait index key: `[WAIT_KEY_TAG] || scope || dep_turn[16] || dep_seq[4 BE]`. */
|
|
236
|
+
export declare function waitKey(scope: WorkScope, dep: TaskRef): Uint8Array;
|
|
237
|
+
/** Value: [RECORD_VERSION] || local_event_cursor[8 BE], matching Rust. */
|
|
238
|
+
export declare function eventCursorKey(scope: WorkScope): Uint8Array;
|
|
239
|
+
/**
|
|
240
|
+
* Task store over a shared IndexedDbStorage owner.
|
|
241
|
+
*
|
|
242
|
+
* Construct with the same IndexedDbStorage the host's Store, RemoteRegistry
|
|
243
|
+
* and CoverageStore use, so tasks, coverage and stream content commit through
|
|
244
|
+
* one fixed owner. The store never opens its own connection and never touches
|
|
245
|
+
* the network.
|
|
246
|
+
*/
|
|
247
|
+
export declare class WorkStore {
|
|
248
|
+
readonly storage: IndexedDbStorage;
|
|
249
|
+
/** The coverage store over the same storage owner, used for the
|
|
250
|
+
* dependency gate's in-transaction reads and the confirm's atomic mark. */
|
|
251
|
+
readonly coverage: CoverageStore;
|
|
252
|
+
constructor(storage: IndexedDbStorage);
|
|
253
|
+
private loadTask;
|
|
254
|
+
/** Persist one page of enumerated operations in a single write
|
|
255
|
+
* transaction (T1): insert-if-absent task creation, wait-index
|
|
256
|
+
* maintenance, task sequence allocation, open-turn tracking (G009) and
|
|
257
|
+
* the monotonic cursor advance commit atomically or not at all. The
|
|
258
|
+
* cursor never regresses; it only ever covers work already persisted. */
|
|
259
|
+
discoverBatch(scope: WorkScope, ops: OpRef[], cursorAdvance: Uint8Array | undefined): Promise<DiscoverResult>;
|
|
260
|
+
/** Last local event covered by this target's durable discovery tasks. */
|
|
261
|
+
eventCursor(scope: WorkScope): Promise<bigint>;
|
|
262
|
+
/** Tasks and checkpoint commit together. A stale expected position
|
|
263
|
+
* returns undefined without writing anything. Also advances the compatible
|
|
264
|
+
* Turn ID high-water mark, without using it to skip late older events. */
|
|
265
|
+
discoverEventBatch(scope: WorkScope, ops: OpRef[], expected: bigint, advance: bigint): Promise<DiscoverResult | undefined>;
|
|
266
|
+
private discoverBatchInner;
|
|
267
|
+
/** Tasks that are runnable: status `ready` or `inflight` (F3) and every
|
|
268
|
+
* dependency satisfied at operation precision (review finding C), in
|
|
269
|
+
* creation order, at most `limit`. `pending_local` tasks are never
|
|
270
|
+
* returned. */
|
|
271
|
+
ready(scope: WorkScope, limit: number): Promise<TaskInfo[]>;
|
|
272
|
+
/** All status `ready` or `inflight` tasks in creation order, WITHOUT the
|
|
273
|
+
* dependency gate (RS2-04): the scheduler's iteration snapshot; `acquire`
|
|
274
|
+
* re-checks the gate per task inside its own transaction (T2). */
|
|
275
|
+
candidates(scope: WorkScope): Promise<TaskInfo[]>;
|
|
276
|
+
/** Candidate keyset in (Turn ID, seq) order. Valid parents have smaller
|
|
277
|
+
* IDs, so reverse imports cannot force repeated descendant retries. */
|
|
278
|
+
candidatesByTurnAfter(scope: WorkScope, after: TaskRef | undefined, limit: number): Promise<TaskInfo[]>;
|
|
279
|
+
/** Status-`ready`|`inflight` candidates with `taskSeq > after`, in
|
|
280
|
+
* creation order, at most `limit` (RS2-04): the keyset page a scheduler
|
|
281
|
+
* sweeps without materializing the whole backlog. The dependency gate is
|
|
282
|
+
* NOT applied here — `acquire` re-checks it per task (T2). */
|
|
283
|
+
candidatesAfter(scope: WorkScope, after: number | undefined, limit: number): Promise<TaskInfo[]>;
|
|
284
|
+
/** All tasks of the scope missing their local bytes, in creation order. */
|
|
285
|
+
pendingLocal(scope: WorkScope): Promise<TaskInfo[]>;
|
|
286
|
+
/** One task's observable state. */
|
|
287
|
+
task(scope: WorkScope, task: TaskRef): Promise<TaskInfo | undefined>;
|
|
288
|
+
/** The persisted discovery position of one scope. */
|
|
289
|
+
discovery(scope: WorkScope): Promise<DiscoveryState>;
|
|
290
|
+
/** Freeze one task for sending (T2): compare-and-swap `ready|inflight` to
|
|
291
|
+
* `inflight` with the attempt counter incremented, and return the frozen
|
|
292
|
+
* package. A repeated acquire of an `inflight` task starts a new attempt;
|
|
293
|
+
* the previous token becomes stale. The same dependency gate as `ready`
|
|
294
|
+
* runs inside this transaction (review C follow-up): a task whose deps
|
|
295
|
+
* stopped matching is rejected with `unsatisfiedDeps` and nothing is
|
|
296
|
+
* frozen. */
|
|
297
|
+
acquire(scope: WorkScope, task: TaskRef): Promise<AcquiredTask>;
|
|
298
|
+
/** Record that the target stored the package: compare-and-swap `inflight`
|
|
299
|
+
* to `acked_local`, bound to the token's attempt. A stale callback (older
|
|
300
|
+
* attempt) is rejected with `attemptMismatch`. */
|
|
301
|
+
ack(token: AttemptToken): Promise<void>;
|
|
302
|
+
/** Confirm one acked task on the target (T3): in a single write
|
|
303
|
+
* transaction — compare-and-swap `acked_local` to `done` bound to the
|
|
304
|
+
* token's attempt, mark the exact operation present in the coverage store
|
|
305
|
+
* (running the closed check with the persisted seal/parents data, T5),
|
|
306
|
+
* advance the turn's prefix watermark, remove the task from its deps'
|
|
307
|
+
* wait lists, and return the tasks waiting on this operation as wakeup
|
|
308
|
+
* hints. Both commit or neither does (F2; a re-mark is a byte-idempotent
|
|
309
|
+
* duplicate).
|
|
310
|
+
*
|
|
311
|
+
* With `checkRegistryGeneration` set, the registry's *current* generation
|
|
312
|
+
* is re-read inside this same transaction and compared against the task's
|
|
313
|
+
* scope: a rebind committed before the confirm transaction starts is
|
|
314
|
+
* always observed and rejected as `generationConflict`, with nothing
|
|
315
|
+
* committed (G009). */
|
|
316
|
+
confirm(token: AttemptToken, checkRegistryGeneration: boolean): Promise<ConfirmResult>;
|
|
317
|
+
/** What a scheduler must replay after a restart (F2/F3): tokens for every
|
|
318
|
+
* `acked_local` task and the refs of every `inflight` task.
|
|
319
|
+
*
|
|
320
|
+
* This is also the upgrade path for databases written before the prefix
|
|
321
|
+
* watermark / status index / open-turn set existed: resume first rebuilds
|
|
322
|
+
* the watermarks from the persisted evidence (each step still requires
|
|
323
|
+
* the seq's task record and an exact present mark in coverage), one turn
|
|
324
|
+
* per write transaction, resuming from the persisted watermark, then
|
|
325
|
+
* rebuilds the missing indexes (one transaction each, markers commit with
|
|
326
|
+
* the rows). */
|
|
327
|
+
resume(scope: WorkScope): Promise<ResumePlan>;
|
|
328
|
+
/** Supply the local bytes of a `pending_local` task, moving it to
|
|
329
|
+
* `ready`. Oversized packages are rejected and the task stays pending. */
|
|
330
|
+
/** Bind the first ciphertext of an inflight task. Encrypt happens
|
|
331
|
+
* outside this transaction; the write only records the exact bytes that
|
|
332
|
+
* will be appended. A second bind of identical bytes is a no-op. */
|
|
333
|
+
bindWire(token: AttemptToken, wire: Uint8Array): Promise<void>;
|
|
334
|
+
fillBytes(scope: WorkScope, task: TaskRef, bytes: Uint8Array): Promise<void>;
|
|
335
|
+
/** The scope's open (still streaming) turns in key order, keyset-paged by
|
|
336
|
+
* `after` (G009): the executor re-reads these turns every discovery cycle
|
|
337
|
+
* and re-offers ops from each recorded `offeredUpto`. A legacy scope
|
|
338
|
+
* without the completeness marker has no rows here; its set is rebuilt by
|
|
339
|
+
* `resume`. */
|
|
340
|
+
openTurns(scope: WorkScope, after: Uint8Array | undefined, limit: number): Promise<OpenTurn[]>;
|
|
341
|
+
/** Operation-precision dependency gate shared by `ready` and `acquire`,
|
|
342
|
+
* inside the caller's transaction. Same-turn ancestry requires the turn's
|
|
343
|
+
* prefix watermark to cover `seq - 1` and every recorded same-turn dep
|
|
344
|
+
* (the direct predecessor) to be present with its exact fingerprint. A
|
|
345
|
+
* cross-turn dep needs the parent's *complete* op range on the target
|
|
346
|
+
* with a matching seal fingerprint (`closed`, the recursive assertion, or
|
|
347
|
+
* the direct complete-turn evidence a reverse-history window establishes
|
|
348
|
+
* — see N017 P1-C), and every direct parent of the task's turn must
|
|
349
|
+
* satisfy the same check (review C follow-up). */
|
|
350
|
+
private depsSatisfiedIn;
|
|
351
|
+
}
|