schema: lattice.agents/procedure/v1
id: tag-index-reconcile
name: "Reconcile a tag index"
surfaces:
  in_process:
    api: "ILatticeTreeAdminOperations.StartTagIndexReconcileAsync"
    source: "src/lattice.api.abstractions/TreeAdmin/ILatticeTreeAdminOperations.cs#StartTagIndexReconcileAsync"
  grpc:
    api: "/orleans.lattice.api.treeadmin/StartTagIndexReconcile"
    source: "src/lattice.api.treeadmin.grpc/LatticeTreeAdminGrpcMethods.cs#StartTagIndexReconcileMethodName"
  mcp_tool:
    api: "lattice_treeadmin_tag_index_reconcile_start"
    source: "src/lattice.api.mcp/Tools/TreeAdmin/TreeAdminToolGroup.cs"
preconditions:
  - id: surface-available
    check: "Every surface this procedure uses is registered on the host: read the availability of api/treeadmin.json and, for each MCP tool used (lattice_treeadmin_tag_index_reconcile_start), its availability in api/mcp.json. An MCP tool must also be listed in the session's tools/list."
    source: "docs/agents/api/treeadmin.json"
  - id: backing-tree-admin
    check: "Caller has Admin authority over the derived backing membership tree."
    source: "docs/lattice.api.treeadmin/README.md"
  - id: index-registered
    check: "The tag index backing tree exists."
    source: "docs/lattice.api.treeadmin/README.md"
  - id: source-readonly
    check: "Covered source trees are scanned read-only by the reconcile."
    source: "docs/lattice.api.treeadmin/README.md"
steps:
  - n: 1
    action: "Read tag index status."
    api: "ILatticeTreeAdmin.GetTagIndexStatusAsync / GetTagIndexStatus"
    expects: "Returns backing tree, covered trees, shard count, and reconcile state."
    source: "src/lattice.api.abstractions/TreeAdmin/ILatticeTreeAdmin.cs#GetTagIndexStatusAsync"
  - n: 2
    action: "Start tracked reconcile for the index name."
    api: "ILatticeTreeAdminOperations.StartTagIndexReconcileAsync / StartTagIndexReconcile / lattice_treeadmin_tag_index_reconcile_start"
    expects: "Returns an operation handle; poll tree-admin operation status for covered tree and orphan row counts."
    source: "src/lattice.api.abstractions/TreeAdmin/ILatticeTreeAdminOperations.cs#StartTagIndexReconcileAsync"
  - n: 3
    action: "Read status again to confirm background reconcile is idle, or list operations to recover a lost handle."
    api: "ILatticeTreeAdmin.GetTagIndexStatusAsync / GetTagIndexStatus and ILatticeTreeAdminOperations.ListOperationsAsync"
    expects: "Reports whether the background reconcile sweep is idle and exposes visible tracked reconcile operations newest-first."
    source: "src/lattice.api.abstractions/TreeAdmin/ILatticeTreeAdminOperations.cs#StartTagIndexReconcileAsync"
postconditions:
  - check: "Reconcile writes only to the backing membership tree."
    source: "docs/lattice.api.treeadmin/README.md"
  - check: "Result returns counts and does not disclose key or value content."
    source: "docs/lattice.api.treeadmin/README.md"
failure_modes:
  - id: factory-missing
    signal: "InvalidOperationException if the tag-index factory invariant is broken."
    effect: "No reconcile is performed."
    response: "Fix host registration."
  - id: operation-runner-lost
    signal: "Tracked tag-index operation status becomes Failed after the accepting silo is lost or stops heartbeating."
    effect: "The background reconcile is not resumed."
    response: "Start a new tracked reconcile after confirming the previous status."
  - id: missing-backing-tree
    signal: "Facade rejects an index whose backing tree is not registered."
    effect: "No reconcile is performed."
    response: "Define the tag index through the host code layer."
  - id: surface-not-available
    signal: "The in-process interface cannot be resolved, the gRPC service is not mapped, or the MCP tool is not listed in the session's tools/list."
    effect: "The operation cannot be carried out through that surface on this host."
    response: "Stop and report which registration or opt-in the availability block names as missing; do not emulate the operation through a different surface."
rollback:
  supported: false
  mechanism: "No inverse operation for removed orphan membership rows is surfaced; reconcile is idempotent against current source state."
  steps: []
  source: "docs/lattice.api.treeadmin/README.md"
concurrency:
  - rule: "Covered source trees are scanned read-only while backing membership rows are repaired."
    source: "docs/lattice.api.treeadmin/README.md"
  - rule: "Index definition and drop are not surfaced through tree administration."
    source: "docs/lattice.api.treeadmin/README.md"
sources:
  - "src/lattice.api.abstractions/TreeAdmin/ILatticeTreeAdmin.cs"
  - "src/lattice.api.treeadmin.grpc/LatticeTreeAdminGrpcMethods.cs"
  - "src/lattice.api.mcp/Tools/TreeAdmin/TreeAdminToolGroup.cs"
  - "docs/lattice.api.treeadmin/README.md"
  - "docs/lattice/api.md"
