AprilNEA/OpenLogi · error

the Agent snapshot changed during target selection

Error message

the Agent snapshot changed during target selection

What it means

Raised in `capture_profile` when the target-location index chosen for an inventory-backed device no longer resolves in the Agent snapshot's inventory vector. Target candidates were computed from a snapshot, but the index lookup via `inventory.get(inventory_index)` failed, which in practice means the snapshot supplied to selection did not match the collection being indexed. It is an internal consistency guard, not a user-facing hardware error.

Solutions

  1. Verify `selection::target_candidates` returns indices into the same `inventory`/`standalone` vectors passed to `capture_profile` (no filtering between snapshot and selection).
  2. Re-run the command against a freshly started Agent so the snapshot is current and coherent.
  3. If you hit this as a user, report it: it indicates a CLI bug or a genuinely mutated snapshot, not a configuration problem.

Example fix

// before: candidates filtered, indices into full vec
let candidates = selection::target_candidates(&inventory, &standalone);
// after: ensure candidates carry the same vec the match indexes, or reconstruct the source
let source = inventory.get(inventory_index).ok_or_else(|| anyhow!("the Agent snapshot changed during target selection"))?;
Defensive patterns

Strategy: validation

Validate before calling

// caller-side: ensure the snapshot handed to selection is the same one indexed
assert!(inventory_index < snapshot.inventory.len(), "stale inventory index");

Type guard

fn inventory_at(snapshot: &AgentSnapshot, i: usize) -> Option<&DeviceInventory> { snapshot.inventory.get(i) }

Prevention

When it happens

Trigger: Calling `capture_profile` (via `openlogi fixture record profile` or `capture_for_contribution`) where `selection::select_target` returns a `TargetLocation::Inventory { inventory_index, .. }` whose index is out of bounds of the `snapshot.inventory` vec — i.e. selection ran against different/older inventory data than the vector being indexed.

Common situations: A code change makes `target_candidates` filter or reorder inventories but return indices into the unfiltered original (or vice versa); the agent snapshot was mutated between selection and lookup in a future refactor; stale index cached from a previous snapshot.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of AprilNEA/OpenLogi@e846e6f4b4 (2026-09-13). Data as JSON: /api/errors/0c802de664212e99. Report an issue: GitHub.

Appendix: source

Thrown at crates/openlogi-cli/src/cmd/fixture/record_profile.rs:195

) -> Result<CapturedProfile> {
    // Runtime status, camera, foreground-app, and pairing facts are dropped at
    // this boundary and can never enter the serializable profile value.
    let AgentSnapshot {
        inventory,
        standalone,
        ..
    } = snapshot;
    let candidates = selection::target_candidates(&inventory, &standalone);
    let selected = selection::select_target(&candidates, selector)?;

    let (inventories, standalone, settings, selected_route) = match selected.location {
        TargetLocation::Inventory {
            inventory: inventory_index,
            device: device_index,
        } => {
            let source = inventory
                .get(inventory_index)
                .ok_or_else(|| anyhow!("the Agent snapshot changed during target selection"))?;
            capture_inventory(client, source, device_index).await?
        }
        TargetLocation::Standalone { device } => {
            let source = standalone
                .get(device)
                .ok_or_else(|| anyhow!("the Agent snapshot changed during target selection"))?;
            capture_standalone(source)?
        }
    };

    Ok(CapturedProfile {
        profile: DeviceProfile {
            schema_version: FIXTURE_SCHEMA_VERSION,
            id,
            name,
            inventories,
            standalone,
            settings,

View on GitHub (pinned to e846e6f4b4)