@oathe/oathe 0.0.1 → 0.2.1
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/.claude-plugin/marketplace.json +14 -0
- package/LICENSE +202 -21
- package/NOTICE +7 -0
- package/README.md +104 -12
- package/assets/oathe-hero.svg +92 -0
- package/bin/oathe.mjs +376 -0
- package/docs/PRIVACY.md +45 -0
- package/package.json +33 -23
- package/plugin/.claude-plugin/plugin.json +10 -0
- package/plugin/.mcp.json +13 -0
- package/plugin/hooks/frame-note.mjs +24 -0
- package/plugin/hooks/heartbeat.mjs +49 -0
- package/plugin/hooks/hooks.json +39 -0
- package/plugin/hooks/lib.mjs +83 -0
- package/plugin/hooks/render-board.mjs +11 -0
- package/plugin/skills/oathe-work/SKILL.md +33 -0
- package/src/atif.mjs +633 -0
- package/src/blocks.mjs +192 -0
- package/src/board-render.mjs +106 -0
- package/src/config.mjs +169 -0
- package/src/context.mjs +35 -0
- package/src/doctor.mjs +108 -0
- package/src/harness.mjs +271 -0
- package/src/init.mjs +92 -0
- package/src/launch-env.mjs +25 -0
- package/src/launch.mjs +259 -0
- package/src/manifest.mjs +89 -0
- package/src/mcp/oathe-tools.mjs +517 -0
- package/src/paths.mjs +49 -0
- package/src/plans.mjs +50 -0
- package/src/runtime/discharge.mjs +57 -0
- package/src/runtime/provider.mjs +154 -0
- package/src/runtime/simple-cage.mjs +67 -0
- package/src/runtime/sql-acceptance-lane.mjs +89 -0
- package/src/session-host.mjs +81 -0
- package/src/substrate.mjs +337 -0
- package/src/successor.mjs +31 -0
- package/src/traces.mjs +242 -0
- package/src/uninstall.mjs +45 -0
- package/src/verifier.mjs +322 -0
- package/src/workspace.mjs +47 -0
- package/vendor/ddl/001_core.sql +312 -0
- package/vendor/ddl/002_claim.sql +438 -0
- package/vendor/ddl/003_verification.sql +480 -0
- package/vendor/ddl/004_delegation.sql +397 -0
- package/vendor/ddl/005_escalation.sql +303 -0
- package/vendor/ddl/006_dependency.sql +384 -0
- package/vendor/ddl/007_assignment.sql +502 -0
- package/vendor/ddl/008_effect_receipt.sql +290 -0
- package/vendor/ddl/009_verified_edge.sql +452 -0
- package/vendor/ddl/010_parent_child_verification.sql +320 -0
- package/vendor/ddl/011_confirm.sql +288 -0
- package/vendor/ddl/012_evaluator_lane.sql +444 -0
- package/vendor/ddl/013_claim_terminal.sql +279 -0
- package/vendor/ddl/014_claim_settlement.sql +327 -0
- package/vendor/ddl/015_claim_yield.sql +213 -0
- package/vendor/ddl/016_reopened_reclaim.sql +285 -0
- package/vendor/ddl/017_claim_yield_causes.sql +357 -0
- package/vendor/ddl/018_receiptless_unknown.sql +249 -0
- package/vendor/ddl/019_verification_contract_freeze.sql +335 -0
- package/vendor/ddl/020_context_compilation.sql +105 -0
- package/vendor/ddl/021_execution_attempt_closure.sql +95 -0
- package/vendor/ddl/022_verification_clause.sql +106 -0
- package/vendor/ddl/023_executor_role.sql +66 -0
- package/vendor/ddl/024_executor_role_hardening.sql +439 -0
- package/vendor/ddl/025_running_attempt_uniqueness.sql +102 -0
- package/vendor/ddl/026_acceptance_authority.sql +230 -0
- package/vendor/ddl/027_ownership_return.sql +836 -0
- package/vendor/ddl/028_attempt_bind_ownership.sql +173 -0
- package/vendor/ddl/manifest.json +183 -0
- package/index.js +0 -33
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
-- 017_claim_yield_causes.sql — THE ONE PRODUCER OF THE YIELD MEANING, the
|
|
2
|
+
-- registry of the causes that may reach it, and the SECOND cause: a parent
|
|
3
|
+
-- handing responsibility back with delegated work outstanding.
|
|
4
|
+
--
|
|
5
|
+
-- Contract: docs/a1-cell-work-spine-contract.md §1.2 (claim terminals;
|
|
6
|
+
-- responsibility passes by yield; a terminal is identified by event MEANING
|
|
7
|
+
-- rather than by producing code path), §1.6 (completion and settlement are
|
|
8
|
+
-- separate facts), §2.1 shape (a) (the delegated child claim), FOUNDER RULING
|
|
9
|
+
-- R1 and R8. Requires 001_core.sql, 002_claim.sql (cell.written_by, the producer
|
|
10
|
+
-- registry) and 015_claim_yield.sql (the first cause, whose terminal write moves
|
|
11
|
+
-- here in this same change).
|
|
12
|
+
--
|
|
13
|
+
-- Re-apply: idempotent (CREATE OR REPLACE, ON CONFLICT registry seeds).
|
|
14
|
+
-- Revert: DROP SCHEMA cell CASCADE; (this file installs nothing outside it)
|
|
15
|
+
--
|
|
16
|
+
-- WHY THIS FILE EXISTS, MEASURED
|
|
17
|
+
--
|
|
18
|
+
-- `C1-CHILD-LEASE-ON-PARENT-YIELD` asks for one row: the parent's claim at a
|
|
19
|
+
-- yield terminal carrying a typed basis, while the child claim stays ACTIVE and
|
|
20
|
+
-- no `child_retraction` is written — a yield is not a withdrawal. Both bake-off
|
|
21
|
+
-- entrants were red on it in every repetition of the 20260818T2100Z pair and
|
|
22
|
+
-- NEITHER RED WAS THEIRS. 015's own header named this cause in as many words
|
|
23
|
+
-- ("a yield has several lawful causes — a holder handing back unfinished work, a
|
|
24
|
+
-- parent yielding with delegated work outstanding, a reassignment") and shipped
|
|
25
|
+
-- a verb for exactly one of them. That verb takes a `token_id` and reads
|
|
26
|
+
-- everything off the ask, so a parent with no ask had nothing to hand it, and
|
|
27
|
+
-- the only road to the row was a direct `UPDATE cell.work_claim` from executor
|
|
28
|
+
-- code — forbidden absolutely to every candidate by the one-writer census
|
|
29
|
+
-- (A2.4-F0). The leg sat between a missing domain verb and a boundary.
|
|
30
|
+
--
|
|
31
|
+
-- WHY ONE PRODUCER AND SEVERAL CAUSES IS NOT A CONTRADICTION
|
|
32
|
+
--
|
|
33
|
+
-- §1.2 identifies a terminal by its MEANING, and 002's registry holds exactly
|
|
34
|
+
-- one producer per meaning. So the MEANING gets one writer — `cell.record_claim_
|
|
35
|
+
-- yield`, which owns the lock, the idempotency predicate, the not-reversible
|
|
36
|
+
-- rule, the row and the event — and the CAUSES are separate verbs that each
|
|
37
|
+
-- answer a different question: which recorded fact ends this claim, at which
|
|
38
|
+
-- instants that fact is already true, and what basis it derives. Splitting it
|
|
39
|
+
-- the other way (a verb per cause, each writing its own row and its own event)
|
|
40
|
+
-- is what would put two producers behind one meaning, which is the state 002's
|
|
41
|
+
-- guard exists to refuse.
|
|
42
|
+
--
|
|
43
|
+
-- `cell.claim_yield_cause` is the review surface for that split: it names which
|
|
44
|
+
-- verb may transcribe which basis, and the writer refuses a caller on neither
|
|
45
|
+
-- list. A cause cannot write another cause's basis, and nothing outside the
|
|
46
|
+
-- declared causes can write the meaning at all. Adding a cause is a row here and
|
|
47
|
+
-- a verb; it is never a second writer.
|
|
48
|
+
--
|
|
49
|
+
-- WHY THE HANDBACK'S FACT IS THE OUTSTANDING WORK AND NOT THE ESCALATION
|
|
50
|
+
--
|
|
51
|
+
-- Case 1's parent raises an escalation on its way out — `YIELD_SCRIPT` declares
|
|
52
|
+
-- one, addressed to the CEO — and this verb deliberately never reads it.
|
|
53
|
+
-- 005_escalation.sql: nothing keys a row to an escalation and no trigger turns
|
|
54
|
+
-- one into a consequence, precisely so the request-for-help lane cannot become a
|
|
55
|
+
-- second authority over the work lifecycle (L1). What ends this claim is the
|
|
56
|
+
-- DELEGATED WORK ITSELF — active child claims hanging off it, a fact the claim
|
|
57
|
+
-- transaction recorded — and a parent with nothing outstanding is REFUSED. So "I
|
|
58
|
+
-- would like to stop" is not something a runtime can say to this verb; the only
|
|
59
|
+
-- claims it can end are ones the substrate already says somebody else is
|
|
60
|
+
-- carrying work for.
|
|
61
|
+
--
|
|
62
|
+
-- WHY THERE IS STILL NO ROW TRIGGER ON THIS TRANSITION
|
|
63
|
+
--
|
|
64
|
+
-- 015 deferred it under a dated L8 bridge, and this file narrows that bridge by
|
|
65
|
+
-- one span rather than closing it: a guard naming `cell.record_claim_yield`
|
|
66
|
+
-- would now be TRUE of every yield the cell can perform, and false of every
|
|
67
|
+
-- yield the two causes that still have no verb perform — the holder's plain
|
|
68
|
+
-- handback and the reassignment — including the ones the matrix's own scenes
|
|
69
|
+
-- declare as history. A guard that has to be true of a meaning cannot be
|
|
70
|
+
-- installed while that meaning still has causes with no verb.
|
|
71
|
+
--
|
|
72
|
+
-- L8, dated, narrowed by one span: the row-level guard lands in the same change
|
|
73
|
+
-- as the remaining yield causes' verbs (plain handback, reassignment).
|
|
74
|
+
-- Retirement condition unchanged — all of contract §1.2's yield causes reachable
|
|
75
|
+
-- through a verb in this schema. Deletion owner: the A1 work-spine lane.
|
|
76
|
+
--
|
|
77
|
+
-- Declared failure vocabulary (SQLSTATE class FC; this lane reserves
|
|
78
|
+
-- FC140-FC149):
|
|
79
|
+
-- FC140 CLAIM_YIELD_WRITTEN_OUTSIDE_A_DECLARED_CAUSE the yield meaning
|
|
80
|
+
-- written by something that is not one
|
|
81
|
+
-- of the registered causes
|
|
82
|
+
-- FC141 CLAIM_YIELD_BASIS_IS_NOT_THE_CAUSES a declared cause writing a basis
|
|
83
|
+
-- registered to a different cause
|
|
84
|
+
-- FC142 CLAIM_YIELD_CLAIM_ALREADY_ENDED a yield onto a claim whose
|
|
85
|
+
-- responsibility ended by another
|
|
86
|
+
-- terminal
|
|
87
|
+
-- FC143 CLAIM_YIELD_HANDBACK_CLAIM_UNKNOWN a handback by a claim the company
|
|
88
|
+
-- has no record of
|
|
89
|
+
-- FC144 CLAIM_YIELD_HANDBACK_NOTHING_OUTSTANDING a handback by a parent with
|
|
90
|
+
-- no delegated work anybody is carrying
|
|
91
|
+
-- FC145 CLAIM_YIELD_HANDBACK_PRECEDES_THE_DELEGATION a handback stamped
|
|
92
|
+
-- before the work being handed back was
|
|
93
|
+
-- delegated
|
|
94
|
+
-- FC146 CLAIM_YIELD_CLAIM_UNKNOWN the yield meaning written against a
|
|
95
|
+
-- claim that is not there
|
|
96
|
+
|
|
97
|
+
-- ------------------------------------------------------------ the cause registry
|
|
98
|
+
--
|
|
99
|
+
-- Shaped like `cell.claim_event_producer` on purpose: substrate VOCABULARY
|
|
100
|
+
-- installed by a migration, read by a guard, and checkable rather than asserted.
|
|
101
|
+
-- The basis prefix is UNIQUE as well as the cause, because the pair is what
|
|
102
|
+
-- makes "why did responsibility pass" resolvable — a reader holding a terminal
|
|
103
|
+
-- basis can name the cause that wrote it, and exactly one.
|
|
104
|
+
CREATE TABLE IF NOT EXISTS cell.claim_yield_cause (
|
|
105
|
+
cause text NOT NULL,
|
|
106
|
+
basis_prefix text NOT NULL,
|
|
107
|
+
|
|
108
|
+
CONSTRAINT claim_yield_cause_pkey PRIMARY KEY (cause),
|
|
109
|
+
CONSTRAINT claim_yield_cause_prefix_names_one_cause UNIQUE (basis_prefix),
|
|
110
|
+
|
|
111
|
+
-- A prefix with a colon in it could not be split back out of the basis, and
|
|
112
|
+
-- a blank one would match every basis there is.
|
|
113
|
+
CONSTRAINT claim_yield_cause_prefix_is_a_single_token
|
|
114
|
+
CHECK (basis_prefix <> '' AND strpos(basis_prefix, ':') = 0)
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
COMMENT ON TABLE cell.claim_yield_cause IS
|
|
118
|
+
'Contract §1.2. The declared causes of a work_claim.yielded MEANING, and the '
|
|
119
|
+
'basis each may derive. One producer writes the meaning; these are the facts '
|
|
120
|
+
'that may reach it.';
|
|
121
|
+
|
|
122
|
+
INSERT INTO cell.claim_yield_cause (cause, basis_prefix) VALUES
|
|
123
|
+
('cell.yield_claim_on_expired_ask', 'confirm_ask_expired'),
|
|
124
|
+
('cell.yield_claim_with_delegated_work_outstanding',
|
|
125
|
+
'delegated_work_outstanding')
|
|
126
|
+
ON CONFLICT (cause) DO UPDATE SET basis_prefix = EXCLUDED.basis_prefix;
|
|
127
|
+
|
|
128
|
+
-- ------------------------------------------------------ the producer registry
|
|
129
|
+
--
|
|
130
|
+
-- 002 named the terminal verbs as an L8 dated bridge and registered the meanings
|
|
131
|
+
-- whose verb had landed. 015 seeded this row with its own name, because it was
|
|
132
|
+
-- then the only cause there was; the producer of the MEANING is now the shared
|
|
133
|
+
-- writer below, and 015's registration is deleted in the same change (L5) rather
|
|
134
|
+
-- than left beside this one for a reader to reconcile.
|
|
135
|
+
INSERT INTO cell.claim_event_producer (topic, producer)
|
|
136
|
+
VALUES ('work_claim.yielded', 'cell.record_claim_yield')
|
|
137
|
+
ON CONFLICT (topic) DO UPDATE SET producer = EXCLUDED.producer;
|
|
138
|
+
|
|
139
|
+
-- --------------------------------------------------------- the one producer
|
|
140
|
+
--
|
|
141
|
+
-- Everything that is true of a yield REGARDLESS of what caused it, in one place:
|
|
142
|
+
-- the claim lock, the idempotency predicate, the terminals-are-not-reversible
|
|
143
|
+
-- rule, the row, and the meaning event in the same transaction. A rule that
|
|
144
|
+
-- lives in one cause is a rule the next cause has to remember, and 015 was
|
|
145
|
+
-- written when there was no next cause.
|
|
146
|
+
--
|
|
147
|
+
-- It takes a BASIS rather than deriving one, and that is not a hole: the basis
|
|
148
|
+
-- is checked against the registry row of the cause on the call stack, so a
|
|
149
|
+
-- caller may only pass a basis its own cause declares. What each cause derives
|
|
150
|
+
-- the rest of that basis FROM is the cause's business, and it is a recorded fact
|
|
151
|
+
-- in every case — an ask's canonical key, the task ids of the work still
|
|
152
|
+
-- outstanding.
|
|
153
|
+
CREATE OR REPLACE FUNCTION cell.record_claim_yield(
|
|
154
|
+
p_work_claim_id uuid,
|
|
155
|
+
p_basis text,
|
|
156
|
+
p_at timestamptz,
|
|
157
|
+
p_event_id uuid
|
|
158
|
+
)
|
|
159
|
+
RETURNS boolean
|
|
160
|
+
LANGUAGE plpgsql
|
|
161
|
+
AS $record_yield$
|
|
162
|
+
DECLARE
|
|
163
|
+
v_cause text;
|
|
164
|
+
v_prefix text;
|
|
165
|
+
v_org text;
|
|
166
|
+
v_state text;
|
|
167
|
+
v_moved integer;
|
|
168
|
+
BEGIN
|
|
169
|
+
-- WHICH DECLARED CAUSE IS ON THE STACK. Not a column, not a setting: a
|
|
170
|
+
-- caller cannot put a frame on the PL/pgSQL call stack that is not there,
|
|
171
|
+
-- and MEASURED, three transaction-local settings that any session could set
|
|
172
|
+
-- were exactly what the cell's guards used to read.
|
|
173
|
+
SELECT c.cause, c.basis_prefix INTO v_cause, v_prefix
|
|
174
|
+
FROM cell.claim_yield_cause c
|
|
175
|
+
WHERE cell.written_by(c.cause)
|
|
176
|
+
ORDER BY c.cause
|
|
177
|
+
LIMIT 1;
|
|
178
|
+
|
|
179
|
+
IF NOT FOUND THEN
|
|
180
|
+
RAISE EXCEPTION
|
|
181
|
+
'CLAIM_YIELD_WRITTEN_OUTSIDE_A_DECLARED_CAUSE:% — a work_claim.'
|
|
182
|
+
'yielded meaning is written by this verb and reached by a DECLARED '
|
|
183
|
+
'CAUSE (cell.claim_yield_cause), and nothing on this call stack is '
|
|
184
|
+
'one. Contract §1.2: responsibility passes by a terminal, and a '
|
|
185
|
+
'terminal nobody can resolve to a recorded fact is a principal '
|
|
186
|
+
'relieved of work for a reason the company does not hold.',
|
|
187
|
+
p_work_claim_id
|
|
188
|
+
USING ERRCODE = 'FC140';
|
|
189
|
+
END IF;
|
|
190
|
+
|
|
191
|
+
IF split_part(p_basis, ':', 1) IS DISTINCT FROM v_prefix THEN
|
|
192
|
+
RAISE EXCEPTION
|
|
193
|
+
'CLAIM_YIELD_BASIS_IS_NOT_THE_CAUSES:%:%:% — this cause derives a '
|
|
194
|
+
'basis under ''%'', and the basis offered is not one. A cause that '
|
|
195
|
+
'could write another''s basis would make the terminal''s reason '
|
|
196
|
+
'unresolvable: a reader holding the row could not tell which '
|
|
197
|
+
'recorded fact it stands on.',
|
|
198
|
+
p_work_claim_id, v_cause, p_basis, v_prefix
|
|
199
|
+
USING ERRCODE = 'FC141';
|
|
200
|
+
END IF;
|
|
201
|
+
|
|
202
|
+
-- The claim, locked before its state is read: two causes reaching the same
|
|
203
|
+
-- claim on the same tick serialize here, and the loser re-reads AFTER the
|
|
204
|
+
-- winner has committed rather than both seeing `active`.
|
|
205
|
+
SELECT org_id, state INTO v_org, v_state
|
|
206
|
+
FROM cell.work_claim
|
|
207
|
+
WHERE work_claim_id = p_work_claim_id
|
|
208
|
+
FOR UPDATE;
|
|
209
|
+
|
|
210
|
+
IF NOT FOUND THEN
|
|
211
|
+
RAISE EXCEPTION
|
|
212
|
+
'CLAIM_YIELD_CLAIM_UNKNOWN:% — there is no such claim, so nothing '
|
|
213
|
+
'ended and there is no responsibility this call could be evidence '
|
|
214
|
+
'of. An UPDATE that matched nothing fires no trigger at all, which '
|
|
215
|
+
'is how a terminal path comes to report success for a row it never '
|
|
216
|
+
'touched.',
|
|
217
|
+
p_work_claim_id
|
|
218
|
+
USING ERRCODE = 'FC146';
|
|
219
|
+
END IF;
|
|
220
|
+
|
|
221
|
+
-- Idempotency is the PREDICATE, not a set this verb remembers: a restart
|
|
222
|
+
-- takes a remembered set with it, which is the whole reason L2 puts durable
|
|
223
|
+
-- state below the agent. A recovery that finds the terminal already recorded
|
|
224
|
+
-- has nothing to do and says so.
|
|
225
|
+
IF v_state = 'yielded' THEN
|
|
226
|
+
RETURN false;
|
|
227
|
+
END IF;
|
|
228
|
+
|
|
229
|
+
IF v_state IS DISTINCT FROM 'active' THEN
|
|
230
|
+
RAISE EXCEPTION
|
|
231
|
+
'CLAIM_YIELD_CLAIM_ALREADY_ENDED:%:% — responsibility for this work '
|
|
232
|
+
'already ended by another terminal, and claim terminals are not '
|
|
233
|
+
'reversible by a second one arriving. Contract §1.2: a yield written '
|
|
234
|
+
'over a completion, an abort or a takeover would record that the '
|
|
235
|
+
'principal who was relieved of the work handed it back.',
|
|
236
|
+
p_work_claim_id, v_state
|
|
237
|
+
USING ERRCODE = 'FC142';
|
|
238
|
+
END IF;
|
|
239
|
+
|
|
240
|
+
-- The terminal. `settled_at` is untouched and belongs to the evaluator seat
|
|
241
|
+
-- (§1.6): handing work back settles nothing, whatever handed it back.
|
|
242
|
+
UPDATE cell.work_claim
|
|
243
|
+
SET state = 'yielded',
|
|
244
|
+
terminal_basis = p_basis,
|
|
245
|
+
yielded_at = p_at,
|
|
246
|
+
ownership_ended_at = p_at
|
|
247
|
+
WHERE work_claim_id = p_work_claim_id
|
|
248
|
+
AND state = 'active';
|
|
249
|
+
|
|
250
|
+
GET DIAGNOSTICS v_moved = ROW_COUNT;
|
|
251
|
+
|
|
252
|
+
-- The meaning event, in the SAME transaction as the row. A terminal visible
|
|
253
|
+
-- as a row but not as an event (or the reverse) is the split-brain 002's
|
|
254
|
+
-- claim transaction exists to make impossible. The producer trigger reads
|
|
255
|
+
-- THIS frame off the call stack, so this INSERT is lawful here and nowhere
|
|
256
|
+
-- else.
|
|
257
|
+
INSERT INTO cell.work_claim_event (event_id, org_id, work_claim_id, topic, ts,
|
|
258
|
+
producer)
|
|
259
|
+
VALUES (p_event_id, v_org, p_work_claim_id, 'work_claim.yielded', p_at,
|
|
260
|
+
'cell.record_claim_yield');
|
|
261
|
+
|
|
262
|
+
RETURN v_moved = 1;
|
|
263
|
+
END;
|
|
264
|
+
$record_yield$;
|
|
265
|
+
|
|
266
|
+
COMMENT ON FUNCTION cell.record_claim_yield IS
|
|
267
|
+
'Contract §1.2: the ONE producer of a work_claim.yielded meaning. Owns the '
|
|
268
|
+
'lock, the idempotency predicate, the not-reversible rule, the row and the '
|
|
269
|
+
'event; reached only by a verb registered in cell.claim_yield_cause, and only '
|
|
270
|
+
'with the basis that cause declares.';
|
|
271
|
+
|
|
272
|
+
-- ------------------------------------------------------------- the second cause
|
|
273
|
+
--
|
|
274
|
+
-- Every argument is required and none may grow a default. The caller supplies an
|
|
275
|
+
-- IDENTITY, an INSTANT and an EVENT ID — the same three 015 takes — and
|
|
276
|
+
-- everything the terminal MEANS is read off the substrate.
|
|
277
|
+
--
|
|
278
|
+
-- The INSTANT is the caller's because this cause has no stored moment of its
|
|
279
|
+
-- own: the fact it rests on is a state (work delegated out and still carried),
|
|
280
|
+
-- not an event with a timestamp. It cannot be used to end responsibility before
|
|
281
|
+
-- that fact was true, because the verb REFUSES any instant earlier than the
|
|
282
|
+
-- delegation it names.
|
|
283
|
+
CREATE OR REPLACE FUNCTION cell.yield_claim_with_delegated_work_outstanding(
|
|
284
|
+
p_work_claim_id uuid,
|
|
285
|
+
p_at timestamptz,
|
|
286
|
+
p_event_id uuid
|
|
287
|
+
)
|
|
288
|
+
RETURNS boolean
|
|
289
|
+
LANGUAGE plpgsql
|
|
290
|
+
AS $yield_handback$
|
|
291
|
+
DECLARE
|
|
292
|
+
v_outstanding text;
|
|
293
|
+
v_delegated timestamptz;
|
|
294
|
+
BEGIN
|
|
295
|
+
IF NOT EXISTS (SELECT 1 FROM cell.work_claim
|
|
296
|
+
WHERE work_claim_id = p_work_claim_id) THEN
|
|
297
|
+
RAISE EXCEPTION
|
|
298
|
+
'CLAIM_YIELD_HANDBACK_CLAIM_UNKNOWN:% — a handback is an act by a '
|
|
299
|
+
'principal holding an interval of responsibility, and there is no '
|
|
300
|
+
'such interval. Writing anyway would end responsibility nobody took.',
|
|
301
|
+
p_work_claim_id
|
|
302
|
+
USING ERRCODE = 'FC143';
|
|
303
|
+
END IF;
|
|
304
|
+
|
|
305
|
+
-- THE RECORDED FACT, and the whole of what this cause stands on: work
|
|
306
|
+
-- delegated out of this claim (§2.1 shape (a)) that a DIFFERENT principal is
|
|
307
|
+
-- still carrying. `active` and nothing else — a child that reached its own
|
|
308
|
+
-- terminal is work nobody is holding, so it is not something to hand back
|
|
309
|
+
-- with.
|
|
310
|
+
SELECT string_agg(child.task_id, ',' ORDER BY child.task_id),
|
|
311
|
+
max(child.claimed_at)
|
|
312
|
+
INTO v_outstanding, v_delegated
|
|
313
|
+
FROM cell.work_claim child
|
|
314
|
+
WHERE child.parent_work_claim_id = p_work_claim_id
|
|
315
|
+
AND child.state = 'active';
|
|
316
|
+
|
|
317
|
+
IF v_outstanding IS NULL THEN
|
|
318
|
+
RAISE EXCEPTION
|
|
319
|
+
'CLAIM_YIELD_HANDBACK_NOTHING_OUTSTANDING:% — this claim has no '
|
|
320
|
+
'delegated work anybody is carrying, so there is nothing to hand '
|
|
321
|
+
'back with. A holder that simply wants to stop is a DIFFERENT yield '
|
|
322
|
+
'cause with a different recorded fact behind it, and it has no verb '
|
|
323
|
+
'yet: a runtime that could reach this one would be ending its '
|
|
324
|
+
'principal''s responsibility on its own say-so, which is the whole '
|
|
325
|
+
'thing the cause registry exists to prevent.',
|
|
326
|
+
p_work_claim_id
|
|
327
|
+
USING ERRCODE = 'FC144';
|
|
328
|
+
END IF;
|
|
329
|
+
|
|
330
|
+
IF p_at < v_delegated THEN
|
|
331
|
+
RAISE EXCEPTION
|
|
332
|
+
'CLAIM_YIELD_HANDBACK_PRECEDES_THE_DELEGATION:%:% — the work being '
|
|
333
|
+
'handed back was delegated at %, and this yield is stamped %. A '
|
|
334
|
+
'parent cannot hand back work it had not yet delegated, and a '
|
|
335
|
+
'runtime that could pick the instant could write one by choosing an '
|
|
336
|
+
'earlier clock.',
|
|
337
|
+
p_work_claim_id, v_outstanding, v_delegated, p_at
|
|
338
|
+
USING ERRCODE = 'FC145';
|
|
339
|
+
END IF;
|
|
340
|
+
|
|
341
|
+
-- The basis is DERIVED from the work still outstanding — the task ids
|
|
342
|
+
-- themselves, not a count — so "why did responsibility pass" resolves to
|
|
343
|
+
-- rows an operator can go and read, rather than to a sentence a runtime
|
|
344
|
+
-- composed about itself. There is nowhere in this call to put one.
|
|
345
|
+
RETURN cell.record_claim_yield(
|
|
346
|
+
p_work_claim_id => p_work_claim_id,
|
|
347
|
+
p_basis => 'delegated_work_outstanding:' || v_outstanding,
|
|
348
|
+
p_at => p_at,
|
|
349
|
+
p_event_id => p_event_id);
|
|
350
|
+
END;
|
|
351
|
+
$yield_handback$;
|
|
352
|
+
|
|
353
|
+
COMMENT ON FUNCTION cell.yield_claim_with_delegated_work_outstanding IS
|
|
354
|
+
'Contract §1.2 / §2.1: the second declared cause of a claim yield — a parent '
|
|
355
|
+
'handing responsibility back while a different principal is still carrying '
|
|
356
|
+
'work delegated out of it. The basis is derived from that work; the '
|
|
357
|
+
'escalation such a parent also raises is deliberately never read (005).';
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
-- 018_receiptless_unknown.sql — THE RESOLVER'S VERB: the one `unknown` no
|
|
2
|
+
-- reconciler can ever read a remote about, and the judgment that closes it.
|
|
3
|
+
--
|
|
4
|
+
-- Contract: docs/a1-cell-work-spine-contract.md §1.2 (R3's interrupted attempts,
|
|
5
|
+
-- their deadline and their named resolver), §8/F2 leg (c) ("unknown past its
|
|
6
|
+
-- reconcile_by is RED"), FOUNDER RULING R3 ("bundled inseparably: effect
|
|
7
|
+
-- receipts — an irreversible external effect claims a durable receipt
|
|
8
|
+
-- in-substrate before firing; WITHOUT RECEIPTS, UNKNOWN IS PERMANENT BY
|
|
9
|
+
-- CONSTRUCTION").
|
|
10
|
+
-- Requires 001_core.sql (cell.execution_attempt), 008_effect_receipt.sql.
|
|
11
|
+
--
|
|
12
|
+
-- Re-apply: idempotent (CREATE OR REPLACE throughout).
|
|
13
|
+
-- Revert: DROP SCHEMA cell CASCADE; (this file installs nothing outside it)
|
|
14
|
+
--
|
|
15
|
+
-- WHY THIS FILE EXISTS, AND WHY THE SENTENCE IT IS BUILT ON IS A DERIVATION
|
|
16
|
+
--
|
|
17
|
+
-- "Without receipts, unknown is permanent by construction" is quoted everywhere
|
|
18
|
+
-- in this substrate as a WARNING — build the receipt lane or lose the ability to
|
|
19
|
+
-- reconcile. It is also a DERIVATION, and nothing in the cell had drawn it:
|
|
20
|
+
--
|
|
21
|
+
-- R3 makes the receipt the PRECONDITION of firing an irreversible effect.
|
|
22
|
+
-- An attempt that holds no receipt at all therefore fired none.
|
|
23
|
+
-- An attempt that fired no irreversible effect left nothing outside the cell
|
|
24
|
+
-- carrying a consequence of it.
|
|
25
|
+
-- So its outcome is not unknowable. It is `known_failure` — the work did not
|
|
26
|
+
-- land, and there is nobody to ask because there is nothing to ask about.
|
|
27
|
+
--
|
|
28
|
+
-- What keeps that from being a way to launder every unknown into a resolution is
|
|
29
|
+
-- the DEADLINE. Before `reconcile_by`, "somebody may yet find out" is the honest
|
|
30
|
+
-- state and R3 put a name on the row saying who. Past it, R3 says unknown is
|
|
31
|
+
-- never a tolerated state — and F2 leg (c) is the falsifier that says so out
|
|
32
|
+
-- loud. So this verb resolves exactly the intersection: no receipt, past the
|
|
33
|
+
-- deadline, with a named resolver on the row.
|
|
34
|
+
--
|
|
35
|
+
-- WHY IT IS THE RESOLVER'S AND NOT THE EXECUTOR'S
|
|
36
|
+
--
|
|
37
|
+
-- MEASURED, in both bake-off candidates: each of them reconciles an `unknown` by
|
|
38
|
+
-- reading the REMOTE's own append-only ledger for a receipt key it can name, and
|
|
39
|
+
-- each of them refuses this case explicitly. The dispatcher's own comment names
|
|
40
|
+
-- the owner — "an attempt with NO receipts is deliberately left alone: there is
|
|
41
|
+
-- no remote to ask about it, so its outcome stays unknown until its deadline and
|
|
42
|
+
-- the named resolver in the evaluator lane answers. Manufacturing 'known_failure'
|
|
43
|
+
-- for it here would be this process minting an unobserved fact."
|
|
44
|
+
--
|
|
45
|
+
-- That refusal is right, and this file is its other half. The name on the row is
|
|
46
|
+
-- a PRINCIPAL (`resolver_principal`), and an executor is not one; a runtime that
|
|
47
|
+
-- signed a principal's answer would be exactly the L1 crossing the evaluator seat
|
|
48
|
+
-- was extracted to close. The seat reads the name off the row, refuses a caller
|
|
49
|
+
-- that supplies a different one, and refuses a resolution taken early.
|
|
50
|
+
--
|
|
51
|
+
-- WHAT IS DELIBERATELY NOT HERE: A CALL-STACK WRITER GUARD
|
|
52
|
+
--
|
|
53
|
+
-- Every settlement lane in this substrate guards its table with
|
|
54
|
+
-- `cell.written_by` (002_claim.sql), and this one does not. That is a decision,
|
|
55
|
+
-- argued rather than skipped. `cell.execution_attempt` is the DISPOSABLE runtime
|
|
56
|
+
-- binding beneath the claim (R1): writing one is an executor's whole job, it is
|
|
57
|
+
-- the one-writer census's anti-vacuity probe, and both candidates legitimately
|
|
58
|
+
-- write `outcome_status` on it every time they reconcile a receipt against a
|
|
59
|
+
-- remote. A guard over that column would refuse the write that is properly
|
|
60
|
+
-- theirs, and a guard narrowed to "receiptless transitions only" would refuse
|
|
61
|
+
-- the frozen falsifier envelopes' own satisfied-controls, which state a resolved
|
|
62
|
+
-- world directly and must keep being able to.
|
|
63
|
+
--
|
|
64
|
+
-- So what the seat owns here is the JUDGMENT, not the column, and the judgment's
|
|
65
|
+
-- preconditions live in the verb where a caller meets them. An executor that
|
|
66
|
+
-- wrote this row itself would not be refused by the substrate; it would be
|
|
67
|
+
-- refused by the one-writer census reading its source, and by the fact that it
|
|
68
|
+
-- has no principal to sign as.
|
|
69
|
+
--
|
|
70
|
+
-- Declared failure vocabulary added by this file (SQLSTATE class FC; this lane
|
|
71
|
+
-- reserves FC150-FC159):
|
|
72
|
+
-- FC150 RECEIPTLESS_UNKNOWN_NOT_RESOLVABLE the attempt is not this verb's to
|
|
73
|
+
-- answer for: it is not there, or it
|
|
74
|
+
-- holds an effect receipt and is the
|
|
75
|
+
-- reconciler's
|
|
76
|
+
-- FC151 RECEIPTLESS_UNKNOWN_RESOLVER_MISMATCH a caller signing an answer the
|
|
77
|
+
-- row names somebody else for
|
|
78
|
+
-- FC152 RECEIPTLESS_UNKNOWN_NOT_YET_DUE a resolution taken before the deadline
|
|
79
|
+
-- the unknown was given
|
|
80
|
+
-- FC153 RECEIPTLESS_UNKNOWN_OUTCOME_CONTRADICTED a receiptless attempt already
|
|
81
|
+
-- carrying a known outcome that is NOT
|
|
82
|
+
-- the one R3 derives — two answers about
|
|
83
|
+
-- one runtime, which is a fact to
|
|
84
|
+
-- investigate rather than a value to
|
|
85
|
+
-- overwrite
|
|
86
|
+
|
|
87
|
+
-- ---------------------------------------------------------------------------
|
|
88
|
+
-- cell.v_receiptless_unknown_attempt — what the resolver may answer for
|
|
89
|
+
--
|
|
90
|
+
-- The seat's read surface, and a VIEW rather than a predicate spelled at the
|
|
91
|
+
-- call site for the reason every other lane in this substrate has one: the half
|
|
92
|
+
-- that FINDS the work and the verb that DOES it must agree on which rows
|
|
93
|
+
-- qualify, and two spellings of that eventually disagree in the direction nobody
|
|
94
|
+
-- sees — a seat that quietly stops resolving reads exactly like a cell with
|
|
95
|
+
-- nothing to resolve.
|
|
96
|
+
--
|
|
97
|
+
-- The deadline is deliberately NOT in this view. "Which attempts can only ever be
|
|
98
|
+
-- resolved by judgment" and "which of them are due" are different questions: the
|
|
99
|
+
-- first is a property of the world, the second is a property of the instant a
|
|
100
|
+
-- caller is reasoning at, and this substrate takes every instant as an explicit
|
|
101
|
+
-- argument rather than reading now() inside a definition. The verb applies the
|
|
102
|
+
-- clock; the seat's reader passes its own.
|
|
103
|
+
--
|
|
104
|
+
-- Nor does it re-check that the deadline and the resolver are PRESENT.
|
|
105
|
+
-- 001_core.sql already carries both as CHECK constraints — `unknown` holds
|
|
106
|
+
-- exactly when `reconcile_by` does and exactly when `resolver_principal` does —
|
|
107
|
+
-- so an `unknown` row without them cannot be inserted at all. Restating them
|
|
108
|
+
-- here would read as a predicate that selects a subset while selecting nothing
|
|
109
|
+
-- out, which is how a reader learns to distrust the ones that do.
|
|
110
|
+
-- ---------------------------------------------------------------------------
|
|
111
|
+
CREATE OR REPLACE VIEW cell.v_receiptless_unknown_attempt AS
|
|
112
|
+
SELECT
|
|
113
|
+
a.attempt_id,
|
|
114
|
+
a.org_id,
|
|
115
|
+
a.work_claim_id,
|
|
116
|
+
a.state,
|
|
117
|
+
a.reconcile_by,
|
|
118
|
+
a.resolver_principal
|
|
119
|
+
FROM cell.execution_attempt a
|
|
120
|
+
WHERE a.outcome_status = 'unknown'
|
|
121
|
+
AND NOT EXISTS (SELECT 1 FROM cell.effect_receipt r
|
|
122
|
+
WHERE r.attempt_id = a.attempt_id);
|
|
123
|
+
|
|
124
|
+
COMMENT ON VIEW cell.v_receiptless_unknown_attempt IS
|
|
125
|
+
'R3: the unknowns no reconciler can read a remote about, because the attempt '
|
|
126
|
+
'claimed no receipt and therefore fired no irreversible effect. Carries the '
|
|
127
|
+
'deadline and the named resolver; applying the clock is the caller''s.';
|
|
128
|
+
|
|
129
|
+
-- ------------------------------------------------------ the resolver's verb
|
|
130
|
+
--
|
|
131
|
+
-- RETURNS the outcome that STANDS on the row when this call is done, and returns
|
|
132
|
+
-- it whether this call wrote it or found it. That is a correction, and it was
|
|
133
|
+
-- MEASURED rather than reasoned: the first version refused an already-resolved
|
|
134
|
+
-- attempt by name, and a full dispatcher matrix run took a 500 out of the
|
|
135
|
+
-- candidate on `C2-KILL-DURING-RECOVERY` because a claim gets woken more than
|
|
136
|
+
-- once — at each bind, at each scope end, and on the tick — so two wakes over one
|
|
137
|
+
-- claim both survey the same overdue unknown and the second arrives after the
|
|
138
|
+
-- first has closed it. A benign re-resolution is not a caller reasoning about a
|
|
139
|
+
-- world that moved; it is the ordinary shape of a seat that may be woken by
|
|
140
|
+
-- anybody, and `cell.claim_effect_receipt` already carries the argument one lane
|
|
141
|
+
-- over: an idempotent restatement answers, a CONTRADICTION raises.
|
|
142
|
+
--
|
|
143
|
+
-- THE READ IS `FOR UPDATE` ON THE ATTEMPT ITSELF, not on the view, and that is
|
|
144
|
+
-- what makes the check and the write one decision. Two concurrent calls then
|
|
145
|
+
-- serialise on the row: the first resolves, the second reads `known_failure` and
|
|
146
|
+
-- answers it. A verb that re-read the view after somebody else's commit would
|
|
147
|
+
-- have the same race one layer down.
|
|
148
|
+
CREATE OR REPLACE FUNCTION cell.resolve_receiptless_unknown(
|
|
149
|
+
p_attempt_id uuid,
|
|
150
|
+
p_resolver_principal text,
|
|
151
|
+
p_resolved_at timestamptz
|
|
152
|
+
)
|
|
153
|
+
RETURNS text
|
|
154
|
+
LANGUAGE plpgsql
|
|
155
|
+
AS $resolve_receiptless$
|
|
156
|
+
DECLARE
|
|
157
|
+
v_outcome text;
|
|
158
|
+
v_named text;
|
|
159
|
+
v_due timestamptz;
|
|
160
|
+
v_receipts integer;
|
|
161
|
+
BEGIN
|
|
162
|
+
SELECT outcome_status, resolver_principal, reconcile_by
|
|
163
|
+
INTO v_outcome, v_named, v_due
|
|
164
|
+
FROM cell.execution_attempt
|
|
165
|
+
WHERE attempt_id = p_attempt_id
|
|
166
|
+
FOR UPDATE;
|
|
167
|
+
|
|
168
|
+
IF NOT FOUND THEN
|
|
169
|
+
RAISE EXCEPTION
|
|
170
|
+
'RECEIPTLESS_UNKNOWN_NOT_RESOLVABLE:% — no runtime binding under this '
|
|
171
|
+
'id, so there is no outcome for a resolver to answer for.',
|
|
172
|
+
p_attempt_id
|
|
173
|
+
USING ERRCODE = 'FC150';
|
|
174
|
+
END IF;
|
|
175
|
+
|
|
176
|
+
SELECT count(*) INTO v_receipts
|
|
177
|
+
FROM cell.effect_receipt r
|
|
178
|
+
WHERE r.attempt_id = p_attempt_id;
|
|
179
|
+
|
|
180
|
+
IF v_receipts > 0 THEN
|
|
181
|
+
RAISE EXCEPTION
|
|
182
|
+
'RECEIPTLESS_UNKNOWN_NOT_RESOLVABLE:%:% — this attempt holds effect '
|
|
183
|
+
'receipts, so its outcome is the RECONCILER''s to read off the '
|
|
184
|
+
'remote''s own ledger. Answering it from the absence of a receipt that '
|
|
185
|
+
'is not absent would overwrite an answer somebody can check with a '
|
|
186
|
+
'guess.',
|
|
187
|
+
p_attempt_id, v_receipts
|
|
188
|
+
USING ERRCODE = 'FC150';
|
|
189
|
+
END IF;
|
|
190
|
+
|
|
191
|
+
-- THE IDEMPOTENT ARM, and the contradiction beside it. A receiptless attempt
|
|
192
|
+
-- already carrying the outcome R3 derives is this verb's own work, seen a
|
|
193
|
+
-- second time — the ordinary result of one claim being woken more than once.
|
|
194
|
+
-- Any OTHER known outcome is two answers about one runtime with no ledger
|
|
195
|
+
-- behind either, and that is a fact to investigate.
|
|
196
|
+
IF v_outcome IS DISTINCT FROM 'unknown' THEN
|
|
197
|
+
IF v_outcome = 'known_failure' THEN
|
|
198
|
+
RETURN v_outcome;
|
|
199
|
+
END IF;
|
|
200
|
+
RAISE EXCEPTION
|
|
201
|
+
'RECEIPTLESS_UNKNOWN_OUTCOME_CONTRADICTED:%:% — this attempt claimed '
|
|
202
|
+
'no receipt, so R3 derives `known_failure` for it, and the row already '
|
|
203
|
+
'says ''%''. Two answers about one runtime with no remote behind either '
|
|
204
|
+
'is not a value to overwrite; it is a fact to investigate.',
|
|
205
|
+
p_attempt_id, coalesce(v_outcome, '<none>'), coalesce(v_outcome, '<none>')
|
|
206
|
+
USING ERRCODE = 'FC153';
|
|
207
|
+
END IF;
|
|
208
|
+
|
|
209
|
+
IF v_named IS DISTINCT FROM p_resolver_principal THEN
|
|
210
|
+
RAISE EXCEPTION
|
|
211
|
+
'RECEIPTLESS_UNKNOWN_RESOLVER_MISMATCH:%:% — R3 names the resolver ON '
|
|
212
|
+
'THE ROW (%), and this call signs as somebody else. The name is read '
|
|
213
|
+
'here and checked against the caller''s rather than taken from it: a '
|
|
214
|
+
'verb that accepted whatever principal it was handed would let any '
|
|
215
|
+
'waker sign any resolver''s answer.',
|
|
216
|
+
p_attempt_id, p_resolver_principal, v_named
|
|
217
|
+
USING ERRCODE = 'FC151';
|
|
218
|
+
END IF;
|
|
219
|
+
|
|
220
|
+
IF p_resolved_at < v_due THEN
|
|
221
|
+
RAISE EXCEPTION
|
|
222
|
+
'RECEIPTLESS_UNKNOWN_NOT_YET_DUE:%:% — the unknown''s deadline is % '
|
|
223
|
+
'and this resolution is earlier. Before the deadline, "somebody may '
|
|
224
|
+
'yet find out" is the honest state and the row says who; resolving '
|
|
225
|
+
'early closes the window R3 opened. Past it, unknown is never a '
|
|
226
|
+
'tolerated state, which is what makes this a judgment rather than a '
|
|
227
|
+
'read.',
|
|
228
|
+
p_attempt_id, p_resolved_at, v_due
|
|
229
|
+
USING ERRCODE = 'FC152';
|
|
230
|
+
END IF;
|
|
231
|
+
|
|
232
|
+
-- The deadline and the name go WITH the unknown they were there to bound: a
|
|
233
|
+
-- resolved outcome has nothing left to reconcile, and a deadline left behind
|
|
234
|
+
-- on it would sit in F2 leg (c)'s path forever, reporting a resolved attempt
|
|
235
|
+
-- as an overdue one.
|
|
236
|
+
UPDATE cell.execution_attempt
|
|
237
|
+
SET outcome_status = 'known_failure',
|
|
238
|
+
reconcile_by = NULL,
|
|
239
|
+
resolver_principal = NULL
|
|
240
|
+
WHERE attempt_id = p_attempt_id;
|
|
241
|
+
|
|
242
|
+
RETURN 'known_failure';
|
|
243
|
+
END;
|
|
244
|
+
$resolve_receiptless$;
|
|
245
|
+
|
|
246
|
+
COMMENT ON FUNCTION cell.resolve_receiptless_unknown IS
|
|
247
|
+
'FOUNDER RULING R3, derived: an attempt holding no receipt fired no '
|
|
248
|
+
'irreversible effect, so past its deadline its outcome is known_failure and '
|
|
249
|
+
'the named resolver on the row is who may say so.';
|