{"record":{"id":"0f5ee2ddc0249c9e","repo":"temporalio/temporal","slug":"unexpected-result-from-transitionhistory-compare","errorCode":null,"errorMessage":"unexpected result from transitionhistory.Compare","messagePattern":"unexpected result from transitionhistory\\.Compare","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"chasm/transition_history.go","lineNumber":34,"sourceCode":"\tcurrentRef, err := ctx.structuredRef(c)\n\tif err != nil {\n\t\treturn false, err\n\t}\n\tif ref.ExecutionKey != currentRef.ExecutionKey {\n\t\treturn false, ErrInvalidComponentRef\n\t}\n\tswitch transitionhistory.Compare(ref.executionLastUpdateVT, currentRef.executionLastUpdateVT) {\n\tcase -1:\n\t\t// Execution state has advanced beyond submitted ref\n\t\treturn true, nil\n\tcase 0:\n\t\t// Execution state has not advanced beyond submitted ref\n\t\treturn false, nil\n\tcase 1:\n\t\t// Execution state is behind submitted ref\n\t\treturn false, consts.ErrStaleState\n\t}\n\tpanic(\"unexpected result from transitionhistory.Compare\") //nolint:forbidigo\n}\n","sourceCodeStart":16,"sourceCodeEnd":36,"githubUrl":"https://github.com/temporalio/temporal/blob/bde624efd13fbd3843654058db6d9c716166318b/chasm/transition_history.go#L16-L36","documentation":"This panic guards the exhaustive switch over transitionhistory.Compare results when comparing an execution state against a submitted ref versioned transition. Compare should only yield -1, 0, or 1 (the handled cases 0 and 1 plus the default/0 path); any other result means the comparison primitive returned something unexpected, indicating a bug in transition history data or the Compare implementation. It is reached via the public ExecutionStateChanged path.","triggerScenarios":"ExecutionStateChanged (or code calling it) compares a versioned transition against the submitted ref and the switch on transitionhistory.Compare(...) falls through all expected cases — i.e. Compare returns a value outside {-1,0,1} (Go's switch here relies on Compare returning a normalized -1/0/1).","commonSituations":"Corrupted or malformed VersionedTransition metadata in persistence (e.g. unset/zero-valued fields interacting oddly); a change to transitionhistory.Compare that no longer clamps to -1/0/1; a new case value introduced by an upgrade without updating this switch.","solutions":["Inspect the versioned transitions being compared (task/ref metadata) for malformed or zero values in persistence","Verify transitionhistory.Compare normalizes its result to -1/0/1; fix or update it if changed","Update the switch in this function if a new legitimate comparison result was introduced","Report as a bug if internal data is well-formed — this is an internal invariant violation"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        if s, ok := r.(string); ok && strings.Contains(s, \"unexpected result from transitionhistory.Compare\") {\n            // log execution + versioned transitions, report bug\n            return\n        }\n        panic(r)\n    }\n}()","preventionTips":["Keep versioned transition metadata well-formed in persistence","Don't modify transitionhistory.Compare to return unclamped values without auditing all switches","Report occurrences as internal bugs with full state"],"tags":["chasm","panic","internal-invariant","transition-history"],"backgroundTag":"unexpected-compare-result","analyzedSha":"bde624efd13fbd3843654058db6d9c716166318b","analyzedAt":"2026-09-01T07:18:39.080Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}