MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / runtime_application_worker

Function runtime_application_worker

src/daemon/runtime.c:1231–1271  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1229}
1230
1231static void *runtime_application_worker(void *opaque) {
1232 cbm_daemon_runtime_worker_t *worker = opaque;
1233 cbm_daemon_runtime_service_t *service = worker->service;
1234 uint8_t *response = NULL;
1235 uint32_t response_length = 0;
1236 cbm_daemon_runtime_application_status_t status = service->application.request(
1237 service->application.context, worker->application_session,
1238 worker->application_request_token, worker->application_request,
1239 worker->application_request_length, &response, &response_length);
1240
1241 bool valid_status = runtime_application_status_is_callback_result(status);
1242 bool valid_response =
1243 response_length <= CBM_DAEMON_RUNTIME_APPLICATION_PAYLOAD_MAX &&
1244 (response_length == 0 || response != NULL) &&
1245 (status == CBM_DAEMON_RUNTIME_APPLICATION_OK || (response == NULL && response_length == 0));
1246 if (!valid_status || !valid_response) {
1247 free(response);
1248 response = NULL;
1249 response_length = 0;
1250 status = CBM_DAEMON_RUNTIME_APPLICATION_HANDLER_ERROR;
1251 }
1252
1253 /* Completion must be one atomic transition from the client's point of
1254 * view: publish the done flag BEFORE the response bytes leave, so by the
1255 * time any client can react to the response, admission already observes
1256 * this slot as reusable. With the store after the send, a client that
1257 * pipelines its next request the moment it sees a response raced this
1258 * thread's final instructions and was rejected BUSY — on loaded Windows
1259 * hosts roughly half of all back-to-back requests on one connection,
1260 * surfacing as the wandering Phase 5 session drops. The admission side
1261 * joins this thread after observing the flag, which safely absorbs the
1262 * tail of the send. */
1263 atomic_store_explicit(&worker->application_thread_done, true, memory_order_release);
1264 bool sent = runtime_worker_send_application_response(worker, worker->application_request_token,
1265 status, response, response_length, true);
1266 free(response);
1267 if (!sent && !atomic_load_explicit(&worker->disconnecting, memory_order_acquire)) {
1268 cbm_daemon_ipc_connection_interrupt(worker->connection);
1269 }
1270 return NULL;
1271}
1272
1273static bool runtime_worker_reap_application(cbm_daemon_runtime_worker_t *worker, bool wait) {
1274 if (!worker->application_thread_started) {

Callers

nothing calls this directly

Tested by

no test coverage detected