| 9037 | * never roll the session backward just to build a disk cache entry: that would |
| 9038 | * turn cache population into a second hidden prefill. |
| 9039 | * |
| 9040 | * File layout: |
| 9041 | * |
| 9042 | * "KVC" version |
| 9043 | * quant bits, save reason, token count, hit count, context size |
| 9044 | * creation time, last-used time, payload byte count |
| 9045 | * rendered text byte count + rendered text for human inspection |
| 9046 | * DS4 engine payload written by ds4_session_save_payload() |
| 9047 | * optional tool-id map section |
| 9048 | * |
| 9049 | * The filename is SHA1(cache text bytes), not SHA1(token ids). For ordinary |
| 9050 | * checkpoints the cache text is the rendered token prefix. For live hidden |
| 9051 | * state it can instead be the client-visible transcript: the payload still |
| 9052 | * contains sampled reasoning KV, but the lookup key must be what the client can |
| 9053 | * replay after a process restart or session switch. |
| 9054 | * |
| 9055 | * The optional tool-id map is not part of model state, but it is needed to |
| 9056 | * render future client JSON back to the exact DSML sampled by the model. We |
| 9057 | * persist only mappings whose DSML block appears in the saved cache text. |
| 9058 | */ |
| 9059 | |
| 9060 | #define KV_CACHE_FIXED_HEADER DS4_KVSTORE_FIXED_HEADER |
| 9061 | #define KV_CACHE_HIT_HALF_LIFE_SECONDS DS4_KVSTORE_HIT_HALF_LIFE_SECONDS |
| 9062 | #define KV_EXT_TOOL_MAP DS4_KVSTORE_EXT_TOOL_MAP |
| 9063 | #define KV_EXT_RESPONSES_VISIBLE DS4_KVSTORE_EXT_RESPONSES_VISIBLE |
| 9064 | #define KV_EXT_THINKING_VISIBLE DS4_KVSTORE_EXT_THINKING_VISIBLE |
| 9065 | #define KV_TOOL_MAP_MAGIC0 'K' |
| 9066 | #define KV_TOOL_MAP_MAGIC1 'T' |
| 9067 | #define KV_TOOL_MAP_MAGIC2 'M' |
| 9068 | #define KV_TOOL_MAP_VERSION 1u |
| 9069 | #define KV_TOOL_MAP_HEADER 8u |
| 9070 | |
| 9071 | typedef enum { |
| 9072 | KV_REASON_UNKNOWN = DS4_KVSTORE_REASON_UNKNOWN, |