• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

knowledgepixels / nanopub-registry / 24087564875

07 Apr 2026 02:44PM UTC coverage: 32.913% (-0.01%) from 32.924%
24087564875

push

github

web-flow
Merge pull request #95 from knowledgepixels/fix/trust-ratio-leak

fix: retain only 10% of trust ratio when expanding trust paths

242 of 796 branches covered (30.4%)

Branch coverage included in aggregate %.

750 of 2218 relevant lines covered (33.81%)

5.73 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

12.64
src/main/java/com/knowledgepixels/registry/Task.java
1
package com.knowledgepixels.registry;
2

3
import com.knowledgepixels.registry.db.IndexInitializer;
4
import com.mongodb.client.ClientSession;
5
import com.mongodb.client.FindIterable;
6
import com.mongodb.client.MongoCollection;
7
import com.mongodb.client.MongoCursor;
8
import net.trustyuri.TrustyUriUtils;
9
import org.apache.commons.lang.Validate;
10
import org.bson.Document;
11
import org.eclipse.rdf4j.model.IRI;
12
import org.eclipse.rdf4j.model.Statement;
13
import org.nanopub.Nanopub;
14
import org.nanopub.extra.index.IndexUtils;
15
import org.nanopub.extra.index.NanopubIndex;
16
import org.nanopub.extra.security.KeyDeclaration;
17
import org.nanopub.extra.setting.IntroNanopub;
18
import org.nanopub.extra.setting.NanopubSetting;
19
import org.slf4j.Logger;
20
import org.slf4j.LoggerFactory;
21

22
import java.io.Serializable;
23
import java.time.ZonedDateTime;
24
import java.util.*;
25
import java.util.concurrent.atomic.AtomicLong;
26

27
import static com.knowledgepixels.registry.EntryStatus.*;
28
import static com.knowledgepixels.registry.NanopubLoader.*;
29
import static com.knowledgepixels.registry.RegistryDB.*;
30
import static com.knowledgepixels.registry.ServerStatus.*;
31
import static com.mongodb.client.model.Filters.eq;
32
import static com.mongodb.client.model.Sorts.*;
33

