Skip to content

Commit 5b93645

Browse files
committed
feat(session): Step 4.A — remove the GENAI:/LLM: query-prefix escape hatches
Per decision Q2 in the GenAI plugin carve-out design doc, the in-line MySQL-protocol prefixes that bypassed routing, ACLs, and the query processor are removed. Users reach GenAI features through MCP, admin SQL, or the REST endpoint -- as the rest of the carve-out finishes, nothing else needs the in-core GENAI:/LLM: handlers. Removals: lib/MySQL_Session.cpp (-933 lines) - handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_QUERY___genai - handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_QUERY___llm - handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___genai_send_async - handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___handle_genai_response - genai_cleanup_request - check_genai_events - The COM_QUERY prefix-detection block that dispatched to those handlers - The check_genai_events poll-loop hook in WAITING_CLIENT_DATA include/MySQL_Session.h (-67 lines) - All matching method declarations, with their doxygen include/Base_Session.h (-15 lines) - GenAI_PendingRequest struct - pending_genai_requests_ map - next_genai_request_id_ counter - genai_epoll_fd_ per-session epoll fd lib/Base_Session.cpp (-9 lines) - The init block that created the per-session genai_epoll_fd_ LLM: was deleted alongside GENAI: even though only GENAI: is named in the design. They share the same `#ifdef PROXYSQLGENAI` gate, the same async-genai socketpair plumbing, and the same rationale. Leaving LLM: behind would have left a half-block referencing functions that no longer exist; if we want LLM: back later the plugin can re-implement it (or a more general request-multiplexer ABI extension can land). The async-genai socketpair protocol (GenAI_RequestHeader / GenAI_ResponseHeader, defined in include/GenAI_Thread.h) is now unreferenced from outside lib/GenAI_Thread.cpp itself; those structs disappear when GenAI_Thread moves to plugins/genai/ in Step 5. Verified: - clean rebuild of libproxysql.a + proxysql + ProxySQL_GenAI_Plugin.so - all 60 unit-test binaries pass - smoke test: daemon starts, SELECT through admin works, SIGTERM shuts down cleanly Net diff: -1010 / +28 lines. Largest deletion of the carve-out so far.
1 parent 1656c24 commit 5b93645

4 files changed

Lines changed: 28 additions & 1010 deletions

File tree

