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)
| 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. |
| 65 | func 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. |
no outgoing calls