Skip to content

Commit 98b37ef

Browse files
quic-boyucclaude
andcommitted
observatory: default graph compare sync to sparse_match_key for per-layer accuracy
Add `default_sync` field to `GraphCompareSpec` so lenses can declare their preferred compare sync strategy. The per-layer accuracy lens now defaults to `mode: "layer"` on `sparse_match_key` instead of the generic auto mode, giving immediate node correspondence when comparing records side-by-side. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3521c1a commit 98b37ef

5 files changed

Lines changed: 18 additions & 4 deletions

File tree

devtools/fx_viewer/templates/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ layout.container
9494
| `'layer'` | Ext: \<extId\>.\<field\> | Matches by `extensions[layer].nodes[nodeId].info[field]` value equality; picks last in topo order on multiple matches |
9595
| `'none'` | Don't sync | No cross-viewer selection propagation |
9696

97+
The initial sync mode can be set programmatically via `config.sync` at construction time. Observatory's `GraphCompareSpec.default_sync` maps directly to this field, allowing lenses to declare their preferred default sync strategy.
98+
9799
#### `debug_handle` normalization (`mode: 'auto'`)
98100

99101
`debug_handle` in `node.info` is `int` (scalar) or `int[]` (list, for fused nodes). The sync engine normalizes both to a `Set<int>` and uses **set intersection** to find matches:

devtools/observatory/REFERENCE.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,9 +447,10 @@ Fields:
447447
1. `mode: "auto" | "disabled" | "custom"`
448448
2. `max_parallel: int >= 1`
449449
3. `sync_toggle: bool`
450-
4. `viewer_options_compare: dict`
451-
5. `js_func: str | None`
452-
6. `args: dict`
450+
4. `default_sync: dict` — initial `FXGraphCompare` sync config passed as `config.sync`. Keys: `mode` (`"auto"`, `"id"`, `"layer"`, `"none"`), `layer` (extension id), `field` (info key). Empty dict (default) falls back to `{ mode: "auto" }`.
451+
5. `viewer_options_compare: dict`
452+
6. `js_func: str | None`
453+
7. `args: dict`
453454
454455
#### 2. Validation API
455456

devtools/observatory/interfaces.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ class GraphCompareSpec:
189189
mode: Literal["auto", "disabled", "custom"] = "auto"
190190
max_parallel: int = 2
191191
sync_toggle: bool = True
192+
default_sync: Dict[str, str] = field(default_factory=dict)
192193
viewer_options_compare: Dict[str, Serializable] = field(default_factory=dict)
193194
js_func: Optional[str] = None
194195
args: Dict[str, Serializable] = field(default_factory=dict)

devtools/observatory/lenses/per_layer_accuracy.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from ..interfaces import (
3030
AnalysisResult,
3131
Frontend,
32+
GraphCompareSpec,
3233
GraphView,
3334
HtmlBlock,
3435
HtmlRecordSpec,
@@ -811,6 +812,13 @@ def record(
811812
graph_ref=graph_ref,
812813
default_layers=[f"{lens_name}/cosine_sim"],
813814
default_color_by=f"{lens_name}/cosine_sim",
815+
compare=GraphCompareSpec(
816+
default_sync={
817+
"mode": "layer",
818+
"layer": f"{lens_name}/cosine_sim",
819+
"field": "sparse_match_key",
820+
}
821+
),
814822
order=21,
815823
).as_block(),
816824
HtmlBlock(

devtools/observatory/templates/js/03_blocks.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,9 @@
436436
const compare = CompareCtor.create({
437437
viewers: viewerMap,
438438
layout: { container: content },
439-
sync: { mode: 'auto' },
439+
sync: compareSpec.default_sync && compareSpec.default_sync.mode
440+
? compareSpec.default_sync
441+
: { mode: 'auto' },
440442
});
441443

442444
state.graphCompareInstances.set(cacheKey, { compare, nameToIndex });

0 commit comments

Comments
 (0)