@spine-event-engine/storage-postgres 2.0.0-snapshot.22 → 2.0.0-snapshot.24
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/README.md +13 -4
- package/REFERENCE.md +60 -6
- package/dist/postgres/agent-execution.d.ts +285 -0
- package/dist/postgres/agent-execution.d.ts.map +1 -0
- package/dist/postgres/agent-execution.js +648 -0
- package/dist/postgres/agent-execution.js.map +1 -0
- package/dist/postgres/agent-history.d.ts +114 -0
- package/dist/postgres/agent-history.d.ts.map +1 -0
- package/dist/postgres/agent-history.js +225 -0
- package/dist/postgres/agent-history.js.map +1 -0
- package/dist/postgres/entity-commit.d.ts +23 -38
- package/dist/postgres/entity-commit.d.ts.map +1 -1
- package/dist/postgres/entity-commit.js +101 -144
- package/dist/postgres/entity-commit.js.map +1 -1
- package/dist/postgres/entity-history.d.ts.map +1 -1
- package/dist/postgres/entity-history.js +60 -232
- package/dist/postgres/entity-history.js.map +1 -1
- package/dist/postgres/errors.d.ts +1 -1
- package/dist/postgres/errors.d.ts.map +1 -1
- package/dist/postgres/errors.js +5 -3
- package/dist/postgres/errors.js.map +1 -1
- package/dist/postgres/record-storage.d.ts +87 -111
- package/dist/postgres/record-storage.d.ts.map +1 -1
- package/dist/postgres/record-storage.js +159 -186
- package/dist/postgres/record-storage.js.map +1 -1
- package/dist/postgres/storage-factory.d.ts +11 -8
- package/dist/postgres/storage-factory.d.ts.map +1 -1
- package/dist/postgres/storage-factory.js +93 -23
- package/dist/postgres/storage-factory.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/dist/postgres/delivery-cleanup.d.ts +0 -76
- package/dist/postgres/delivery-cleanup.d.ts.map +0 -1
- package/dist/postgres/delivery-cleanup.js +0 -224
- package/dist/postgres/delivery-cleanup.js.map +0 -1
package/README.md
CHANGED
|
@@ -8,6 +8,10 @@ with live acceptance recorded against PostgreSQL 16.15 and 18.6.
|
|
|
8
8
|
This is an experimental snapshot package. Use Node 24 or newer. For the precise
|
|
9
9
|
public API and operational rules, see the [coding-agent reference](REFERENCE.md).
|
|
10
10
|
|
|
11
|
+
Agent repositories can use this factory to retain accepted work and conversation
|
|
12
|
+
history across restarts. Their state and execution completion are saved together
|
|
13
|
+
in PostgreSQL; a model call does not keep a database transaction open.
|
|
14
|
+
|
|
11
15
|
## Install
|
|
12
16
|
|
|
13
17
|
```sh
|
|
@@ -60,14 +64,15 @@ tenant or database targets are rejected during construction.
|
|
|
60
64
|
## Lifecycle and operations
|
|
61
65
|
|
|
62
66
|
Tables are initialized lazily and checked against the expected PostgreSQL
|
|
63
|
-
layout. Each acquired client is released
|
|
64
|
-
|
|
67
|
+
layout. Each acquired client is released; history maintenance applies deletion
|
|
68
|
+
pages independently. Call `factory.close()` when the application stops; it is
|
|
65
69
|
idempotent and drains live handles and pools. A closed factory cannot create new
|
|
66
70
|
handles.
|
|
67
71
|
|
|
68
72
|
The provider supports record CRUD, compare-and-set, immutable append, Entity
|
|
69
|
-
state and event history,
|
|
70
|
-
|
|
73
|
+
state and event history, declared-column filtering, sorting, limits, offsets,
|
|
74
|
+
and continuations through the common storage API. Eligible Inbox cleanup deletes
|
|
75
|
+
the message ID directly through record storage. It uses
|
|
71
76
|
PostgreSQL `BYTEA`, parameterized `$1`-style values, and PostgreSQL's configured
|
|
72
77
|
text collation. Collation ordering can differ from JavaScript ordering, so
|
|
73
78
|
applications should choose and document their database collation deliberately.
|
|
@@ -83,6 +88,10 @@ collisions are rejected before the database is accessed.
|
|
|
83
88
|
## Live integration checks
|
|
84
89
|
|
|
85
90
|
The live suite is opt-in and requires an already running PostgreSQL service.
|
|
91
|
+
Use disposable test databases and a PostgreSQL superuser for this suite. The Agent
|
|
92
|
+
history regressions alter index catalog flags in isolated temporary schemas to
|
|
93
|
+
check rejection of invalid or unfinished indexes; these schemas are removed after
|
|
94
|
+
each test. The production adapter does not require superuser access.
|
|
86
95
|
No container or database is started automatically:
|
|
87
96
|
|
|
88
97
|
```sh
|
package/REFERENCE.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @spine-event-engine/storage-postgres reference
|
|
2
2
|
|
|
3
3
|
This reference describes the public PostgreSQL adapter contract for coding
|
|
4
|
-
agents
|
|
4
|
+
agents.
|
|
5
5
|
|
|
6
6
|
## Public entry point
|
|
7
7
|
|
|
@@ -42,7 +42,7 @@ altered. Missing, extra, or incompatible columns, defaults, nullability,
|
|
|
42
42
|
primary keys, or unique constraints reject with `PostgresStorageSchemaError`.
|
|
43
43
|
|
|
44
44
|
The adapter uses `$1` parameters, `IS NOT DISTINCT FROM`, PostgreSQL upsert,
|
|
45
|
-
|
|
45
|
+
independent bounded history maintenance pages, and a normalized query plan. It preserves
|
|
46
46
|
the common 1,000-bind plan budget and 10,000-row default with one
|
|
47
47
|
overflow lookahead row. The database collation controls text ordering; the
|
|
48
48
|
provider does not invent a JavaScript-compatible collation.
|
|
@@ -60,13 +60,64 @@ plain, non-reserved ASCII identifiers only. Reserved and quoted-required names
|
|
|
60
60
|
preserve their spelling; all names reject NUL, unsafe values, 63-byte overflow,
|
|
61
61
|
and collisions before DDL, DML, or catalog inspection.
|
|
62
62
|
|
|
63
|
+
## Entity commit behavior
|
|
64
|
+
|
|
65
|
+
The provider captures and validates one Entity commit input before database I/O,
|
|
66
|
+
then prepares its record families. It writes state history, diagnostic Events,
|
|
67
|
+
canonical delivery Events, and finally the current state as ordered independent
|
|
68
|
+
records. A later failure leaves the completed prefix in place; an Event row
|
|
69
|
+
alone does not prove that the current state was written. Concurrent commits can
|
|
70
|
+
interleave, including their current-state writes. This is not one SQL
|
|
71
|
+
transaction across the four families.
|
|
72
|
+
|
|
73
|
+
After preparation succeeds, a PostgreSQL deadlock (`40P01`) or serialization
|
|
74
|
+
failure (`40001`) during the ordered record writes triggers one replay of the
|
|
75
|
+
captured input. A failure during preparation is not retried. Commit does not
|
|
76
|
+
rerun the handler or create new
|
|
77
|
+
versions or Event IDs. An immutable retry accepts an existing row only when its
|
|
78
|
+
wire bytes match; the same ID with different bytes is a collision. A caller
|
|
79
|
+
retry must likewise reuse the original versions and Event IDs. See the
|
|
80
|
+
[shared storage contract](../storage/REFERENCE.md) for the provider SPI and
|
|
81
|
+
cross-provider limits.
|
|
82
|
+
|
|
83
|
+
## Agent history
|
|
84
|
+
|
|
85
|
+
The provider-only Agent history handle stores `AgentHistoryRecord` in one
|
|
86
|
+
`agent_history` record family per selected tenant database. Its payload retains
|
|
87
|
+
the original complete `AgentHistoryEntry` and full state type and Agent key.
|
|
88
|
+
SHA-256 digests provide bounded physical record IDs and indexed scope keys;
|
|
89
|
+
reads also compare the complete state type and Agent key. Three validated B-tree
|
|
90
|
+
indexes cover scope plus full order, scope plus category plus full order, and
|
|
91
|
+
scope plus conversation digest plus full order. Conversation reads also compare
|
|
92
|
+
the complete conversation key. `order_key` encodes original seconds,
|
|
93
|
+
nanoseconds, category, and unsigned UTF-8 record ID under PostgreSQL `C`
|
|
94
|
+
collation. The handle rejects incompatible existing same-name indexes; native
|
|
95
|
+
B-tree entry limits still apply to exceptionally long record IDs. Pages use
|
|
96
|
+
bounded SQL chunks and sum serialized entry bytes; a fetched chunk can be
|
|
97
|
+
larger than the returned byte budget.
|
|
98
|
+
|
|
99
|
+
## Agent execution
|
|
100
|
+
|
|
101
|
+
Agent execution records and per-instance pending entries are stored in separate
|
|
102
|
+
tenant database tables. Indexed queries select the next eligible instance and
|
|
103
|
+
the first unresolved signal within it. Required B-tree indexes use complete
|
|
104
|
+
binary-comparable ordering keys and are checked before admission.
|
|
105
|
+
|
|
106
|
+
Claims, history updates and conditional Entity completion use the same native
|
|
107
|
+
transaction connection. Completion compares the original Entity Version before
|
|
108
|
+
writing the resulting state, history, preferences and outgoing Commands. Reopening
|
|
109
|
+
a factory can read the saved work. No database transaction remains open while a
|
|
110
|
+
model request runs.
|
|
111
|
+
|
|
63
112
|
## Lifecycle and errors
|
|
64
113
|
|
|
65
114
|
`factory.close()` is idempotent, closes registered handles, prevents new handle
|
|
66
115
|
creation, and drains pools. Record and Entity handles can close independently.
|
|
67
|
-
Acquired clients are released in `finally` blocks
|
|
68
|
-
|
|
69
|
-
credentials, SQL text,
|
|
116
|
+
Acquired clients are released in `finally` blocks. History maintenance applies
|
|
117
|
+
each deletion page independently. Top-level provider error messages and public
|
|
118
|
+
responses omit URLs, credentials, SQL text, and driver details. The original
|
|
119
|
+
driver failure remains available as the internal `cause`; do not expose it in
|
|
120
|
+
public responses or unfiltered logs.
|
|
70
121
|
|
|
71
122
|
Custom table creation may use `useOperationFactory(factory)` with the exported
|
|
72
123
|
`PostgresTableSpec`, `PostgresCreateOperation`, and
|
|
@@ -77,7 +128,10 @@ compiler internals.
|
|
|
77
128
|
|
|
78
129
|
## Live verification
|
|
79
130
|
|
|
80
|
-
The infrastructure suite is intentionally excluded from ordinary CI.
|
|
131
|
+
The infrastructure suite is intentionally excluded from ordinary CI. Its Agent
|
|
132
|
+
history regressions require a superuser to alter index catalog flags within
|
|
133
|
+
disposable temporary schemas, which are removed after each test. This is a test
|
|
134
|
+
requirement; the production adapter does not require superuser access. Supply
|
|
81
135
|
explicit `SPINE_TS_POSTGRESQL_URL`, `SPINE_TS_POSTGRESQL_TENANT_A_URL`, and
|
|
82
136
|
`SPINE_TS_POSTGRESQL_TENANT_B_URL` values naming three test databases, then run
|
|
83
137
|
the package's `test:postgresql:16`
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { type Message } from "@bufbuild/protobuf";
|
|
2
|
+
import type { Timestamp } from "@bufbuild/protobuf/wkt";
|
|
3
|
+
import type { CommandId } from "@spine-event-engine/proto";
|
|
4
|
+
import { type AgentAcceptedInvocation, type AgentExecutionHead, type AgentExecutionRecord, type AgentInvocationKey } from "@spine-event-engine/proto/generated/spine/server/agent/execution_record_pb.js";
|
|
5
|
+
import type { AgentHistoryRecord } from "@spine-event-engine/proto/generated/spine/server/agent/history_record_pb.js";
|
|
6
|
+
import type { EntityRecord } from "@spine-event-engine/proto/generated/spine/server/entity/entity_pb.js";
|
|
7
|
+
import { type AgentExecutionStorage, type AgentExecutionCapacity, type AgentExecutionStorageInput, type AgentExecutionClaim, type AgentExecutionUpdate, type AgentExecutionComplete, type AgentPendingRead, type AgentPendingPage } from "@spine-event-engine/storage/provider";
|
|
8
|
+
import { PostgresRecordStorage } from "./record-storage.js";
|
|
9
|
+
import { PostgresEntityCommitStorage } from "./entity-commit.js";
|
|
10
|
+
/**
|
|
11
|
+
* Persists accepted Agent work, exclusive claims and deterministic evidence.
|
|
12
|
+
*
|
|
13
|
+
* @typeParam I Typed Agent identifier.
|
|
14
|
+
* @typeParam S Generated Agent state.
|
|
15
|
+
*/
|
|
16
|
+
export declare class PostgresAgentExecution<I, S extends Message> implements AgentExecutionStorage<I, S> {
|
|
17
|
+
#private;
|
|
18
|
+
private readonly input;
|
|
19
|
+
private readonly invocation;
|
|
20
|
+
private readonly head;
|
|
21
|
+
private readonly history;
|
|
22
|
+
private readonly current;
|
|
23
|
+
private readonly commits;
|
|
24
|
+
/**
|
|
25
|
+
* PostgreSQL has no tighter fixed row limit in this provider contract.
|
|
26
|
+
*/
|
|
27
|
+
readonly capacity: AgentExecutionCapacity;
|
|
28
|
+
/**
|
|
29
|
+
* Binds prepared record families to one Agent repository and tenant boundary.
|
|
30
|
+
*
|
|
31
|
+
* @param input Agent repository and current Entity layout.
|
|
32
|
+
* @param invocation Mutable invocation records.
|
|
33
|
+
* @param head Per-instance claim and current preference records.
|
|
34
|
+
* @param history Immutable Agent conversation, System and domain entries.
|
|
35
|
+
* @param current Existing Entity current records used for no-op version checks.
|
|
36
|
+
* @param commits Opens the existing conditional Entity commit coordinator.
|
|
37
|
+
*/
|
|
38
|
+
constructor(input: AgentExecutionStorageInput<I, S>, invocation: PostgresRecordStorage<string, AgentExecutionRecord>, head: PostgresRecordStorage<string, AgentExecutionHead>, history: PostgresRecordStorage<string, AgentHistoryRecord>, current: PostgresRecordStorage<I, EntityRecord>, commits: () => PostgresEntityCommitStorage<I, S>);
|
|
39
|
+
/**
|
|
40
|
+
* Persists original accepted work idempotently under its per-instance lock.
|
|
41
|
+
*
|
|
42
|
+
* @param accepted Complete source signal and selected bindings.
|
|
43
|
+
* @returns Detached stored invocation.
|
|
44
|
+
*/
|
|
45
|
+
admit(accepted: AgentAcceptedInvocation): Promise<AgentExecutionRecord>;
|
|
46
|
+
/**
|
|
47
|
+
* Reads a bounded indexed page of eligible accepted or interrupted work.
|
|
48
|
+
*
|
|
49
|
+
* @param request Complete continuation and page count.
|
|
50
|
+
* @returns Detached records and continuation state.
|
|
51
|
+
*/
|
|
52
|
+
pending(request: AgentPendingRead): Promise<AgentPendingPage>;
|
|
53
|
+
/**
|
|
54
|
+
* Builds one binary-collated native pending-head query.
|
|
55
|
+
*
|
|
56
|
+
* @param request Bounded pending-page request.
|
|
57
|
+
* @param asOf Fixed provider-time eligibility cutoff.
|
|
58
|
+
* @param table Resolved head table in the current schema.
|
|
59
|
+
* @returns Native SQL and exact bound values.
|
|
60
|
+
*/
|
|
61
|
+
private pendingQuery;
|
|
62
|
+
/**
|
|
63
|
+
* Reads one complete persisted invocation.
|
|
64
|
+
*
|
|
65
|
+
* @param key Original source and Agent instance identity.
|
|
66
|
+
* @returns Detached record if present.
|
|
67
|
+
*/
|
|
68
|
+
read(key: AgentInvocationKey): Promise<AgentExecutionRecord | undefined>;
|
|
69
|
+
/**
|
|
70
|
+
* Acquires only earliest unresolved same-instance work under a fresh transaction clock.
|
|
71
|
+
*
|
|
72
|
+
* @param key Original source and Agent instance identity.
|
|
73
|
+
* @param token New exclusive token.
|
|
74
|
+
* @param expiresAt Requested future expiry.
|
|
75
|
+
* @returns Claimed record and current preferences, when eligible.
|
|
76
|
+
*/
|
|
77
|
+
claim(key: AgentInvocationKey, token: string, expiresAt: Timestamp): Promise<AgentExecutionClaim | undefined>;
|
|
78
|
+
/**
|
|
79
|
+
* Checks the locked instance and persists one exclusive lease.
|
|
80
|
+
*
|
|
81
|
+
* @param client Native client in the current transaction.
|
|
82
|
+
* @param rows Tenant record executors.
|
|
83
|
+
* @param key Original Agent invocation identity.
|
|
84
|
+
* @param token New exclusive token.
|
|
85
|
+
* @param expiresAt Requested future lease expiry.
|
|
86
|
+
* @returns Claimed record and preferences when eligible.
|
|
87
|
+
*/
|
|
88
|
+
private claimLocked;
|
|
89
|
+
/**
|
|
90
|
+
* Checks the current head and earliest same-instance source.
|
|
91
|
+
*
|
|
92
|
+
* @param client Native client in the current transaction.
|
|
93
|
+
* @param rows Tenant record executors.
|
|
94
|
+
* @param head Per-instance pending and lease record.
|
|
95
|
+
* @param key Original Agent invocation identity.
|
|
96
|
+
* @param now Fresh time read under the per-instance lock.
|
|
97
|
+
* @returns Whether this invocation may receive the next lease.
|
|
98
|
+
*/
|
|
99
|
+
private eligibleClaim;
|
|
100
|
+
/**
|
|
101
|
+
* Updates one still-current lease under the per-instance transaction lock.
|
|
102
|
+
*
|
|
103
|
+
* @param key Original source and Agent instance identity.
|
|
104
|
+
* @param token Current exclusive token.
|
|
105
|
+
* @param expiresAt Requested later expiry.
|
|
106
|
+
* @returns Whether renewal succeeded.
|
|
107
|
+
*/
|
|
108
|
+
renew(key: AgentInvocationKey, token: string, expiresAt: Timestamp): Promise<boolean>;
|
|
109
|
+
/**
|
|
110
|
+
* Persists one execution update and its immutable history rows in the same transaction.
|
|
111
|
+
*
|
|
112
|
+
* @param input Exact read image, next execution record and history entries.
|
|
113
|
+
* @returns Completion after fenced evidence is persisted.
|
|
114
|
+
*/
|
|
115
|
+
update(input: AgentExecutionUpdate): Promise<void>;
|
|
116
|
+
/**
|
|
117
|
+
* Commits Entity state, history, preferences and outgoing obligations together.
|
|
118
|
+
*
|
|
119
|
+
* @param input Complete conditional transition.
|
|
120
|
+
* @returns Completion after conditional Entity and evidence commit.
|
|
121
|
+
*/
|
|
122
|
+
complete(input: AgentExecutionComplete<I, S>): Promise<void>;
|
|
123
|
+
/**
|
|
124
|
+
* Applies every conditional completion row on one transaction client.
|
|
125
|
+
*
|
|
126
|
+
* @param client Native database client in the current transaction.
|
|
127
|
+
* @param input Requested fenced execution change.
|
|
128
|
+
* @param prepared Prepared Entity state and Version write.
|
|
129
|
+
* @param rows Provider record handles bound to the tenant.
|
|
130
|
+
* @returns Completion after Entity and execution evidence commit.
|
|
131
|
+
*/
|
|
132
|
+
private completeLocked;
|
|
133
|
+
/**
|
|
134
|
+
* Validates one Version increment or no-op and a nonterminal prior phase.
|
|
135
|
+
*
|
|
136
|
+
* @param input Requested fenced execution change.
|
|
137
|
+
* @param prior Previously persisted execution record.
|
|
138
|
+
* @returns Expected initial Entity Version.
|
|
139
|
+
*/
|
|
140
|
+
private validateCompletion;
|
|
141
|
+
/**
|
|
142
|
+
* Marks original outgoing IDs accepted by normal delivery.
|
|
143
|
+
*
|
|
144
|
+
* @param key Original source and Agent instance identity.
|
|
145
|
+
* @param token Current exclusive token.
|
|
146
|
+
* @param expectedRecordBytes Exact previous record bytes.
|
|
147
|
+
* @param signals Original accepted output IDs.
|
|
148
|
+
* @returns Completion after original output IDs are marked delivered.
|
|
149
|
+
*/
|
|
150
|
+
markDelivered(key: AgentInvocationKey, token: string, expectedRecordBytes: Uint8Array, signals: readonly CommandId[]): Promise<void>;
|
|
151
|
+
/**
|
|
152
|
+
* Marks original output IDs while the per-instance native lock is held.
|
|
153
|
+
*
|
|
154
|
+
* @param client Native client in the current transaction.
|
|
155
|
+
* @param rows Tenant record executors.
|
|
156
|
+
* @param key Original Agent invocation identity.
|
|
157
|
+
* @param token Current exclusive claim token.
|
|
158
|
+
* @param expectedRecordBytes Exact prior execution record bytes.
|
|
159
|
+
* @param signals Original accepted output IDs.
|
|
160
|
+
* @returns Completion after persisted output status is updated.
|
|
161
|
+
*/
|
|
162
|
+
private deliverLocked;
|
|
163
|
+
/**
|
|
164
|
+
* Closes all provider record handles without deleting persisted work.
|
|
165
|
+
*/
|
|
166
|
+
close(): void;
|
|
167
|
+
/**
|
|
168
|
+
* Rejects calls after handle closure.
|
|
169
|
+
*/
|
|
170
|
+
private requireOpen;
|
|
171
|
+
/**
|
|
172
|
+
* Prepares three existing record families and required native indexes once.
|
|
173
|
+
*
|
|
174
|
+
* @returns Completion after provider capabilities are checked.
|
|
175
|
+
*/
|
|
176
|
+
private ready;
|
|
177
|
+
/**
|
|
178
|
+
* Ensures full scoped order and expiry indexes before accepted work.
|
|
179
|
+
*
|
|
180
|
+
* @returns Completion after native tables and indexes are prepared.
|
|
181
|
+
*/
|
|
182
|
+
private initialize;
|
|
183
|
+
/**
|
|
184
|
+
* Acquires a transaction-scoped lock even when the head row is absent.
|
|
185
|
+
*
|
|
186
|
+
* @param client Native database client in the current transaction.
|
|
187
|
+
* @param key Original Agent invocation identity.
|
|
188
|
+
* @param rows Provider record handles bound to the tenant.
|
|
189
|
+
* @returns Completion after locking the per-instance head.
|
|
190
|
+
*/
|
|
191
|
+
private lockHead;
|
|
192
|
+
/**
|
|
193
|
+
* Reads one head and rejects a physical digest collision.
|
|
194
|
+
*
|
|
195
|
+
* @param client Native database client in the current transaction.
|
|
196
|
+
* @param key Original Agent invocation identity.
|
|
197
|
+
* @param rows Provider record handles bound to the tenant.
|
|
198
|
+
* @returns Per-instance head when present.
|
|
199
|
+
*/
|
|
200
|
+
private currentHead;
|
|
201
|
+
/**
|
|
202
|
+
* Reads one invocation and rejects a physical digest collision.
|
|
203
|
+
*
|
|
204
|
+
* @param client Native database client in the current transaction.
|
|
205
|
+
* @param key Original Agent invocation identity.
|
|
206
|
+
* @param rows Provider record handles bound to the tenant.
|
|
207
|
+
* @returns Stored invocation when present.
|
|
208
|
+
*/
|
|
209
|
+
private existing;
|
|
210
|
+
/**
|
|
211
|
+
* Checks fresh Time, exact token and complete previous record bytes.
|
|
212
|
+
*
|
|
213
|
+
* @param checkNext Whether to validate the proposed next record.
|
|
214
|
+
* @param client Native database client in the current transaction.
|
|
215
|
+
* @param input Requested fenced execution change.
|
|
216
|
+
* @param rows Provider record handles bound to the tenant.
|
|
217
|
+
* @returns Current fenced record and head.
|
|
218
|
+
*/
|
|
219
|
+
private expected;
|
|
220
|
+
/**
|
|
221
|
+
* Reads claimed rows under the already acquired per-instance lock.
|
|
222
|
+
*
|
|
223
|
+
* @param client Native database client in the current transaction.
|
|
224
|
+
* @param key Original Agent invocation identity.
|
|
225
|
+
* @param rows Provider record handles bound to the tenant.
|
|
226
|
+
* @param token Exclusive claim token.
|
|
227
|
+
* @returns Current record and head if the token remains valid.
|
|
228
|
+
*/
|
|
229
|
+
private claimed;
|
|
230
|
+
/**
|
|
231
|
+
* Checks no earlier unresolved signal in the same full Agent scope.
|
|
232
|
+
*
|
|
233
|
+
* @param client Native database client in the current transaction.
|
|
234
|
+
* @param key Original Agent invocation identity.
|
|
235
|
+
* @param rows Provider record handles bound to the tenant.
|
|
236
|
+
* @returns Whether this invocation is earliest unresolved work.
|
|
237
|
+
*/
|
|
238
|
+
private earliest;
|
|
239
|
+
/**
|
|
240
|
+
* Adds an earlier accepted source without resetting an existing eligibility.
|
|
241
|
+
*
|
|
242
|
+
* @param head Per-instance pending and lease record.
|
|
243
|
+
* @param record Persisted Agent execution record.
|
|
244
|
+
*/
|
|
245
|
+
private offerCandidate;
|
|
246
|
+
/**
|
|
247
|
+
* Updates the head to one bounded native successor before terminal publication.
|
|
248
|
+
*
|
|
249
|
+
* @param client Native database client in the current transaction.
|
|
250
|
+
* @param head Per-instance pending and lease record.
|
|
251
|
+
* @param key Original Agent invocation identity.
|
|
252
|
+
* @param order Original Inbox order.
|
|
253
|
+
* @param rows Provider record handles bound to the tenant.
|
|
254
|
+
* @returns Completion after updating the next pending head.
|
|
255
|
+
*/
|
|
256
|
+
private advanceCandidate;
|
|
257
|
+
/**
|
|
258
|
+
* Reads at most two rows per unresolved status in original Inbox order.
|
|
259
|
+
*
|
|
260
|
+
* @param client Native database client in the current transaction.
|
|
261
|
+
* @param exclude Invocation omitted while selecting the successor.
|
|
262
|
+
* @param key Original Agent invocation identity.
|
|
263
|
+
* @param rows Provider record handles bound to the tenant.
|
|
264
|
+
* @returns Earliest unresolved invocation when present.
|
|
265
|
+
*/
|
|
266
|
+
private successor;
|
|
267
|
+
/**
|
|
268
|
+
* Builds the bounded native query for one unresolved invocation status.
|
|
269
|
+
*
|
|
270
|
+
* @param table Resolved invocation table in the current schema.
|
|
271
|
+
* @returns Complete indexed successor query.
|
|
272
|
+
*/
|
|
273
|
+
private successorSql;
|
|
274
|
+
/**
|
|
275
|
+
* Validates current Version and applies optional Entity rows in this transaction.
|
|
276
|
+
*
|
|
277
|
+
* @param client Native database client in the current transaction.
|
|
278
|
+
* @param expectedVersion Expected current Entity Version.
|
|
279
|
+
* @param input Requested fenced execution change.
|
|
280
|
+
* @param prepared Prepared Entity state and Version write.
|
|
281
|
+
* @returns Completion after conditional Entity state and Version write.
|
|
282
|
+
*/
|
|
283
|
+
private completeEntity;
|
|
284
|
+
}
|
|
285
|
+
//# sourceMappingURL=agent-execution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-execution.d.ts","sourceRoot":"","sources":["../../src/postgres/agent-execution.ts"],"names":[],"mappings":"AAcA,OAAO,EAAoB,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAExD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAE3D,OAAO,EAIL,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACxB,MAAM,+EAA+E,CAAC;AACvF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6EAA6E,CAAC;AACtH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sEAAsE,CAAC;AACzG,OAAO,EAKL,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,0BAA0B,EAC/B,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,sBAAsB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