{"record":{"id":"4aa73622927fae08","repo":"microsoft/garnet","slug":"invalid-keymigrationstatus-state","errorCode":null,"errorMessage":"Invalid KeyMigrationStatus: {state}","messagePattern":"Invalid KeyMigrationStatus: (.+?)","errorType":"exception","errorClass":"GarnetException","httpStatus":null,"severity":"error","filePath":"libs/cluster/Server/Migration/MigrateSessionKeyAccess.cs","lineNumber":59,"sourceCode":"            var state = SketchStatus.INITIALIZING;\n            foreach (var migrateTask in migrateOperation)\n            {\n                if (migrateTask.sketch.Probe(key, out state))\n                    goto found;\n            }\n\n            return true;\n\n        found:\n            // NOTE:\n            // Caller responsible for spin-wait\n            // Check definition of KeyMigrationStatus for more info\n            return state switch\n            {\n                SketchStatus.INITIALIZING or SketchStatus.MIGRATED => true,// Both reads and write commands can access key if it exists\n                SketchStatus.TRANSMITTING => readOnly, // If key exists read commands can access key but write commands will be delayed\n                SketchStatus.DELETING => false, // Neither read or write commands can access key\n                _ => throw new GarnetException($\"Invalid KeyMigrationStatus: {state}\")\n            };\n        }\n    }\n}","sourceCodeStart":41,"sourceCodeEnd":63,"githubUrl":"https://github.com/microsoft/garnet/blob/951b0fc6838721f89d102c2bbe1b914e8d39d700/libs/cluster/Server/Migration/MigrateSessionKeyAccess.cs#L41-L63","documentation":"Thrown by CanAccessKey's status switch when a SketchStatus is not one of INITIALIZING, MIGRATED, TRANSMITTING, or DELETING. All four documented statuses are handled, so the default arm only fires for an invalid/out-of-range cast. It guards the per-key access decision during slot/key migration.","triggerScenarios":"Reading a SketchStatus field that holds a value outside 0..3 (uninitialized memory or an unsafe cast), or a new SketchStatus member added to the enum without updating this switch.","commonSituations":"Concurrent migration reset that leaves a sketch in a transient/garbage status; memory corruption or a stale sketch reused after migration completed.","solutions":["Verify sketches are always constructed with Status = INITIALIZING and transitioned only through the defined statuses.","Ensure no sketch object is reused after its migration lifecycle ends.","Keep the switch exhaustive when SketchStatus is extended."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Validate sketch status before access decision\nif ((byte)state > (byte)SketchStatus.MIGRATED)\n    throw new ArgumentOutOfRangeException(nameof(state), state, \"Unknown SketchStatus\");\nreturn CanAccessKey(key, slot, readOnly);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure sketches are only constructed and transitioned through defined SketchStatus values.","Never reuse a sketch object after its migration completes.","Keep the status switch exhaustive when extending SketchStatus."],"tags":["cluster","migration","sketch","enum-switch","garnet"],"backgroundTag":null,"analyzedSha":"951b0fc6838721f89d102c2bbe1b914e8d39d700","analyzedAt":"2026-08-13T19:01:32.939Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}