34
public enum Task implements Serializable {
6✔
35

36
    INIT_DB {
33✔
37
        public void run(ClientSession s, Document taskDoc) {
38
            setServerStatus(s, launching);
9✔
39

40
            increaseStateCounter(s);
6✔
41
            if (RegistryDB.isInitialized(s)) {
9!
42
                throw new RuntimeException("DB already initialized");
×
43
            }
44
            setValue(s, Collection.SERVER_INFO.toString(), "setupId", Math.abs(Utils.getRandom().nextLong()));
27✔
45
            setValue(s, Collection.SERVER_INFO.toString(), "testInstance", "true".equals(System.getenv("REGISTRY_TEST_INSTANCE")));
30✔
46
            schedule(s, LOAD_CONFIG);
9✔
47
        }
3✔
48

49
    },
50

51
    LOAD_CONFIG {
33✔
52
        public void run(ClientSession s, Document taskDoc) {
53
            if (getServerStatus(s) != launching) {
12!
54
                throw new IllegalTaskStatusException("Illegal status for this task: " + getServerStatus(s));
×
55
            }
56

57
            if (System.getenv("REGISTRY_COVERAGE_TYPES") != null) {
9!
58
                setValue(s, Collection.SERVER_INFO.toString(), "coverageTypes", System.getenv("REGISTRY_COVERAGE_TYPES"));
×
59
            }
60
            if (System.getenv("REGISTRY_COVERAGE_AGENTS") != null) {
9!
61
                setValue(s, Collection.SERVER_INFO.toString(), "coverageAgents", System.getenv("REGISTRY_COVERAGE_AGENTS"));
×
62
            }
63
            schedule(s, LOAD_SETTING);
9✔
64
        }
3✔
65

66
    },
67

68
    LOAD_SETTING {
33✔
69
        public void run(ClientSession s, Document taskDoc) throws Exception {
70
            if (getServerStatus(s) != launching) {
12!
71
                throw new IllegalTaskStatusException("Illegal status for this task: " + getServerStatus(s));
×
72
            }
73

74
            NanopubSetting settingNp = Utils.getSetting();
6✔
75
            String settingId = TrustyUriUtils.getArtifactCode(settingNp.getNanopub().getUri().stringValue());
18✔
76
            setValue(s, Collection.SETTING.toString(), "original", settingId);
18✔
77
            setValue(s, Collection.SETTING.toString(), "current", settingId);
18✔
78
            loadNanopub(s, settingNp.getNanopub());
15✔
79
            List<Document> bootstrapServices = new ArrayList<>();
12✔
80
            for (IRI i : settingNp.getBootstrapServices()) {
33✔
81
                bootstrapServices.add(new Document("_id", i.stringValue()));
27✔
82
            }
3✔
83
            // potentially currently hardcoded in the nanopub lib
84
            setValue(s, Collection.SETTING.toString(), "bootstrap-services", bootstrapServices);
18✔
85

86
            if (!"false".equals(System.getenv("REGISTRY_PERFORM_FULL_LOAD"))) {
15!
87
                schedule(s, LOAD_FULL.withDelay(60 * 1000));
15✔
88
            }
89

90
            setServerStatus(s, coreLoading);
9✔
91
            schedule(s, INIT_COLLECTIONS);
9✔
92
        }
3✔
93

94
    },
95

96
    INIT_COLLECTIONS {
33✔
97

98
        // DB read from:
99
        // DB write to:  trustPaths, endorsements, accounts
100
        // This state is periodically executed
101

102
        public void run(ClientSession s, Document taskDoc) throws Exception {
103
            if (getServerStatus(s) != coreLoading && getServerStatus(s) != updating) {
×
104
                throw new IllegalTaskStatusException("Illegal status for this task: " + getServerStatus(s));
×
105
            }
106

107
            IndexInitializer.initLoadingCollections(s);
×
108

109
            // since this may take long, we start with postfix "_loading"
110
            // and only at completion it's changed to trustPath, endorsements, accounts
111
            insert(s, "trustPaths_loading",
×
112
                    new Document("_id", "$")
113
                            .append("sorthash", "")
×
114
                            .append("agent", "$")
×
115
                            .append("pubkey", "$")
×
116
                            .append("depth", 0)
×
117
                            .append("ratio", 1.0d)
×
118
                            .append("type", "extended")
×
119
            );
120

121
            NanopubIndex agentIndex = IndexUtils.castToIndex(NanopubLoader.retrieveNanopub(s, Utils.getSetting().getAgentIntroCollection().stringValue()));
×
122
            loadNanopub(s, agentIndex);
×
123
            for (IRI el : agentIndex.getElements()) {
×
124
                String declarationAc = TrustyUriUtils.getArtifactCode(el.stringValue());
×
125
                Validate.notNull(declarationAc);
×
126

127
                insert(s, "endorsements_loading",
×
128
                        new Document("agent", "$")
129
                                .append("pubkey", "$")
×
130
                                .append("endorsedNanopub", declarationAc)
×
131
                                .append("source", getValue(s, Collection.SETTING.toString(), "current").toString())
×
132
                                .append("status", toRetrieve.getValue())
×
133

134
                );
135

136
            }
×
137
            insert(s, "accounts_loading",
×
138
                    new Document("agent", "$")
139
                            .append("pubkey", "$")
×
140
                            .append("status", visited.getValue())
×
141
                            .append("depth", 0)
×
142
            );
143

144
            log.info("Starting iteration at depth 0");
×
145
            schedule(s, LOAD_DECLARATIONS.with("depth", 1));
×
146
        }
×
147

148
        // At the end of this task, the base agent is initialized:
149
        // ------------------------------------------------------------
150
        //
151
        //              $$$$ ----endorses----> [intro]
152
        //              base                (to-retrieve)
153
        //              $$$$
154
        //            (visited)
155
        //
156
        //              [0] trust path
157
        //
158
        // ------------------------------------------------------------
159
        // Only one endorses-link to an introduction is shown here,
160
        // but there are typically several.
161

162
    },
163

164
    LOAD_DECLARATIONS {
33✔
165

166
        // In general, we have at this point accounts with
167
        // endorsement links to unvisited agent introductions:
168
        // ------------------------------------------------------------
169
        //
170
        //         o      ----endorses----> [intro]
171
        //    --> /#\  /o\___            (to-retrieve)
172
        //        / \  \_/^^^
173
        //         (visited)
174
        //
175
        //    ========[X] trust path
176
        //
177
        // ------------------------------------------------------------
178

179
        // DB read from: endorsements, trustEdges, accounts
180
        // DB write to:  endorsements, trustEdges, accounts
181

182
        public void run(ClientSession s, Document taskDoc) {
183

184
            int depth = taskDoc.getInteger("depth");
×
185

186
            if (has(s, "endorsements_loading", new Document("status", toRetrieve.getValue()))) {
×
187
                Document d = getOne(s, "endorsements_loading",
×
188
                        new DbEntryWrapper(toRetrieve).getDocument());
×
189

190
                IntroNanopub agentIntro = getAgentIntro(s, d.getString("endorsedNanopub"));
×
191
                if (agentIntro != null) {
×
192
                    String agentId = agentIntro.getUser().stringValue();
×
193

194
                    for (KeyDeclaration kd : agentIntro.getKeyDeclarations()) {
×
195
                        String sourceAgent = d.getString("agent");
×
196
                        Validate.notNull(sourceAgent);
×
197
                        String sourcePubkey = d.getString("pubkey");
×
198
                        Validate.notNull(sourcePubkey);
×
199
                        String sourceAc = d.getString("source");
×
200
                        Validate.notNull(sourceAc);
×
201
                        String agentPubkey = Utils.getHash(kd.getPublicKeyString());
×
202
                        Validate.notNull(agentPubkey);
×
203
                        Document trustEdge = new Document("fromAgent", sourceAgent)
×
204
                                .append("fromPubkey", sourcePubkey)
×
205
                                .append("toAgent", agentId)
×
206
                                .append("toPubkey", agentPubkey)
×
207
                                .append("source", sourceAc);
×
208
                        if (!has(s, "trustEdges", trustEdge)) {
×
209
                            boolean invalidated = has(s, "invalidations", new Document("invalidatedNp", sourceAc).append("invalidatingPubkey", sourcePubkey));
×
210
                            insert(s, "trustEdges", trustEdge.append("invalidated", invalidated));
×
211
                        }
212

213
                        Document agent = new Document("agent", agentId).append("pubkey", agentPubkey);
×
214
                        if (!has(s, "accounts_loading", agent)) {
×
215
                            insert(s, "accounts_loading", agent.append("status", seen.getValue()).append("depth", depth));
×
216
                        }
217
                    }
×
218

219
                    set(s, "endorsements_loading", d.append("status", retrieved.getValue()));
×
220
                } else {
×
221
                    set(s, "endorsements_loading", d.append("status", discarded.getValue()));
×
222
                }
223

224
                schedule(s, LOAD_DECLARATIONS.with("depth", depth));
×
225

226
            } else {
×
227
                schedule(s, EXPAND_TRUST_PATHS.with("depth", depth));
×
228
            }
229
        }
×
230

231
        // At the end of this step, the key declarations in the agent
232
        // introductions are loaded and the corresponding trust edges
233
        // established:
234
        // ------------------------------------------------------------
235
        //
236
        //        o      ----endorses----> [intro]
237
        //   --> /#\  /o\___                o
238
        //       / \  \_/^^^ ---trusts---> /#\  /o\___
239
        //        (visited)                / \  \_/^^^
240
        //                                   (seen)
241
        //
242
        //   ========[X] trust path
243
        //
244
        // ------------------------------------------------------------
245
        // Only one trust edge per introduction is shown here, but
246
        // there can be several.
247

248
    },
249

250
    EXPAND_TRUST_PATHS {
33✔
251

252
        // DB read from: accounts, trustPaths, trustEdges
253
        // DB write to:  accounts, trustPaths
254

255
        public void run(ClientSession s, Document taskDoc) {
256

257
            int depth = taskDoc.getInteger("depth");
×
258

259
            Document d = getOne(s, "accounts_loading",
×
260
                    new Document("status", visited.getValue())
×
261
                            .append("depth", depth - 1)
×
262
            );
263

264
            if (d != null) {
×
265

266
                String agentId = d.getString("agent");
×
267
                Validate.notNull(agentId);
×
268
                String pubkeyHash = d.getString("pubkey");
×
269
                Validate.notNull(pubkeyHash);
×
270

271
                Document trustPath = collection("trustPaths_loading").find(s,
×
272
                        new Document("agent", agentId).append("pubkey", pubkeyHash).append("type", "extended").append("depth", depth - 1)
×
273
                ).sort(orderBy(descending("ratio"), ascending("sorthash"))).first();
×
274

275
                if (trustPath == null) {
×
276
                    // Check it again in next iteration:
277
                    set(s, "accounts_loading", d.append("depth", depth));
×
278
                } else {
279
                    // Only first matching trust path is considered
280

281
                    Map<String, Document> newPaths = new HashMap<>();
×
282
                    Map<String, Set<String>> pubkeySets = new HashMap<>();
×
283
                    String currentSetting = getValue(s, Collection.SETTING.toString(), "current").toString();
×
284

285
                    MongoCursor<Document> edgeCursor = get(s, "trustEdges",
×
286
                            new Document("fromAgent", agentId)
287
                                    .append("fromPubkey", pubkeyHash)
×
288
                                    .append("invalidated", false)
×
289
                    );
290
                    while (edgeCursor.hasNext()) {
×
291
                        Document e = edgeCursor.next();
×
292

293
                        String agent = e.getString("toAgent");
×
294
                        Validate.notNull(agent);
×
295
                        String pubkey = e.getString("toPubkey");
×
296
                        Validate.notNull(pubkey);
×
297
                        String pathId = trustPath.getString("_id") + " " + agent + "|" + pubkey;
×
298
                        newPaths.put(pathId,
×
299
                                new Document("_id", pathId)
300
                                        .append("sorthash", Utils.getHash(currentSetting + " " + pathId))
×
301
                                        .append("agent", agent)
×
302
                                        .append("pubkey", pubkey)
×
303
                                        .append("depth", depth)
×
304
                                        .append("type", "extended")
×
305
                        );
306
                        if (!pubkeySets.containsKey(agent)) pubkeySets.put(agent, new HashSet<>());
×
307
                        pubkeySets.get(agent).add(pubkey);
×
308
                    }
×
309
                    for (String pathId : newPaths.keySet()) {
×
310
                        Document pd = newPaths.get(pathId);
×
311
                        // first divide by agents; then for each agent, divide by number of pubkeys:
312
                        double newRatio = (trustPath.getDouble("ratio") * 0.9) / pubkeySets.size() / pubkeySets.get(pd.getString("agent")).size();
×
313
                        insert(s, "trustPaths_loading", pd.append("ratio", newRatio));
×
314
                    }
×
315
                    // Retain only 10% of the ratio — the other 90% was distributed to children
316
                    double retainedRatio = trustPath.getDouble("ratio") * 0.1;
×
317
                    set(s, "trustPaths_loading", trustPath.append("type", "primary").append("ratio", retainedRatio));
×
318
                    set(s, "accounts_loading", d.append("status", expanded.getValue()));
×
319
                }
320
                schedule(s, EXPAND_TRUST_PATHS.with("depth", depth));
×
321

322
            } else {
×
323

324
                schedule(s, LOAD_CORE.with("depth", depth).append("load-count", 0));
×
325

326
            }
327

328
        }
×
329

330
        // At the end of this step, trust paths are updated to include
331
        // the new accounts:
332
        // ------------------------------------------------------------
333
        //
334
        //         o      ----endorses----> [intro]
335
        //    --> /#\  /o\___                o
336
        //        / \  \_/^^^ ---trusts---> /#\  /o\___
337
        //        (expanded)                / \  \_/^^^
338
        //                                    (seen)
339
        //
340
        //    ========[X]=====================[X+1] trust path
341
        //
342
        // ------------------------------------------------------------
343
        // Only one trust path is shown here, but they branch out if
344
        // several trust edges are present.
345

346
    },
347

348
    LOAD_CORE {
33✔
349

350
        // From here on, we refocus on the head of the trust paths:
351
        // ------------------------------------------------------------
352
        //
353
        //         o
354
        //    --> /#\  /o\___
355
        //        / \  \_/^^^
356
        //          (seen)
357
        //
358
        //    ========[X] trust path
359
        //
360
        // ------------------------------------------------------------
361

362
        // DB read from: accounts, trustPaths, endorsements, lists
363
        // DB write to:  accounts, endorsements, lists
364

365
        public void run(ClientSession s, Document taskDoc) {
366

367
            int depth = taskDoc.getInteger("depth");
×
368
            int loadCount = taskDoc.getInteger("load-count");
×
369

370
            Document agentAccount = getOne(s, "accounts_loading",
×
371
                    new Document("depth", depth).append("status", seen.getValue()));
×
372
            final String agentId;
373
            final String pubkeyHash;
374
            final Document trustPath;
375
            if (agentAccount != null) {
×
376
                agentId = agentAccount.getString("agent");
×
377
                Validate.notNull(agentId);
×
378
                pubkeyHash = agentAccount.getString("pubkey");
×
379
                Validate.notNull(pubkeyHash);
×
380
                trustPath = getOne(s, "trustPaths_loading",
×
381
                        new Document("depth", depth)
×
382
                                .append("agent", agentId)
×
383
                                .append("pubkey", pubkeyHash)
×
384
                );
385
            } else {
386
                agentId = null;
×
387
                pubkeyHash = null;
×
388
                trustPath = null;
×
389
            }
390

391
            if (agentAccount == null) {
×
392
                schedule(s, FINISH_ITERATION.with("depth", depth).append("load-count", loadCount));
×
393
            } else if (trustPath == null) {
×
394
                // Account was seen but has no trust path at this depth; skip it
395
                set(s, "accounts_loading", agentAccount.append("status", skipped.getValue()));
×
396
                schedule(s, LOAD_CORE.with("depth", depth).append("load-count", loadCount));
×
397
            } else if (trustPath.getDouble("ratio") < MIN_TRUST_PATH_RATIO) {
×
398
                set(s, "accounts_loading", agentAccount.append("status", skipped.getValue()));
×
399
                Document d = new Document("pubkey", pubkeyHash).append("type", INTRO_TYPE_HASH);
×
400
                if (!has(s, "lists", d)) {
×
401
                    insert(s, "lists", d.append("status", encountered.getValue()));
×
402
                }
403
                schedule(s, LOAD_CORE.with("depth", depth).append("load-count", loadCount + 1));
×
404
            } else {
×
405
                // TODO check intro limit
406
                Document introList = new Document()
×
407
                        .append("pubkey", pubkeyHash)
×
408
                        .append("type", INTRO_TYPE_HASH)
×
409
                        .append("status", loading.getValue());
×
410
                if (!has(s, "lists", new Document("pubkey", pubkeyHash).append("type", INTRO_TYPE_HASH))) {
×
411
                    insert(s, "lists", introList);
×
412
                }
413

414
                // No checksum skip in LOAD_CORE: the endorsement extraction logic (below) needs to
415
                // see every nanopub to populate endorsements_loading, which is rebuilt from scratch each UPDATE.
416
                try (var stream = NanopubLoader.retrieveNanopubsFromPeers(INTRO_TYPE_HASH, pubkeyHash)) {
×
417
                    NanopubLoader.loadStreamInParallel(stream, np -> {
×
418
                        try (ClientSession ws = RegistryDB.getClient().startSession()) {
×
419
                            loadNanopub(ws, np, pubkeyHash, INTRO_TYPE);
×
420
                        }
421
                    });
×
422
                }
423

424
                set(s, "lists", introList.append("status", loaded.getValue()));
×
425

426
                // TODO check endorsement limit
427
                Document endorseList = new Document()
×
428
                        .append("pubkey", pubkeyHash)
×
429
                        .append("type", ENDORSE_TYPE_HASH)
×
430
                        .append("status", loading.getValue());
×
431
                if (!has(s, "lists", new Document("pubkey", pubkeyHash).append("type", ENDORSE_TYPE_HASH))) {
×
432
                    insert(s, "lists", endorseList);
×
433
                }
434

435
                try (var stream = NanopubLoader.retrieveNanopubsFromPeers(ENDORSE_TYPE_HASH, pubkeyHash)) {
×
436
                    stream.forEach(m -> {
×
437
                        if (!m.isSuccess())
×
438
                            throw new AbortingTaskException("Failed to download nanopub; aborting task...");
×
439
                        Nanopub nanopub = m.getNanopub();
×
440
                        loadNanopub(s, nanopub, pubkeyHash, ENDORSE_TYPE);
×
441
                        String sourceNpId = TrustyUriUtils.getArtifactCode(nanopub.getUri().stringValue());
×
442
                        Validate.notNull(sourceNpId);
×
443
                        for (Statement st : nanopub.getAssertion()) {
×
444
                            if (!st.getPredicate().equals(Utils.APPROVES_OF)) continue;
×
445
                            if (!(st.getObject() instanceof IRI)) continue;
×
446
                            if (!agentId.equals(st.getSubject().stringValue())) continue;
×
447
                            String objStr = st.getObject().stringValue();
×
448
                            if (!TrustyUriUtils.isPotentialTrustyUri(objStr)) continue;
×
449
                            String endorsedNpId = TrustyUriUtils.getArtifactCode(objStr);
×
450
                            Validate.notNull(endorsedNpId);
×
451
                            Document endorsement = new Document("agent", agentId)
×
452
                                    .append("pubkey", pubkeyHash)
×
453
                                    .append("endorsedNanopub", endorsedNpId)
×
454
                                    .append("source", sourceNpId);
×
455
                            if (!has(s, "endorsements_loading", endorsement)) {
×
456
                                insert(s, "endorsements_loading",
×
457
                                        endorsement.append("status", toRetrieve.getValue()));
×
458
                            }
459
                        }
×
460
                    });
×
461
                }
462

463
                set(s, "lists", endorseList.append("status", loaded.getValue()));
×
464

465
                Document df = new Document("pubkey", pubkeyHash).append("type", "$");
×
466
                if (!has(s, "lists", df)) insert(s, "lists",
×
467
                        df.append("status", encountered.getValue()));
×
468

469
                set(s, "accounts_loading", agentAccount.append("status", visited.getValue()));
×
470

471
                schedule(s, LOAD_CORE.with("depth", depth).append("load-count", loadCount + 1));
×
472
            }
473

474
        }
×
475

476
        // At the end of this step, we have added new endorsement
477
        // links to yet-to-retrieve agent introductions:
478
        // ------------------------------------------------------------
479
        //
480
        //         o      ----endorses----> [intro]
481
        //    --> /#\  /o\___            (to-retrieve)
482
        //        / \  \_/^^^
483
        //         (visited)
484
        //
485
        //    ========[X] trust path
486
        //
487
        // ------------------------------------------------------------
488
        // Only one endorsement is shown here, but there are typically
489
        // several.
490

491
    },
492

493
    FINISH_ITERATION {
33✔
494
        public void run(ClientSession s, Document taskDoc) {
495

496
            int depth = taskDoc.getInteger("depth");
×
497
            int loadCount = taskDoc.getInteger("load-count");
×
498

499
            if (loadCount == 0) {
×
500
                log.info("No new cores loaded; finishing iteration");
×
501
                schedule(s, CALCULATE_TRUST_SCORES);
×
502
            } else if (depth == MAX_TRUST_PATH_DEPTH) {
×
503
                log.info("Maximum depth reached: {}", depth);
×
504
                schedule(s, CALCULATE_TRUST_SCORES);
×
505
            } else {
506
                log.info("Progressing iteration at depth {}", depth + 1);
×
507
                schedule(s, LOAD_DECLARATIONS.with("depth", depth + 1));
×
508
            }
509

510
        }
×
511

512
    },
513

514
    CALCULATE_TRUST_SCORES {
33✔
515

516
        // DB read from: accounts, trustPaths
517
        // DB write to:  accounts
518

519
        public void run(ClientSession s, Document taskDoc) {
520

521
            Document d = getOne(s, "accounts_loading", new Document("status", expanded.getValue()));
×
522

523
            if (d == null) {
×
524
                schedule(s, AGGREGATE_AGENTS);
×
525
            } else {
526
                double ratio = 0.0;
×
527
                Map<String, Boolean> seenPathElements = new HashMap<>();
×
528
                int pathCount = 0;
×
529
                MongoCursor<Document> trustPaths = collection("trustPaths_loading").find(s,
×
530
                        new Document("agent", d.get("agent").toString()).append("pubkey", d.get("pubkey").toString())
×
531
                ).sort(orderBy(ascending("depth"), descending("ratio"), ascending("sorthash"))).cursor();
×
532
                while (trustPaths.hasNext()) {
×
533
                    Document trustPath = trustPaths.next();
×
534
                    ratio += trustPath.getDouble("ratio");
×
535
                    boolean independentPath = true;
×
536
                    String[] pathElements = trustPath.getString("_id").split(" ");
×
537
                    // Iterate over path elements, ignoring first (root) and last (this agent/pubkey):
538
                    for (int i = 1; i < pathElements.length - 1; i++) {
×
539
                        String p = pathElements[i];
×
540
                        if (seenPathElements.containsKey(p)) {
×
541
                            independentPath = false;
×
542
                            break;
×
543
                        }
544
                        seenPathElements.put(p, true);
×
545
                    }
546
                    if (independentPath) pathCount += 1;
×
547
                }
×
548
                double rawQuota = GLOBAL_QUOTA * ratio;
×
549
                int quota = (int) rawQuota;
×
550
                if (rawQuota < MIN_USER_QUOTA) {
×
551
                    quota = MIN_USER_QUOTA;
×
552
                } else if (rawQuota > MAX_USER_QUOTA) {
×
553
                    quota = MAX_USER_QUOTA;
×
554
                }
555
                set(s, "accounts_loading",
×
556
                        d.append("status", processed.getValue())
×
557
                                .append("ratio", ratio)
×
558
                                .append("pathCount", pathCount)
×
559
                                .append("quota", quota)
×
560
                );
561
                schedule(s, CALCULATE_TRUST_SCORES);
×
562
            }
563

564
        }
×
565

566
    },
567

568
    AGGREGATE_AGENTS {
33✔
569

570
        // DB read from: accounts, agents
571
        // DB write to:  accounts, agents
572

573
        public void run(ClientSession s, Document taskDoc) {
574

575
            Document a = getOne(s, "accounts_loading", new Document("status", processed.getValue()));
×
576
            if (a == null) {
×
577
                schedule(s, ASSIGN_PUBKEYS);
×
578
            } else {
579
                Document agentId = new Document("agent", a.get("agent").toString()).append("status", processed.getValue());
×
580
                int count = 0;
×
581
                int pathCountSum = 0;
×
582
                double totalRatio = 0.0d;
×
583
                MongoCursor<Document> agentAccounts = collection("accounts_loading").find(s, agentId).cursor();
×
584
                while (agentAccounts.hasNext()) {
×
585
                    Document d = agentAccounts.next();
×
586
                    count++;
×
587
                    pathCountSum += d.getInteger("pathCount");
×
588
                    totalRatio += d.getDouble("ratio");
×
589
                }
×
590
                collection("accounts_loading").updateMany(s, agentId, new Document("$set",
×
591
                        new DbEntryWrapper(aggregated).getDocument()));
×
592
                insert(s, "agents_loading",
×
593
                        agentId.append("accountCount", count)
×
594
                                .append("avgPathCount", (double) pathCountSum / count)
×
595
                                .append("totalRatio", totalRatio)
×
596
                );
597
                schedule(s, AGGREGATE_AGENTS);
×
598
            }
599

600
        }
×
601

602
    },
603

604
    ASSIGN_PUBKEYS {
33✔
605

606
        // DB read from: accounts
607
        // DB write to:  accounts
608

609
        public void run(ClientSession s, Document taskDoc) {
610

611
            Document a = getOne(s, "accounts_loading", new DbEntryWrapper(aggregated).getDocument());
×
612
            if (a == null) {
×
613
                schedule(s, DETERMINE_UPDATES);
×
614
            } else {
615
                Document pubkeyId = new Document("pubkey", a.get("pubkey").toString());
×
616
                if (collection("accounts_loading").countDocuments(s, pubkeyId) == 1) {
×
617
                    collection("accounts_loading").updateMany(s, pubkeyId,
×
618
                            new Document("$set", new DbEntryWrapper(approved).getDocument()));
×
619
                } else {
620
                    // TODO At the moment all get marked as 'contested'; implement more nuanced algorithm
621
                    collection("accounts_loading").updateMany(s, pubkeyId, new Document("$set",
×
622
                            new DbEntryWrapper(contested).getDocument()));
×
623
                }
624
                schedule(s, ASSIGN_PUBKEYS);
×
625
            }
626

627
        }
×
628

629
    },
630

631
    DETERMINE_UPDATES {
33✔
632

633
        // DB read from: accounts
634
        // DB write to:  accounts
635

636
        public void run(ClientSession s, Document taskDoc) {
637

638
            // TODO Handle contested accounts properly:
639
            for (Document d : collection("accounts_loading").find(
×
640
                    new DbEntryWrapper(approved).getDocument())) {
×
641
                // TODO Consider quota too:
642
                Document accountId = new Document("agent", d.get("agent").toString()).append("pubkey", d.get("pubkey").toString());
×
643
                if (collection(Collection.ACCOUNTS.toString()) == null || !has(s, Collection.ACCOUNTS.toString(),
×
644
                        accountId.append("status", loaded.getValue()))) {
×
645
                    set(s, "accounts_loading", d.append("status", toLoad.getValue()));
×
646
                } else {
647
                    set(s, "accounts_loading", d.append("status", loaded.getValue()));
×
648
                }
649
            }
×
650
            schedule(s, FINALIZE_TRUST_STATE);
×
651

652
        }
×
653

654
    },
655

656
    FINALIZE_TRUST_STATE {
33✔
657
        // We do this is a separate task/transaction, because if we do it at the beginning of RELEASE_DATA, that task hangs and cannot
658
        // properly re-run (as some renaming outside of transactions will have taken place).
659
        public void run(ClientSession s, Document taskDoc) {
660
            String newTrustStateHash = RegistryDB.calculateTrustStateHash(s);
×
661
            String previousTrustStateHash = (String) getValue(s, Collection.SERVER_INFO.toString(), "trustStateHash");  // may be null
×
662
            setValue(s, Collection.SERVER_INFO.toString(), "lastTrustStateUpdate", ZonedDateTime.now().toString());
×
663

664
            schedule(s, RELEASE_DATA.with("newTrustStateHash", newTrustStateHash).append("previousTrustStateHash", previousTrustStateHash));
×
665
        }
×
666

667
    },
668

669
    RELEASE_DATA {
33✔
670
        public void run(ClientSession s, Document taskDoc) {
671
            ServerStatus status = getServerStatus(s);
×
672

673
            String newTrustStateHash = taskDoc.get("newTrustStateHash").toString();
×
674
            String previousTrustStateHash = taskDoc.getString("previousTrustStateHash");  // may be null
×
675

676
            // Renaming collections is run outside of a transaction, but is idempotent operation, so can safely be retried if task fails:
677
            rename("accounts_loading", Collection.ACCOUNTS.toString());
×
678
            rename("trustPaths_loading", "trustPaths");
×
679
            rename("agents_loading", Collection.AGENTS.toString());
×
680
            rename("endorsements_loading", "endorsements");
×
681

682
            if (previousTrustStateHash == null || !previousTrustStateHash.equals(newTrustStateHash)) {
×
683
                increaseStateCounter(s);
×
684
                setValue(s, Collection.SERVER_INFO.toString(), "trustStateHash", newTrustStateHash);
×
685
                insert(s, "debug_trustPaths", new Document()
×
686
                        .append("trustStateTxt", DebugPage.getTrustPathsTxt(s))
×
687
                        .append("trustStateHash", newTrustStateHash)
×
688
                        .append("trustStateCounter", getValue(s, Collection.SERVER_INFO.toString(), "trustStateCounter"))
×
689
                );
690
            }
691

692
            if (status == coreLoading) {
×
693
                setServerStatus(s, coreReady);
×
694
            } else {
695
                setServerStatus(s, ready);
×
696
            }
697

698
            // Run update after 1h:
699
            schedule(s, UPDATE.withDelay(60 * 60 * 1000));
×
700
        }
×
701

702
    },
703

704
    UPDATE {
33✔
705
        public void run(ClientSession s, Document taskDoc) {
706
            ServerStatus status = getServerStatus(s);
×
707
            if (status == ready || status == coreReady) {
×
708
                setServerStatus(s, updating);
×
709
                schedule(s, INIT_COLLECTIONS);
×
710
            } else {
711
                log.info("Postponing update; currently in status {}", status);
×
712
                schedule(s, UPDATE.withDelay(10 * 60 * 1000));
×
713
            }
714

715
        }
×
716

717
    },
718

719
    LOAD_FULL {
33✔
720
        public void run(ClientSession s, Document taskDoc) {
721
            if ("false".equals(System.getenv("REGISTRY_PERFORM_FULL_LOAD"))) return;
15!
722

723
            ServerStatus status = getServerStatus(s);
9✔
724
            if (status != coreReady && status != ready && status != updating) {
27!
725
                log.info("Server currently not ready; checking again later");
9✔
726
                schedule(s, LOAD_FULL.withDelay(60 * 1000));
15✔
727
                return;
3✔
728
            }
729

730
            Document a = getOne(s, Collection.ACCOUNTS.toString(), new DbEntryWrapper(toLoad).getDocument());
×
731
            if (a == null) {
×
732
                log.info("Nothing to load");
×
733
                if (status == coreReady) {
×
734
                    log.info("Full load finished");
×
735
                    setServerStatus(s, ready);
×
736
                }
737
                log.info("Scheduling optional loading checks");
×
738
                schedule(s, RUN_OPTIONAL_LOAD.withDelay(100));
×
739
            } else {
740
                final String ph = a.getString("pubkey");
×
741
                if (!ph.equals("$")) {
×
742
                    long startTime = System.nanoTime();
×
743
                    AtomicLong totalLoaded = new AtomicLong(0);
×
744

745
                    // Load per covered type (or "$" if no restriction) with checksum skip-ahead
746
                    for (String typeHash : getLoadTypeHashes(s, ph)) {
×
747
                        String checksums = buildChecksumFallbacks(s, ph, typeHash);
×
748
                        try (var stream = NanopubLoader.retrieveNanopubsFromPeers(typeHash, ph, checksums)) {
×
749
                            NanopubLoader.loadStreamInParallel(stream, np -> {
×
750
                                if (!CoverageFilter.isCovered(np)) return;
×
751
                                try (ClientSession ws = RegistryDB.getClient().startSession()) {
×
752
                                    loadNanopub(ws, np, ph, "$");
×
753
                                    totalLoaded.incrementAndGet();
×
754
                                }
755
                            });
×
756
                        }
757
                    }
×
758

759
                    double timeSeconds = (System.nanoTime() - startTime) * 1e-9;
×
760
                    log.info("Loaded {} nanopubs in {}s, {} np/s",
×
761
                            totalLoaded.get(), timeSeconds, String.format("%.2f", totalLoaded.get() / timeSeconds));
×
762
                }
763

764
                Document l = getOne(s, "lists", new Document().append("pubkey", ph).append("type", "$"));
×
765
                if (l != null) set(s, "lists", l.append("status", loaded.getValue()));
×
766
                set(s, Collection.ACCOUNTS.toString(), a.append("status", loaded.getValue()));
×
767

768
                schedule(s, LOAD_FULL.withDelay(100));
×
769
            }
770
        }
×
771

772
        @Override
773
        public boolean runAsTransaction() {
774
            // TODO Make this a transaction once we connect to other Nanopub Registry instances:
775
            return false;
×
776
        }
777

778
    },
779

780
    RUN_OPTIONAL_LOAD {
33✔
781

782
        private static final int BATCH_SIZE = Integer.parseInt(
15✔
783
                Utils.getEnv("REGISTRY_OPTIONAL_LOAD_BATCH_SIZE", "100"));
3✔
784

785
        public void run(ClientSession s, Document taskDoc) {
786
            AtomicLong totalLoaded = new AtomicLong(0);
×
787

788
            // Phase 1: Process encountered intro lists (core loading)
789
            while (totalLoaded.get() < BATCH_SIZE) {
×
790
                Document di = getOne(s, "lists", new Document("type", INTRO_TYPE_HASH).append("status", encountered.getValue()));
×
791
                if (di == null) break;
×
792

793
                final String pubkeyHash = di.getString("pubkey");
×
794
                Validate.notNull(pubkeyHash);
×
795
                log.info("Optional core loading: {}", pubkeyHash);
×
796

797
                String introChecksums = buildChecksumFallbacks(s, pubkeyHash, INTRO_TYPE_HASH);
×
798
                try (var stream = NanopubLoader.retrieveNanopubsFromPeers(INTRO_TYPE_HASH, pubkeyHash, introChecksums)) {
×
799
                    NanopubLoader.loadStreamInParallel(stream, np -> {
×
800
                        try (ClientSession ws = RegistryDB.getClient().startSession()) {
×
801
                            loadNanopub(ws, np, pubkeyHash, INTRO_TYPE);
×
802
                            totalLoaded.incrementAndGet();
×
803
                        }
804
                    });
×
805
                }
806
                set(s, "lists", di.append("status", loaded.getValue()));
×
807

808
                String endorseChecksums = buildChecksumFallbacks(s, pubkeyHash, ENDORSE_TYPE_HASH);
×
809
                try (var stream = NanopubLoader.retrieveNanopubsFromPeers(ENDORSE_TYPE_HASH, pubkeyHash, endorseChecksums)) {
×
810
                    NanopubLoader.loadStreamInParallel(stream, np -> {
×
811
                        try (ClientSession ws = RegistryDB.getClient().startSession()) {
×
812
                            loadNanopub(ws, np, pubkeyHash, ENDORSE_TYPE);
×
813
                            totalLoaded.incrementAndGet();
×
814
                        }
815
                    });
×
816
                }
817

818
                Document de = new Document("pubkey", pubkeyHash).append("type", ENDORSE_TYPE_HASH);
×
819
                if (has(s, "lists", de)) {
×
820
                    set(s, "lists", de.append("status", loaded.getValue()));
×
821
                } else {
822
                    insert(s, "lists", de.append("status", loaded.getValue()));
×
823
                }
824

825
                Document df = new Document("pubkey", pubkeyHash).append("type", "$");
×
826
                if (!has(s, "lists", df)) insert(s, "lists", df.append("status", encountered.getValue()));
×
827
            }
×
828

829
            // Phase 2: Process encountered full lists (if budget remains)
830
            while (totalLoaded.get() < BATCH_SIZE) {
×
831
                Document df = getOne(s, "lists", new Document("type", "$").append("status", encountered.getValue()));
×
832
                if (df == null) break;
×
833

834
                final String pubkeyHash = df.getString("pubkey");
×
835
                log.info("Optional full loading: {}", pubkeyHash);
×
836

837
                // Load per covered type (or "$" if no restriction) with checksum skip-ahead
838
                for (String typeHash : getLoadTypeHashes(s, pubkeyHash)) {
×
839
                    String checksums = buildChecksumFallbacks(s, pubkeyHash, typeHash);
×
840
                    try (var stream = NanopubLoader.retrieveNanopubsFromPeers(typeHash, pubkeyHash, checksums)) {
×
841
                        NanopubLoader.loadStreamInParallel(stream, np -> {
×
842
                            if (!CoverageFilter.isCovered(np)) return;
×
843
                            try (ClientSession ws = RegistryDB.getClient().startSession()) {
×
844
                                loadNanopub(ws, np, pubkeyHash, "$");
×
845
                                totalLoaded.incrementAndGet();
×
846
                            }
847
                        });
×
848
                    }
849
                }
×
850

851
                set(s, "lists", df.append("status", loaded.getValue()));
×
852
            }
×
853

854
            if (totalLoaded.get() > 0) {
×
855
                log.info("Optional load batch completed: {} nanopubs across multiple pubkeys", totalLoaded.get());
×
856
            }
857

858
            if (prioritizeAllPubkeys()) {
×
859
                // Check if there are more pubkeys waiting to be processed
860
                boolean moreWork = has(s, "lists", new Document("type", INTRO_TYPE_HASH).append("status", encountered.getValue()))
×
861
                        || has(s, "lists", new Document("type", "$").append("status", encountered.getValue()));
×
862
                if (moreWork) {
×
863
                    // Continue processing without a full CHECK_NEW cycle in between.
864
                    // CHECK_NEW will run naturally once all encountered lists are processed.
865
                    schedule(s, RUN_OPTIONAL_LOAD.withDelay(10));
×
866
                } else {
867
                    schedule(s, CHECK_NEW.withDelay(500));
×
868
                }
869
            } else {
×
870
                // Throttled: yield to CHECK_NEW after each batch to prioritize approved pubkeys
871
                schedule(s, CHECK_NEW.withDelay(500));
×
872
            }
873
        }
×
874

875
    },
876

877
    CHECK_NEW {
33✔
878
        public void run(ClientSession s, Document taskDoc) {
879
            RegistryPeerConnector.checkPeers(s);
×
880
            // Keep legacy connection during transition period:
881
            LegacyConnector.checkForNewNanopubs(s);
×
882
            // TODO Somehow throttle the loading of such potentially non-approved nanopubs
883

884
            schedule(s, LOAD_FULL.withDelay(100));
×
885
        }
×
886

887
        @Override
888
        public boolean runAsTransaction() {
889
            // Peer sync includes long-running streaming fetches that would exceed
890
            // MongoDB's transaction timeout; each operation is individually safe.
891
            return false;
×
892
        }
893

894
    };
895

896
    private static final Logger log = LoggerFactory.getLogger(Task.class);
9✔
897

898
    public abstract void run(ClientSession s, Document taskDoc) throws Exception;
899

900
    public boolean runAsTransaction() {
901
        return true;
×
902
    }
903

904
    Document asDocument() {
905
        return withDelay(0L);
12✔
906
    }
907

908
    private Document withDelay(long delay) {
909
        // TODO Rename "not-before" to "notBefore" for consistency with other field names
910
        return new Document()
15✔
911
                .append("not-before", System.currentTimeMillis() + delay)
21✔
912
                .append("action", name());
6✔
913
    }
914

915
    private Document with(String key, Object value) {
916
        return asDocument().append(key, value);
×
917
    }
918

919
    private static boolean prioritizeAllPubkeys() {
920
        return "true".equals(System.getenv("REGISTRY_PRIORITIZE_ALL_PUBKEYS"));
×
921
    }
922

923
    /**
924
     * Returns the type hashes to load for a given pubkey. When coverage is unrestricted,
925
     * returns just "$" (all types in one request). When restricted, returns each covered
926
     * type hash for per-type fetching with checksum skip-ahead.
927
     *
928
     * TODO: Fetching "$" from peers with type restrictions will only return their covered
929
     * types, not all types. To get full coverage, we'd need to fetch per-type from such peers.
930
     * Additionally, checksum-based skip-ahead won't work correctly against such peers, because
931
     * their "$" list has different checksums due to the differing type subset. This means full
932
     * re-downloads on every cycle. Per-type fetching would solve both issues.
933
     */
934
    private static java.util.List<String> getLoadTypeHashes(ClientSession s, String pubkeyHash) {
935
        if (CoverageFilter.coversAllTypes()) {
×
936
            return java.util.List.of("$");
×
937
        }
938
        return java.util.List.copyOf(CoverageFilter.getCoveredTypeHashes());
×
939
    }
940

941
    // TODO Move these to setting:
942
    private static final int MAX_TRUST_PATH_DEPTH = 10;
943
    private static final double MIN_TRUST_PATH_RATIO = 0.00000001;
944
    //private static final double MIN_TRUST_PATH_RATIO = 0.01; // For testing
945
    private static final int GLOBAL_QUOTA = 100000000;
946
    private static final int MIN_USER_QUOTA = 100;
947
    private static final int MAX_USER_QUOTA = 10000;
948

949
    private static MongoCollection<Document> tasksCollection = collection(Collection.TASKS.toString());
15✔
950

951
    private static volatile String currentTaskName;
952
    private static volatile long currentTaskStartTime;
953

954
    public static String getCurrentTaskName() {
955
        return currentTaskName;
×
956
    }
957

958
    public static long getCurrentTaskStartTime() {
959
        return currentTaskStartTime;
×
960
    }
961

962
    /**
963
     * The super important base entry point!
964
     */
965
    static void runTasks() {
966
        try (ClientSession s = RegistryDB.getClient().startSession()) {
×
967
            if (!RegistryDB.isInitialized(s)) {
×
968
                schedule(s, INIT_DB); // does not yet execute, only schedules
×
969
            }
970

971
            while (true) {
972
                FindIterable<Document> taskResult = tasksCollection.find(s).sort(ascending("not-before"));
×
973
                Document taskDoc = taskResult.first();
×
974
                long sleepTime = 10;
×
975
                if (taskDoc != null && taskDoc.getLong("not-before") < System.currentTimeMillis()) {
×
976
                    Task task = valueOf(taskDoc.getString("action"));
×
977
                    log.info("Running task: {}", task.name());
×
978
                    if (task.runAsTransaction()) {
×
979
                        try {
980
                            s.startTransaction();
×
981
                            log.info("Transaction started");
×
982
                            runTask(task, taskDoc);
×
983
                            s.commitTransaction();
×
984
                            log.info("Transaction committed");
×
985
                        } catch (Exception ex) {
×
986
                            log.info("Aborting transaction", ex);
×
987
                            abortTransaction(s, ex.getMessage());
×
988
                            log.info("Transaction aborted");
×
989
                            sleepTime = 1000;
×
990
                        } finally {
991
                            cleanTransactionWithRetry(s);
×
992
                        }
×
993
                    } else {
994
                        try {
995
                            runTask(task, taskDoc);
×
996
                        } catch (Exception ex) {
×
997
                            log.info("Transaction failed", ex);
×
998
                        }
×
999
                    }
1000
                }
1001
                try {
1002
                    Thread.sleep(sleepTime);
×
1003
                } catch (InterruptedException ex) {
×
1004
                    // ignore
1005
                }
×
1006
            }
×
1007
        }
1008
    }
1009

1010
    static void runTask(Task task, Document taskDoc) throws Exception {
1011
        try (ClientSession s = RegistryDB.getClient().startSession()) {
9✔
1012
            log.info("Executing task: {}", task.name());
15✔
1013
            currentTaskName = task.name();
9✔
1014
            currentTaskStartTime = System.currentTimeMillis();
6✔
1015
            task.run(s, taskDoc);
12✔
1016
            tasksCollection.deleteOne(s, eq("_id", taskDoc.get("_id")));
27✔
1017
            log.info("Task {} completed and removed from queue.", task.name());
15✔
1018
        } finally {
1019
            currentTaskName = null;
6✔
1020
        }
1021
    }
3✔
1022

1023
    public static void abortTransaction(ClientSession mongoSession, String message) {
1024
        boolean successful = false;
×
1025
        while (!successful) {
×
1026
            try {
1027
                if (mongoSession.hasActiveTransaction()) {
×
1028
                    mongoSession.abortTransaction();
×
1029
                }
1030
                successful = true;
×
1031
            } catch (Exception ex) {
×
1032
                log.info("Aborting transaction failed. ", ex);
×
1033
                try {
1034
                    Thread.sleep(1000);
×
1035
                } catch (InterruptedException iex) {
×
1036
                    // ignore
1037
                }
×
1038
            }
×
1039
        }
1040
    }
×
1041

1042
    public synchronized static void cleanTransactionWithRetry(ClientSession mongoSession) {
1043
        boolean successful = false;
×
1044
        while (!successful) {
×
1045
            try {
1046
                if (mongoSession.hasActiveTransaction()) {
×
1047
                    mongoSession.abortTransaction();
×
1048
                }
1049
                successful = true;
×
1050
            } catch (Exception ex) {
×
1051
                log.info("Cleaning transaction failed. ", ex);
×
1052
                try {
1053
                    Thread.sleep(1000);
×
1054
                } catch (InterruptedException iex) {
×
1055
                    // ignore
1056
                }
×
1057
            }
×
1058
        }
1059
    }
×
1060

1061
    private static IntroNanopub getAgentIntro(ClientSession mongoSession, String nanopubId) {
1062
        IntroNanopub agentIntro = new IntroNanopub(NanopubLoader.retrieveNanopub(mongoSession, nanopubId));
×
1063
        if (agentIntro.getUser() == null) return null;
×
1064
        loadNanopub(mongoSession, agentIntro.getNanopub());
×
1065
        return agentIntro;
×
1066
    }
1067

1068
    private static void setServerStatus(ClientSession mongoSession, ServerStatus status) {
1069
        setValue(mongoSession, Collection.SERVER_INFO.toString(), "status", status.toString());
21✔
1070
    }
3✔
1071

1072
    private static ServerStatus getServerStatus(ClientSession mongoSession) {
1073
        Object status = getValue(mongoSession, Collection.SERVER_INFO.toString(), "status");
18✔
1074
        if (status == null) {
6!
1075
            throw new RuntimeException("Illegal DB state: serverInfo status unavailable");
×
1076
        }
1077
        return ServerStatus.valueOf(status.toString());
12✔
1078
    }
1079

1080
    private static void schedule(ClientSession mongoSession, Task task) {
1081
        schedule(mongoSession, task.asDocument());
12✔
1082
    }
3✔
1083

1084
    private static void schedule(ClientSession mongoSession, Document taskDoc) {
1085
        log.info("Scheduling task: {}", taskDoc.getString("action"));
18✔
1086
        tasksCollection.insertOne(mongoSession, taskDoc);
12✔
1087
    }
3✔
1088

1089
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc