@teevee98/synapse-hub 4.2.3 → 4.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/.agents/agents/api-engineer.md +1 -1
  2. package/.agents/agents/failure-analyst.md +1 -1
  3. package/.agents/agents/live-explorer.md +1 -1
  4. package/.agents/agents/orchestrator.md +1 -1
  5. package/.agents/agents/perf-engineer.md +1 -1
  6. package/.agents/agents/pom-crafter.md +1 -1
  7. package/.agents/agents/quality-gatekeeper.md +1 -1
  8. package/.agents/agents/test-designer.md +1 -1
  9. package/.agents/agents/test-runner.md +1 -1
  10. package/.agents/rules/git-push-protocol.md +2 -2
  11. package/.agents/rules/lessons-learned.md +10 -12
  12. package/.agents/rules/mandatory-playwright-live.md +1 -1
  13. package/.agents/rules/skill-precedence.md +1 -1
  14. package/.agents/rules/systematic-debugging.md +3 -3
  15. package/.agents/skills/01-web-automation/playwright-live-interaction/SKILL.md +2 -2
  16. package/.agents/skills/01-web-automation/playwright-live-interaction/references/recipes.md +14 -31
  17. package/.agents/skills/05-security-and-compliance/wcag-audit-patterns/SKILL.md +5 -4
  18. package/.agents/workflows/analyze_requirement_document.md +1 -1
  19. package/.agents/workflows/export_testcases_excel.md +1 -1
  20. package/.agents/workflows/generate_combinatorial_test_data.md +1 -1
  21. package/.agents/workflows/generate_cross_module_test_plan.md +1 -1
  22. package/.agents/workflows/generate_manual_testcases_rbt.md +1 -1
  23. package/.agents/workflows/generate_requirements_from_website.md +1 -1
  24. package/.agents/workflows/generate_testcases_from_requirements.md +1 -1
  25. package/.agents/workflows/test-impact.md +1 -1
  26. package/.agents/workflows/verify.md +1 -1
  27. package/AGENTS.md +1 -1
  28. package/README.en.md +2 -2
  29. package/README.md +2 -2
  30. package/agentskills.json +1 -1
  31. package/docs/ARCHITECTURE.en.md +1 -1
  32. package/docs/ARCHITECTURE.md +1 -1
  33. package/docs/PERFORMANCE_AUDIT_REPORT.md +2 -2
  34. package/docs/TOOL_CATALOG.md +25 -20
  35. package/package.json +1 -1
  36. package/plugin.json +1 -1
  37. package/scripts/setup.sh +6 -1
  38. package/skills_manifest.json +1 -1
  39. package/synapse.config.json +1 -1
  40. package/tools/TOOL_CATALOG.json +112 -31
  41. package/tools/__init__.py +1 -1
  42. package/tools/browser_helpers.js +2 -2
  43. package/tools/cli.py +3 -3
  44. package/tools/core/file_lock.py +7 -0
  45. package/tools/core/memory_bus.py +44 -40
  46. package/tools/core/process_supervisor.py +12 -4
  47. package/tools/core/telemetry.py +54 -16
  48. package/tools/dashboard_generator.py +6 -6
  49. package/tools/db_sandbox.py +8 -2
  50. package/tools/generate_tool_catalog.py +32 -2
  51. package/tools/mcp_docx_server.py +1 -1
  52. package/tools/mcp_excel_server.py +1 -1
  53. package/tools/mcp_server.py +1 -1
  54. package/tools/package_release.py +22 -27
  55. package/tools/reversible_sandbox.py +43 -10
  56. package/tools/task_memory_manager.py +2 -1
  57. package/tools/ui_server.py +1 -1
  58. package/tools/update_sentinel.py +3 -3
  59. package/tools/welcome_page.py +1 -1
@@ -389,47 +389,51 @@ class UnifiedMemoryBus:
389
389
  mark_read: bool = True,
390
390
  session_id: Optional[str] = None
391
391
  ) -> List[Dict[str, Any]]:
392
- """Retrieves and optionally marks messages as PROCESSED for recipient."""
392
+ """Retrieves and atomically marks messages as PROCESSED for recipient across processes."""
393
393
  with self._lock:
