1mod execution_trace;
7#[cfg(test)]
8mod tests;
9
10use crate::{
11 db::{
12 Db, EntityRuntimeHooks,
13 commit::CommitRowOp,
14 data::{DataKey, StorageKey, decode_structural_row_cbor},
15 index::IndexKey,
16 registry::StoreHandle,
17 },
18 error::{ErrorClass, InternalError},
19 traits::CanisterKind,
20 types::EntityTag,
21};
22use candid::CandidType;
23use serde::Deserialize;
24use std::collections::{BTreeMap, BTreeSet};
25
26pub use execution_trace::{
27 ExecutionAccessPathVariant, ExecutionMetrics, ExecutionOptimization, ExecutionTrace,
28};
29
30#[cfg_attr(doc, doc = "StorageReport\n\nLive storage snapshot payload.")]
31#[derive(CandidType, Clone, Debug, Default, Deserialize)]
32pub struct StorageReport {
33 pub(crate) storage_data: Vec<DataStoreSnapshot>,
34 pub(crate) storage_index: Vec<IndexStoreSnapshot>,
35 pub(crate) entity_storage: Vec<EntitySnapshot>,
36 pub(crate) corrupted_keys: u64,
37 pub(crate) corrupted_entries: u64,
38}
39
40#[cfg_attr(
41 doc,
42 doc = "IntegrityTotals\n\nAggregated integrity-scan counters across all stores."
43)]
44#[derive(CandidType, Clone, Debug, Default, Deserialize)]
45pub struct IntegrityTotals {
46 pub(crate) data_rows_scanned: u64,
47 pub(crate) index_entries_scanned: u64,
48 pub(crate) corrupted_data_keys: u64,
49 pub(crate) corrupted_data_rows: u64,
50 pub(crate) corrupted_index_keys: u64,
51 pub(crate) corrupted_index_entries: u64,
52 pub(crate) missing_index_entries: u64,
53 pub(crate) divergent_index_entries: u64,
54 pub(crate) orphan_index_references: u64,
55 pub(crate) compatibility_findings: u64,
56 pub(crate) misuse_findings: u64,
57}
58
59impl IntegrityTotals {
60 const fn add_store_snapshot(&mut self, store: &IntegrityStoreSnapshot) {
61 self.data_rows_scanned = self
62 .data_rows_scanned
63 .saturating_add(store.data_rows_scanned);
64 self.index_entries_scanned = self
65 .index_entries_scanned
66 .saturating_add(store.index_entries_scanned);
67 self.corrupted_data_keys = self
68 .corrupted_data_keys
69 .saturating_add(store.corrupted_data_keys);
70 self.corrupted_data_rows = self
71 .corrupted_data_rows
72 .saturating_add(store.corrupted_data_rows);
73 self.corrupted_index_keys = self
74 .corrupted_index_keys
75 .saturating_add(store.corrupted_index_keys);
76 self.corrupted_index_entries = self
77 .corrupted_index_entries
78 .saturating_add(store.corrupted_index_entries);
79 self.missing_index_entries = self
80 .missing_index_entries
81 .saturating_add(store.missing_index_entries);
82 self.divergent_index_entries = self
83 .divergent_index_entries
84 .saturating_add(store.divergent_index_entries);
85 self.orphan_index_references = self
86 .orphan_index_references
87 .saturating_add(store.orphan_index_references);
88 self.compatibility_findings = self
89 .compatibility_findings
90 .saturating_add(store.compatibility_findings);
91 self.misuse_findings = self.misuse_findings.saturating_add(store.misuse_findings);
92 }
93
94 #[must_use]
96 pub const fn data_rows_scanned(&self) -> u64 {
97 self.data_rows_scanned
98 }
99
100 #[must_use]
102 pub const fn index_entries_scanned(&self) -> u64 {
103 self.index_entries_scanned
104 }
105
106 #[must_use]
108 pub const fn corrupted_data_keys(&self) -> u64 {
109 self.corrupted_data_keys
110 }
111
112 #[must_use]
114 pub const fn corrupted_data_rows(&self) -> u64 {
115 self.corrupted_data_rows
116 }
117
118 #[must_use]
120 pub const fn corrupted_index_keys(&self) -> u64 {
121 self.corrupted_index_keys
122 }
123
124 #[must_use]
126 pub const fn corrupted_index_entries(&self) -> u64 {
127 self.corrupted_index_entries
128 }
129
130 #[must_use]
132 pub const fn missing_index_entries(&self) -> u64 {
133 self.missing_index_entries
134 }
135
136 #[must_use]
138 pub const fn divergent_index_entries(&self) -> u64 {
139 self.divergent_index_entries
140 }
141
142 #[must_use]
144 pub const fn orphan_index_references(&self) -> u64 {
145 self.orphan_index_references
146 }
147
148 #[must_use]
150 pub const fn compatibility_findings(&self) -> u64 {
151 self.compatibility_findings
152 }
153
154 #[must_use]
156 pub const fn misuse_findings(&self) -> u64 {
157 self.misuse_findings
158 }
159}
160
161#[cfg_attr(
162 doc,
163 doc = "IntegrityStoreSnapshot\n\nPer-store integrity findings and scan counters."
164)]
165#[derive(CandidType, Clone, Debug, Default, Deserialize)]
166pub struct IntegrityStoreSnapshot {
167 pub(crate) path: String,
168 pub(crate) data_rows_scanned: u64,
169 pub(crate) index_entries_scanned: u64,
170 pub(crate) corrupted_data_keys: u64,
171 pub(crate) corrupted_data_rows: u64,
172 pub(crate) corrupted_index_keys: u64,
173 pub(crate) corrupted_index_entries: u64,
174 pub(crate) missing_index_entries: u64,
175 pub(crate) divergent_index_entries: u64,
176 pub(crate) orphan_index_references: u64,
177 pub(crate) compatibility_findings: u64,
178 pub(crate) misuse_findings: u64,
179}
180
181impl IntegrityStoreSnapshot {
182 #[must_use]
184 pub fn new(path: String) -> Self {
185 Self {
186 path,
187 ..Self::default()
188 }
189 }
190
191 #[must_use]
193 pub const fn path(&self) -> &str {
194 self.path.as_str()
195 }
196
197 #[must_use]
199 pub const fn data_rows_scanned(&self) -> u64 {
200 self.data_rows_scanned
201 }
202
203 #[must_use]
205 pub const fn index_entries_scanned(&self) -> u64 {
206 self.index_entries_scanned
207 }
208
209 #[must_use]
211 pub const fn corrupted_data_keys(&self) -> u64 {
212 self.corrupted_data_keys
213 }
214
215 #[must_use]
217 pub const fn corrupted_data_rows(&self) -> u64 {
218 self.corrupted_data_rows
219 }
220
221 #[must_use]
223 pub const fn corrupted_index_keys(&self) -> u64 {
224 self.corrupted_index_keys
225 }
226
227 #[must_use]
229 pub const fn corrupted_index_entries(&self) -> u64 {
230 self.corrupted_index_entries
231 }
232
233 #[must_use]
235 pub const fn missing_index_entries(&self) -> u64 {
236 self.missing_index_entries
237 }
238
239 #[must_use]
241 pub const fn divergent_index_entries(&self) -> u64 {
242 self.divergent_index_entries
243 }
244
245 #[must_use]
247 pub const fn orphan_index_references(&self) -> u64 {
248 self.orphan_index_references
249 }
250
251 #[must_use]
253 pub const fn compatibility_findings(&self) -> u64 {
254 self.compatibility_findings
255 }
256
257 #[must_use]
259 pub const fn misuse_findings(&self) -> u64 {
260 self.misuse_findings
261 }
262}
263
264#[cfg_attr(
265 doc,
266 doc = "IntegrityReport\n\nFull integrity-scan output across all registered stores."
267)]
268#[derive(CandidType, Clone, Debug, Default, Deserialize)]
269pub struct IntegrityReport {
270 pub(crate) stores: Vec<IntegrityStoreSnapshot>,
271 pub(crate) totals: IntegrityTotals,
272}
273
274impl IntegrityReport {
275 #[must_use]
277 pub const fn new(stores: Vec<IntegrityStoreSnapshot>, totals: IntegrityTotals) -> Self {
278 Self { stores, totals }
279 }
280
281 #[must_use]
283 pub const fn stores(&self) -> &[IntegrityStoreSnapshot] {
284 self.stores.as_slice()
285 }
286
287 #[must_use]
289 pub const fn totals(&self) -> &IntegrityTotals {
290 &self.totals
291 }
292}
293
294impl StorageReport {
295 #[must_use]
297 pub const fn new(
298 storage_data: Vec<DataStoreSnapshot>,
299 storage_index: Vec<IndexStoreSnapshot>,
300 entity_storage: Vec<EntitySnapshot>,
301 corrupted_keys: u64,
302 corrupted_entries: u64,
303 ) -> Self {
304 Self {
305 storage_data,
306 storage_index,
307 entity_storage,
308 corrupted_keys,
309 corrupted_entries,
310 }
311 }
312
313 #[must_use]
315 pub const fn storage_data(&self) -> &[DataStoreSnapshot] {
316 self.storage_data.as_slice()
317 }
318
319 #[must_use]
321 pub const fn storage_index(&self) -> &[IndexStoreSnapshot] {
322 self.storage_index.as_slice()
323 }
324
325 #[must_use]
327 pub const fn entity_storage(&self) -> &[EntitySnapshot] {
328 self.entity_storage.as_slice()
329 }
330
331 #[must_use]
333 pub const fn corrupted_keys(&self) -> u64 {
334 self.corrupted_keys
335 }
336
337 #[must_use]
339 pub const fn corrupted_entries(&self) -> u64 {
340 self.corrupted_entries
341 }
342}
343
344#[cfg_attr(doc, doc = "DataStoreSnapshot\n\nData-store snapshot row.")]
345#[derive(CandidType, Clone, Debug, Default, Deserialize)]
346pub struct DataStoreSnapshot {
347 pub(crate) path: String,
348 pub(crate) entries: u64,
349 pub(crate) memory_bytes: u64,
350}
351
352impl DataStoreSnapshot {
353 #[must_use]
355 pub const fn new(path: String, entries: u64, memory_bytes: u64) -> Self {
356 Self {
357 path,
358 entries,
359 memory_bytes,
360 }
361 }
362
363 #[must_use]
365 pub const fn path(&self) -> &str {
366 self.path.as_str()
367 }
368
369 #[must_use]
371 pub const fn entries(&self) -> u64 {
372 self.entries
373 }
374
375 #[must_use]
377 pub const fn memory_bytes(&self) -> u64 {
378 self.memory_bytes
379 }
380}
381
382#[cfg_attr(doc, doc = "IndexStoreSnapshot\n\nIndex-store snapshot row.")]
383#[derive(CandidType, Clone, Debug, Default, Deserialize)]
384pub struct IndexStoreSnapshot {
385 pub(crate) path: String,
386 pub(crate) entries: u64,
387 pub(crate) user_entries: u64,
388 pub(crate) system_entries: u64,
389 pub(crate) memory_bytes: u64,
390}
391
392impl IndexStoreSnapshot {
393 #[must_use]
395 pub const fn new(
396 path: String,
397 entries: u64,
398 user_entries: u64,
399 system_entries: u64,
400 memory_bytes: u64,
401 ) -> Self {
402 Self {
403 path,
404 entries,
405 user_entries,
406 system_entries,
407 memory_bytes,
408 }
409 }
410
411 #[must_use]
413 pub const fn path(&self) -> &str {
414 self.path.as_str()
415 }
416
417 #[must_use]
419 pub const fn entries(&self) -> u64 {
420 self.entries
421 }
422
423 #[must_use]
425 pub const fn user_entries(&self) -> u64 {
426 self.user_entries
427 }
428
429 #[must_use]
431 pub const fn system_entries(&self) -> u64 {
432 self.system_entries
433 }
434
435 #[must_use]
437 pub const fn memory_bytes(&self) -> u64 {
438 self.memory_bytes
439 }
440}
441
442#[cfg_attr(doc, doc = "EntitySnapshot\n\nPer-entity storage snapshot row.")]
443#[derive(CandidType, Clone, Debug, Default, Deserialize)]
444pub struct EntitySnapshot {
445 pub(crate) store: String,
446
447 pub(crate) path: String,
448
449 pub(crate) entries: u64,
450
451 pub(crate) memory_bytes: u64,
452}
453
454impl EntitySnapshot {
455 #[must_use]
457 pub const fn new(store: String, path: String, entries: u64, memory_bytes: u64) -> Self {
458 Self {
459 store,
460 path,
461 entries,
462 memory_bytes,
463 }
464 }
465
466 #[must_use]
468 pub const fn store(&self) -> &str {
469 self.store.as_str()
470 }
471
472 #[must_use]
474 pub const fn path(&self) -> &str {
475 self.path.as_str()
476 }
477
478 #[must_use]
480 pub const fn entries(&self) -> u64 {
481 self.entries
482 }
483
484 #[must_use]
486 pub const fn memory_bytes(&self) -> u64 {
487 self.memory_bytes
488 }
489}
490
491#[cfg_attr(
492 doc,
493 doc = "EntityStats\n\nInternal struct for building per-entity stats before snapshotting."
494)]
495#[derive(Default)]
496struct EntityStats {
497 entries: u64,
498 memory_bytes: u64,
499}
500
501impl EntityStats {
502 const fn update(&mut self, value_len: u64) {
504 self.entries = self.entries.saturating_add(1);
505 self.memory_bytes = self
506 .memory_bytes
507 .saturating_add(DataKey::entry_size_bytes(value_len));
508 }
509}
510
511fn storage_report_name_for_hook<'a, C: CanisterKind>(
512 name_map: &BTreeMap<&'static str, &'a str>,
513 hooks: &EntityRuntimeHooks<C>,
514) -> &'a str {
515 name_map
516 .get(hooks.entity_path)
517 .copied()
518 .or_else(|| name_map.get(hooks.model.name()).copied())
519 .unwrap_or(hooks.entity_path)
520}
521
522#[cfg_attr(
523 doc,
524 doc = "Build one deterministic storage snapshot with per-entity rollups.\n\nThis path is read-only and fail-closed on decode/validation errors by counting corrupted keys/entries instead of panicking."
525)]
526pub(crate) fn storage_report<C: CanisterKind>(
527 db: &Db<C>,
528 name_to_path: &[(&'static str, &'static str)],
529) -> Result<StorageReport, InternalError> {
530 db.ensure_recovered_state()?;
531 let name_map: BTreeMap<&'static str, &str> = name_to_path.iter().copied().collect();
535 let mut tag_name_map = BTreeMap::<EntityTag, &str>::new();
536 for hooks in db.entity_runtime_hooks {
537 tag_name_map
538 .entry(hooks.entity_tag)
539 .or_insert_with(|| storage_report_name_for_hook(&name_map, hooks));
540 }
541 let mut data = Vec::new();
542 let mut index = Vec::new();
543 let mut entity_storage: Vec<EntitySnapshot> = Vec::new();
544 let mut corrupted_keys = 0u64;
545 let mut corrupted_entries = 0u64;
546
547 db.with_store_registry(|reg| {
548 let mut stores = reg.iter().collect::<Vec<_>>();
550 stores.sort_by_key(|(path, _)| *path);
551
552 for (path, store_handle) in stores {
553 store_handle.with_data(|store| {
555 data.push(DataStoreSnapshot::new(
556 path.to_string(),
557 store.len(),
558 store.memory_bytes(),
559 ));
560
561 let mut by_entity: BTreeMap<EntityTag, EntityStats> = BTreeMap::new();
563
564 for entry in store.iter() {
565 let Ok(dk) = DataKey::try_from_raw(entry.key()) else {
566 corrupted_keys = corrupted_keys.saturating_add(1);
567 continue;
568 };
569
570 let value_len = entry.value().len() as u64;
571
572 by_entity
573 .entry(dk.entity_tag())
574 .or_default()
575 .update(value_len);
576 }
577
578 for (entity_tag, stats) in by_entity {
579 let path_name = tag_name_map
580 .get(&entity_tag)
581 .copied()
582 .map(str::to_string)
583 .or_else(|| {
584 db.runtime_hook_for_entity_tag(entity_tag)
585 .ok()
586 .map(|hooks| {
587 storage_report_name_for_hook(&name_map, hooks).to_string()
588 })
589 })
590 .unwrap_or_else(|| format!("#{}", entity_tag.value()));
591 entity_storage.push(EntitySnapshot::new(
592 path.to_string(),
593 path_name,
594 stats.entries,
595 stats.memory_bytes,
596 ));
597 }
598 });
599
600 store_handle.with_index(|store| {
602 let mut user_entries = 0u64;
603 let mut system_entries = 0u64;
604
605 for (key, value) in store.entries() {
606 let Ok(decoded_key) = IndexKey::try_from_raw(&key) else {
607 corrupted_entries = corrupted_entries.saturating_add(1);
608 continue;
609 };
610
611 if decoded_key.uses_system_namespace() {
612 system_entries = system_entries.saturating_add(1);
613 } else {
614 user_entries = user_entries.saturating_add(1);
615 }
616
617 if value.validate().is_err() {
618 corrupted_entries = corrupted_entries.saturating_add(1);
619 }
620 }
621
622 index.push(IndexStoreSnapshot::new(
623 path.to_string(),
624 store.len(),
625 user_entries,
626 system_entries,
627 store.memory_bytes(),
628 ));
629 });
630 }
631 });
632
633 entity_storage
636 .sort_by(|left, right| (left.store(), left.path()).cmp(&(right.store(), right.path())));
637
638 Ok(StorageReport::new(
639 data,
640 index,
641 entity_storage,
642 corrupted_keys,
643 corrupted_entries,
644 ))
645}
646
647#[cfg_attr(
648 doc,
649 doc = "Build one deterministic integrity scan over all registered stores.\n\nThis scan is read-only and classifies findings as:\n- corruption: malformed persisted bytes or inconsistent structural links\n- compatibility: persisted payloads outside decode compatibility windows\n- misuse: unsupported runtime wiring (for example missing entity hooks)"
650)]
651pub(crate) fn integrity_report<C: CanisterKind>(
652 db: &Db<C>,
653) -> Result<IntegrityReport, InternalError> {
654 db.ensure_recovered_state()?;
655
656 integrity_report_after_recovery(db)
657}
658
659#[cfg_attr(
660 doc,
661 doc = "Build one deterministic integrity scan after recovery has already completed.\n\nCallers running inside recovery flow should use this variant to avoid recursive recovery gating."
662)]
663pub(in crate::db) fn integrity_report_after_recovery<C: CanisterKind>(
664 db: &Db<C>,
665) -> Result<IntegrityReport, InternalError> {
666 build_integrity_report(db)
667}
668
669fn build_integrity_report<C: CanisterKind>(db: &Db<C>) -> Result<IntegrityReport, InternalError> {
670 let mut stores = Vec::new();
671 let mut totals = IntegrityTotals::default();
672 let global_live_keys_by_entity = collect_global_live_keys_by_entity(db)?;
673
674 db.with_store_registry(|reg| {
675 let mut store_entries = reg.iter().collect::<Vec<_>>();
677 store_entries.sort_by_key(|(path, _)| *path);
678
679 for (path, store_handle) in store_entries {
680 let mut snapshot = IntegrityStoreSnapshot::new(path.to_string());
681 scan_store_forward_integrity(db, store_handle, &mut snapshot)?;
682 scan_store_reverse_integrity(store_handle, &global_live_keys_by_entity, &mut snapshot);
683
684 totals.add_store_snapshot(&snapshot);
685 stores.push(snapshot);
686 }
687
688 Ok::<(), InternalError>(())
689 })?;
690
691 Ok(IntegrityReport::new(stores, totals))
692}
693
694fn collect_global_live_keys_by_entity<C: CanisterKind>(
696 db: &Db<C>,
697) -> Result<BTreeMap<EntityTag, BTreeSet<StorageKey>>, InternalError> {
698 let mut keys = BTreeMap::<EntityTag, BTreeSet<StorageKey>>::new();
699
700 db.with_store_registry(|reg| {
701 for (_, store_handle) in reg.iter() {
702 store_handle.with_data(|data_store| {
703 for entry in data_store.iter() {
704 if let Ok(data_key) = DataKey::try_from_raw(entry.key()) {
705 keys.entry(data_key.entity_tag())
706 .or_default()
707 .insert(data_key.storage_key());
708 }
709 }
710 });
711 }
712
713 Ok::<(), InternalError>(())
714 })?;
715
716 Ok(keys)
717}
718
719fn scan_store_forward_integrity<C: CanisterKind>(
721 db: &Db<C>,
722 store_handle: StoreHandle,
723 snapshot: &mut IntegrityStoreSnapshot,
724) -> Result<(), InternalError> {
725 store_handle.with_data(|data_store| {
726 for entry in data_store.iter() {
727 snapshot.data_rows_scanned = snapshot.data_rows_scanned.saturating_add(1);
728
729 let raw_key = *entry.key();
730
731 let Ok(data_key) = DataKey::try_from_raw(&raw_key) else {
732 snapshot.corrupted_data_keys = snapshot.corrupted_data_keys.saturating_add(1);
733 continue;
734 };
735
736 let hooks = match db.runtime_hook_for_entity_tag(data_key.entity_tag()) {
737 Ok(hooks) => hooks,
738 Err(err) => {
739 classify_scan_error(err, snapshot)?;
740 continue;
741 }
742 };
743
744 let marker_row = CommitRowOp::new(
745 hooks.entity_path,
746 raw_key,
747 None,
748 Some(entry.value().as_bytes().to_vec()),
749 crate::db::schema::commit_schema_fingerprint_for_model(
750 hooks.entity_path,
751 hooks.model,
752 ),
753 );
754
755 if let Err(err) = decode_structural_row_cbor(&entry.value()) {
758 classify_scan_error(err, snapshot)?;
759 continue;
760 }
761
762 let prepared = match db.prepare_row_commit_op(&marker_row) {
763 Ok(prepared) => prepared,
764 Err(err) => {
765 classify_scan_error(err, snapshot)?;
766 continue;
767 }
768 };
769
770 for index_op in prepared.index_ops {
771 let Some(expected_value) = index_op.value else {
772 continue;
773 };
774
775 let actual = index_op
776 .store
777 .with_borrow(|index_store| index_store.get(&index_op.key));
778 match actual {
779 Some(actual_value) if actual_value == expected_value => {}
780 Some(_) => {
781 snapshot.divergent_index_entries =
782 snapshot.divergent_index_entries.saturating_add(1);
783 }
784 None => {
785 snapshot.missing_index_entries =
786 snapshot.missing_index_entries.saturating_add(1);
787 }
788 }
789 }
790 }
791
792 Ok::<(), InternalError>(())
793 })
794}
795
796fn scan_store_reverse_integrity(
798 store_handle: StoreHandle,
799 live_keys_by_entity: &BTreeMap<EntityTag, BTreeSet<StorageKey>>,
800 snapshot: &mut IntegrityStoreSnapshot,
801) {
802 store_handle.with_index(|index_store| {
803 for (raw_index_key, raw_index_entry) in index_store.entries() {
804 snapshot.index_entries_scanned = snapshot.index_entries_scanned.saturating_add(1);
805
806 let Ok(decoded_index_key) = IndexKey::try_from_raw(&raw_index_key) else {
807 snapshot.corrupted_index_keys = snapshot.corrupted_index_keys.saturating_add(1);
808 continue;
809 };
810
811 let index_entity_tag = data_entity_tag_for_index_key(&decoded_index_key);
812
813 let Ok(indexed_primary_keys) = raw_index_entry.decode_keys() else {
814 snapshot.corrupted_index_entries =
815 snapshot.corrupted_index_entries.saturating_add(1);
816 continue;
817 };
818
819 for primary_key in indexed_primary_keys {
820 let exists = live_keys_by_entity
821 .get(&index_entity_tag)
822 .is_some_and(|entity_keys| entity_keys.contains(&primary_key));
823 if !exists {
824 snapshot.orphan_index_references =
825 snapshot.orphan_index_references.saturating_add(1);
826 }
827 }
828 }
829 });
830}
831
832fn classify_scan_error(
834 err: InternalError,
835 snapshot: &mut IntegrityStoreSnapshot,
836) -> Result<(), InternalError> {
837 match err.class() {
838 ErrorClass::Corruption => {
839 snapshot.corrupted_data_rows = snapshot.corrupted_data_rows.saturating_add(1);
840 Ok(())
841 }
842 ErrorClass::IncompatiblePersistedFormat => {
843 snapshot.compatibility_findings = snapshot.compatibility_findings.saturating_add(1);
844 Ok(())
845 }
846 ErrorClass::Unsupported | ErrorClass::NotFound | ErrorClass::Conflict => {
847 snapshot.misuse_findings = snapshot.misuse_findings.saturating_add(1);
848 Ok(())
849 }
850 ErrorClass::Internal | ErrorClass::InvariantViolation => Err(err),
851 }
852}
853
854const fn data_entity_tag_for_index_key(index_key: &IndexKey) -> EntityTag {
856 index_key.index_id().entity_tag
857}