{
  "schema_version": "ai_agent_matched_playbook_learning_gap_v1",
  "generated_at": "2026-06-13T00:51:50+08:00",
  "program_status": {
    "overall_completion_percent": 100,
    "current_priority": "P2",
    "current_task_id": "P2-104",
    "next_task_id": "P2-105",
    "read_only_mode": true,
    "runtime_authority": "matched_playbook_learning_gap_contract_only_no_live_trust_write",
    "status_note": "P2-104 以正式 DB 只讀回查確認：近 24h approval 的 matched_playbook_id 已 66/66；真正缺口已移到 approved 之後未進 execution learning、PlayBook trust updated_24h=0。本快照只呈現證據與 gate，不寫 learning、不更新 PlayBook trust、不送 Telegram。"
  },
  "source_refs": [
    "docs/evaluations/ai_agent_task_result_audit_trail_2026-06-13.json",
    "apps/api/src/services/learning_service.py",
    "apps/api/src/services/approval_execution.py",
    "apps/api/src/services/decision_manager.py",
    "apps/api/src/services/proposal_service.py",
    "apps/api/src/services/repair_candidate_service.py",
    "docs/ai/AI_AGENT_AUTOMATION_WORKLIST_2026-06-04.md",
    "docs/superpowers/specs/2026-04-15-MASTER-ai-autonomous-flywheel-v2.md"
  ],
  "production_readback": {
    "readback_at": "2026-06-13T00:48:00+08:00",
    "readback_mode": "read_only_db_readback",
    "project_id_scope": "awoooi",
    "rls_fail_closed_verified": true,
    "approval_total": 1945,
    "approval_matched_total": 1104,
    "approval_24h_total": 66,
    "approval_24h_matched": 66,
    "matched_rate_24h_percent": 100,
    "playbook_total": 247,
    "playbook_with_execution_stats": 9,
    "playbook_updated_24h": 0,
    "readback_note": "未帶 project_id 時 RLS fail-closed；帶 project_id=awoooi 後只讀回查顯示 24h matched_playbook_id 覆蓋率 100%，但 PlayBook trust 近 24h 無更新。"
  },
  "recent_status_breakdown": [
    {
      "status": "APPROVED",
      "total": 63,
      "matched": 63,
      "execution_kind_present": 0,
      "repair_attempted_true": 0,
      "repair_executed_true": 0,
      "learning_candidate_count": 63,
      "readback_note": "已批准且已匹配，但 execution_kind / repair metadata 為空，代表尚未形成可餵給 learning_service 的 execution result。"
    },
    {
      "status": "PENDING",
      "total": 2,
      "matched": 2,
      "execution_kind_present": 0,
      "repair_attempted_true": 0,
      "repair_executed_true": 0,
      "learning_candidate_count": 0,
      "readback_note": "仍在人工 gate，不能寫入 learning 或 PlayBook trust。"
    },
    {
      "status": "EXECUTION_FAILED",
      "total": 1,
      "matched": 1,
      "execution_kind_present": 1,
      "repair_attempted_true": 1,
      "repair_executed_true": 0,
      "learning_candidate_count": 1,
      "readback_note": "已有失敗 execution metadata，可成為 learning 候選，但仍需 owner gate 與 post-write verifier。"
    }
  ],
  "learning_gap_truth": {
    "p2_103_task_result_audit_loaded": true,
    "production_db_readback_completed": true,
    "rls_fail_closed_verified": true,
    "matched_playbook_id_present_24h": true,
    "matched_playbook_id_gap_resolved": true,
    "execution_learning_gap_detected": true,
    "approved_without_execution_meta_detected": true,
    "playbook_trust_update_gap_detected": true,
    "runtime_learning_write_enabled": false,
    "playbook_trust_write_enabled": false,
    "approval_auto_execute_enabled": false,
    "km_write_enabled": false,
    "logbook_runtime_write_enabled": false,
    "audit_db_write_enabled": false,
    "timeline_write_enabled": false,
    "gateway_queue_write_enabled": false,
    "telegram_send_enabled": false,
    "production_write_enabled": false,
    "secret_value_read_enabled": false,
    "destructive_operation_enabled": false,
    "work_window_transcript_display_allowed": false,
    "approval_24h_total": 66,
    "approval_24h_matched": 66,
    "approved_without_execution_meta_24h": 63,
    "pending_with_matched_24h": 2,
    "execution_failed_with_matched_24h": 1,
    "playbook_updated_24h": 0,
    "live_learning_write_count_24h": 0,
    "playbook_trust_write_count_24h": 0,
    "gateway_queue_write_count_24h": 0,
    "telegram_send_count_24h": 0,
    "production_write_count_24h": 0,
    "secret_value_read_count_24h": 0,
    "destructive_operation_count_24h": 0,
    "truth_note": "P2-104 不再把問題描述為 matched_playbook_id 遺失；正式資料顯示 matched id 已存在。下一個工程 gate 是把 approved / failed result 安全轉成 execution learning 候選，通過 owner review 與 verifier 後才可寫入 PlayBook trust。"
  },
  "gap_lanes": [
    {
      "lane_id": "lane_matched_id_present",
      "display_name": "matched_playbook_id 已存在",
      "owner_agent": "openclaw",
      "status": "passed",
      "risk_tier": "low",
      "count_24h": 66,
      "matched_count_24h": 66,
      "live_write_enabled": false,
      "evidence": "24h approval readback: 66 / 66 matched",
      "next_gate": "保留 matched id 作為 execution learning payload 的必要欄位，不再重做匹配修復。",
      "evidence_hash": "sha256:1212121212121212121212121212121212121212121212121212121212121212"
    },
    {
      "lane_id": "lane_approved_without_execution_meta",
      "display_name": "approved 未形成 execution learning",
      "owner_agent": "openclaw",
      "status": "blocked",
      "risk_tier": "high",
      "count_24h": 63,
      "matched_count_24h": 63,
      "live_write_enabled": false,
      "evidence": "APPROVED total=63, matched=63, execution_kind_present=0",
      "next_gate": "P2-105 需建立 critic / reviewer score 與 approved result capture，才能進入 owner-approved learning writeback。",
      "evidence_hash": "sha256:2323232323232323232323232323232323232323232323232323232323232323"
    },
    {
      "lane_id": "lane_pending_human_gate",
      "display_name": "pending 仍在人工 gate",
      "owner_agent": "hermes",
      "status": "owner_review_required",
      "risk_tier": "medium",
      "count_24h": 2,
      "matched_count_24h": 2,
      "live_write_enabled": false,
      "evidence": "PENDING total=2, matched=2",
      "next_gate": "保持人工審核；未批准前不得寫入 learning 或 PlayBook trust。",
      "evidence_hash": "sha256:3434343434343434343434343434343434343434343434343434343434343434"
    },
    {
      "lane_id": "lane_execution_failed_learning_candidate",
      "display_name": "execution failed 可成為學習候選",
      "owner_agent": "nemotron",
      "status": "owner_review_required",
      "risk_tier": "high",
      "count_24h": 1,
      "matched_count_24h": 1,
      "live_write_enabled": false,
      "evidence": "EXECUTION_FAILED total=1, matched=1, repair_attempted=true, repair_executed=false",
      "next_gate": "只允許產生 failure learning 候選；需 owner review、redacted payload 與 post-write verifier 後才能更新 trust。",
      "evidence_hash": "sha256:4545454545454545454545454545454545454545454545454545454545454545"
    },
    {
      "lane_id": "lane_playbook_trust_not_updated",
      "display_name": "PlayBook trust 近 24h 未更新",
      "owner_agent": "hermes",
      "status": "blocked",
      "risk_tier": "high",
      "count_24h": 0,
      "matched_count_24h": 0,
      "live_write_enabled": false,
      "evidence": "playbook_updated_24h=0, playbook_with_execution_stats=9",
      "next_gate": "先完成 writeback approval package 與 verifier，再開 PlayBook trust 候選更新。",
      "evidence_hash": "sha256:5656565656565656565656565656565656565656565656565656565656565656"
    }
  ],
  "learning_gates": [
    {
      "gate_id": "gate_result_capture_contract",
      "display_name": "approved result capture contract",
      "owner_agent": "openclaw",
      "status": "needs_owner_review",
      "required_before": "execution learning payload",
      "failure_if_missing": "approval 只停在 APPROVED，learning_service 無法判斷成功、失敗、no-op 或需補證。",
      "creates_runtime_write": false
    },
    {
      "gate_id": "gate_critic_reviewer_score",
      "display_name": "critic / reviewer score",
      "owner_agent": "openclaw",
      "status": "needs_owner_review",
      "required_before": "中低風險自動處理",
      "failure_if_missing": "AI Agent 會缺少互相判斷與接手依據，不能自動把 approved 結果升級成信任更新。",
      "creates_runtime_write": false
    },
    {
      "gate_id": "gate_learning_writeback_approval",
      "display_name": "learning writeback approval",
      "owner_agent": "hermes",
      "status": "blocked_by_policy",
      "required_before": "learning_service.process_execution_result",
      "failure_if_missing": "未批准前不可寫 KM、timeline、PlayBook trust 或任何 production 狀態。",
      "creates_runtime_write": false
    },
    {
      "gate_id": "gate_post_write_verifier",
      "display_name": "post-write verifier",
      "owner_agent": "nemotron",
      "status": "needs_owner_review",
      "required_before": "PlayBook trust score change",
      "failure_if_missing": "trust score 可能被失敗、no-op 或低可信資料污染。",
      "creates_runtime_write": false
    },
    {
      "gate_id": "gate_telegram_operator_receipt",
      "display_name": "Telegram operator receipt",
      "owner_agent": "hermes",
      "status": "blocked_by_policy",
      "required_before": "通知與回執 E2E",
      "failure_if_missing": "統帥看不到 learning 候選、被阻擋原因與人工批准點。",
      "creates_runtime_write": false
    }
  ],
  "writeback_candidates": [
    {
      "candidate_id": "candidate_approval_execution_bridge",
      "display_name": "approval → execution result bridge",
      "owner_agent": "openclaw",
      "target_system": "approval_execution",
      "allowed_mode": "gated_owner_review",
      "write_enabled": false,
      "runtime_writer_enabled": false,
      "required_fields": ["approval_id", "matched_playbook_id", "execution_kind", "result_state", "verifier_result"],
      "blocker_summary": "近 24h 63 筆 APPROVED 缺 execution metadata；需 P2-105 先定義 reviewer score 與 result capture。",
      "evidence_hash": "sha256:6767676767676767676767676767676767676767676767676767676767676767"
    },
    {
      "candidate_id": "candidate_learning_service_payload",
      "display_name": "learning service payload",
      "owner_agent": "hermes",
      "target_system": "learning_service.process_execution_result",
      "allowed_mode": "committed_snapshot_only",
      "write_enabled": false,
      "runtime_writer_enabled": false,
      "required_fields": ["incident_id", "approval_id", "matched_playbook_id", "success", "failure_reason"],
      "blocker_summary": "只能先固定 payload contract；未批准前不呼叫 learning write path。",
      "evidence_hash": "sha256:7878787878787878787878787878787878787878787878787878787878787878"
    },
    {
      "candidate_id": "candidate_playbook_trust_update",
      "display_name": "PlayBook trust 候選更新",
      "owner_agent": "nemotron",
      "target_system": "playbook_service.record_execution",
      "allowed_mode": "gated_owner_review",
      "write_enabled": false,
      "runtime_writer_enabled": false,
      "required_fields": ["playbook_id", "success", "verifier_result", "owner_review", "rollback_context"],
      "blocker_summary": "playbook_updated_24h=0；需 post-write verifier 與人工批准才可開始 trust update。",
      "evidence_hash": "sha256:8989898989898989898989898989898989898989898989898989898989898989"
    },
    {
      "candidate_id": "candidate_operator_learning_report",
      "display_name": "operator learning report",
      "owner_agent": "hermes",
      "target_system": "KM / LOGBOOK / Telegram digest",
      "allowed_mode": "manual_append_plan",
      "write_enabled": false,
      "runtime_writer_enabled": false,
      "required_fields": ["readback_at", "gap_lane", "next_gate", "risk_tier", "redacted_evidence_hash"],
      "blocker_summary": "報告可顯示 committed evidence；KM / LOGBOOK runtime append 與 Telegram 實發仍未開 gate。",
      "evidence_hash": "sha256:9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a"
    }
  ],
  "display_redaction_contract": {
    "redaction_required": true,
    "raw_prompt_display_allowed": false,
    "private_reasoning_display_allowed": false,
    "secret_value_display_allowed": false,
    "raw_telegram_payload_display_allowed": false,
    "work_window_transcript_display_allowed": false,
    "allowed_display_fields": [
      "schema_version",
      "generated_at",
      "program_status",
      "production_readback",
      "recent_status_breakdown",
      "learning_gap_truth",
      "gap_lanes",
      "learning_gates",
      "writeback_candidates",
      "rollups"
    ],
    "blocked_display_fields": [
      "raw DB URL",
      "raw approval payload",
      "raw Telegram payload",
      "prompt",
      "private reasoning",
      "secret value",
      "internal collaboration transcript"
    ]
  },
  "rollups": {
    "gap_lane_count": 5,
    "passed_lane_count": 1,
    "blocked_lane_count": 2,
    "owner_review_lane_count": 2,
    "approval_24h_total": 66,
    "approval_24h_matched": 66,
    "matched_rate_24h_percent": 100,
    "approved_without_execution_meta_24h": 63,
    "pending_with_matched_24h": 2,
    "execution_failed_with_matched_24h": 1,
    "playbook_with_execution_stats_count": 9,
    "playbook_updated_24h_count": 0,
    "learning_gate_count": 5,
    "writeback_candidate_count": 4,
    "live_learning_write_count": 0,
    "playbook_trust_write_count": 0,
    "gateway_queue_write_count": 0,
    "telegram_send_count": 0,
    "production_write_count": 0,
    "secret_value_read_count": 0,
    "destructive_operation_count": 0
  }
}