394
- cur = self._conn.cursor()
395
- query = "SELECT * FROM actor_mailbox WHERE recipient = ? AND status = ?"
396
- params: List[Any] = [recipient, status]
397
- if stage:
398
- query += " AND stage = ?"
399
- params.append(stage)
400
- if session_id:
401
- query += " AND (session_id = ? OR session_id IS NULL)"
402
- params.append(session_id)
403
- query += " ORDER BY created_at ASC;"
404
-
405
- cur.execute(query, params)
406
- rows = cur.fetchall()
407
-
408
- messages = []
409
- msg_ids = []
410
- for r in rows:
411
- msg_ids.append(r["message_id"])
412
- messages.append({
413
- "message_id": r["message_id"],
414
- "session_id": r["session_id"] if "session_id" in r.keys() else None,
415
- "sender": r["sender"],
416
- "recipient": r["recipient"],
417
- "stage": r["stage"],
418
- "payload": _json_loads(r["payload"]),
419
- "status": r["status"],
420
- "created_at": r["created_at"],
421
- "read_at": r["read_at"]
422
- })
423
-
424
- if mark_read and msg_ids:
425
- now = _now_iso()
426
- placeholders = ",".join("?" for _ in msg_ids)
427
- cur.execute(
428
- f"UPDATE actor_mailbox SET status = 'PROCESSED', read_at = ? WHERE message_id IN ({placeholders});",
429
- [now] + msg_ids
430
- )
431
- cur.close()
432
- return messages
394
+ # Multi-process atomic claim: acquire transaction if marking read and not in caller transaction
395
+ import contextlib
396
+ cm = self.transaction() if (mark_read and not self._in_transaction) else contextlib.nullcontext()
397
+ with cm:
398
+ cur = self._conn.cursor()
399
+ query = "SELECT * FROM actor_mailbox WHERE recipient = ? AND status = ?"
400
+ params: List[Any] = [recipient, status]
401
+ if stage:
402
+ query += " AND stage = ?"
403
+ params.append(stage)
404
+ if session_id:
405
+ query += " AND (session_id = ? OR session_id IS NULL)"
406
+ params.append(session_id)
407
+ query += " ORDER BY created_at ASC;"
408
+
409
+ cur.execute(query, params)
410
+ rows = cur.fetchall()
411
+
412
+ messages = []
413
+ msg_ids = []
414
+ for r in rows:
415
+ msg_ids.append(r["message_id"])
416
+ messages.append({
417
+ "message_id": r["message_id"],
418
+ "session_id": r["session_id"] if "session_id" in r.keys() else None,
419
+ "sender": r["sender"],
420
+ "recipient": r["recipient"],
421
+ "stage": r["stage"],
422
+ "payload": _json_loads(r["payload"]),
423
+ "status": r["status"],
424
+ "created_at": r["created_at"],
425
+ "read_at": r["read_at"]
426
+ })
427
+
428
+ if mark_read and msg_ids:
429
+ now = _now_iso()
430
+ placeholders = ",".join("?" for _ in msg_ids)
431
+ cur.execute(
432
+ f"UPDATE actor_mailbox SET status = 'PROCESSED', read_at = ? WHERE message_id IN ({placeholders});",
433
+ [now] + msg_ids
434
+ )
435
+ cur.close()
436
+ return messages
433
437
 
