@webex/plugin-meetings 3.13.0-next.12 → 3.13.0-next.14

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.
Files changed (100) hide show
  1. package/.repo-context.json +577 -0
  2. package/.sdd/manifest.json +1320 -428
  3. package/AGENTS.md +528 -72
  4. package/dist/aiEnableRequest/index.js +1 -1
  5. package/dist/breakouts/breakout.js +1 -1
  6. package/dist/breakouts/index.js +1 -1
  7. package/dist/config.js +1 -1
  8. package/dist/interpretation/index.js +1 -1
  9. package/dist/interpretation/siLanguage.js +1 -1
  10. package/dist/webinar/index.js +1 -1
  11. package/docs/adr/0001-migrate-existing-docs-into-sdd.md +141 -0
  12. package/docs/adr/index.md +26 -0
  13. package/docs/architecture.md +816 -0
  14. package/docs/getting-started.md +177 -0
  15. package/docs/index.md +53 -0
  16. package/docs/specs/README.md +126 -0
  17. package/package.json +21 -21
  18. package/schemas/repo-context.schema.json +796 -0
  19. package/src/aiEnableRequest/docs/README.md +376 -0
  20. package/src/annotation/docs/README.md +402 -0
  21. package/src/breakouts/docs/README.md +643 -0
  22. package/src/controls-options-manager/docs/README.md +365 -0
  23. package/src/hashTree/docs/README.md +566 -0
  24. package/src/interceptors/docs/README.md +434 -0
  25. package/src/interpretation/docs/README.md +420 -0
  26. package/src/locus-info/docs/README.md +609 -0
  27. package/src/media/docs/README.md +488 -0
  28. package/src/meeting/docs/README.md +834 -0
  29. package/src/meeting-info/docs/README.md +352 -0
  30. package/src/meetings/docs/README.md +549 -0
  31. package/src/member/docs/README.md +347 -0
  32. package/src/members/docs/README.md +514 -0
  33. package/src/metrics/docs/README.md +287 -0
  34. package/src/multistream/docs/README.md +523 -0
  35. package/src/personal-meeting-room/docs/README.md +322 -0
  36. package/src/reachability/docs/README.md +548 -0
  37. package/src/reactions/docs/README.md +296 -0
  38. package/src/reconnection-manager/docs/README.md +485 -0
  39. package/src/recording-controller/docs/README.md +335 -0
  40. package/src/roap/docs/README.md +444 -0
  41. package/src/webinar/docs/README.md +425 -0
  42. package/.sdd/templates/.source.json +0 -30
  43. package/.sdd/templates/component-repo/module-docs/module-spec-quality.md +0 -111
  44. package/.sdd/templates/component-repo/module-docs/module-spec.template.md +0 -321
  45. package/.sdd/templates/component-repo/reference-docs/adr/_adr-example.md +0 -59
  46. package/.sdd/templates/component-repo/reference-docs/patterns/_pattern-example.md +0 -49
  47. package/.sdd/templates/component-repo/reference-docs/rules/_rule-example.md +0 -42
  48. package/.sdd/templates/component-repo/standing-docs/AGENTS.template.md +0 -120
  49. package/.sdd/templates/component-repo/standing-docs/ARCHITECTURE.template.md +0 -206
  50. package/.sdd/templates/component-repo/standing-docs/CONTRACTS.template.md +0 -90
  51. package/.sdd/templates/component-repo/standing-docs/DATA_MODEL.template.md +0 -68
  52. package/.sdd/templates/component-repo/standing-docs/GETTING_STARTED.template.md +0 -111
  53. package/.sdd/templates/component-repo/standing-docs/GLOSSARY.template.md +0 -57
  54. package/.sdd/templates/component-repo/standing-docs/REVIEW_CHECKLIST.template.md +0 -69
  55. package/.sdd/templates/component-repo/standing-docs/RULES.template.md +0 -96
  56. package/.sdd/templates/component-repo/standing-docs/SECURITY.template.md +0 -84
  57. package/.sdd/templates/component-repo/standing-docs/SERVICE_STATE.template.md +0 -82
  58. package/.sdd/templates/component-repo/standing-docs/SPEC_INDEX.template.md +0 -94
  59. package/.sdd/templates/component-repo/standing-docs/TEST_INDEX.template.md +0 -64
  60. package/.sdd/templates/component-repo/template-map.json +0 -112
  61. package/ai-docs/ARCHITECTURE.md +0 -208
  62. package/ai-docs/CONTRACTS.md +0 -267
  63. package/ai-docs/DATA_MODEL.md +0 -64
  64. package/ai-docs/GETTING_STARTED.md +0 -73
  65. package/ai-docs/GLOSSARY.md +0 -56
  66. package/ai-docs/REVIEW_CHECKLIST.md +0 -45
  67. package/ai-docs/RULES.md +0 -79
  68. package/ai-docs/SECURITY.md +0 -74
  69. package/ai-docs/SERVICE_STATE.md +0 -59
  70. package/ai-docs/SPEC_INDEX.md +0 -85
  71. package/ai-docs/TEST_INDEX.md +0 -45
  72. package/ai-docs/adr/0001-migrate-existing-docs-into-sdd.md +0 -61
  73. package/ai-docs/patterns/defensive-error-propagation.md +0 -55
  74. package/ai-docs/patterns/event-scope-emission.md +0 -46
  75. package/ai-docs/patterns/source-to-test-path-mirroring.md +0 -45
  76. package/ai-docs/patterns/stateless-plugin-request-classes.md +0 -53
  77. package/ai-docs/patterns/typed-constants-and-enum-values.md +0 -47
  78. package/src/aiEnableRequest/ai-docs/ai-enable-request-spec.md +0 -223
  79. package/src/annotation/ai-docs/annotation-spec.md +0 -236
  80. package/src/breakouts/ai-docs/breakouts-spec.md +0 -324
  81. package/src/controls-options-manager/ai-docs/controls-options-manager-spec.md +0 -243
  82. package/src/hashTree/ai-docs/hash-tree-spec.md +0 -267
  83. package/src/interceptors/ai-docs/interceptors-spec.md +0 -247
  84. package/src/interpretation/ai-docs/interpretation-spec.md +0 -256
  85. package/src/locus-info/ai-docs/locus-info-spec.md +0 -293
  86. package/src/media/ai-docs/media-spec.md +0 -267
  87. package/src/meeting/ai-docs/meeting-spec.md +0 -404
  88. package/src/meeting-info/ai-docs/meeting-info-spec.md +0 -261
  89. package/src/meetings/ai-docs/meetings-spec.md +0 -298
  90. package/src/member/ai-docs/member-spec.md +0 -196
  91. package/src/members/ai-docs/members-spec.md +0 -256
  92. package/src/metrics/ai-docs/metrics-spec.md +0 -185
  93. package/src/multistream/ai-docs/multistream-spec.md +0 -295
  94. package/src/personal-meeting-room/ai-docs/personal-meeting-room-spec.md +0 -234
  95. package/src/reachability/ai-docs/reachability-spec.md +0 -261
  96. package/src/reactions/ai-docs/reactions-spec.md +0 -198
  97. package/src/reconnection-manager/ai-docs/reconnection-manager-spec.md +0 -272
  98. package/src/recording-controller/ai-docs/recording-controller-spec.md +0 -223
  99. package/src/roap/ai-docs/roap-spec.md +0 -241
  100. package/src/webinar/ai-docs/webinar-spec.md +0 -243
