@@ -42,14 +42,18 @@ async def resolve_incident(incident_id: str, rcca_context: dict):
4242 await submit_proposals (incident_id , actions )
4343
4444async def search_runbooks (query_text : str ):
45- # ES|QL Search or Text Search
46- # Using simple text search via ES|QL as per tool def, or standard search if needed for vectors
47- # Let's match the tool definition conceptually: FROM runbooks-knowledge...
45+ """
46+ Search for runbooks using ES|QL with basic sanitization.
47+ Future: Integrate with Elastic Inference API for ELSER/Vector search.
48+ """
49+ # Basic sanitization for ES|QL
50+ safe_query = query_text .replace ('"' , '\\ "' )
51+
4852 esql_query = f"""
4953 FROM runbooks-knowledge
50- | WHERE MATCH(content, "{ query_text } ")
51- | LIMIT 3
52- | KEEP title, url, content
54+ | WHERE MATCH(content, "{ safe_query } ") OR MATCH(title, " { safe_query } ")
55+ | LIMIT 5
56+ | KEEP title, url, content, runbook_id
5357 """
5458 results = []
5559 try :
@@ -60,6 +64,17 @@ async def search_runbooks(query_text: str):
6064 results .append (dict (zip (cols , row )))
6165 except Exception as e :
6266 logger .error (f"Error searching runbooks: { e } " )
67+ # Fallback to standard search if ES|QL fails
68+ try :
69+ search_resp = await es .search (
70+ index = "runbooks-knowledge" ,
71+ query = {"multi_match" : {"query" : query_text , "fields" : ["title" , "content" ]}}
72+ )
73+ for hit in search_resp ["hits" ]["hits" ]:
74+ results .append (hit ["_source" ])
75+ except Exception as es_err :
76+ logger .error (f"Fallback search also failed: { es_err } " )
77+
6378 return results
6479
6580def generate_action_id (incident_id : str , action : dict , sequence : int ) -> str :
@@ -72,32 +87,49 @@ def generate_action_id(incident_id: str, action: dict, sequence: int) -> str:
7287
7388def synthesize_actions (incident_id , runbooks , hypothesis ):
7489 actions = []
90+ cause = (hypothesis .get ("cause" ) or "" ).lower ()
91+ description = (hypothesis .get ("description" ) or "" ).lower ()
7592
76- # Heuristic based on hypothesis type
77- if "Deployment" in hypothesis . get ( "cause " , "" ):
93+ # More robust heuristic based on keywords
94+ if any ( k in cause or k in description for k in [ "deploy" , "version" , "rollout " , "update" ] ):
7895 actions .append ({
7996 "action_type" : "rollback" ,
80- "title" : "Rollback Deployment " ,
81- "description" : "Rollback the service to the previous specific version." ,
97+ "title" : "Rollback to Previous Version " ,
98+ "description" : "Perform an automated rollback to the last known-good container version." ,
8299 "estimated_time" : "5m" ,
83- "requires_approval" : True
100+ "requires_approval" : True ,
101+ "risk_score" : 0.2
84102 })
85- elif "Database" in hypothesis .get ("cause" , "" ) or "Connection" in hypothesis .get ("description" , "" ):
86- actions .append ({
103+
104+ if any (k in cause or k in description for k in ["db" , "database" , "connection" , "pool" , "timeout" ]):
105+ actions .append ({
87106 "action_type" : "scale_up" ,
88- "title" : "Increase DB Connection Pool" ,
89- "description" : "Update config map to increase pool size by 50% ." ,
107+ "title" : "Increase Connection Pool" ,
108+ "description" : "Increase the database connection pool size via ConfigMap update ." ,
90109 "estimated_time" : "2m" ,
91- "requires_approval" : True
110+ "requires_approval" : True ,
111+ "risk_score" : 0.1
112+ })
113+
114+ if any (k in cause or k in description for k in ["cpu" , "memory" , "load" , "latency" , "spike" ]):
115+ actions .append ({
116+ "action_type" : "scale_out" ,
117+ "title" : "Horizontal Scale Out" ,
118+ "description" : "Increase replica count by 1 to handle traffic spike." ,
119+ "estimated_time" : "3m" ,
120+ "requires_approval" : False , # Low risk for auto-approval
121+ "risk_score" : 0.05
92122 })
93123
94- # Always attach runbook links
124+ # Attach runbook links as informational actions
95125 for r in runbooks :
96126 actions .append ({
97127 "action_type" : "documentation" ,
98- "title" : "Read Runbook: " + r .get ("title" , "Unknown" ),
128+ "title" : f"Runbook: { r .get ('title' , 'Reference Guide' )} " ,
129+ "description" : "Manual remediation guide from knowledge base." ,
99130 "url" : r .get ("url" ),
100- "requires_approval" : False
131+ "requires_approval" : False ,
132+ "risk_score" : 0.0
101133 })
102134
103135 for idx , action in enumerate (actions ):
0 commit comments