Execute one request on the worker-owned session. * * Clients resend full prompts as text. The worker first tries the old exact * token-prefix hit, then a rendered-text prefix hit for the live checkpoint, * then disk text-prefix restart snapshots, then a cold prefill. On text-prefix * hits we build a fresh effective prompt from the checkpoint's exact token * history plus a newly tokenized s
| 9989 | "memory_token_reusable: %d\n" |
| 9990 | "memory_miss_reason: %s\n" |
| 9991 | "tool_replay: mem=%d disk=%d canonical=%d missing_ids=%d\n" |
| 9992 | "cache_source: %s\n" |
| 9993 | "cached_tokens: %d\n" |
| 9994 | "disk_cached_tokens: %d\n", |
| 9995 | d && d->valid ? d->old_pos : 0, |
| 9996 | d && d->valid ? d->prompt_len : 0, |
| 9997 | d && d->valid ? d->common : 0, |
| 9998 | trace_cache_memory_reusable(d) ? 1 : 0, |
| 9999 | trace_cache_miss_reason(d), |
| 10000 | tool_replay ? tool_replay->mem : 0, |
| 10001 | tool_replay ? tool_replay->disk : 0, |
| 10002 | tool_replay ? tool_replay->canonical : 0, |
| 10003 | tool_replay ? tool_replay->missing_ids : 0, |
| 10004 | cache_source ? cache_source : "none", |
| 10005 | cached, |
| 10006 | disk_cached); |
| 10007 | if (disk_path && disk_path[0]) fprintf(s->trace, "disk_cache_file: %s\n", disk_path); |
| 10008 | |
| 10009 | if (!d || !d->valid || d->old_pos == 0 || |
| 10010 | trace_cache_memory_reusable(d)) |
| 10011 | { |
| 10012 | return; |
| 10013 | } |
| 10014 | |
| 10015 | fprintf(s->trace, |
| 10016 | "\nfirst_mismatch_token: %d\n" |
| 10017 | "token_window: [%d..%d)\n", |
| 10018 | d->common, |
| 10019 | d->start, |
| 10020 | d->start + d->count); |
| 10021 | for (int i = 0; i < d->count; i++) { |
| 10022 | int pos = d->start + i; |
| 10023 | int live = d->live_id[i]; |
| 10024 | int prompt = d->prompt_id[i]; |
| 10025 | const char *mark; |
| 10026 | if (live < 0) mark = "prompt-only"; |
| 10027 | else if (prompt < 0) mark = "live-only"; |
| 10028 | else mark = live == prompt ? "==" : "!="; |
| 10029 | |
| 10030 | fprintf(s->trace, "%7d %-11s live ", pos, mark); |
| 10031 | trace_write_token(s->trace, s->engine, live); |
| 10032 | fputs(" | prompt ", s->trace); |
| 10033 | trace_write_token(s->trace, s->engine, prompt); |
| 10034 | fputc('\n', s->trace); |
| 10035 | } |
| 10036 | } |
| 10037 | |
| 10038 | static int live_prefix_rewind_target(bool backend_can_rewind, |
| 10039 | int old_pos, int prompt_len, int common) { |
| 10040 | if (!backend_can_rewind || prompt_len <= 1 || prompt_len >= old_pos) return -1; |
| 10041 | if (common != prompt_len) return -1; |
| 10042 | return prompt_len - 1; |
| 10043 | } |
| 10044 | |
| 10045 | static void trace_time(FILE *fp) { |
| 10046 | time_t now = time(NULL); |
| 10047 | struct tm tm; |
| 10048 | localtime_r(&now, &tm); |
no test coverage detected