@@ -0,0 +1,566 @@
1
+ ---
2
+ type: Module Spec
3
+ title: 'Hash tree specification'
4
+ description: Responsibilities, boundaries, design, state, invariants, and verification for the hash-tree Locus dataset synchronization module.
5
+ tags: [module, specification]
6
+ ---
7
+ <!-- sdd-generated-metadata
8
+ doc_kind: module-spec
9
+ generated_from: module-spec@0.3.0
10
+ generated_by: claude-code
11
+ approved_by: rarajes2@cisco.com
12
+ updated_at: 2026-11-17T03:14:21Z
13
+ validation_status: pass-with-warnings
14
+ -->
15
+
16
+ # Hash tree
17
+
18
+ This source-local document at `src/hashTree/docs/README.md` owns the stable specification for
19
+ **the hash tree module**: `HashTreeParser`, which keeps one client copy of each visible Locus dataset
20
+ in step with Locus by comparing hash trees, and `HashTree`, the versioned leaf structure it hashes.
21
+ `LocusInfo` creates one parser per Locus URL and receives its typed updates; see the
22
+ [Locus info specification](../../locus-info/docs/README.md). Ground every claim in package evidence
23
+ and link to the [package architecture](../../../docs/architecture.md) instead of repeating broader
24
+ facts. No service specification exists because this package is a library.
25
+
26
+ Related context: [documentation index](../../../docs/index.md) ·
27
+ [package agent instructions](../../../AGENTS.md)
28
+
29
+ ## Metadata
30
+
31
+ | Field | Value |
32
+ | ----- | ----- |
33
+ | Owner | @webex/web-client, @webex/web-sdk |
34
+ | Source path | `src/hashTree` |
35
+ | Resource kind | module |
36
+ | Status | Draft |
37
+ | Last verified | 2026-11-16 at `0b8c34db7f` |
38
+ | Module id | `plugin-meetings/hashTree` |
39
+ | Parent spec | — |
40
+ | Doc kind | Module spec |
41
+ | Coverage score | Pending coverage assessment |
42
+ | Validation status | not-run |
43
+
44
+ ## Applicability
45
+
46
+ | Condition ID | Status | Evidence or reason | Owned section |
47
+ | ------------------------------------ | ---------- | ------------------ | ------------- |
48
+ | `module.has_tiers` | N/A | No tier policy exists in `package.json` or `.sdd/manifest.json` | Tier |
49
+ | `module.has_ui` | N/A | `src/hashTree/hashTreeParser.ts` returns data through callbacks and renders nothing | UI use-case flow |
50
+ | `module.crosses_service_boundaries` | Applicable | `src/hashTree/hashTreeParser.ts` sends GET visibleDataSetsUrl, GET dataset hashtree, and POST dataset sync requests to Locus through the injected request function | Cross-boundary use-case flow |
51
+ | `module.holds_client_state` | Applicable | `src/hashTree/hashTreeParser.ts` keeps per-dataset hash trees, timers, the sync queue, and the parser state; `src/hashTree/hashTree.ts` keeps leaf items | Client state model |
52
+ | `module.enforces_domain_rules` | Applicable | Version rules in `src/hashTree/hashTree.ts`; update filtering, sentinel and visibility rules in `src/hashTree/hashTreeParser.ts` | Business rules and invariants |
53
+ | `module.is_concurrent_async` | Applicable | Idle and watchdog timers, a sequential sync queue, abort controllers, and a backoff sleep in `src/hashTree/hashTreeParser.ts` and `src/hashTree/utils.ts` | Concurrency and reactive flow |
54
+ | `module.owns_persistence` | N/A | Everything is in memory; `src/hashTree/hashTreeParser.ts` writes no storage | Data, schema, and migration discipline |
55
+ | `module.stateful_transitions` | Applicable | The parser moves between active and stopped through stop, resumeFromMessage, and resumeFromApiResponse in `src/hashTree/hashTreeParser.ts` | State machine |
56
+ | `module.exposes_wire_protocol` | Applicable | The hash tree message, heartbeat, hashtree, and sync payload shapes in `src/hashTree/hashTreeParser.ts` and `src/hashTree/types.ts`, and the hash algorithm in `src/hashTree/hashTree.ts` | Protocol and wire format |
57
+ | `module.ui_multi_screen` | N/A | No UI | UI flow |
58
+ | `module.large_data_model` | N/A | The few types are listed under Protocol and wire format; `src/hashTree/types.ts` is 43 lines | Data model |
59
+ | `module.returns_caller_errors` | Applicable | Constructors throw, initialization and resume promises reject with sentinel errors, and updates report MEETING_ENDED or LOCUS_NOT_FOUND, in `src/hashTree/hashTree.ts` and `src/hashTree/hashTreeParser.ts` | Caller-visible failure modes |
60
+ | `module.module_specific_conventions` | N/A | The module follows the package-wide logging and metrics conventions in `src/hashTree/hashTreeParser.ts`; no extra rule is set | Module-specific rules |
61
+ | `module.published_package` | N/A | `src/index.ts` exports nothing from this module; it is internal to the package | Export stability |
62
+ | `module.embedded_in_host` | N/A | No host theme or embed API | Host integration and theming |
63
+ | `module.has_design_tradeoff` | Applicable | Incremental datasets reconciled by hashes instead of full Locus state, in `src/hashTree/hashTreeParser.ts` | Key design trade-off |
64
+ | `module.has_submodules` | N/A | The src/hashTree directory has no child module in `.sdd/manifest.json` | Sub-modules |
65
+
66
+ ## Evidence register
67
+
68
+ Requirements cite current implementation and mirrored unit-test paths. Current code wins over prose
69
+ when they conflict; commit and PR history are excluded by repository-owner decision. Missing test
70
+ evidence is stated as a gap rather than inferred.
71
+
72
+ | Evidence | What it establishes |
73
+ | -------- | ------------------- |
74
+ | `src/hashTree/hashTree.ts` | `HashTree`: leaves keyed by `id % numLeaves`, version rules for put and remove, XXH3-128 leaf and node hashes, `resize`, `diffHashes` |
75
+ | `src/hashTree/hashTreeParser.ts` | `HashTreeParser`, its exported types, `SyncAllBackoffType`, `LocusInfoUpdateType`, `MeetingEndedError`, `LocusNotFoundError`; every request to Locus, the timers, the sync queue, and the update filter |
76
+ | `src/hashTree/constants.ts` | `EMPTY_HASH`, `DataSetNames`, `DATA_SET_INIT_PRIORITY` (main before self, with the reason in a comment), `LLM_DATASET_NAMES` |
77
+ | `src/hashTree/types.ts` | `ObjectType`, `ObjectTypeToLocusKeyMap`, `HtMeta`, `HashTreeObject` |
78
+ | `src/hashTree/utils.ts` | `isSelf`, `isMetadata`, `deleteNestedObjectsWithHtMeta`, `sortByInitPriority`, `sleep` |
79
+ | `src/locus-info/index.ts` | The only creator of parsers (`createHashTreeParser`): injects `webex.request`, `updateFromHashTree`, the sync latency tracker, `isLlmExpected` (self `joinedWith.state` is `JOINED`), a tracking id generator, and `excludedDataSets`; calls `reevaluateLlmWatchdogs` when LLM becomes expected |
80
+ | `src/locus-info/types.ts` | `LocusErrorCodes.LOCUS_INACTIVE` (`2403004`) used by the meeting-ended sentinel |
81
+ | `src/config.ts` | Default `meetings.locus.excludedDataSets` is `['attendees']` |
82
+ | `src/metrics/constants.ts` | `HASH_TREE_SYNC_FAILURE`, `HASH_TREE_HEARTBEAT_WATCHDOG_EXPIRED`, `HASH_TREE_EMPTY_LOCUS_STATE_ELEMENTS` metric names |
83
+ | `src/meeting/index.ts`, `src/meetings/index.ts` | Import only types (`DataSet`, `HashTreeMessage`, `Metadata`, `HashTreeObject`) and `isSelf` |
84
+ | `package.json` | `xxh3-ts` dependency; `test:unit` runs `webex-legacy-tools test --unit --runner mocha` |
85
+ | `test/unit/spec/hashTree/hashTree.ts` | Put, remove, update, resize, diff, hash, and version cases for `HashTree` |
86
+ | `test/unit/spec/hashTree/hashTreeParser.ts` | Initialization, messages, sync algorithm, sentinels, visible dataset changes, heartbeat watchdog, update filtering, stop, resume, `syncAllDatasets`, sync queue, abort controller, and sync metrics cases |
87
+ | `test/unit/spec/hashTree/utils.ts` | `deleteNestedObjectsWithHtMeta`, `isSelf`, `sortByInitPriority`, `sleep` cases |
88
+ | Observation, `src/hashTree/hashTreeParser.ts` | `parseMessage` logs a warning and sends `HASH_TREE_EMPTY_LOCUS_STATE_ELEMENTS` when a message carries an empty `locusStateElements` array; the code gives no reason why this case is measured, so it is recorded here rather than as a requirement |
89
+ | Observation, `src/hashTree/hashTree.ts` | `getLeafData` returns a leaf's items sorted by id; its comment calls the sort optional, and `performSync` sends that order in `leafDataEntries`; no reason for the order is recorded, so it is not a requirement |
90
+
91
+ ## Purpose and boundary
92
+
93
+ - Responsibility: tracks incremental Locus dataset versions, detects gaps, fetches missing datasets,
94
+ and emits typed update callbacks.
95
+ - In scope: the `HashTree` leaf structure and its hashes; one `HashTreeParser` per Locus URL with
96
+ its dataset table, visible dataset list, root-hash sync timers, heartbeat watchdogs, sync queue,
97
+ `syncAllDatasets`, the meeting-ended and Locus-not-found sentinels, and the filter that drops
98
+ stale updates before the callback.
99
+ - Out of scope: turning hash tree objects into the Locus DTO and meeting events (`LocusInfo`,
100
+ [Locus info specification](../../locus-info/docs/README.md)); choosing which parser a message
101
+ belongs to; the Mercury and LLM sockets; the HTTP pipeline behind the injected request function;
102
+ the sync latency metrics store behind `syncLatencyTracker`.
103
+ - Consumers: `src/locus-info/index.ts` creates and drives every parser. `src/meeting/index.ts`,
104
+ `src/meetings/index.ts`, and `src/locus-info/types.ts` import types and `isSelf`. Nothing is
105
+ exported from `src/index.ts`.
106
+
107
+ ## Structure and key files
108
+
109
+ `src/hashTree` contains 5 direct source files and has 3 mirrored unit-test files under
110
+ `test/unit/spec/hashTree`; the sections below separate its public operations, runtime data
111
+ movement, component ownership, state, and verification boundary. The code is TypeScript in the Node 22.14 Yarn workspace, built by
112
+ `yarn workspace @webex/plugin-meetings build:src`; tests use Mocha (`test:unit` runs
113
+ `webex-legacy-tools test --unit --runner mocha`), Sinon, and `@webex/test-helper-chai`.
114
+
115
+ | File | Holds |
116
+ |---|---|
117
+ | `src/hashTree/constants.ts` | module constants and wire values: `EMPTY_HASH`, `DataSetNames`, `DATA_SET_INIT_PRIORITY`, `LLM_DATASET_NAMES` |
118
+ | `src/hashTree/hashTree.ts` | `HashTree`: versioned leaf items, XXH3-128 leaf and tree hashes, resize, and hash diff; no I/O |
119
+ | `src/hashTree/hashTreeParser.ts` | `HashTreeParser`: dataset table, message and API-response handling, sync queue, timers, sentinels, and the update callback; plus the exported message, dataset, and callback types and the two sentinel error classes |
120
+ | `src/hashTree/types.ts` | module type declarations: `ObjectType`, `ObjectTypeToLocusKeyMap`, `HtMeta`, `HashTreeObject` |
121
+ | `src/hashTree/utils.ts` | normalization/helper functions: `isSelf`, `isMetadata`, `deleteNestedObjectsWithHtMeta`, `sortByInitPriority`, `sleep` |
122
+ | `test/unit/spec/hashTree/hashTree.ts`, `test/unit/spec/hashTree/hashTreeParser.ts`, `test/unit/spec/hashTree/utils.ts` | mirrored unit coverage of the structure, the parser, and the helpers |
123
+ | `src/hashTree/docs/README.md` | This module specification |
124
+
125
+ ## Public surface
126
+
127
+ | Contract ID | Type | Surface | Purpose | Compatibility / deprecation | Schema / detail link | Root index |
128
+ |---|---|---|---|---|---|---|
129
+ | `hash-tree-sync` | in-memory structure | `HashTree.putItem()`, `putItems()`, `removeItem()`, `removeItems()`, and `updateItems()` | Apply version-aware leaf mutations to the pure hash-tree data structure. | Older/equal item versions do not replace newer data; a removal applies only when its version is equal to or newer than the stored one; preserve leaf-bucket semantics (`id % numLeaves`). | `src/hashTree/hashTree.ts` | [architecture](../../../docs/architecture.md) |
130
+ | `hash-tree-sync` | in-memory structure | `computeLeafHash()`, `computeTreeHashes()`, `getHashes()`, `getRootHash()`, `getLeafCount()`, `getTotalItemCount()`, `getLeafData()`, and `getItemVersion()` | Compute and inspect dataset hashes and stored item/version information. | Hash ordering (internal nodes then leaves) and result shapes are synchronization contracts. | `src/hashTree/hashTree.ts` | [architecture](../../../docs/architecture.md) |
131
+ | `hash-tree-sync` | in-memory structure | `HashTree.resize()` and `diffHashes()` | Resize the leaf layout and locate differing leaf indexes during synchronization. | Preserve deterministic redistribution and diff-index semantics; a too-short external list marks every leaf as different. | `src/hashTree/hashTree.ts` | [architecture](../../../docs/architecture.md) |
132
+ | `hash-tree-sync` | parser initialization | `HashTreeParser.initializeFromMessage()` and `initializeFromGetLociResponse()` | Fetch dataset metadata from the visibleDataSetsUrl of a Mercury hash-tree message or a get-loci response, then run an initialization sync per visible dataset. | Preserve dataset initialization priority (main, then self) and wait for the queued syncs; sentinel errors reject the promise. | `src/hashTree/hashTreeParser.ts` | [architecture](../../../docs/architecture.md) |
133
+ | `hash-tree-sync` | parser updates | `handleMetadataUpdate()`, `handleLocusUpdate()`, and `handleMessage()` | Apply message or API-response items, emit the resulting callback, and schedule any root-hash reconciliation required for the dataset. | Preserve the implemented ordering: `parseMessage()` mutates item state, `handleMessage()` invokes the callback and then re-arms watchdogs, and the delayed sync algorithm checks the resulting root hash separately. | `src/hashTree/hashTreeParser.ts` | [architecture](../../../docs/architecture.md) |
134
+ | `hash-tree-sync` | parser synchronization | `syncAllDatasets({onlyLLM})`, `resumeFromMessage()`, and `resumeFromApiResponse()` | Sync every dataset with a hash tree after one weighted backoff, or rebuild a stopped parser from a message or API response and resume processing. | Preserve ended/not-found sentinel handling, the backoff scope upgrade, and stopped-parser guards; `resumeFromMessage()` ignores a message without Metadata visibleDataSets. | `src/hashTree/hashTreeParser.ts` | [architecture](../../../docs/architecture.md) |
135
+ | `hash-tree-sync` | parser lifecycle | `stop()`, `cleanUp()`, and `reevaluateLlmWatchdogs()` | Stop future mutation and release queued/parser-owned state; arm LLM dataset watchdogs that were skipped while LLM was not expected. | Work completed after stop must not mutate the stopped parser; `cleanUp()` also empties the dataset table. | `src/hashTree/hashTreeParser.ts` | [architecture](../../../docs/architecture.md) |
136
+ | `hash-tree-sync` | exported contracts/helpers | `EMPTY_HASH`, `DataSetNames`, `DATA_SET_INIT_PRIORITY`, `LLM_DATASET_NAMES`, `LeafDataItem`, `SyncAllBackoffType`, `DataSet`, `RootHashMessage`, `HashTreeMessage`, `VisibleDataSetInfo`, `Metadata`, `LocusInfoUpdateType`, `LocusInfoUpdate`, `LocusInfoUpdateCallback`, `SyncLatencyTracker`, `HashTreeParserCallbacks`, `MeetingEndedError`, `LocusNotFoundError`, `ObjectType`, `ObjectTypeToLocusKeyMap`, `HtMeta`, `HashTreeObject`, `isSelf()`, `isMetadata()`, `deleteNestedObjectsWithHtMeta()`, `sortByInitPriority()`, and `sleep()` | Share the exact dataset protocol vocabulary, sentinel errors, and normalization helpers used by Locus integration. | Preserve dataset names, error identity, ordering, and raw message fields. | `src/hashTree/hashTree.ts`, `src/hashTree/hashTreeParser.ts`, `src/hashTree/types.ts`, `src/hashTree/constants.ts`, `src/hashTree/utils.ts` | [architecture](../../../docs/architecture.md) |
137
+
138
+ Compatibility notes:
139
+
140
+ - Prefer additive options and payload fields. Preserve method/event names, rejection semantics, and
141
+ cleanup timing. The module is internal: change its surface together with `src/locus-info/index.ts`,
142
+ the owning object, rather than through `src/index.ts`, which exports none of it.
143
+
144
+ Contract ID `hash-tree-sync` is registered in `.sdd/manifest.json` with source
145
+ `src/hashTree/hashTreeParser.ts` and indexed in the
146
+ [package architecture](../../../docs/architecture.md). The module requires `locus-http`, the Locus
147
+ REST service, reached here only through the injected request function.
148
+
149
+ ## Dependencies
150
+
151
+ Hash-tree wire messages, the injected dataset request function, Locus identifiers, the XXH3 checksum,
152
+ and the consumer callbacks are the module's inputs.
153
+
154
+ | Dependency | Why it is required | Failure behavior |
155
+ | ---------- | ------------------ | ---------------- |
156
+ | Injected `webexRequest` (`webex.request` bound by `LocusInfo`) | GET visibleDataSetsUrl, GET `<dataset url>/hashtree`, POST `<dataset url>/sync` | 404 and 409/2403004 become sentinel errors; other errors are logged, reported as `HASH_TREE_SYNC_FAILURE` (hashtree and sync), and rethrown to the parser's own catch |
157
+ | `HashTreeParserCallbacks.locusInfoUpdateCallback` (`LocusInfo.updateFromHashTree`) | Receives `OBJECTS_UPDATED`, `MEETING_ENDED`, and `LOCUS_NOT_FOUND` | Called synchronously; never called once the parser is stopped |
158
+ | `HashTreeParserCallbacks.isLlmExpected` | Gates heartbeat watchdogs of the LLM datasets (main, atd-active, atd-unmuted) | Declared required but guarded at the call site; absent means the watchdog is armed |
159
+ | `syncLatencyTracker`, `generateTrackingId` (optional callbacks) | Sync latency timestamps and per-request tracking ids for main, atd-active, and atd-unmuted | Absent tracker means no sync metrics and no forced tracking ids |
160
+ | `xxh3-ts` (`XXH3_128`) | Leaf and internal node hashes that must equal Locus's | — |
161
+ | `lodash` (`cloneDeep`, `isEmpty`, `zip`) | Copying leaf data, empty-body checks, pairing put results with leaves | — |
162
+ | `src/common/logs/logger-proxy.ts`, `src/metrics/index.ts`, `src/metrics/constants.ts` | Logging and the three hash tree behavioral metrics | — |
163
+ | `src/locus-info/types.ts` (`LocusDTO`, `LocusErrorCodes`) | The get-loci response type and the `LOCUS_INACTIVE` code | — |
164
+ | `src/constants.ts` (`Enum`, `HTTP_VERBS`) | Type helper and HTTP verbs | — |
165
+
166
+ ## Requirements
167
+
168
+ | ID | WHAT | WHY | Source Evidence | Test / Example Evidence | Assumptions / Gaps | Confidence |
169
+ |---|---|---|---|---|---|---|
170
+ | `HASH-TREE-R-001` | `HashTreeParser` parses hash-tree messages, tracks dataset versions, detects gaps by root hash, fetches datasets, and emits typed update callbacks; `HashTree` stores leaf items and computes leaf/tree hashes without any I/O. | Parser synchronization behavior and the hash data structure have different ownership and must not be attributed to the same file. | `src/hashTree/hashTreeParser.ts`, `src/hashTree/hashTree.ts` | `test/unit/spec/hashTree/hashTreeParser.ts`, `test/unit/spec/hashTree/hashTree.ts` | none | PRESENT |
171
+ | `HASH-TREE-R-002` | `HashTreeParser.parseMessage()` updates dataset metadata, cancels pending and in-flight syncs for the message's datasets, and applies message items; `handleMessage()` then invokes the object-update callback. `runSyncAlgorithm()` performs the root-hash comparison later, after the dataset's `idleMs` plus a weighted random backoff, and queues synchronization on mismatch. | Callers need the real callback-versus-reconciliation ordering and must not assume the callback waits for the deferred root-hash check. | `src/hashTree/hashTreeParser.ts`, `src/hashTree/hashTree.ts`, `src/hashTree/utils.ts` | `test/unit/spec/hashTree/hashTreeParser.ts`, `test/unit/spec/hashTree/hashTree.ts`, `test/unit/spec/hashTree/utils.ts` | none | PRESENT |
172
+ | `HASH-TREE-R-003` | `performSync()` converts meeting-ended/not-found responses into their sentinel callback paths (`LOCUS_NOT_FOUND` also stops the parser), catches and logs other synchronization failures after the request layer sends `HASH_TREE_SYNC_FAILURE`, and prevents stopped-parser work from being applied. | Sentinel dataset outcomes, logged sync failure, and stopped work must remain distinct so no failed fetch is misreported as a caller-visible rejection or current state. | `src/hashTree/hashTreeParser.ts` | `test/unit/spec/hashTree/hashTreeParser.ts` | the queue continuing with the next entry after a non-sentinel failure has no explicit case | PRESENT |
173
+ | `HASH-TREE-R-004` | `resetHeartbeatWatchdogs()` clears and re-arms a per-dataset timer at `heartbeatIntervalMs + getWeightedBackoffTime(backoff)`, preferring the dataset-level `heartbeatIntervalMs` over `topLevelHeartbeatIntervalMs`. It skips any dataset without a `hashTree`, without a resolved non-zero interval, or that `isVisibleDataSet()` rejects, and skips a dataset in `LLM_DATASET_NAMES` when the injected `callbacks.isLlmExpected()` returns false, remembering it so `reevaluateLlmWatchdogs()` arms it once LLM becomes expected. On expiry it emits `HASH_TREE_HEARTBEAT_WATCHDOG_EXPIRED`, saves the backoff latency, enqueues a sync for that dataset, and re-arms itself. `handleMessage()` re-arms the watchdogs *after* `callLocusInfoUpdateCallback()` on the state-elements path, and immediately after `handleRootHashHeartBeatMessage()` on the heartbeat-only path. | A watchdog armed for a dataset whose transport is not connected would fire on every interval and enqueue perpetual syncs, so visibility and LLM-expectation gating are part of the contract, not an optimization. Re-arming after the update callback keeps the timer anchored to the point the message was actually applied; the pending set avoids missing a watchdog when an LLM dataset arrives before the self update (code comment). | `src/hashTree/hashTreeParser.ts`, `src/hashTree/constants.ts`, `src/locus-info/index.ts` | `test/unit/spec/hashTree/hashTreeParser.ts` | the `isLlmExpected` callback is declared required on `HashTreeParserCallbacks` but is also guarded for absence at the call site; treat the guard as current behavior | PRESENT |
174
+ | `HASH-TREE-R-005` | `HashTree` puts an item into leaf `id % numLeaves` only when no item with that type and id exists or the stored version is lower; it removes an item only when the stored version is lower than or equal to the given one. Every mutation returns `false` on a tree with 0 leaves. The constructor and `resize()` throw unless the leaf count is 0 or a power of 2. | The leaf layout must match Locus's, because `diffHashes()` compares our leaf hashes with the hashes Locus returns for the same leaf count, and a stale message must never roll an item back. | `src/hashTree/hashTree.ts` | `test/unit/spec/hashTree/hashTree.ts` | none | PRESENT |
175
+ | `HASH-TREE-R-006` | A leaf hash is `XXH3_128` (seed 0) over the leaf's items, types in lexicographic order and ids ascending within a type, each written as 64-bit little-endian id then version, rendered as 32 hex digits. Internal nodes hash the byte-reversed halves of the left and right child hashes (the left child repeats when there is no right one). `getHashes()` returns internal nodes then leaves; an empty leaf and a 0-leaf tree hash to `EMPTY_HASH`. | The parser compares `getRootHash()` with the root Locus sends and sends it on every hashtree and sync request, so the algorithm must reproduce Locus's hashes byte for byte. | `src/hashTree/hashTree.ts`, `src/hashTree/constants.ts` | `test/unit/spec/hashTree/hashTree.ts` | none | PRESENT |
176
+ | `HASH-TREE-R-007` | Before calling `locusInfoUpdateCallback`, `OBJECTS_UPDATED` objects are dropped when any visible dataset holds a higher version of the same type and id, and removals are dropped while any visible dataset still holds a version equal or higher; nothing is called when every object is dropped or the list is empty. `MEETING_ENDED` and `LOCUS_NOT_FOUND` always pass. Nothing is called on a stopped parser. | One object can belong to several datasets, so an update or removal arriving through one dataset must not override what another dataset still holds (code comments in the filter). | `src/hashTree/hashTreeParser.ts` | `test/unit/spec/hashTree/hashTreeParser.ts` | none | PRESENT |
177
+ | `HASH-TREE-R-008` | A message in which any dataset named main, self, or unjoined has `leafCount` 1, root `EMPTY_HASH`, and a version newer than ours (or is unknown to us) is the end-of-meeting sentinel: the parser stops all timers and reports `MEETING_ENDED` without applying the message. | The code comment: this is a special way for Locus to indicate that the meeting has ended. | `src/hashTree/hashTreeParser.ts`, `src/hashTree/constants.ts` | `test/unit/spec/hashTree/hashTreeParser.ts` | none | PRESENT |
178
+ | `HASH-TREE-R-009` | Any request to Locus that fails with 404 stops all timers and throws `LocusNotFoundError`; a 409 whose `body.errorCode` is `LOCUS_INACTIVE` (`2403004`), for main, self, unjoined, or the visibleDataSetsUrl request, stops all timers and throws `MeetingEndedError`. Inside a sync they become `LOCUS_NOT_FOUND` (and `stop()`) or `MEETING_ENDED`; from initialization and resume they reject the caller. Any other 409 from the hashtree request ends that sync silently. | The code comments: a 404 means the Locus URL is no longer valid (moved to a breakout, or ended), while a dataset that is only not visible answers 400; a plain 409 is a leaf count mismatch, so the client waits for the next heartbeat. | `src/hashTree/hashTreeParser.ts`, `src/locus-info/types.ts` | `test/unit/spec/hashTree/hashTreeParser.ts` | the plain-409 hashtree branch has no case | PRESENT |
179
+ | `HASH-TREE-R-010` | Syncs run from one queue, one at a time; a dataset already queued is not queued again (an initialization request upgrades the entry), entries for datasets without a hash tree are skipped, and the loop stops when the parser stops. A message or heartbeat for a dataset removes its queued entries and aborts its in-flight sync, which is abandoned before the sync request is sent. | The code comment: all syncs are executed sequentially and no more than one runs at a time; a message received during a sync makes that sync's result obsolete. | `src/hashTree/hashTreeParser.ts` | `test/unit/spec/hashTree/hashTreeParser.ts` | none | PRESENT |
180
+ | `HASH-TREE-R-011` | A normal sync of a dataset with `leafCount` other than 1 GETs `<url>/hashtree?rootHash=<ours>`; an empty body means the hashes match. Otherwise the tree is resized to the returned leaf count, `diffHashes()` picks the mismatched leaves, and `POST <url>/sync?rootHash=<ours>` sends `{leafCount, leafDataEntries: [{leafIndex, elementIds}]}`. A 1-leaf dataset skips the hashtree request and sends leaf 0. An initialization sync sends `leafCount` 1 and one empty leaf. A non-empty sync response is filtered to the requested dataset and handled as a message; the root-hash timer is re-armed after every sync. | The code comments: Locus requires leafCount 1 with one empty leaf for initialization; filtering prevents shared datasets such as unjoined from being applied once per dataset; the timer is a safety net in case the data does not arrive by message. | `src/hashTree/hashTreeParser.ts`, `src/hashTree/hashTree.ts` | `test/unit/spec/hashTree/hashTreeParser.ts` | none | PRESENT |
181
+ | `HASH-TREE-R-012` | `syncAllDatasets({onlyLLM})` returns at once when stopped or when nothing has a hash tree; otherwise it sleeps `round(random ** exponent * maxMs)` from the first dataset's backoff, then queues every dataset with a hash tree (only the LLM datasets when `onlyLLM`) in priority order, skipping datasets that received a message during the sleep. A call during the sleep returns at once and can only widen the scope from LLM-only to all. | The code comment: delaying the start of the syncs is a Locus requirement to avoid thundering herd issues. | `src/hashTree/hashTreeParser.ts`, `src/hashTree/utils.ts`, `src/hashTree/constants.ts` | `test/unit/spec/hashTree/hashTreeParser.ts` | none | PRESENT |
182
+ | `HASH-TREE-R-013` | Visible datasets change only through a newer Metadata object. A dataset that leaves the list produces a removal object (data `null`) for every leaf item and loses its hash tree, timers, and in-flight sync. A dataset that joins gets an empty hash tree and a sync timer when its info is known, or is initialized asynchronously from visibleDataSetsUrl in priority order. Datasets in `excludedDataSets` (default attendees) never become visible. | The code comments: when a visible dataset is removed the client must be told that all its objects are removed; the attendees dataset is never needed (`src/config.ts`). | `src/hashTree/hashTreeParser.ts`, `src/hashTree/utils.ts`, `src/config.ts` | `test/unit/spec/hashTree/hashTreeParser.ts` | none | PRESENT |
183
+ | `HASH-TREE-R-014` | Dataset initialization, new visible dataset initialization, and `syncAllDatasets` order datasets main first, then self, then the rest in their received order. | The code comment: `LocusInfo` processes updated objects in order, and the self handler reads `locus.info.isWebinar`, which comes from main, to decide whether to create a webinar attendee's participant. | `src/hashTree/constants.ts`, `src/hashTree/utils.ts` | `test/unit/spec/hashTree/utils.ts`, `test/unit/spec/hashTree/hashTreeParser.ts` | none | PRESENT |
184
+ | `HASH-TREE-R-015` | Sync latency metrics are recorded only for main, atd-active, and atd-unmuted, only for non-initialization syncs, and only with a `syncLatencyTracker`. Each sync generates two tracking ids, hashtree first, and forces them onto the hashtree and sync request headers; a sync that sends no sync request clears only its own record. Completion is not recorded here. | The code comments: each Locus request must carry its own tracking id, the sync request's id is the one Locus echoes on the LLM message, and completion is driven from the LLM message path in `Meeting`. | `src/hashTree/hashTreeParser.ts` | `test/unit/spec/hashTree/hashTreeParser.ts` | none | PRESENT |
185
+ | `HASH-TREE-R-016` | The constructor builds a hash tree only for datasets in the Metadata visibleDataSets list that are also in `dataSets` and not excluded, seeding it from the `htMeta` found anywhere in the initial Locus and from the Metadata object; it throws when the Metadata `htMeta.dataSetNames` is not exactly `["self"]`. | The code comment: Locus always sends Metadata objects only in the self dataset, and code that relies on it must change if that changes; Locus sends visibleDataSets and dataSets as separate lists that can differ. | `src/hashTree/hashTreeParser.ts` | `test/unit/spec/hashTree/hashTreeParser.ts` | the throwing branch has no case | PRESENT |
186
+
187
+ ## Design overview
188
+
189
+ `HashTreeParser` consumes state-element messages and API responses, applies their items to one
190
+ `HashTree` per visible dataset (`hashTree.ts` owns the version comparison), uses `utils.ts` for
191
+ Metadata detection, nested-object stripping, priority ordering, and the backoff sleep, fetches hashes
192
+ and missing leaves through its injected `webexRequest`, and reports normalized changes through
193
+ callbacks.
194
+
195
+ The parser keeps a table of every dataset Locus mentions, keyed by name, but builds a hash tree only
196
+ for the visible ones. Leaf items hold only type, id, and version; the object data passes through to
197
+ the callback and is not stored. Reconciliation is lazy: a message is applied at once, and only a
198
+ later timer compares our root hash with the one Locus sent. A mismatch queues a sync that asks Locus
199
+ for its hashes, finds the differing leaves, and sends our leaf contents so Locus can return or
200
+ re-send what differs. Heartbeat messages carry only dataset versions and roots and run the same
201
+ timer; a watchdog per dataset queues a sync when heartbeats stop.
202
+
203
+ `LocusInfo` owns the parsers. It creates one per Locus URL, stops the previous one when Locus
204
+ replaces the URL, resumes a stopped one, and passes `isLlmExpected` so LLM-only datasets are
205
+ supervised only while this device is joined.
206
+
207
+ ## Data flow and sequence coverage
208
+
209
+ Call style: in-process method calls from `LocusInfo`; outbound HTTPS through the injected
210
+ `webexRequest`; timers (`setTimeout`) and a microtask for asynchronous dataset initialization.
211
+
212
+ Sequence coverage:
213
+
214
+ | Operation group | Diagram | Failure coverage |
215
+ |---|---|---|
216
+ | UC-1…UC-5 — hash-tree mutation and synchronization operation groups | Diagram 1, hash-tree mutation and synchronization primary sequence | stale/gapped metadata, hashes that already match, logged sync failure, and stopped-parser suppression |
217
+ | UC-1…UC-5 — hash-tree mutation and synchronization alternate/failure paths | Diagram 1 alt branches, hash-tree mutation and synchronization sequence | hash mismatch, dataset 404, 409 meeting-ended, plain 409 leaf count mismatch, non-sentinel rejection, or a stopped parser receiving queued work |
218
+ | Heartbeats and watchdogs (`UC-6`) | Diagram 2 | the end-of-meeting sentinel, the LLM-not-expected skip and later arming, watchdog expiry |
219
+ | Initialization and visible dataset changes (`UC-2`, `UC-7`) | Diagram 3 | missing visibleDataSetsUrl, excluded datasets, 404 or 409 rejecting initialization |
220
+ | Sync of all datasets (`UC-8`) | Diagram 4 | stopped during the backoff sleep, scope upgrade, datasets skipped after a message |
221
+ | API responses (`UC-9`) | `src/hashTree/hashTreeParser.ts` handleLocusUpdate; same apply and callback steps as Diagram 1 without timers | unknown or invisible datasets are ignored with a log |
222
+
223
+ Diagram 1 — hash-tree mutation and synchronization primary sequence:
224
+
225
+ ```mermaid
226
+ sequenceDiagram
227
+ participant M as Mercury or LLM message (via LocusInfo)
228
+ participant P as HashTreeParser
229
+ participant H as HashTree dataset state
230
+ participant W as webexRequest
231
+ participant O as Injected owner callback
232
+ M-->>P: state-elements message
233
+ alt parser has been stopped
234
+ P->>P: discard queued work without applying it
235
+ else parser is active
236
+ P->>H: update dataset metadata and apply message leaves
237
+ P-->>O: invoke injected owner callback with applied objects
238
+ P->>P: after idle/backoff, compare computed and received root hashes
239
+ opt deferred root mismatch or visible-dataset change requires synchronization
240
+ P->>W: GET dataset url /hashtree?rootHash
241
+ alt empty body (hashes match)
242
+ W-->>P: nothing to sync
243
+ else hashes and leafCount
244
+ W-->>P: hashes and leafCount
245
+ P->>H: resize and diff leaf hashes
246
+ P->>W: POST dataset url /sync with mismatched leaves
247
+ W-->>P: empty body, or a response in message format
248
+ P->>H: apply synchronized dataset leaves
249
+ P-->>O: invoke injected owner callback with synchronized objects
250
+ else ended (409/2403004) or not-found (404) sentinel
251
+ W--xP: sentinel error
252
+ P-->>O: ended or not-found callback (not-found also stops the parser)
253
+ else plain 409 from hashtree
254
+ W--xP: 409
255
+ P->>P: leaf count mismatch, wait for the next heartbeat
256
+ else non-sentinel rejection
257
+ W--xP: rejection
258
+ P->>P: log failure and send HASH_TREE_SYNC_FAILURE, invoke no owner callback
259
+ end
260
+ end
261
+ end
262
+ ```
263
+
264
+ Diagram 2 — heartbeats and watchdogs:
265
+
266
+ ```mermaid
267
+ sequenceDiagram
268
+ participant L as LocusInfo
269
+ participant P as HashTreeParser
270
+ participant T as Dataset timers
271
+ participant C as Owning callback
272
+ L->>P: handleMessage(message without locusStateElements)
273
+ alt end-of-meeting sentinel (leafCount 1, EMPTY_HASH root, newer version)
274
+ P->>T: stop all timers
275
+ P-->>C: MEETING_ENDED
276
+ else heartbeat
277
+ P->>P: cancel queued and in-flight syncs for these datasets
278
+ P->>T: update version and root, re-arm root-hash timer
279
+ P->>T: re-arm heartbeat watchdog per visible dataset
280
+ opt LLM dataset while isLlmExpected() is false
281
+ P->>P: skip the watchdog and remember the dataset
282
+ end
283
+ end
284
+ opt LocusInfo sees self JOINED with this device
285
+ L->>P: reevaluateLlmWatchdogs()
286
+ P->>T: arm the remembered LLM watchdogs
287
+ end
288
+ opt no heartbeat within interval plus backoff
289
+ T->>P: watchdog fires
290
+ P->>P: send HASH_TREE_HEARTBEAT_WATCHDOG_EXPIRED, queue a sync, re-arm
291
+ end
292
+ ```
293
+
294
+ Diagram 3 — initialization and visible dataset changes:
295
+
296
+ ```mermaid
297
+ sequenceDiagram
298
+ participant L as LocusInfo
299
+ participant P as HashTreeParser
300
+ participant W as webexRequest
301
+ participant C as Owning callback
302
+ L->>P: initializeFromMessage(message) or initializeFromGetLociResponse(locus)
303
+ P->>W: GET visibleDataSetsUrl
304
+ alt 404 or 409/2403004
305
+ W--xP: rejection
306
+ P--xL: LocusNotFoundError or MeetingEndedError rejects the promise
307
+ else dataset list
308
+ W-->>P: body.dataSets
309
+ loop main, then self, then the rest (excluded datasets skipped)
310
+ P->>P: create an empty hash tree and queue an initialization sync
311
+ P->>W: POST dataset url /sync with leafCount 1 and one empty leaf
312
+ W-->>P: message-format response or empty body
313
+ P-->>C: OBJECTS_UPDATED for applied objects
314
+ end
315
+ P-->>L: resolves after the queued syncs
316
+ end
317
+ Note over P,C: a newer Metadata object with a changed visibleDataSets list reports removals for a dropped dataset and creates or initializes the added ones
318
+ ```
319
+
320
+ Diagram 4 — sync of all datasets:
321
+
322
+ ```mermaid
323
+ sequenceDiagram
324
+ participant L as LocusInfo
325
+ participant P as HashTreeParser
326
+ participant Q as Sync queue
327
+ L->>P: syncAllDatasets({onlyLLM})
328
+ alt stopped, or no dataset has a hash tree
329
+ P-->>L: resolve at once
330
+ else backoff already sleeping
331
+ P->>P: widen the pending scope to all when onlyLLM is false
332
+ P-->>L: resolve at once
333
+ else
334
+ P->>P: sleep the weighted backoff of the first dataset
335
+ P->>P: drop datasets that received a message during the sleep
336
+ P->>Q: queue each remaining dataset in priority order
337
+ Q->>Q: run syncs one at a time
338
+ P-->>L: resolve when the queue drains
339
+ end
340
+ ```
341
+
342
+ ## Class and component relationships
343
+
344
+ ```mermaid
345
+ classDiagram
346
+ class LocusInfo
347
+ class HashTreeParser {
348
+ dataSets
349
+ visibleDataSets
350
+ state
351
+ initializeFromMessage(message)
352
+ initializeFromGetLociResponse(locus)
353
+ handleMessage(message, debugText)
354
+ handleLocusUpdate(update)
355
+ handleMetadataUpdate(metadata, updatedObjects)
356
+ syncAllDatasets(options)
357
+ reevaluateLlmWatchdogs()
358
+ stop()
359
+ cleanUp()
360
+ resumeFromMessage(message)
361
+ resumeFromApiResponse(locus)
362
+ }
363
+ class InternalDataSet {
364
+ hashTree
365
+ timer
366
+ heartbeatWatchdogTimer
367
+ syncAbortController
368
+ }
369
+ class HashTree {
370
+ putItems(items)
371
+ updateItems(itemUpdates)
372
+ getRootHash()
373
+ diffHashes(externalHashes)
374
+ resize(newNumLeaves)
375
+ }
376
+ class HashTreeParserCallbacks
377
+ class WebexRequestMethod
378
+ LocusInfo --> HashTreeParser : creates one per Locus URL
379
+ HashTreeParser *-- InternalDataSet : one per dataset
380
+ InternalDataSet *-- HashTree : one hash tree per visible dataset
381
+ HashTreeParser --> WebexRequestMethod : injected request function
382
+ HashTreeParser --> HashTreeParserCallbacks : injected at construction, invokes updates
383
+ HashTreeParser ..> MeetingEndedError : throws
384
+ HashTreeParser ..> LocusNotFoundError : throws
385
+ ```
386
+
387
+ The arrows identify ownership and delegation inside `src/hashTree/`; files that only declare types or
388
+ constants (`types.ts`, `constants.ts`) and the stateless helpers in `utils.ts` are not drawn as
389
+ components.
390
+
391
+ ## Use cases and flows
392
+
393
+ | Use case | Actor or caller | Primary steps and outcome | Failure or boundary behavior | Evidence |
394
+ | -------- | --------------- | ------------------------- | ---------------------------- | -------- |
395
+ | `UC-1` | `HashTreeParser` | Insert, update, remove, resize, and diff versioned items in the pure `HashTree` without invoking remote synchronization. | Older versions are ignored; a 0-leaf tree accepts nothing; a bad leaf count throws | `src/hashTree/hashTree.ts`, `test/unit/spec/hashTree/hashTree.ts` |
396
+ | `UC-2` | `LocusInfo` when a meeting starts or a parser is created | Initialize parser datasets from a Mercury message or get-loci response in declared dataset priority (main, then self), each with an initialization sync. | A missing visibleDataSetsUrl resolves without work (get-loci) or yields no datasets (message); 404 and 409/2403004 reject | `src/hashTree/hashTreeParser.ts`, `src/hashTree/constants.ts` |
397
+ | `UC-3` | `LocusInfo` with a Mercury or LLM message | Apply message items in `parseMessage()` and invoke the normalized Locus callback from `handleMessage()` before the delayed root-hash reconciliation runs. | Stale objects are filtered out; nothing happens when stopped | `src/hashTree/hashTreeParser.ts`, `test/unit/spec/hashTree/hashTreeParser.ts` |
398
+ | `UC-4` | Root-hash timer, watchdog, or `syncAllDatasets` | Queue and synchronize missing datasets when a hash mismatch is detected, mapping ended/not-found sentinels to their callback paths. | Non-sentinel failures are logged and the sync is dropped | `src/hashTree/hashTreeParser.ts`, `test/unit/spec/hashTree/hashTreeParser.ts` |
399
+ | `UC-5` | `LocusInfo` replacing or discarding a parser | Stop and clean up a parser so queued or later-completing work cannot mutate its state; later resume it from a message or an API response. | Resume from a message without Metadata visibleDataSets is ignored | `src/hashTree/hashTreeParser.ts`, `src/locus-info/index.ts` |
400
+ | `UC-6` | Locus heartbeats | Heartbeats update versions and roots and re-arm timers; a silent dataset's watchdog queues a sync. | The end-of-meeting sentinel reports MEETING_ENDED; LLM datasets are not supervised while LLM is not expected | `src/hashTree/hashTreeParser.ts`, `test/unit/spec/hashTree/hashTreeParser.ts` |
401
+ | `UC-7` | Locus changing what this client may see | A newer Metadata object changes visibleDataSets: removed datasets report removals, added ones are created or initialized. | Excluded datasets are ignored; a 404 during asynchronous initialization reports LOCUS_NOT_FOUND | `src/hashTree/hashTreeParser.ts`, `test/unit/spec/hashTree/hashTreeParser.ts` |
402
+ | `UC-8` | `LocusInfo.syncAllHashTreeDatasets`, for example after a network reconnection | `syncAllDatasets` waits one backoff and syncs every dataset, or only the LLM ones. | Concurrent calls collapse into one; the scope can only widen | `src/hashTree/hashTreeParser.ts`, `src/locus-info/index.ts` |
403
+ | `UC-9` | `LocusInfo` with a Locus API response | `handleLocusUpdate` applies the response's datasets, Metadata, and `htMeta` objects and reports what changed. | Unknown or invisible datasets are logged and ignored | `src/hashTree/hashTreeParser.ts`, `test/unit/spec/hashTree/hashTreeParser.ts` |
404
+
405
+ <!-- Include if: the module calls another service or crosses an event or network boundary. [condition-id: module.crosses_service_boundaries] -->
406
+
407
+ ### Cross-boundary use-case flow
408
+
409
+ | Boundary | Transport and ordering | Compatibility | Timeout, retry, and recovery |
410
+ | -------- | ---------------------- | ------------- | ---------------------------- |
411
+ | Locus visibleDataSetsUrl (`UC-2`, `UC-7`) | HTTPS GET through the injected request function | Response `body.dataSets` | No retry; 404 and 409/2403004 become sentinel errors |
412
+ | Locus dataset hashtree (`UC-4`) | HTTPS GET `<dataset url>/hashtree?rootHash`, then the sync request, one dataset at a time | Empty body means match; otherwise `hashes` and `dataSet.leafCount` | A plain 409 waits for the next heartbeat; a later timer or watchdog retries |
413
+ | Locus dataset sync (`UC-2`, `UC-4`) | HTTPS POST `<dataset url>/sync?rootHash` with the leaf entries; tracking id forced in the header | Response is empty or a hash tree message | The root-hash timer is re-armed after every sync as the retry path |
414
+ | Inbound messages through `LocusInfo` (`UC-3`, `UC-6`) | Synchronous `handleMessage` calls in arrival order | Message fields under Protocol and wire format | A message cancels queued and in-flight syncs for its datasets |
415
+
416
+ <!-- Include if: the module holds client-side state. [condition-id: module.holds_client_state] -->
417
+
418
+ ## Client state model
419
+
420
+ Per-dataset version, root, leaf count, timing, and leaf items (type, id, version), pending
421
+ synchronization work, and timers are held in memory; object data is passed to the callback and not
422
+ kept.
423
+
424
+ | State or slice | Owner | Initial state | Transition triggers | Reset or persistence boundary |
425
+ | -------------- | ---------- | ------------- | ------------------- | ----------------------------- |
426
+ | `dataSets` (name to dataset info, optional hash tree, timers, abort controller) | `HashTreeParser` | From the constructor's `initialLocus.dataSets` | Messages, heartbeats, API responses, initialization, visible dataset changes | `stop()` drops the hash trees; `cleanUp()` and both resumes empty the table |
427
+ | `visibleDataSets` | `HashTreeParser` | Metadata visibleDataSets present in dataSets and not excluded | Metadata changes, initialization | Emptied by `stop()`; rebuilt by resume |
428
+ | Hash tree leaves | `HashTree` | Seeded from initial `htMeta` items, or empty | put, remove, update, resize | Dropped with the hash tree |
429
+ | `syncQueue`, `isSyncInProgress` | `HashTreeParser` | Empty, false | Timers, watchdogs, initialization, `syncAllDatasets` | Emptied by `stop()` |
430
+ | `syncAllBackoffType`, `dataSetsSyncedDuringBackoff` | `HashTreeParser` | `none`, empty | `syncAllDatasets` and messages during its sleep | Reset after the sleep and by `stop()` |
431
+ | `topLevelHeartbeatIntervalMs`, `pendingLlmWatchdogDataSetNames` | `HashTreeParser` | Unset, empty | Messages with `heartbeatIntervalMs`; LLM watchdog skips; `reevaluateLlmWatchdogs` | Cleared by `stop()` |
432
+ | `state` | `HashTreeParser` | `active` | `stop()`, resume | See State machine |
433
+
434
+ <!-- Include if: the module enforces domain rules or entity invariants. [condition-id: module.enforces_domain_rules] -->
435
+
436
+ ## Business rules and invariants
437
+
438
+ | ID | Invariant | WHY | Enforcement source | Test evidence |
439
+ | -- | --------- | --- | ------------------ | ------------- |
440
+ | `INV-001` | `HashTreeParser` applies only newer item versions and emits the applied-object callback for the received message after filtering out objects another visible dataset holds in a newer version. Root-hash mismatch detection is a later idle/backoff task that can enqueue synchronization; it is not a precondition for the first callback. | Consumers get applied changes promptly, and reconciliation cannot reorder or hold them back (`HASH-TREE-R-002`, `HASH-TREE-R-007`). | `src/hashTree/hashTreeParser.ts`, `src/hashTree/hashTree.ts` | `test/unit/spec/hashTree/hashTreeParser.ts` |
441
+ | `INV-002` | Only visible datasets have a hash tree, and only datasets with a hash tree are synced, timed, or supervised. | Locus answers 400 for a dataset that is not visible, and Locus mentions datasets the client cannot see (code comments). | `src/hashTree/hashTreeParser.ts` | `test/unit/spec/hashTree/hashTreeParser.ts` |
442
+ | `INV-003` | At most one sync runs at a time per parser, and each dataset is queued at most once. | `HASH-TREE-R-010`. | `src/hashTree/hashTreeParser.ts` | `test/unit/spec/hashTree/hashTreeParser.ts` |
443
+ | `INV-004` | A stopped parser never calls `locusInfoUpdateCallback` and never starts a new sync. | A replaced Locus URL must not change the meeting state of its successor (`LocusInfo` stops the old parser when it creates a new one). | `src/hashTree/hashTreeParser.ts`, `src/locus-info/index.ts` | `test/unit/spec/hashTree/hashTreeParser.ts` |
444
+
445
+ <!-- Include if: the module is concurrent, asynchronous, reactive, or event-driven. [condition-id: module.is_concurrent_async] -->
446
+
447
+ ## Concurrency and reactive flow
448
+
449
+ - State-elements work applies through `parseMessage()` and callbacks synchronously within
450
+ `handleMessage()`, while root-hash reconciliation is deferred by dataset timers. `stop()` prevents
451
+ queued or subsequently completed dataset work from mutating the stopped parser: the queue loop
452
+ ends, in-flight syncs are aborted, and the callback is suppressed.
453
+ - Heartbeat watchdog timers are per dataset and are re-armed after the owning message has been
454
+ applied, so watchdog delay is measured from application rather than from receipt.
455
+ `stopAllTimers()` clears them alongside the sync timers.
456
+ - Execution model: one JavaScript event loop; timers for root-hash checks and watchdogs; one async
457
+ sync loop; `queueMicrotask` starts the asynchronous initialization of new visible datasets.
458
+ - Ordering guarantees: messages are applied in the order `LocusInfo` passes them; syncs run in queue
459
+ order; initialization and `syncAllDatasets` follow main, self, then the rest.
460
+ - Idempotency and retry: re-applying an item with the same version changes nothing; a dataset is
461
+ queued once; nothing is retried immediately — the next timer, watchdog, or heartbeat is the retry.
462
+ - Shared-state protection: one owner (the parser); an `AbortController` per dataset lets a message
463
+ cancel the sync it makes obsolete.
464
+ - Blocking restrictions: `handleMessage`, `handleLocusUpdate`, and `handleMetadataUpdate` are
465
+ synchronous and deliver their callback before returning; the only awaits are in initialization,
466
+ resume from an API response, `syncAllDatasets`, and the sync loop.
467
+
468
+ <!-- Include if: the module has non-trivial state transitions. [condition-id: module.stateful_transitions] -->
469
+
470
+ ## State machine
471
+
472
+ ```mermaid
473
+ stateDiagram-v2
474
+ [*] --> active: construct
475
+ active --> active: apply or synchronize dataset update
476
+ active --> stopped: stop(), cleanUp(), or LOCUS_NOT_FOUND
477
+ stopped --> active: resumeFromMessage() or resumeFromApiResponse()
478
+ stopped --> stopped: messages, syncs, and callbacks ignored
479
+ ```
480
+
481
+ The parser stores only `active` or `stopped` in `src/hashTree/hashTreeParser.ts`. The
482
+ end-of-meeting sentinel and `MEETING_ENDED` stop the timers but leave the state `active`;
483
+ `resumeFromMessage()` stays stopped when the message has no Metadata visibleDataSets.
484
+
485
+ <!-- Include if: callers depend on a wire protocol or serialized format. [condition-id: module.exposes_wire_protocol] -->
486
+
487
+ ## Protocol and wire format
488
+
489
+ - External payloads are parsed/serialized by files under `src/hashTree/` and the injected Webex
490
+ request function. Preserve current field names, enum/raw values, dataset versions, and
491
+ compatibility behavior; do not treat the normalized client model as the wire schema.
492
+
493
+ | Message or frame | Version | Producer or serializer | Consumer or parser | Compatibility and ordering rule |
494
+ | ---------------- | ------- | ---------------------- | ------------------ | ------------------------------- |
495
+ | Hash tree message: `dataSets`, `visibleDataSetsUrl`, `locusStateElements`, `locusSessionId`, `locusUrl`, `heartbeatIntervalMs` | Per dataset `version` | Locus (Mercury, LLM, or a sync response) | `handleMessage` in `src/hashTree/hashTreeParser.ts` | A dataset's info is replaced only by a higher version; an element without `data` is a removal |
496
+ | Heartbeat (root hash) message: `dataSets` with no `locusStateElements` | Per dataset `version` | Locus | `handleRootHashHeartBeatMessage` | Updates version and root only |
497
+ | `DataSet`: `url`, `root`, `version`, `leafCount`, `name`, `idleMs`, `backoff {maxMs, exponent}`, `heartbeatIntervalMs` | `version` | Locus | `updateDataSetInfo` | Dataset-level `heartbeatIntervalMs` wins over the top-level one |
498
+ | `HashTreeObject`: `htMeta.elementId {type, id, version}`, `htMeta.dataSetNames`, `data` | `elementId.version` | Locus | `src/hashTree/types.ts`, `src/hashTree/hashTree.ts` | Types are matched case-insensitively for self and metadata; `ObjectTypeToLocusKeyMap` maps types to Locus DTO keys |
499
+ | Metadata object with `visibleDataSets [{name, url, dataChannelUrl}]` | `elementId.version` | Locus, in the self dataset only | `checkForVisibleDataSetChanges` | Only Metadata changes the visible dataset list |
500
+ | GET `<dataset url>/hashtree?rootHash=<ours>` | — | `getHashesFromLocus` | Locus | Empty body means our hashes match; else `{hashes, dataSet}` |
501
+ | POST `<dataset url>/sync?rootHash=<ours>` with `{leafCount, leafDataEntries: [{leafIndex, elementIds}]}` | — | `sendSyncRequestToLocus` | Locus | Initialization sends leafCount 1 and leaf 0 empty; the response is a hash tree message or empty |
502
+ | Leaf and node hashes | — | `src/hashTree/hashTree.ts` | Locus comparison | XXH3-128 over 64-bit little-endian id and version pairs (`HASH-TREE-R-006`) |
503
+
504
+ <!-- Include if: the module returns or raises errors callers must handle. [condition-id: module.returns_caller_errors] -->
505
+
506
+ ## Caller-visible failure modes
507
+
508
+ | Condition | Signal | Caller recovery |
509
+ |---|---|---|
510
+ | Hash comparison requires a missing dataset leaf set | `hashTreeParser.ts` requests the dataset hashes and then syncs the mismatched leaves through the injected request function; the response, or later messages, carry the synchronized items. | Let the synchronization request settle; do not apply the incomplete delta directly. |
511
+ | Dataset request returns 404, Locus returns 409 with `LOCUS_INACTIVE`, or an end-of-meeting sentinel message arrives | The parser invokes its established not-found/ended callback path: `LOCUS_NOT_FOUND` (the parser also stops) or `MEETING_ENDED`. | The owner decides whether to stop or establish a new dataset. |
512
+ | Dataset fetch fails outside the ended/not-found sentinels, or queued work reaches a stopped parser | `performSync()` catches/logs the fetch failure after `HASH_TREE_SYNC_FAILURE` is sent; stopped-parser work is not applied. | Observe parser diagnostics and establish a new synchronization trigger if the owner still needs current state. |
513
+ | No heartbeat arrives for a visible dataset within its interval plus backoff | The watchdog fires, emits `HASH_TREE_HEARTBEAT_WATCHDOG_EXPIRED`, enqueues a sync for that dataset, and re-arms. For an LLM dataset while `isLlmExpected()` is false, no watchdog is armed and the skip is logged; `reevaluateLlmWatchdogs()` arms it later. | Do not treat a missing watchdog metric as proof of a healthy transport; check whether the dataset is visible and whether LLM is expected. |
514
+ | `initializeFromMessage`, `initializeFromGetLociResponse`, or `resumeFromApiResponse` gets 404 or 409/2403004 from visibleDataSetsUrl | The returned promise rejects with `LocusNotFoundError` or `MeetingEndedError`; other request errors reject unchanged. | Catch the rejection and treat it as Locus not found or meeting ended. |
515
+ | A Metadata object whose `htMeta.dataSetNames` is not exactly self is passed to the constructor | `Error` naming the unexpected dataset names. | Do not create the parser from that input. |
516
+ | `new HashTree` or `resize` with a leaf count that is not 0 or a power of 2 | `Error`. | Pass the leaf count Locus sent. |
517
+
518
+ ## Pitfalls and constraints
519
+
520
+ - Dataset and item versions are compared as plain numbers (`<`, `<=`, `>`); there is no rollover
521
+ handling. Changing the operators changes which updates and removals apply.
522
+ - Public behavior of this module is reachable only through a parent `Meeting` (its `LocusInfo`) and
523
+ `Meetings` object: no source helper here is exported directly from `src/index.ts`.
524
+ - On the state-elements path `handleMessage` always passes its result to the update filter, even an
525
+ empty list; the filter then makes no call, so `LocusInfo` sees no update.
526
+ - `MEETING_ENDED` from a sync or sentinel stops the timers but leaves the parser `active`; only
527
+ `LOCUS_NOT_FOUND` also calls `stop()`.
528
+ - A sync response that includes other datasets is cut down to the requested one; applying it whole
529
+ would apply shared datasets such as unjoined twice.
530
+ - `stop()` drops every hash tree, so a resumed parser starts empty and must sync.
531
+
532
+ <!-- Include if: the module has a non-obvious design trade-off consumers or maintainers must preserve. [condition-id: module.has_design_tradeoff] -->
533
+
534
+ ## Key design trade-off
535
+
536
+ | Chosen trade-off | Preserved invariant or benefit | Cost or limitation | Decision evidence |
537
+ | ---------------- | ------------------------------ | ------------------ | ----------------- |
538
+ | Incremental datasets reduce full-state traffic but require version, checksum, and resynchronization bookkeeping. | Messages carry only changed objects; a short hash exchange finds and repairs only the differing leaves. | The client must reproduce Locus's leaf layout and hash bytes, and keep per-dataset timers, watchdogs, and a sync queue. | `src/hashTree/hashTreeParser.ts`, `src/hashTree/hashTree.ts` |
539
+ | Reconciliation runs after an idle delay plus a random backoff, not on every message. | Callbacks are not delayed; many clients do not sync at the same moment. | State can be briefly wrong until the timer or a message repairs it. | `src/hashTree/hashTreeParser.ts` |
540
+
541
+ ## Verification
542
+
543
+ Use the current mirrored suites: `test/unit/spec/hashTree/hashTree.ts`,
544
+ `test/unit/spec/hashTree/hashTreeParser.ts`, `test/unit/spec/hashTree/utils.ts`. Characterize the
545
+ hashTree-specific use cases above and each listed failure condition; add cleanup or transition cases
546
+ only for resources and state this module actually owns.
547
+
548
+ | Behavior / Requirement | Existing test evidence | Gap |
549
+ |---|---|---|
550
+ | `HASH-TREE-R-001` | `test/unit/spec/hashTree/hashTree.ts`, `test/unit/spec/hashTree/hashTreeParser.ts` | none: versioned put/remove/resize/diff are covered separately from parser synchronization |
551
+ | `HASH-TREE-R-002` | `test/unit/spec/hashTree/hashTreeParser.ts` | non-sentinel synchronization failures are logged internally and clear the abort controller; the queue moving on to the next entry after that failure has no case |
552
+ | `HASH-TREE-R-003` | `test/unit/spec/hashTree/hashTreeParser.ts` | sentinel callbacks (409/2403004, 404), the `HASH_TREE_SYNC_FAILURE` metric, and stopped-parser suppression have cases; the plain-409 hashtree branch has none |
553
+ | `HASH-TREE-R-004` | `test/unit/spec/hashTree/hashTreeParser.ts` | none: the dataset-level interval preference, the invisible-dataset and LLM-not-expected skips, `reevaluateLlmWatchdogs`, expiry re-arming, and re-arm on normal messages have cases |
554
+ | `HASH-TREE-R-005`, `HASH-TREE-R-006` | `test/unit/spec/hashTree/hashTree.ts` | none |
555
+ | `HASH-TREE-R-007` | `test/unit/spec/hashTree/hashTreeParser.ts` | none |
556
+ | `HASH-TREE-R-008` | `test/unit/spec/hashTree/hashTreeParser.ts` | none |
557
+ | `HASH-TREE-R-009` | `test/unit/spec/hashTree/hashTreeParser.ts` | the plain-409 leaf count mismatch branch has no case |
558
+ | `HASH-TREE-R-010`, `HASH-TREE-R-011` | `test/unit/spec/hashTree/hashTreeParser.ts` | none |
559
+ | `HASH-TREE-R-012` | `test/unit/spec/hashTree/hashTreeParser.ts` | none |
560
+ | `HASH-TREE-R-013` | `test/unit/spec/hashTree/hashTreeParser.ts` | none |
561
+ | `HASH-TREE-R-014` | `test/unit/spec/hashTree/utils.ts`, `test/unit/spec/hashTree/hashTreeParser.ts` | none |
562
+ | `HASH-TREE-R-015` | `test/unit/spec/hashTree/hashTreeParser.ts` | none |
563
+ | `HASH-TREE-R-016` | `test/unit/spec/hashTree/hashTreeParser.ts` | the constructor throwing for Metadata outside self has no case |
564
+ | `INV-004` | `test/unit/spec/hashTree/hashTreeParser.ts` | none |
565
+
566
+ Record coverage gaps explicitly; the gaps above are the follow-up work.