| 5502 | int ds4_dist_session_route_ready(ds4_dist_session *d, char *err, size_t errlen) { |
| 5503 | if (!d) { |
| 5504 | if (errlen) snprintf(err, errlen, "missing distributed session"); |
| 5505 | return -1; |
| 5506 | } |
| 5507 | |
| 5508 | ds4_dist_route_plan probe = {0}; |
| 5509 | if (!dist_coordinator_build_route_plan(&d->state, &probe, NULL, err, errlen)) { |
| 5510 | return 0; |
| 5511 | } |
| 5512 | dist_route_plan_free(&probe); |
| 5513 | if (errlen) err[0] = '\0'; |
| 5514 | return 1; |
| 5515 | } |
| 5516 | |
| 5517 | int ds4_dist_session_sync( |
| 5518 | ds4_dist_session *d, |
| 5519 | ds4_session *owner, |
| 5520 | const ds4_tokens *checkpoint, |
| 5521 | const ds4_tokens *prompt, |
| 5522 | float *logits, |
| 5523 | char *err, |
| 5524 | size_t errlen) { |
| 5525 | if (!d || !owner || !prompt || prompt->len <= 0 || !logits) { |
| 5526 | if (errlen) snprintf(err, errlen, "invalid distributed sync request"); |
| 5527 | return 1; |
| 5528 | } |
| 5529 | if (dist_session_ensure_route(d, err, errlen) != 0) return 1; |
| 5530 | |
| 5531 | if (checkpoint && |
| 5532 | checkpoint->len >= 0 && |
| 5533 | checkpoint->len <= prompt->len && |
| 5534 | ds4_tokens_starts_with(prompt, checkpoint)) |
| 5535 | { |
| 5536 | if (checkpoint->len == prompt->len) return 0; |
| 5537 | |
| 5538 | uint32_t chunk_cap = 0; |
| 5539 | if (dist_coordinator_prefill_chunk_cap(&d->state, owner, &chunk_cap, err, errlen) != 0) { |
| 5540 | return 1; |
| 5541 | } |
| 5542 | const uint32_t pos0 = (uint32_t)checkpoint->len; |
| 5543 | const uint32_t suffix = (uint32_t)prompt->len - pos0; |
| 5544 | if (dist_coordinator_can_pipeline_prefill(&d->state, &d->plan, owner, suffix, chunk_cap)) { |
| 5545 | int prefill_rc = dist_coordinator_prefill_prompt_pipelined(&d->state, |
| 5546 | owner, |
| 5547 | &d->plan, |
| 5548 | prompt, |
| 5549 | pos0, |
| 5550 | suffix, |
| 5551 | false, |
| 5552 | chunk_cap, |
| 5553 | d->session_id, |
| 5554 | &d->request_id, |
| 5555 | logits, |
| 5556 | err, |
| 5557 | errlen); |
| 5558 | if (prefill_rc != 0) { |
| 5559 | if (dist_coordinator_rebuild_from_transcript(&d->state, |
| 5560 | owner, |
| 5561 | &d->plan, |
no test coverage detected