petter2025 commited on
Commit
046e6cb
Β·
verified Β·
1 Parent(s): 34a2540

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +106 -50
app.py CHANGED
@@ -3,7 +3,7 @@
3
  # Enhanced with clear OSS vs Enterprise boundaries
4
  # UPDATED: Added realism panel integration for enterprise-seasoned SRE experience
5
  # UPDATED: Added dynamic performance metrics for Phase 2
6
- # SURGICAL FIX: Added doctrinally pure ARF OSS UI adapter
7
 
8
  import logging
9
  import sys
@@ -187,10 +187,10 @@ class BoundaryManager:
187
  """
188
 
189
  # ===========================================
190
- # ASYNC UTILITIES
191
  # ===========================================
192
  class AsyncRunner:
193
- """Enhanced async runner with better error handling"""
194
 
195
  @staticmethod
196
  def run_async(coro):
@@ -205,17 +205,109 @@ class AsyncRunner:
205
  return loop.run_until_complete(coro)
206
  except Exception as e:
207
  logger.error(f"Async execution failed: {e}")
208
- return {"error": str(e), "status": "failed", "boundary_note": "Execution boundary reached"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
209
 
210
  @staticmethod
211
  def async_to_sync(async_func):
212
- """Decorator to convert async function to sync"""
213
  def wrapper(*args, **kwargs):
214
  try:
215
- return AsyncRunner.run_until_complete(async_func(*args, **kwargs))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
216
  except Exception as e:
217
  logger.error(f"Async to sync conversion failed: {e}")
218
- return {"error": str(e), "status": "failed", "boundary_context": "OSS advisory only - execution requires Enterprise"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
219
  return wrapper
220
 
221
  # ===========================================
@@ -1604,7 +1696,7 @@ class AuditTrailManager:
1604
  <td style="padding: 12px; font-size: 13px; color: #1e293b;">
1605
  {status} {exec["scenario"]}
1606
  </td>
1607
- <td style="padding: 12px; font-size=13px; color: #64748b;">
1608
  {exec["mode"]}
1609
  </td>
1610
  <td style="padding: 12px; font-size: 13px;">
@@ -2155,53 +2247,17 @@ def create_demo_interface():
2155
  )
2156
 
2157
  # ===========================================
2158
- # FIXED: OSS Analysis Button Connection - USING TRUE ARF OSS ADAPTER
2159
  # ===========================================
2160
  def run_oss_analysis_real_arf(scenario_name: str) -> tuple:
2161
  """
