Skip to content

Commit 358d6e7

Browse files
committed
fix(mcp): recover unsent requests after daemon loss
Signed-off-by: Pxx500 <pbartulik@gmail.com>
1 parent 094c895 commit 358d6e7

9 files changed

Lines changed: 547 additions & 118 deletions

File tree

‎src/daemon/application.c‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3116,7 +3116,7 @@ cbm_daemon_runtime_application_callbacks_t cbm_daemon_application_runtime_callba
31163116
static cbm_daemon_runtime_application_status_t application_client_exchange_tagged(
31173117
cbm_daemon_runtime_client_t *client, cbm_daemon_runtime_application_token_t request_token,
31183118
uint8_t *request, uint32_t request_length, uint8_t **response_out,
3119-
uint32_t *response_length_out, uint32_t timeout_ms) {
3119+
uint32_t *response_length_out, bool *request_sent_out, uint32_t timeout_ms) {
31203120
uint8_t *response = NULL;
31213121
uint32_t response_length = 0;
31223122
if (response_out) {
@@ -3125,13 +3125,16 @@ static cbm_daemon_runtime_application_status_t application_client_exchange_tagge
31253125
if (response_length_out) {
31263126
*response_length_out = 0;
31273127
}
3128+
if (request_sent_out) {
3129+
*request_sent_out = false;
3130+
}
31283131
cbm_daemon_runtime_application_status_t status =
31293132
request_token == CBM_DAEMON_RUNTIME_APPLICATION_TOKEN_INVALID
31303133
? cbm_daemon_runtime_client_application_request(client, request, request_length,
31313134
&response, &response_length, timeout_ms)
3132-
: cbm_daemon_runtime_client_application_request_tagged(client, request_token, request,
3133-
request_length, &response,
3134-
&response_length, timeout_ms);
3135+
: cbm_daemon_runtime_client_application_request_tagged(
3136+
client, request_token, request, request_length, &response, &response_length,
3137+
request_sent_out, timeout_ms);
31353138
free(request);
31363139
if (status != CBM_DAEMON_RUNTIME_APPLICATION_OK) {
31373140
free(response);
@@ -3162,7 +3165,7 @@ static cbm_daemon_runtime_application_status_t application_client_exchange(
31623165
uint8_t **response_out, uint32_t *response_length_out, uint32_t timeout_ms) {
31633166
return application_client_exchange_tagged(client, CBM_DAEMON_RUNTIME_APPLICATION_TOKEN_INVALID,
31643167
request, request_length, response_out,
3165-
response_length_out, timeout_ms);
3168+
response_length_out, NULL, timeout_ms);
31663169
}
31673170

31683171
cbm_daemon_runtime_application_status_t cbm_daemon_application_client_set_context(
@@ -3290,7 +3293,7 @@ cbm_daemon_runtime_application_status_t cbm_daemon_application_client_ui_readine
32903293
static cbm_daemon_runtime_application_status_t application_client_text_request_tagged(
32913294
cbm_daemon_runtime_client_t *client, cbm_daemon_runtime_application_token_t request_token,
32923295
cbm_daemon_application_request_kind_t kind, const char *text, uint8_t **response_out,
3293-
uint32_t *response_length_out, uint32_t timeout_ms) {
3296+
uint32_t *response_length_out, bool *request_sent_out, uint32_t timeout_ms) {
32943297
if (!client || !text || !text[0]) {
32953298
return CBM_DAEMON_RUNTIME_APPLICATION_REJECTED;
32963299
}
@@ -3306,15 +3309,15 @@ static cbm_daemon_runtime_application_status_t application_client_text_request_t
33063309
memcpy(request + 1, text, text_length);
33073310
return application_client_exchange_tagged(client, request_token, request,
33083311
(uint32_t)text_length + 1U, response_out,
3309-
response_length_out, timeout_ms);
3312+
response_length_out, request_sent_out, timeout_ms);
33103313
}
33113314

33123315
static cbm_daemon_runtime_application_status_t application_client_text_request(
33133316
cbm_daemon_runtime_client_t *client, cbm_daemon_application_request_kind_t kind,
33143317
const char *text, uint8_t **response_out, uint32_t *response_length_out, uint32_t timeout_ms) {
33153318
return application_client_text_request_tagged(
33163319
client, CBM_DAEMON_RUNTIME_APPLICATION_TOKEN_INVALID, kind, text, response_out,
3317-
response_length_out, timeout_ms);
3320+
response_length_out, NULL, timeout_ms);
33183321
}
33193322

33203323
cbm_daemon_runtime_application_status_t cbm_daemon_application_client_mcp(
@@ -3327,10 +3330,10 @@ cbm_daemon_runtime_application_status_t cbm_daemon_application_client_mcp(
33273330
cbm_daemon_runtime_application_status_t cbm_daemon_application_client_mcp_tagged(
33283331
cbm_daemon_runtime_client_t *client, cbm_daemon_runtime_application_token_t request_token,
33293332
const char *message, uint8_t **response_out, uint32_t *response_length_out,
3330-
uint32_t timeout_ms) {
3331-
return application_client_text_request_tagged(client, request_token,
3332-
CBM_DAEMON_APPLICATION_REQUEST_MCP, message,
3333-
response_out, response_length_out, timeout_ms);
3333+
bool *request_sent_out, uint32_t timeout_ms) {
3334+
return application_client_text_request_tagged(
3335+
client, request_token, CBM_DAEMON_APPLICATION_REQUEST_MCP, message, response_out,
3336+
response_length_out, request_sent_out, timeout_ms);
33343337
}
33353338

33363339
cbm_daemon_runtime_application_status_t cbm_daemon_application_client_tool(

‎src/daemon/application.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,12 @@ cbm_daemon_runtime_application_status_t cbm_daemon_application_client_mcp(
149149
cbm_daemon_runtime_client_t *client, const char *message, uint8_t **response_out,
150150
uint32_t *response_length_out, uint32_t timeout_ms);
151151

152-
/* Cancellable frontend variant using a token reserved on the runtime client. */
152+
/* Cancellable frontend variant using a token reserved on the runtime client.
153+
* request_sent_out preserves the runtime's application-frame delivery fact. */
153154
cbm_daemon_runtime_application_status_t cbm_daemon_application_client_mcp_tagged(
154155
cbm_daemon_runtime_client_t *client, cbm_daemon_runtime_application_token_t request_token,
155156
const char *message, uint8_t **response_out, uint32_t *response_length_out,
156-
uint32_t timeout_ms);
157+
bool *request_sent_out, uint32_t timeout_ms);
157158

158159
cbm_daemon_runtime_application_status_t cbm_daemon_application_client_tool(
159160
cbm_daemon_runtime_client_t *client, const char *tool_name, const char *args_json,

0 commit comments

Comments
 (0)