MCPcopy Create free account
hub / github.com/alibaba/open-code-review / SessionTaskKey

Function SessionTaskKey

internal/llm/sessionkey.go:65–81  ·  view source on GitHub ↗

SessionTaskKey derives the prompt-cache affinity key for one task conversation within a session. Prompt caches match on prefixes, and OCR's task types (plan, main tool-loop, compression, dedup, ...) use unrelated prompts — routing a whole run under one key would pin every concurrent per-file convers

(sessionKey, taskType, scope string)

Source from the content-addressed store, hash-verified

63// within the provider-safe limit. The shortened component is only a cache
64// routing hint; the complete session ID remains unchanged in persisted state.
65func SessionTaskKey(sessionKey, taskType, scope string) string {
66 if len(sessionKey) > sessionTaskKeySessionPrefixLength {
67 sessionKey = sessionKey[:sessionTaskKeySessionPrefixLength]
68 }
69 if len(taskType) > maxSessionTaskKeyTaskTypeLength {
70 taskType = taskType[:maxSessionTaskKeyTaskTypeLength]
71 }
72
73 if taskType == "" && scope == "" {
74 return sessionKey
75 }
76 if scope == "" {
77 return sessionKey + "-" + taskType
78 }
79 sum := sha256.Sum256([]byte(scope))
80 return fmt.Sprintf("%s-%s-%x", sessionKey, taskType, sum[:8])
81}
82
83// SessionKeyFromContext returns the session key carried by ctx, or "" when
84// none was set.

Callers 15

maybeRunPlanMethod · 0.92
maybeRunDedupMethod · 0.92
RunMainTaskMethod · 0.92
executeToolCallMethod · 0.92
runCompressionMethod · 0.92
callGroupingLLMFunction · 0.92
executeGroupPlanPhaseMethod · 0.92
TestSessionTaskKeyFunction · 0.85

Calls

no outgoing calls