2162
- Use TRUE ARF OSS with doctrinally pure adapter
2163
- Returns: (detection_html, recall_html, decision_html, oss_results_dict, incident_df)
2164
  """
2165
  logger.info(f"πŸš€ Running TRUE ARF OSS analysis for: {scenario_name}")
2166
-
2167
- try:
2168
- # Use the updated run_true_arf_analysis() which includes the adapter
2169
- detection_html, recall_html, decision_html, oss_results_dict, incident_df = run_true_arf_analysis(scenario_name)
2170
-
2171
- logger.info(f"βœ… OSS analysis completed for {scenario_name}")
2172
- return detection_html, recall_html, decision_html, oss_results_dict, incident_df
2173
-
2174
- except Exception as e:
2175
- logger.error(f"OSS analysis failed: {e}")
2176
- # Return error state with proper HTML for all agents
2177
- error_html = f"""
2178
- <div style="border: 2px solid #ef4444; border-radius: 14px; padding: 18px;
2179
- background: linear-gradient(135deg, #fef2f2 0%, #ffffff 100%);
2180
- text-align: center; flex: 1; margin: 5px; min-height: 180px;">
2181
- <div style="font-size: 32px; margin-bottom: 10px; color: #ef4444;">❌</div>
2182
- <div style="width: 100%;">
2183
- <h4 style="margin: 0 0 8px 0; font-size: 16px; color: #1e293b;">Analysis Error</h4>
2184
- <p style="font-size: 13px; color: #64748b; margin-bottom: 12px; line-height: 1.4;">
2185
- {str(e)[:100]}
2186
- </p>
2187
- </div>
2188
- </div>
2189
- """
2190
-
2191
- error_dict = {
2192
- "status": "error",
2193
- "error": str(e),
2194
- "scenario": scenario_name,
2195
- "arf_version": "3.3.9",
2196
- "recommendation": "Check ARF OSS installation"
2197
- }
2198
- error_df = pd.DataFrame(columns=["Error", "Message"]).from_records([
2199
- {"Error": "Analysis Failed", "Message": str(e)}
2200
- ])
2201
-
2202
- return error_html, error_html, error_html, error_dict, error_df
2203
 
2204
- # Run OSS Analysis - FIXED: Uses TRUE ARF OSS with adapter
2205
  oss_btn.click(
2206
  fn=run_oss_analysis_real_arf,
2207
  inputs=[scenario_dropdown],
@@ -2641,7 +2697,7 @@ if __name__ == "__main__":
2641
  logger.info("=" * 60)
2642
  logger.info("Enhanced with clear OSS vs Enterprise boundaries")
2643
  logger.info("Now with Realism Panel for enterprise-seasoned SRE experience")
2644
- logger.info("PHASE 2: Dynamic Performance Metrics by Scenario Type")
2645
  logger.info(f"True ARF OSS v3.3.9 integration with simulated Enterprise execution")
2646
  logger.info("=" * 60)
2647
 
 
3
  # Enhanced with clear OSS vs Enterprise boundaries
4
  # UPDATED: Added realism panel integration for enterprise-seasoned SRE experience
5
  # UPDATED: Added dynamic performance metrics for Phase 2
6
+ # SURGICAL FIX: Fixed AsyncRunner.async_to_sync contract violation
7
 
8
  import logging
9
  import sys
 
187
  """
188
 
189
  # ===========================================
190
+ # FIXED: AsyncRunner - CONTRACT-PRESERVING VERSION
191
  # ===========================================
192
  class AsyncRunner:
193
+ """Enhanced async runner with better error handling - FIXED to preserve return contracts"""
194
 
195
  @staticmethod
196
  def run_async(coro):
 
205
  return loop.run_until_complete(coro)
206
  except Exception as e:
207
  logger.error(f"Async execution failed: {e}")
208
+ # CRITICAL FIX: Return contract-compatible values instead of dict
209
+ error_html = f"""
210
+ <div style="border: 2px solid #ef4444; border-radius: 14px; padding: 18px;
211
+ background: linear-gradient(135deg, #fef2f2 0%, #ffffff 100%);
212
+ text-align: center; flex: 1; margin: 5px; min-height: 180px;">
213
+ <div style="font-size: 32px; margin-bottom: 10px; color: #ef4444;">❌</div>
214
+ <div style="width: 100%;">
215
+ <h4 style="margin: 0 0 8px 0; font-size: 16px; color: #1e293b;">Async Error</h4>
216
+ <p style="font-size: 13px; color: #64748b; margin-bottom: 12px; line-height: 1.4;">
217
+ Async operation failed
218
+ </p>
219
+ </div>
220
+ </div>
221
+ """
222
+
223
+ error_dict = {
224
+ "status": "error",
225
+ "error": str(e),
226
+ "scenario": "Unknown",
227
+ "arf_version": "3.3.9",
228
+ "boundary_note": "Async execution boundary reached"
229
+ }
230
+
231
+ error_df = pd.DataFrame(columns=["Error", "Message"]).from_records([
232
+ {"Error": "Async Execution Failed", "Message": str(e)}
233
+ ])
234
+
235
+ # πŸ”’ SHAPE CONTRACT ENFORCED: Always return 5-tuple matching expected signature
236
+ return error_html, error_html, error_html, error_dict, error_df
237
 
238
  @staticmethod
239
  def async_to_sync(async_func):
240
+ """Decorator to convert async function to sync - FIXED to preserve return contract"""
241
  def wrapper(*args, **kwargs):
242
  try:
243
+ # Direct call to run_async which now preserves contract
244
+ result = AsyncRunner.run_async(async_func(*args, **kwargs))
245
+
246
+ # Ensure result is a 5-tuple (contract validation)
247
+ if isinstance(result, tuple) and len(result) == 5:
248
+ return result
249
+ else:
250
+ # Contract violation - wrap it properly
251
+ logger.warning(f"Contract violation: Expected 5-tuple, got {type(result)}")
252
+ error_html = f"""
253
+ <div style="border: 2px solid #f59e0b; border-radius: 14px; padding: 18px;
254
+ background: linear-gradient(135deg, #fef3c7 0%, #ffffff 100%);
255
+ text-align: center; flex: 1; margin: 5px; min-height: 180px;">
256
+ <div style="font-size: 32px; margin-bottom: 10px; color: #f59e0b;">⚠️</div>
257
+ <div style="width: 100%;">
258
+ <h4 style="margin: 0 0 8px 0; font-size: 16px; color: #1e293b;">Contract Violation</h4>
259
+ <p style="font-size: 13px; color: #64748b; margin-bottom: 12px; line-height: 1.4;">
260
+ Expected 5-tuple, got {type(result).__name__}
261
+ </p>
262
+ </div>
263
+ </div>
264
+ """
265
+
266
+ error_dict = {
267
+ "status": "contract_error",
268
+ "error": f"Expected 5-tuple, got {type(result)}",
269
+ "scenario": args[0] if args else "Unknown",
270
+ "arf_version": "3.3.9",
271
+ "boundary_note": "Return contract violation"
272
+ }
273
+
274
+ error_df = pd.DataFrame(columns=["Error", "Message"]).from_records([
275
+ {"Error": "Contract Error", "Message": "Return shape violation"}
276
+ ])
277
+
278
+ return error_html, error_html, error_html, error_dict, error_df
279
+
280
  except Exception as e:
281
  logger.error(f"Async to sync conversion failed: {e}")
282
+ # πŸ”’ SHAPE CONTRACT ENFORCED: Always return 5-tuple
283
+ error_html = f"""
284
+ <div style="border: 2px solid #ef4444; border-radius: 14px; padding: 18px;
285
+ background: linear-gradient(135deg, #fef2f2 0%, #ffffff 100%);
286
+ text-align: center; flex: 1; margin: 5px; min-height: 180px;">
287
+ <div style="font-size: 32px; margin-bottom: 10px; color: #ef4444;">❌</div>
288
+ <div style="width: 100%;">
289
+ <h4 style="margin: 0 0 8px 0; font-size: 16px; color: #1e293b;">Conversion Error</h4>
290
+ <p style="font-size: 13px; color: #64748b; margin-bottom: 12px; line-height: 1.4;">
291
+ Async to sync failed
292
+ </p>
293
+ </div>
294
+ </div>
295
+ """
296
+
297
+ error_dict = {
298
+ "status": "error",
299
+ "error": str(e),
300
+ "scenario": args[0] if args else "Unknown",
301
+ "arf_version": "3.3.9",
302
+ "boundary_context": "OSS advisory only - execution requires Enterprise"
303
+ }
304
+
305
+ error_df = pd.DataFrame(columns=["Error", "Message"]).from_records([
306
+ {"Error": "Conversion Failed", "Message": str(e)}
307
+ ])
308
+
309
+ # πŸ”’ SHAPE CONTRACT ENFORCED: Always return 5-tuple
310
+ return error_html, error_html, error_html, error_dict, error_df
311
  return wrapper
312
 
313
  # ===========================================
 
1696
  <td style="padding: 12px; font-size: 13px; color: #1e293b;">
1697
  {status} {exec["scenario"]}
1698
  </td>
1699
+ <td style="padding: 12px; font-size: 13px; color: #64748b;">
1700
  {exec["mode"]}
1701
  </td>
1702
  <td style="padding: 12px; font-size: 13px;">
 
2247
  )
2248
 
2249
  # ===========================================
2250
+ # FIXED: OSS Analysis Button Connection - SIMPLE PASSTHROUGH
2251
  # ===========================================
2252
  def run_oss_analysis_real_arf(scenario_name: str) -> tuple:
2253
  """
2254
+ Simple passthrough to run_true_arf_analysis()
2255
+ The decorator now handles contract preservation
2256
  """
2257
  logger.info(f"πŸš€ Running TRUE ARF OSS analysis for: {scenario_name}")
2258
+ return run_true_arf_analysis(scenario_name)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2259
 
2260
+ # Run OSS Analysis - FIXED: Simple passthrough
2261
  oss_btn.click(
2262
  fn=run_oss_analysis_real_arf,
2263
  inputs=[scenario_dropdown],
 
2697
  logger.info("=" * 60)
2698
  logger.info("Enhanced with clear OSS vs Enterprise boundaries")
2699
  logger.info("Now with Realism Panel for enterprise-seasoned SRE experience")
2700
+ logger.info("PHASE 2: Dynamic Performance Metrics by Scenario")
2701
  logger.info(f"True ARF OSS v3.3.9 integration with simulated Enterprise execution")
2702
  logger.info("=" * 60)
2703