@mowaos/host-browser 0.8.0 → 0.9.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/conformance/host-suite.mjs +50 -0
- package/dist/outbox.d.ts +10 -2
- package/dist/outbox.d.ts.map +1 -1
- package/dist/outbox.js +93 -79
- package/dist/outbox.js.map +1 -1
- package/package.json +1 -1
|
@@ -270,6 +270,7 @@ export function hostSuite(name, { lib, wasmPkg, makeStorage, clearSteps }) {
|
|
|
270
270
|
flowHash,
|
|
271
271
|
ctx: { asOf: 1000, contextRefs: {} },
|
|
272
272
|
});
|
|
273
|
+
await outbox.idle(); // the host's own pass after the commit
|
|
273
274
|
|
|
274
275
|
// Advance with MISSING invoice fact -> guard fails, routes to REVIEW
|
|
275
276
|
const commit = await host.advanceSession({
|
|
@@ -289,6 +290,7 @@ export function hostSuite(name, { lib, wasmPkg, makeStorage, clearSteps }) {
|
|
|
289
290
|
},
|
|
290
291
|
ctx: { asOf: 2000, contextRefs: {} },
|
|
291
292
|
});
|
|
293
|
+
await outbox.idle(); // the host's own pass after the commit
|
|
292
294
|
|
|
293
295
|
assert.equal(commit.newSession.state, "REVIEW");
|
|
294
296
|
assert.equal(commit.audit.guardFailed, true);
|
|
@@ -324,6 +326,7 @@ export function hostSuite(name, { lib, wasmPkg, makeStorage, clearSteps }) {
|
|
|
324
326
|
flowHash,
|
|
325
327
|
ctx: { asOf: 1, contextRefs: {} },
|
|
326
328
|
});
|
|
329
|
+
await outbox.idle(); // the host's own pass after the commit
|
|
327
330
|
|
|
328
331
|
const commit = await host.advanceSession({
|
|
329
332
|
sessionId,
|
|
@@ -340,6 +343,7 @@ export function hostSuite(name, { lib, wasmPkg, makeStorage, clearSteps }) {
|
|
|
340
343
|
facts: { facts: { "doc:invoice": "MISSING" } },
|
|
341
344
|
ctx: { asOf: 2, contextRefs: {} },
|
|
342
345
|
});
|
|
346
|
+
await outbox.idle(); // the host's own pass after the commit
|
|
343
347
|
|
|
344
348
|
const draftEffectId = commit.outbox[0].id;
|
|
345
349
|
|
|
@@ -405,6 +409,7 @@ export function hostSuite(name, { lib, wasmPkg, makeStorage, clearSteps }) {
|
|
|
405
409
|
flowHash,
|
|
406
410
|
ctx: { asOf: 1, contextRefs: {} },
|
|
407
411
|
});
|
|
412
|
+
await outbox.idle(); // the host's own pass after the commit
|
|
408
413
|
|
|
409
414
|
// Advance creates REQUEST_REVIEW which has NO handler registered
|
|
410
415
|
await host.advanceSession({
|
|
@@ -422,6 +427,7 @@ export function hostSuite(name, { lib, wasmPkg, makeStorage, clearSteps }) {
|
|
|
422
427
|
facts: { facts: { "doc:invoice": "MISSING" } },
|
|
423
428
|
ctx: { asOf: 2, contextRefs: {} },
|
|
424
429
|
});
|
|
430
|
+
await outbox.idle(); // the host's own pass after the commit
|
|
425
431
|
|
|
426
432
|
// Intake effect was already handled during startSession
|
|
427
433
|
assert.equal(intakeHandled, true);
|
|
@@ -475,6 +481,7 @@ export function hostSuite(name, { lib, wasmPkg, makeStorage, clearSteps }) {
|
|
|
475
481
|
flowHash,
|
|
476
482
|
ctx: { asOf: 1, contextRefs: {} },
|
|
477
483
|
});
|
|
484
|
+
await outbox.idle(); // the host's own pass after the commit
|
|
478
485
|
|
|
479
486
|
await host.advanceSession({
|
|
480
487
|
sessionId,
|
|
@@ -491,6 +498,7 @@ export function hostSuite(name, { lib, wasmPkg, makeStorage, clearSteps }) {
|
|
|
491
498
|
facts: { facts: { "doc:invoice": "MISSING" } },
|
|
492
499
|
ctx: { asOf: 2, contextRefs: {} },
|
|
493
500
|
});
|
|
501
|
+
await outbox.idle(); // the host's own pass after the commit
|
|
494
502
|
|
|
495
503
|
const pending = await storage.getPendingOutbox(10, Date.now() + 20000);
|
|
496
504
|
const unhandled = pending.find((p) => p.effect.kind === "REQUEST_REVIEW");
|
|
@@ -690,6 +698,7 @@ export function hostSuite(name, { lib, wasmPkg, makeStorage, clearSteps }) {
|
|
|
690
698
|
flowHash,
|
|
691
699
|
ctx: { asOf: 1000, contextRefs: {} },
|
|
692
700
|
});
|
|
701
|
+
await outbox.idle(); // the host's own pass after the commit
|
|
693
702
|
|
|
694
703
|
// Run outbox dispatch to move effect to AWAIT_CONFIRMATION
|
|
695
704
|
await outbox.dispatchPending();
|
|
@@ -906,5 +915,46 @@ export function hostSuite(name, { lib, wasmPkg, makeStorage, clearSteps }) {
|
|
|
906
915
|
assert.equal("anchors" in (await bareHost.exportVerificationBundle(["S_ANC"])), false);
|
|
907
916
|
await assert.rejects(bareHost.importAnchors([a0]), /does not support anchors/);
|
|
908
917
|
});
|
|
918
|
+
|
|
919
|
+
it("17. dispatchPending during a running pass waits for it and drains; idle() waits for quiet", async () => {
|
|
920
|
+
// Slow storage, as a networked database is: the host's own pass after a commit is
|
|
921
|
+
// still running when the caller asks to dispatch. Before 0.8.1 that call returned
|
|
922
|
+
// at once, having done nothing.
|
|
923
|
+
const base = await makeStorage();
|
|
924
|
+
const storage = new Proxy(base, {
|
|
925
|
+
get(target, key) {
|
|
926
|
+
const value = target[key];
|
|
927
|
+
if (key === "getPendingOutbox") {
|
|
928
|
+
return async (...args) => {
|
|
929
|
+
await new Promise((r) => setTimeout(r, 20));
|
|
930
|
+
return value.apply(target, args);
|
|
931
|
+
};
|
|
932
|
+
}
|
|
933
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
934
|
+
},
|
|
935
|
+
});
|
|
936
|
+
const outbox = new OutboxDispatcher(storage);
|
|
937
|
+
const host = new MowaBrowserHost(kernel, { storage, outboxDispatcher: outbox });
|
|
938
|
+
const { flowHash } = await host.installFlow(sampleFlow());
|
|
939
|
+
let calls = 0;
|
|
940
|
+
outbox.registerHandler("EMIT_INTAKE_NOTIFICATION", async () => {
|
|
941
|
+
calls += 1;
|
|
942
|
+
return "SUCCESS";
|
|
943
|
+
});
|
|
944
|
+
const ev = (id) => ({
|
|
945
|
+
id, type: "INIT", source: "test", caseId: `CASE_${id}`, timestamp: 1, idempotencyKey: `k_${id}`,
|
|
946
|
+
actor: { type: "SYSTEM", id: "S" }, payload: {},
|
|
947
|
+
});
|
|
948
|
+
|
|
949
|
+
const first = await host.startSession({ sessionId: "S_DISPATCH", event: ev("A"), flowHash, ctx: { asOf: 1, contextRefs: {} } });
|
|
950
|
+
await outbox.dispatchPending();
|
|
951
|
+
assert.equal((await storage.getOutbox(first.outbox[0].id)).status, "DISPATCHED", "dispatched when dispatchPending returns");
|
|
952
|
+
assert.equal(calls, 1, "and only once");
|
|
953
|
+
|
|
954
|
+
const second = await host.startSession({ sessionId: "S_IDLE", event: ev("B"), flowHash, ctx: { asOf: 1, contextRefs: {} } });
|
|
955
|
+
await outbox.idle();
|
|
956
|
+
assert.equal((await storage.getOutbox(second.outbox[0].id)).status, "DISPATCHED", "the host's own pass is done when idle() returns");
|
|
957
|
+
assert.equal(calls, 2);
|
|
958
|
+
});
|
|
909
959
|
});
|
|
910
960
|
}
|
package/dist/outbox.d.ts
CHANGED
|
@@ -30,7 +30,8 @@ export declare class OutboxDispatcher {
|
|
|
30
30
|
private readonly maxBackoffMs;
|
|
31
31
|
private readonly unhandledGraceIntervalMs;
|
|
32
32
|
private readonly maxUnhandledGraceMs;
|
|
33
|
-
|
|
33
|
+
/** The pass in progress, if any. */
|
|
34
|
+
private running;
|
|
34
35
|
constructor(storage: MowaStorage, options?: OutboxDispatcherOptions);
|
|
35
36
|
registerHandler(kind: string, handler: EffectHandler): void;
|
|
36
37
|
/**
|
|
@@ -57,12 +58,19 @@ export declare class OutboxDispatcher {
|
|
|
57
58
|
*/
|
|
58
59
|
requeueEffect(outboxId: string): Promise<void>;
|
|
59
60
|
/**
|
|
60
|
-
* Drain pending outbox records
|
|
61
|
+
* Drain pending outbox records, outside the session lock. If a pass is already
|
|
62
|
+
* running (the host starts one after every commit), this waits for it and then runs
|
|
63
|
+
* its own, so it never returns before the records due when it was called have been
|
|
64
|
+
* tried. Before 0.8.1 it returned at once in that case, having done nothing, which
|
|
65
|
+
* only showed with storage slower than memory.
|
|
61
66
|
*/
|
|
62
67
|
dispatchPending(): Promise<{
|
|
63
68
|
processed: number;
|
|
64
69
|
failed: number;
|
|
65
70
|
pending: number;
|
|
66
71
|
}>;
|
|
72
|
+
/** Resolves once no pass is running: after a commit, to see settled effect statuses. */
|
|
73
|
+
idle(): Promise<void>;
|
|
74
|
+
private runPass;
|
|
67
75
|
}
|
|
68
76
|
//# sourceMappingURL=outbox.d.ts.map
|
package/dist/outbox.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outbox.d.ts","sourceRoot":"","sources":["../src/outbox.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,MAAM,MAAM,qBAAqB,GAC7B,SAAS,GACT,oBAAoB,GACpB,OAAO,CAAC;AAEZ,MAAM,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,YAAY,KAAK,OAAO,CAAC,qBAAqB,CAAC,CAAC;AAErF,MAAM,WAAW,uBAAuB;IACtC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,qBAAa,gBAAgB;
|
|
1
|
+
{"version":3,"file":"outbox.d.ts","sourceRoot":"","sources":["../src/outbox.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,MAAM,MAAM,qBAAqB,GAC7B,SAAS,GACT,oBAAoB,GACpB,OAA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QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAoBpD;;;;;;OAMG;IACG,eAAe,IAAI,OAAO,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAWxF,wFAAwF;IAClF,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;YAIb,OAAO;CAgGtB"}
|
package/dist/outbox.js
CHANGED
|
@@ -18,7 +18,8 @@ export class OutboxDispatcher {
|
|
|
18
18
|
maxBackoffMs;
|
|
19
19
|
unhandledGraceIntervalMs;
|
|
20
20
|
maxUnhandledGraceMs;
|
|
21
|
-
|
|
21
|
+
/** The pass in progress, if any. */
|
|
22
|
+
running = null;
|
|
22
23
|
constructor(storage, options = {}) {
|
|
23
24
|
this.storage = storage;
|
|
24
25
|
this.maxAttempts = options.maxAttempts ?? 5;
|
|
@@ -101,92 +102,84 @@ export class OutboxDispatcher {
|
|
|
101
102
|
});
|
|
102
103
|
}
|
|
103
104
|
/**
|
|
104
|
-
* Drain pending outbox records
|
|
105
|
+
* Drain pending outbox records, outside the session lock. If a pass is already
|
|
106
|
+
* running (the host starts one after every commit), this waits for it and then runs
|
|
107
|
+
* its own, so it never returns before the records due when it was called have been
|
|
108
|
+
* tried. Before 0.8.1 it returned at once in that case, having done nothing, which
|
|
109
|
+
* only showed with storage slower than memory.
|
|
105
110
|
*/
|
|
106
111
|
async dispatchPending() {
|
|
107
|
-
|
|
108
|
-
|
|
112
|
+
while (this.running)
|
|
113
|
+
await this.running.catch(() => undefined);
|
|
114
|
+
const pass = this.runPass();
|
|
115
|
+
this.running = pass;
|
|
116
|
+
try {
|
|
117
|
+
return await pass;
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
if (this.running === pass)
|
|
121
|
+
this.running = null;
|
|
109
122
|
}
|
|
110
|
-
|
|
123
|
+
}
|
|
124
|
+
/** Resolves once no pass is running: after a commit, to see settled effect statuses. */
|
|
125
|
+
async idle() {
|
|
126
|
+
while (this.running)
|
|
127
|
+
await this.running.catch(() => undefined);
|
|
128
|
+
}
|
|
129
|
+
async runPass() {
|
|
111
130
|
let processed = 0;
|
|
112
131
|
let failed = 0;
|
|
113
132
|
let pending = 0;
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
failed++;
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
await this.storage.updateOutboxStatus(record.outboxId, "PENDING", {
|
|
133
|
-
nextAttemptAt: now + this.unhandledGraceIntervalMs,
|
|
134
|
-
unhandledSince,
|
|
135
|
-
});
|
|
136
|
-
pending++;
|
|
137
|
-
}
|
|
138
|
-
continue;
|
|
133
|
+
const now = Date.now();
|
|
134
|
+
const records = await this.storage.getPendingOutbox(this.batchSize, now);
|
|
135
|
+
for (const record of records) {
|
|
136
|
+
const handler = this.handlers.get(record.effect.kind);
|
|
137
|
+
if (!handler) {
|
|
138
|
+
// Effect kind has no handler registered.
|
|
139
|
+
// In MV3 service workers, handlers might register after initial wake-up.
|
|
140
|
+
// Push nextAttemptAt forward so it leaves the due window without blocking other records.
|
|
141
|
+
const unhandledSince = record.unhandledSince ?? now;
|
|
142
|
+
if (now - unhandledSince >= this.maxUnhandledGraceMs) {
|
|
143
|
+
await this.storage.updateOutboxStatus(record.outboxId, "FAILED_DLQ", {
|
|
144
|
+
lastAttemptAt: now,
|
|
145
|
+
lastError: `UNHANDLED_EFFECT_KIND: No handler registered for '${record.effect.kind}' within grace period`,
|
|
146
|
+
});
|
|
147
|
+
failed++;
|
|
139
148
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
lastAttemptAt: Date.now(),
|
|
147
|
-
});
|
|
148
|
-
processed++;
|
|
149
|
-
}
|
|
150
|
-
else if (result === "AWAIT_CONFIRMATION") {
|
|
151
|
-
// Awaiting operator approval: move to AWAIT_CONFIRMATION, do NOT increment attempts!
|
|
152
|
-
await this.storage.updateOutboxStatus(record.outboxId, "AWAIT_CONFIRMATION", {
|
|
153
|
-
lastAttemptAt: Date.now(),
|
|
154
|
-
});
|
|
155
|
-
pending++;
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
// Handler explicitly requested RETRY
|
|
159
|
-
const nextAttempts = record.attempts + 1;
|
|
160
|
-
if (nextAttempts >= this.maxAttempts) {
|
|
161
|
-
await this.storage.updateOutboxStatus(record.outboxId, "FAILED_DLQ", {
|
|
162
|
-
attempts: nextAttempts,
|
|
163
|
-
lastAttemptAt: Date.now(),
|
|
164
|
-
lastError: `Exceeded max retry attempts (${this.maxAttempts})`,
|
|
165
|
-
});
|
|
166
|
-
failed++;
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
const delay = this.calculateBackoff(nextAttempts);
|
|
170
|
-
await this.storage.updateOutboxStatus(record.outboxId, "PENDING", {
|
|
171
|
-
attempts: nextAttempts,
|
|
172
|
-
nextAttemptAt: Date.now() + delay,
|
|
173
|
-
lastAttemptAt: Date.now(),
|
|
174
|
-
lastError: "Handler requested retry",
|
|
175
|
-
});
|
|
176
|
-
pending++;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
149
|
+
else {
|
|
150
|
+
await this.storage.updateOutboxStatus(record.outboxId, "PENDING", {
|
|
151
|
+
nextAttemptAt: now + this.unhandledGraceIntervalMs,
|
|
152
|
+
unhandledSince,
|
|
153
|
+
});
|
|
154
|
+
pending++;
|
|
179
155
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
try {
|
|
159
|
+
// Attempt dispatch
|
|
160
|
+
const result = await handler(record);
|
|
161
|
+
if (result === "SUCCESS") {
|
|
162
|
+
// Success: mark DISPATCHED without incrementing retry attempts
|
|
163
|
+
await this.storage.updateOutboxStatus(record.outboxId, "DISPATCHED", {
|
|
164
|
+
lastAttemptAt: Date.now(),
|
|
165
|
+
});
|
|
166
|
+
processed++;
|
|
167
|
+
}
|
|
168
|
+
else if (result === "AWAIT_CONFIRMATION") {
|
|
169
|
+
// Awaiting operator approval: move to AWAIT_CONFIRMATION, do NOT increment attempts!
|
|
170
|
+
await this.storage.updateOutboxStatus(record.outboxId, "AWAIT_CONFIRMATION", {
|
|
171
|
+
lastAttemptAt: Date.now(),
|
|
172
|
+
});
|
|
173
|
+
pending++;
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
// Handler explicitly requested RETRY
|
|
183
177
|
const nextAttempts = record.attempts + 1;
|
|
184
|
-
|
|
185
|
-
if (isDlq) {
|
|
178
|
+
if (nextAttempts >= this.maxAttempts) {
|
|
186
179
|
await this.storage.updateOutboxStatus(record.outboxId, "FAILED_DLQ", {
|
|
187
180
|
attempts: nextAttempts,
|
|
188
181
|
lastAttemptAt: Date.now(),
|
|
189
|
-
lastError:
|
|
182
|
+
lastError: `Exceeded max retry attempts (${this.maxAttempts})`,
|
|
190
183
|
});
|
|
191
184
|
failed++;
|
|
192
185
|
}
|
|
@@ -196,15 +189,36 @@ export class OutboxDispatcher {
|
|
|
196
189
|
attempts: nextAttempts,
|
|
197
190
|
nextAttemptAt: Date.now() + delay,
|
|
198
191
|
lastAttemptAt: Date.now(),
|
|
199
|
-
lastError:
|
|
192
|
+
lastError: "Handler requested retry",
|
|
200
193
|
});
|
|
201
194
|
pending++;
|
|
202
195
|
}
|
|
203
196
|
}
|
|
204
197
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
198
|
+
catch (err) {
|
|
199
|
+
// Handler threw exception during execution
|
|
200
|
+
const errMsg = err instanceof Error ? err.message : String(err);
|
|
201
|
+
const nextAttempts = record.attempts + 1;
|
|
202
|
+
const isDlq = nextAttempts >= this.maxAttempts;
|
|
203
|
+
if (isDlq) {
|
|
204
|
+
await this.storage.updateOutboxStatus(record.outboxId, "FAILED_DLQ", {
|
|
205
|
+
attempts: nextAttempts,
|
|
206
|
+
lastAttemptAt: Date.now(),
|
|
207
|
+
lastError: errMsg,
|
|
208
|
+
});
|
|
209
|
+
failed++;
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
const delay = this.calculateBackoff(nextAttempts);
|
|
213
|
+
await this.storage.updateOutboxStatus(record.outboxId, "PENDING", {
|
|
214
|
+
attempts: nextAttempts,
|
|
215
|
+
nextAttemptAt: Date.now() + delay,
|
|
216
|
+
lastAttemptAt: Date.now(),
|
|
217
|
+
lastError: errMsg,
|
|
218
|
+
});
|
|
219
|
+
pending++;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
208
222
|
}
|
|
209
223
|
return { processed, failed, pending };
|
|
210
224
|
}
|
package/dist/outbox.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outbox.js","sourceRoot":"","sources":["../src/outbox.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAqBH,MAAM,OAAO,gBAAgB;
|
|
1
|
+
{"version":3,"file":"outbox.js","sourceRoot":"","sources":["../src/outbox.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAqBH,MAAM,OAAO,gBAAgB;IAYR;IAXF,QAAQ,GAAG,IAAI,GAAG,EAAyB,CAAC;IAC5C,WAAW,CAAS;IACpB,SAAS,CAAS;IAClB,aAAa,CAAS;IACtB,YAAY,CAAS;IACrB,wBAAwB,CAAS;IACjC,mBAAmB,CAAS;IAC7C,oCAAoC;IAC5B,OAAO,GAA2E,IAAI,CAAC;IAE/F,YACmB,OAAoB,EACrC,UAAmC,EAAE;QADpB,YAAO,GAAP,OAAO,CAAa;QAGrC,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,CAAC,CAAC;QAC5C,IAAI,C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