434
438
  def peek_messages(
435
439
  self,
@@ -228,14 +228,22 @@ def reap_orphan_processes(
228
228
  continue
229
229
 
230
230
  is_tracked = bool(tracked_pids and pid in tracked_pids)
231
- is_orphan = False
231
+ is_dead_parent = False
232
232
  if ppid is not None:
233
233
  if sys.platform == "win32":
234
- is_orphan = not psutil.pid_exists(ppid)
234
+ is_dead_parent = not psutil.pid_exists(ppid)
235
235
  else:
236
- is_orphan = (ppid == 1) or (not psutil.pid_exists(ppid))
236
+ is_dead_parent = (ppid != 1 and not psutil.pid_exists(ppid))
237
237
 
238
- if is_tracked or is_orphan or allow_system_wide:
238
+ # Guard: Never kill untracked adopted processes (PPID=1) or orphans without explicit allow_system_wide=True
239
+ should_reap = False
240
+ if is_tracked:
241
+ should_reap = True
242
+ elif allow_system_wide:
243
+ is_orphan = is_dead_parent or (ppid == 1 if sys.platform != "win32" else False)
244
+ should_reap = is_orphan or allow_system_wide
245
+
246
+ if should_reap:
239
247
  proc.kill()
240
248
  reaped += 1
241
249
  except (psutil.NoSuchProcess, psutil.AccessDenied):
@@ -417,21 +417,46 @@ def record_session_telemetry(
417
417
  record: SessionTelemetryRecord,
418
418
  ledger_file: Optional[str] = None,
419
419
  ) -> None:
420
- """Appends a closed-loop session telemetry record to the JSON ledger with file locking."""
420
+ """Appends a closed-loop session telemetry record to the JSON ledger with file locking and atomic replace."""
421
421
  target_path = ledger_file or DEFAULT_SESSION_LEDGER
422
422
  os.makedirs(os.path.dirname(os.path.abspath(target_path)), exist_ok=True)
423
+ lock_path = target_path + ".lock"
423
424
 
424
- records: List[Dict[str, Any]] = []
425
- if os.path.exists(target_path):
426
- try:
427
- with open(target_path, "r", encoding="utf-8") as f:
428
- records = json.load(f)
429
- except (OSError, json.JSONDecodeError):
430
- records = []
431
-
432
- records.append(record.to_dict())
433
- with open(target_path, "w", encoding="utf-8") as f:
434
- json.dump(records, f, indent=2, ensure_ascii=False)
425
+ try:
426
+ from tools.core.file_lock import file_lock
427
+ ctx = file_lock(lock_path, timeout=10.0)
428
+ except ImportError:
429
+ import contextlib
430
+ ctx = contextlib.nullcontext()
431
+
432
+ with ctx:
433
+ records: List[Dict[str, Any]] = []
434
+ if os.path.exists(target_path):
435
+ try:
436
+ with open(target_path, "r", encoding="utf-8") as f:
437
+ content = f.read().strip()
438
+ if content:
439
+ loaded = json.loads(content)
440
+ records = loaded if isinstance(loaded, list) else []
441
+ except (OSError, json.JSONDecodeError) as err:
442
+ backup_path = f"{target_path}.corrupted.{int(time.time())}"
443
+ try:
444
+ import shutil
445
+ shutil.copy2(target_path, backup_path)
446
+ sys.stderr.write(f"Warning: Corrupted telemetry ledger detected. Quarantined to {backup_path}: {err}\n")
447
+ except OSError as copy_err:
448
+ sys.stderr.write(f"Notice: Failed to quarantine corrupted ledger: {copy_err}\n")
449
+ records = []
450
+
451
+ records.append(record.to_dict())
452
+
453
+ # Atomic write to avoid partial writes or corrupted json on interruption
454
+ tmp_target = f"{target_path}.tmp.{os.getpid()}.{time.time()}"
455
+ with open(tmp_target, "w", encoding="utf-8") as f:
456
+ json.dump(records, f, indent=2, ensure_ascii=False)
457
+ f.flush()
458
+ os.fsync(f.fileno())
459
+ os.replace(tmp_target, target_path)
435
460
 
436
461
 
437
462
  def get_telemetry_summary(ledger_file: Optional[str] = None) -> Dict[str, Any]:
@@ -449,10 +474,23 @@ def get_telemetry_summary(ledger_file: Optional[str] = None) -> Dict[str, Any]:
449
474
  }
450
475
 
451
476
  try:
452
- with open(target_path, "r", encoding="utf-8") as f:
453
- records: List[Dict[str, Any]] = json.load(f)
454
- except (OSError, json.JSONDecodeError):
455
- records = []
477
+ from tools.core.file_lock import file_lock
478
+ ctx = file_lock(target_path + ".lock", timeout=5.0, shared=True)
479
+ except ImportError:
480
+ import contextlib
481
+ ctx = contextlib.nullcontext()
482
+
483
+ records: List[Dict[str, Any]] = []
484
+ with ctx:
485
+ if os.path.exists(target_path):
486
+ try:
487
+ with open(target_path, "r", encoding="utf-8") as f:
488
+ content = f.read().strip()
489
+ if content:
490
+ loaded = json.loads(content)
491
+ records = loaded if isinstance(loaded, list) else []
492
+ except (OSError, json.JSONDecodeError):
493
+ records = []
456
494
 
457
495
  if not records:
458
496
  return {
@@ -1350,7 +1350,7 @@ def _build_target_translations(
1350
1350
  "th_step_status": "Trạng Thái",
1351
1351
  "th_step_details": "Chi Tiết Kỹ Thuật (OTel & AST)",
1352
1352
 
1353
- "footer_text": "Báo cáo được khởi tạo tự động bởi Synapse-Hub v4.2.3 • Bản quyền © Thế Vị (@TeeVee98) • Chuẩn Clean POM & Kiểm Thử Tự Chủ",
1353
+ "footer_text": "Báo cáo được khởi tạo tự động bởi Synapse-Hub v4.2.5 • Bản quyền © Thế Vị (@TeeVee98) • Chuẩn Clean POM & Kiểm Thử Tự Chủ",
1354
1354
  }
1355
1355
 
1356
1356
  translations_en = {
@@ -1428,7 +1428,7 @@ def _build_target_translations(
1428
1428
  "th_step_status": "Status",
1429
1429
  "th_step_details": "Technical Details (OTel & AST)",
1430
1430
 
1431
- "footer_text": "Generated automatically by Synapse-Hub v4.2.3 • Copyright © Thế Vị (@TeeVee98) • Clean POM & Autonomous Testing",
1431
+ "footer_text": "Generated automatically by Synapse-Hub v4.2.5 • Copyright © Thế Vị (@TeeVee98) • Clean POM & Autonomous Testing",
1432
1432
  }
1433
1433
 
1434
1434
  _inject_gate_translations(translations_vi, translations_en, gates)
@@ -1917,7 +1917,7 @@ def _build_hub_translations(
1917
1917
  """Builds bilingual dictionaries for Hub Dashboard."""
1918
1918
  translations_vi = {
1919
1919
  "header_title": "Bảng Điều Hành Chất Lượng Doanh Nghiệp",
1920
- "header_subtitle": "Synapse-Hub v4.2.3 • Hệ Sinh Thái Kiểm Thử AI Agent Tự Chủ",
1920
+ "header_subtitle": "Synapse-Hub v4.2.5 • Hệ Sinh Thái Kiểm Thử AI Agent Tự Chủ",
1921
1921
  "nav_welcome": "Giới Thiệu",
1922
1922
  "meta_mode": "🏷️ Chế độ: <strong>HỆ SINH THÁI QA HUB</strong>",
1923
1923
  "meta_gen": f"🕒 Khởi tạo: <strong>{now_str}</strong>",
@@ -1987,12 +1987,12 @@ def _build_hub_translations(
1987
1987
  "th_sk_ver": "Phiên Bản",
1988
1988
  "th_sk_cap": "Khả Năng Nghiệp Vụ Cốt Lõi",
1989
1989
 
1990
- "footer_text": "Bảng Điều Hành Chất Lượng Doanh Nghiệp &bull; Synapse-Hub v4.2.3 &bull; Bản quyền &copy; Thế Vị (@TeeVee98) &bull; Hệ Thống Kiểm Thử AI Agent Tự Chủ",
1990
+ "footer_text": "Bảng Điều Hành Chất Lượng Doanh Nghiệp &bull; Synapse-Hub v4.2.5 &bull; Bản quyền &copy; Thế Vị (@TeeVee98) &bull; Hệ Thống Kiểm Thử AI Agent Tự Chủ",
1991
1991
  }
1992
1992
 
1993
1993
  translations_en = {
1994
1994
  "header_title": "Enterprise QA Executive Dashboard",
1995
- "header_subtitle": "Synapse-Hub v4.2.3 &bull; Autonomous AI Agent Testing Ecosystem",
1995
+ "header_subtitle": "Synapse-Hub v4.2.5 &bull; Autonomous AI Agent Testing Ecosystem",
1996
1996
  "nav_welcome": "Welcome",
1997
1997
  "meta_mode": "🏷️ Mode: <strong>QA HUB ECOSYSTEM</strong>",
1998
1998
  "meta_gen": f"🕒 Generated: <strong>{now_str}</strong>",
@@ -2062,7 +2062,7 @@ def _build_hub_translations(
2062
2062
  "th_sk_ver": "Version",
2063
2063
  "th_sk_cap": "Core Capabilities",
2064
2064
 
2065
- "footer_text": "Enterprise QA Executive Dashboard &bull; Synapse-Hub v4.2.3 &bull; Copyright &copy; Thế Vị (@TeeVee98) &bull; Autonomous AI Agent Testing Ecosystem",
2065
+ "footer_text": "Enterprise QA Executive Dashboard &bull; Synapse-Hub v4.2.5 &bull; Copyright &copy; Thế Vị (@TeeVee98) &bull; Autonomous AI Agent Testing Ecosystem",
2066
2066
  }
2067
2067
 
2068
2068
  _inject_gate_translations(translations_vi, translations_en, gates)
@@ -643,7 +643,7 @@ class DBSandbox:
643
643
  "tables_audited": 0,
644
644
  "total_purged_rows": 0,
645
645
  "purge_details": [],
646
- "zero_pollution_achieved": True,
646
+ "zero_pollution_achieved": False,
647
647
  "message": "No database found"
648
648
  }
649
649
 
@@ -688,12 +688,18 @@ class DBSandbox:
688
688
  finally:
689
689
  conn.close()
690
690
 
691
+ # Zero pollution is achieved if:
692
+ # 1. Not a dry run, meaning any identified pollution was actively deleted and committed.
693
+ # 2. Or, dry run audited the tables and found 0 polluted rows (total_purged == 0).
694
+ # If dry run found polluted rows but didn't delete them, zero pollution has NOT been achieved.
695
+ achieved = (not dry_run) or (total_purged == 0)
696
+
691
697
  return {
692
698
  "status": "CLEAN" if not dry_run else "DRY_RUN",
693
699
  "tables_audited": len(tables),
694
700
  "total_purged_rows": total_purged,
695
701
  "purge_details": purge_log,
696
- "zero_pollution_achieved": True,
702
+ "zero_pollution_achieved": achieved,
697
703
  "dry_run": dry_run
698
704
  }
699
705
 
@@ -64,11 +64,31 @@ TOOL_REGISTRY_METADATA = {
64
64
  "category": "CI/CD & Packaging",
65
65
  "owner_role": "orchestrator",
66
66
  "status": "stable",
67
- "risk_level": "read_only",
67
+ "risk_level": "modifying",
68
68
  "inputs": ["--output-dir", "--format zip|tar.gz|both", "--verify-archive"],
69
69
  "outputs": ["dist/synapse-hub-vX.Y.Z.zip", "dist/*-checksums.sha256"],
70
70
  "description": "Enterprise release packager preserving .github/workflows and generating SHA-256 provenance."
71
71
  },
72
+ "db_sandbox.py": {
73
+ "command": "python tools/db_sandbox.py",
74
+ "category": "Sandboxing & Isolation",
75
+ "owner_role": "failure-analyst",
76
+ "status": "stable",
77
+ "risk_level": "modifying",
78
+ "inputs": ["--mode audit|purge|restore", "--db-path", "--consent"],
79
+ "outputs": ["Database snapshots", "Purge audit logs"],
80
+ "description": "Database state isolation sentinel with granular consent-governed snapshot and purge capabilities."
81
+ },
82
+ "reversible_sandbox.py": {
83
+ "command": "python tools/reversible_sandbox.py",
84
+ "category": "Sandboxing & Isolation",
85
+ "owner_role": "failure-analyst",
86
+ "status": "stable",
87
+ "risk_level": "modifying",
88
+ "inputs": ["--execute-stateful", "--rollback", "--recover-wal"],
89
+ "outputs": [".agent_memory/undo_wal.jsonl", "Reversible execution rollbacks"],
90
+ "description": "Two-phase commit write-ahead logging (WAL) execution sandbox providing crash-resilient rollback guarantees."
91
+ },
72
92
  "fsm_enforcer.py": {
73
93
  "command": "python tools/fsm_enforcer.py",
74
94
  "category": "Orchestration",
@@ -395,13 +415,23 @@ def build_catalog() -> Dict[str, Any]:
395
415
  else:
396
416
  # Auto-inferred metadata for auxiliary tools
397
417
  is_test_tool = "test" in fname or "fuzz" in fname or "mock" in fname
418
+ lower_name = fname.lower()
419
+ if any(k in lower_name for k in ("purge", "delete", "destroy", "kill")):
420
+ inferred_risk = "destructive"
421
+ elif any(k in lower_name for k in ("network", "http", "curl", "fetch", "download")):
422
+ inferred_risk = "network"
423
+ elif any(k in lower_name for k in ("mutate", "heal", "patch", "sandbox", "supervisor", "exec", "publish", "deploy", "release", "push", "upload", "write", "sync", "bump", "rollback", "revert", "clean")):
424
+ inferred_risk = "modifying"
425
+ else:
426
+ inferred_risk = "read_only"
427
+
398
428
  entry = {
399
429
  "file": f"tools/{fname}",
400
430
  "command": f"python tools/{fname}",
401
431
  "category": "Testing & Utilities" if is_test_tool else "Auxiliary Utilities",
402
432
  "owner_role": "orchestrator",
403
433
  "status": "stable" if os.path.getsize(full_path) > 1000 else "experimental",
404
- "risk_level": "read_only",
434
+ "risk_level": inferred_risk,
405
435
  "inputs": ["CLI options"],
406
436
  "outputs": ["Artifacts / Telemetry"],
407
437
  "description": doc_summary or f"Synapse Hub utility module: {fname}"
@@ -60,7 +60,7 @@ if hasattr(sys.stdout, 'reconfigure'):
60
60
  except Exception:
61
61
  pass
62
62
 
63
- SERVER_VERSION = "4.2.3"
63
+ SERVER_VERSION = "4.2.5"
64
64
  MAX_DOCX_SIZE = 50 * 1024 * 1024 # 50 MB
65
65
  MAX_UNCOMPRESSED_SIZE = 200 * 1024 * 1024 # 200 MB
66
66
  MAX_RATIO = 100 # 100:1 compression ratio limit
@@ -55,7 +55,7 @@ if hasattr(sys.stdout, 'reconfigure'):
55
55
  except Exception:
56
56
  pass
57
57
 
58
- SERVER_VERSION = "4.2.3"
58
+ SERVER_VERSION = "4.2.5"
59
59
  MAX_XLSX_SIZE = 50 * 1024 * 1024 # 50 MB
60
60
  MAX_UNCOMPRESSED_SIZE = 200 * 1024 * 1024 # 200 MB
61
61
  MAX_RATIO = 100 # 100:1 compression ratio limit
@@ -50,7 +50,7 @@ import gherkin_suite
50
50
  import api_fuzzer
51
51
 
52
52
  SERVER_NAME = "enterprise-agent-qa"
53
- SERVER_VERSION = "4.2.3"
53
+ SERVER_VERSION = "4.2.5"
54
54
 
55
55
  MCP_TOOLS = [
56
56
  {
@@ -221,6 +221,25 @@ def verify_archive_integrity(archive_path: str) -> Tuple[bool, List[str]]:
221
221
  return (len(missing) == 0), missing
222
222
 
223
223
 
224
+ def clean_stale_release_archives(out_dir: str) -> int:
225
+ """
226
+ Safely cleans up older release archives strictly within the designated output directory.
227
+ Guarded against repo root wildcard deletion or cleaning outside the target output scope.
228
+ """
229
+ if not os.path.exists(out_dir):
230
+ return 0
231
+ release_pattern = re.compile(r"^synapse-hub-v\d+\.\d+\.\d+.*?\.(zip|tar\.gz|sha256)$", re.IGNORECASE)
232
+ cleaned = 0
233
+ for f in os.listdir(out_dir):
234
+ if release_pattern.match(f):
235
+ try:
236
+ os.remove(os.path.join(out_dir, f))
237
+ cleaned += 1
238
+ except OSError:
239
+ continue
240
+ return cleaned
241
+
242
+
224
243
  def package_synapse_hub(
225
244
  repo_root: str = REPO_ROOT,
226
245
  output_dir: str = "dist",
@@ -231,35 +250,11 @@ def package_synapse_hub(
231
250
  Main packaging entrypoint: cleans stale archives, builds single target archive, and verifies integrity.
232
251
  """
233
252
  version = get_version(repo_root)
234
- out_dir = os.path.join(repo_root, output_dir)
253
+ out_dir = os.path.abspath(output_dir) if os.path.isabs(output_dir) else os.path.abspath(os.path.join(repo_root, output_dir))
235
254
  os.makedirs(out_dir, exist_ok=True)
236
255
 
237
- # 1. Clean up old release archives safely (guarded against repo root wildcard deletion)
238
- is_same_as_root = False
239
- try:
240
- is_same_as_root = os.path.samefile(out_dir, repo_root)
241
- except (FileNotFoundError, OSError, ValueError):
242
- is_same_as_root = os.path.realpath(out_dir).lower() == os.path.realpath(repo_root).lower()
243
-
244
- for f in os.listdir(out_dir):
245
- if re.match(r"^synapse-hub-v\d+\.\d+\.\d+.*", f, re.IGNORECASE) and f.endswith((".zip", ".tar.gz", ".sha256")):
246
- try:
247
- os.remove(os.path.join(out_dir, f))
248
- except OSError:
249
- continue
250
- elif not is_same_as_root and f.endswith((".zip", ".tar.gz", ".sha256")) and f.lower().startswith("synapse-hub"):
251
- try:
252
- os.remove(os.path.join(out_dir, f))
253
- except OSError:
254
- continue
255
-
256
- if not is_same_as_root:
257
- for f in os.listdir(repo_root):
258
- if re.match(r"^synapse-hub-v\d+\.\d+\.\d+.*", f, re.IGNORECASE) and f.endswith((".zip", ".tar.gz", ".sha256")):
259
- try:
260
- os.remove(os.path.join(repo_root, f))
261
- except OSError:
262
- continue
256
+ # 1. Clean up old release archives strictly inside the designated out_dir
257
+ clean_stale_release_archives(out_dir)
263
258
 
264
259
  files = collect_package_files(repo_root)
265
260
  base_name = f"synapse-hub-v{version}"
@@ -134,8 +134,8 @@ class ExecutionSandbox:
134
134
  raise last_err or PathContainmentError(f"Path '{target_path}' escapes sandbox root containment.")
135
135
  return contained
136
136
 
137
- def _append_wal(self, action: ReversibleAction):
138
- """Persists a pending undo action to disk before side-effects complete."""
137
+ def _append_wal(self, action: ReversibleAction, status: str = "PENDING"):
138
+ """Persists an undo action to disk before side-effects complete with durable fsync. Propagates errors."""
139
139
  if not self.wal_path:
140
140
  return
141
141
  entry = {
@@ -143,7 +143,7 @@ class ExecutionSandbox:
143
143
  "target_resource": action.target_resource,
144
144
  "undo_command": action.undo_command,
145
145
  "metadata": action.metadata,
146
- "status": "PENDING",
146
+ "status": status,
147
147
  "timestamp": time.time()
148
148
  }
149
149
  line = json.dumps(entry, ensure_ascii=False) + "\n"
@@ -154,12 +154,15 @@ class ExecutionSandbox:
154
154
  with open(self.wal_path, "a", encoding="utf-8") as f:
155
155
  f.write(line)
156
156
  f.flush()
157
+ os.fsync(f.fileno())
157
158
  except ImportError:
158
159
  with open(self.wal_path, "a", encoding="utf-8") as f:
159
160
  f.write(line)
160
161
  f.flush()
162
+ os.fsync(f.fileno())
161
163
  except Exception as e:
162
- sys.stderr.write(f"Warning: Failed to write undo WAL journal: {e}\n")
164
+ sys.stderr.write(f"Error: Failed to write undo WAL journal: {e}\n")
165
+ raise RuntimeError(f"Failed to write undo WAL journal: {e}") from e
163
166
 
164
167
  def _clear_wal(self):
165
168
  """Clears or resets WAL journal when stack has been completely unwound without errors."""
@@ -170,10 +173,12 @@ class ExecutionSandbox:
170
173
  from tools.core.file_lock import file_lock
171
174
  with file_lock(self.wal_path + ".lock", timeout=5.0):
172
175
  with open(self.wal_path, "w", encoding="utf-8") as f:
173
- pass
176
+ f.flush()
177
+ os.fsync(f.fileno())
174
178
  except ImportError:
175
179
  with open(self.wal_path, "w", encoding="utf-8") as f:
176
- pass
180
+ f.flush()
181
+ os.fsync(f.fileno())
177
182
  except Exception as clear_err:
178
183
  sys.stderr.write(f"Notice: Failed to clear WAL: {clear_err}\n")
179
184
 
@@ -215,12 +220,15 @@ class ExecutionSandbox:
215
220
  with open(self.wal_path, "w", encoding="utf-8") as f:
216
221
  f.write(content)
217
222
  f.flush()
223
+ os.fsync(f.fileno())
218
224
  except ImportError:
219
225
  with open(self.wal_path, "w", encoding="utf-8") as f:
220
226
  f.write(content)
221
227
  f.flush()
228
+ os.fsync(f.fileno())
222
229
  except Exception as e:
223
230
  sys.stderr.write(f"Warning: Failed to update WAL journal: {e}\n")
231
+ raise RuntimeError(f"Failed to update WAL journal: {e}") from e
224
232
 
225
233
  def record_mutation(
226
234
  self,
@@ -236,8 +244,8 @@ class ExecutionSandbox:
236
244
  undo_command=undo_command,
237
245
  metadata=metadata or {}
238
246
  )
247
+ self._append_wal(action, status="PENDING")
239
248
  self.undo_stack.append(action)
240
- self._append_wal(action)
241
249
 
242
250
  def execute_stateful_action(
243
251
  self,
@@ -246,15 +254,37 @@ class ExecutionSandbox:
246
254
  forward_cmd: str,
247
255
  undo_cmd: str
248
256
  ) -> bool:
249
- """Executes a forward shell command and immediately records its reversible undo counterpart."""
257
+ """
258
+ Executes a forward shell command with strict Write-Ahead Logging (WAL) protocol:
259
+ 1. Persists PREPARED undo record with durable fsync BEFORE executing the side-effect.
260
+ 2. Executes forward command.
261
+ 3. If forward command succeeds, registers action into undo_stack and transitions WAL to PENDING.
262
+ 4. If forward command fails, reverts the PREPARED entry and aborts safely.
263
+ """
264
+ action = ReversibleAction(
265
+ action_type=action_type,
266
+ target_resource=target_resource,
267
+ undo_command=undo_cmd,
268
+ metadata={"forward_cmd": forward_cmd}
269
+ )
270
+ try:
271
+ self._append_wal(action, status="PREPARED")
272
+ except Exception as wal_err:
273
+ sys.stderr.write(f"Abort stateful action: cannot write WAL prepared record: {wal_err}\n")
274
+ return False
275
+
250
276
  try:
251
277
  args = _split_cmd(forward_cmd) if isinstance(forward_cmd, str) else forward_cmd
252
278
  res = subprocess.run(args, text=True, capture_output=True, timeout=60.0)
253
279
  if res.returncode == 0:
254
- self.record_mutation(action_type, target_resource, undo_cmd, {"forward_cmd": forward_cmd})
280
+ self.undo_stack.append(action)
281
+ self._update_wal_journal(self.undo_stack, failed_entries=None)
255
282
  return True
256
- return False
283
+ else:
284
+ self._update_wal_journal(self.undo_stack, failed_entries=None)
285
+ return False
257
286
  except Exception:
287
+ self._update_wal_journal(self.undo_stack, failed_entries=None)
258
288
  return False
259
289
 
260
290
  def rollback_all(self, silent: bool = False) -> List[Dict[str, Any]]:
@@ -366,6 +396,9 @@ class ExecutionSandbox:
366
396
  for line in lines:
367
397
  try:
368
398
  data = json.loads(line)
399
+ status = data.get("status", "PENDING")
400
+ if status in ("ABORTED", "RESOLVED"):
401
+ continue
369
402
  actions.append(ReversibleAction(
370
403
  action_type=data.get("action_type", "WAL_RECOVERED"),
371
404
  target_resource=data.get("target_resource", ""),
@@ -54,11 +54,12 @@ class TaskMemoryManager:
54
54
  def _read_checksums(self) -> Dict[str, str]:
55
55
  if not os.path.isfile(self.checksums_path):
56
56
  return {}
57
- for _ in range(5):
57
+ for attempt in range(10):
58
58
  try:
59
59
  with open(self.checksums_path, "r", encoding="utf-8") as f:
60
60
  return json.load(f)
61
61
  except (json.JSONDecodeError, OSError):
62
+ time.sleep(0.005 * (attempt + 1))
62
63
  continue
63
64
  return {}
64
65
 
@@ -238,7 +238,7 @@ class SynapseUiHandler(BaseHTTPRequestHandler):
238
238
  if path == "/api/status":
239
239
  active_target = JOB_MANAGER.target_dir or REPO_ROOT
240
240
  self.send_json(200, {
241
- "version": "4.2.3",
241
+ "version": "4.2.5",
242
242
  "status": "ONLINE",
243
243
  "os": sys.platform,
244
244
  "workspace": active_target,
@@ -68,7 +68,7 @@ def get_local_version():
68
68
  try:
69
69
  with open(pkg_file, "r", encoding="utf-8") as f:
70
70
  data = json.load(f)
71
- return data.get("version", "4.2.3")
71
+ return data.get("version", "4.2.5")
72
72
  except (OSError, json.JSONDecodeError):
73
73
  data = {}
74
74
 
@@ -77,11 +77,11 @@ def get_local_version():
77
77
  try:
78
78
  with open(manifest_file, "r", encoding="utf-8") as f:
79
79
  data = json.load(f)
80
- return data.get("version", "4.2.3")
80
+ return data.get("version", "4.2.5")
81
81
  except (OSError, json.JSONDecodeError):
82
82
  data = {}
83
83
 
84
- return "4.2.3"
84
+ return "4.2.5"
85
85
 
86
86
 
87
87
  def fetch_remote_version():
@@ -47,7 +47,7 @@ def get_hub_metadata() -> Dict[str, Any]:
47
47
  """Retrieves version and catalog count from skills_manifest.json."""
48
48
  manifest_path = os.path.join(HUB_ROOT, "skills_manifest.json")
49
49
  meta = {
50
- "version": "4.2.3",
50
+ "version": "4.2.5",
51
51
  "totalSkills": 53,
52
52
  "author": "Thế Vị (@TeeVee98)",
53
53
  "repo": "https://github.com/TeeVee98/Synapse-Hub"