include/Base_Session.h

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,20 +99,10 @@ class Base_Session {
9999
//MySQL_STMTs_meta *sess_STMTs_meta;
100100
//StmtLongDataHandler *SLDH;
101101

102-
// GenAI async support
103-
#ifdef epoll_create1
104-
struct GenAI_PendingRequest {
105-
uint64_t request_id;
106-
int client_fd; // MySQL side of socketpair
107-
std::string json_query;
108-
std::chrono::steady_clock::time_point start_time;
109-
PtrSize_t *original_pkt; // Original packet to complete
110-
};
111-
112-
std::unordered_map<uint64_t, GenAI_PendingRequest> pending_genai_requests_;
113-
uint64_t next_genai_request_id_;
114-
int genai_epoll_fd_; // For monitoring GenAI response fds
115-
#endif
102+
// GenAI async support (per-session epoll fd + pending-request map)
103+
// removed in Step 4 of the GenAI plugin carve-out -- the
104+
// GENAI:/LLM: prefix handlers that owned this state are gone.
105+
// See decision Q2 in the design doc.
116106

117107

118108

include/MySQL_Session.h

Lines changed: 8 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -304,74 +304,15 @@ class MySQL_Session: public Base_Session<MySQL_Session, MySQL_Data_Stream, MySQL
304304
void handler_rc0_RefreshActiveTransactions(MySQL_Connection* myconn);
305305
void handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_INIT_DB_replace_CLICKHOUSE(PtrSize_t& pkt);
306306
void handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_QUERY___not_mysql(PtrSize_t& pkt);
307-
void handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_QUERY___genai(const char* query, size_t query_len, PtrSize_t* pkt);
308-
void handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_QUERY___llm(const char* query, size_t query_len, PtrSize_t* pkt);
309-
#ifdef epoll_create1
310-
/**
311-
* @brief Handle GenAI response from socketpair
312-
*
313-
* Called when epoll notifies that a GenAI response is available on a client fd.
314-
* Reads the GenAI_ResponseHeader and JSON result, then sends the resultset
315-
* to the MySQL client.
316-
*
317-
* @param fd The socketpair fd (MySQL side) with data available to read
318-
*
319-
* @see handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___genai_send_async()
320-
* @see check_genai_events()
321-
*/
322-
void handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___handle_genai_response(int fd);
307+
// MYSQL_COM_QUERY___genai / MYSQL_COM_QUERY___llm and the entire
308+
// async-genai socketpair infrastructure (handle_genai_response,
309+
// genai_send_async, genai_cleanup_request, check_genai_events) were
310+
// removed in Step 4 of the GenAI plugin carve-out (decision Q2 in
311+
// the design doc). GenAI now reaches clients through MCP / admin
312+
// SQL / REST -- the in-line MySQL-protocol "GENAI:" / "LLM:"
313+
// prefix escape hatches were a debug/POC convenience that bypassed
314+
// routing, ACLs, and the query processor.
323315

324-
/**
325-
* @brief Send GenAI request asynchronously via socketpair
326-
*
327-
* Creates a socketpair for async communication with the GenAI module:
328-
* 1. Creates socketpair(fds)
329-
* 2. Registers fds[1] with GenAI module
330-
* 3. Sends GenAI_RequestHeader + JSON query via fds[0]
331-
* 4. Adds fds[0] to session's epoll for response notification
332-
* 5. Returns immediately (MySQL thread is free to process other queries)
333-
*
334-
* The response will be handled by handle_genai_response() when ready.
335-
*
336-
* @param query The JSON query string (after "GENAI:" prefix)
337-
* @param query_len Length of the query string
338-
* @param pkt Original packet (stored for later cleanup)
339-
* @return true if request was sent successfully, false on error
340-
*
341-
* @see handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___handle_genai_response()
342-
*/
343-
bool handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___genai_send_async(const char* query, size_t query_len, PtrSize_t* pkt);
344-
345-
/**
346-
* @brief Cleanup a GenAI pending request
347-
*
348-
* Removes the request from the pending map, closes the socketpair fd,
349-
* removes from epoll, and frees the original packet. Called after
350-
* the response is processed or on error.
351-
*
352-
* @param request_id The request ID to clean up
353-
*
354-
* @see handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___genai_send_async()
355-
*/
356-
void genai_cleanup_request(uint64_t request_id);
357-
358-
/**
359-
* @brief Check for pending GenAI responses
360-
*
361-
* Performs a non-blocking epoll_wait on the session's GenAI epoll fd
362-
* to check if any responses are ready. If a response is found, it's
363-
* processed immediately by calling handle_genai_response().
364-
*
365-
* This is called from the main handler() loop in the WAITING_CLIENT_DATA
366-
* case to ensure GenAI responses are processed promptly even when
367-
* there's no new client data.
368-
*
369-
* @return true if a response was processed, false if no responses were ready
370-
*
371-
* @see handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___handle_genai_response()
372-
*/
373-
bool check_genai_events();
374-
#endif
375316
bool handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_QUERY_detect_SQLi();
376317
bool handler___status_WAITING_CLIENT_DATA___STATE_SLEEP_MULTI_PACKET(PtrSize_t& pkt);
377318
bool handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM__various(PtrSize_t* pkt, bool* wrong_pass);

lib/Base_Session.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,9 @@ void Base_Session<S,DS,B,T>::init() {
8686
MySQL_Session* mysession = static_cast<S*>(this);
8787
mysession->sess_STMTs_meta = new MySQL_STMTs_meta();
8888
mysession->SLDH = new StmtLongDataHandler();
89-
#ifdef epoll_create1
90-
// Initialize GenAI async support
91-
mysession->next_genai_request_id_ = 1;
92-
mysession->genai_epoll_fd_ = epoll_create1(EPOLL_CLOEXEC);
93-
if (mysession->genai_epoll_fd_ < 0) {
94-
proxy_error("Failed to create GenAI epoll fd: %s\n", strerror(errno));
95-
mysession->genai_epoll_fd_ = -1;
96-
}
97-
#endif
89+
// GenAI async epoll-fd init removed in Step 4 of the GenAI
90+
// plugin carve-out (Base_Session.h GenAI async members are
91+
// gone with the GENAI:/LLM: prefix handlers).
9892
}
9993
};
10094

0 commit comments

Comments
 (0)