{"record":{"id":"e7c465429fd95b2d","repo":"temporalio/temporal","slug":"cannot-serialize-hsm-task-unable-to-cast-to-expec","errorCode":null,"errorMessage":"cannot serialize HSM task. unable to cast to expected type","messagePattern":"cannot serialize HSM task\\. unable to cast to expected type","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"components/nexusoperations/tasks.go","lineNumber":29,"sourceCode":"\tpersistencespb \"go.temporal.io/server/api/persistence/v1\"\n\t\"go.temporal.io/server/common/persistence/serialization\"\n\t\"go.temporal.io/server/service/history/consts\"\n\t\"go.temporal.io/server/service/history/hsm\"\n\t\"google.golang.org/protobuf/proto\"\n)\n\nconst (\n\tTaskTypeInvocation         = \"nexusoperations.Invocation\"\n\tTaskTypeBackoff            = \"nexusoperations.Backoff\"\n\tTaskTypeCancelation        = \"nexusoperations.Cancelation\"\n\tTaskTypeCancelationBackoff = \"nexusoperations.CancelationBackoff\"\n\t// NOTE: the name `Timeout` is used for backward compatibility with existing persisted tasks and predates the addition of more flexible timeout types.\n\tTaskTypeScheduleToCloseTimeout = \"nexusoperations.Timeout\"\n\tTaskTypeScheduleToStartTimeout = \"nexusoperations.ScheduleToStartTimeout\"\n\tTaskTypeStartToCloseTimeout    = \"nexusoperations.StartToCloseTimeout\"\n)\n\nvar errSerializationCast = errors.New(\"cannot serialize HSM task. unable to cast to expected type\")\n\ntype ScheduleToCloseTimeoutTask struct {\n\tdeadline time.Time\n}\n\nvar _ hsm.Task = ScheduleToCloseTimeoutTask{}\n\nfunc (ScheduleToCloseTimeoutTask) Type() string {\n\treturn TaskTypeScheduleToCloseTimeout\n}\n\nfunc (t ScheduleToCloseTimeoutTask) Deadline() time.Time {\n\treturn t.deadline\n}\n\nfunc (ScheduleToCloseTimeoutTask) Destination() string {\n\treturn \"\"\n}","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/temporalio/temporal/blob/bde624efd13fbd3843654058db6d9c716166318b/components/nexusoperations/tasks.go#L11-L47","documentation":"errSerializationCast is returned when serializing/deserializing HSM (hierarchical state machine) nexusoperation tasks: the code receives a persisted task object and cannot cast it to the expected Go type (one of ScheduleToCloseTimeoutTask, ScheduleToStartTimeoutTask, StartToCloseTimeoutTask, or completion tasks). It signals corrupt or unexpected persisted task data inside the nexusoperations component.","triggerScenarios":"Encoding/decoding an HSM task whose backing struct does not match the type registered for the task type string (e.g. 'nexusoperations.Timeout'); loading a persisted task created by a different server version whose type mapping changed.","commonSituations":"Server upgrades where nexusoperations task types were renamed or restructured (note the backward-compat name 'nexusoperations.Timeout'), corrupted persistence records, or manually edited workflow state.","solutions":["Identify the workflow/task ID from logs and inspect the persisted HSM task record in the database for type mismatch","Upgrade all server nodes to a consistent version so task type mappings agree","If a specific task record is corrupt, let the task fail and rely on HSM failure handling/retries, or reset the workflow","Report to Temporal if it reproduces on current versions - it indicates an internal serialization bug"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid in-place persistence edits of HSM task records","Perform rolling upgrades consistently without version-skew on HSM types","Watch for this error after upgrades and report reproducible casts to Temporal"],"tags":["hsm","serialization","nexus","temporal-server"],"backgroundTag":"hsm-task-serialization-cast-failed","analyzedSha":"bde624efd13fbd3843654058db6d9c716166318b","analyzedAt":"2026-09-01T07:18:39.080Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}