{"record":{"id":"0c802de664212e99","repo":"AprilNEA/OpenLogi","slug":"the-agent-snapshot-changed-during-target-selection","errorCode":null,"errorMessage":"the Agent snapshot changed during target selection","messagePattern":"the Agent snapshot changed during target selection","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/openlogi-cli/src/cmd/fixture/record_profile.rs","lineNumber":195,"sourceCode":") -> Result<CapturedProfile> {\n    // Runtime status, camera, foreground-app, and pairing facts are dropped at\n    // this boundary and can never enter the serializable profile value.\n    let AgentSnapshot {\n        inventory,\n        standalone,\n        ..\n    } = snapshot;\n    let candidates = selection::target_candidates(&inventory, &standalone);\n    let selected = selection::select_target(&candidates, selector)?;\n\n    let (inventories, standalone, settings, selected_route) = match selected.location {\n        TargetLocation::Inventory {\n            inventory: inventory_index,\n            device: device_index,\n        } => {\n            let source = inventory\n                .get(inventory_index)\n                .ok_or_else(|| anyhow!(\"the Agent snapshot changed during target selection\"))?;\n            capture_inventory(client, source, device_index).await?\n        }\n        TargetLocation::Standalone { device } => {\n            let source = standalone\n                .get(device)\n                .ok_or_else(|| anyhow!(\"the Agent snapshot changed during target selection\"))?;\n            capture_standalone(source)?\n        }\n    };\n\n    Ok(CapturedProfile {\n        profile: DeviceProfile {\n            schema_version: FIXTURE_SCHEMA_VERSION,\n            id,\n            name,\n            inventories,\n            standalone,\n            settings,","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/AprilNEA/OpenLogi/blob/e846e6f4b4405e33bd6a9aaf949a482ce34cb6d8/crates/openlogi-cli/src/cmd/fixture/record_profile.rs#L177-L213","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify `selection::target_candidates` returns indices into the same `inventory`/`standalone` vectors passed to `capture_profile` (no filtering between snapshot and selection).","Re-run the command against a freshly started Agent so the snapshot is current and coherent.","If you hit this as a user, report it: it indicates a CLI bug or a genuinely mutated snapshot, not a configuration problem."],"exampleFix":"// before: candidates filtered, indices into full vec\nlet candidates = selection::target_candidates(&inventory, &standalone);\n// after: ensure candidates carry the same vec the match indexes, or reconstruct the source\nlet source = inventory.get(inventory_index).ok_or_else(|| anyhow!(\"the Agent snapshot changed during target selection\"))?;","handlingStrategy":"validation","validationCode":"// caller-side: ensure the snapshot handed to selection is the same one indexed\nassert!(inventory_index < snapshot.inventory.len(), \"stale inventory index\");","typeGuard":"fn inventory_at(snapshot: &AgentSnapshot, i: usize) -> Option<&DeviceInventory> { snapshot.inventory.get(i) }","tryCatchPattern":null,"preventionTips":["Always derive target indices from the exact snapshot vec you later index — pass the same data to selection and lookup.","Add a unit test that selects every candidate and resolves its index against the original snapshot.","Never cache indices across snapshot refreshes."],"tags":["rust","cli","internal-consistency","ipc"],"backgroundTag":"internal-invariant-violation","analyzedSha":"e846e6f4b4405e33bd6a9aaf949a482ce34cb6d8","analyzedAt":"2026-09-13T03:07:16.451Z","contentChangedAt":"2026-09-13T03:07:16.451Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}