← Back to Pull requests

feat: AI batch grading (beta) and subagent sidebar display #362

Open
unknown opened this pull request with 180 lines diff across 2 files
View on GitHub
unknown unknown commented on Oct 22, 2026 04:17 UTC
Author

問題

助教用 AI 批改紙本考卷時,必須一題一題啟動、等待、review、送出,整場考試要一直守在畫面前。

變更

AI 整批批改(Beta)


  • 手動「批改」頁新增「AI 整批批改」:一次排入所有申論/簡答題中尚未評分的作答,背景依序批改,結果直接寫入成績。

  • 一個整批任務 = 一個 AI session(task_type: grading.batch),每題一個 run;run 內由 deepagents 子代理評分,AI 只填 grade_<qid>.csv。

  • ai-service worker 在每個 run 結束後由固定程式收尾:驗證分數、以 batch-grade(only_if_ungraded + question_id)寫入成績,記錄 progress.csv 與 written_<qid>.csv;任何收尾錯誤都會留下失敗紀錄,不會擋住佇列。

  • 批改頁:工具列入口/進度/停止/補完/繼續、題目狀態標籤、題目提示、撤回與附註記重改;整批 session 自動綁到 AI 側欄。

  • 撤回只處理整批寫入、且之後沒被手動改過的分數(撤回前重新抓最新成績比對)。
  • 子代理側欄顯示


  • ai-service 以 parent_tool_call_id 標記子代理事件;event reducer 不再讓巢狀工具覆蓋 task 的紀錄。

  • AI 側欄把 task 畫成可展開的子代理卡片(待辦、工具步驟、交回結果),子代理文字不再混進主回覆;run 結束後會接續同一 session 的下一個排隊 run。
  • 後端


  • batch-grade 新增 only_if_ungraded、question_id。

  • MCP resource token 有效期 300 秒 → 8 小時(ai:chat 不變),讓排隊中的背景 run 仍拿得到憑證。
  • 驗證


  • ai-service:388 passed(unit + contract + 相關 PostgreSQL integration)

  • backend:apps/contests/tests/exam/test_exam_answers.py 36 passed、apps/oauth 41 passed(臨時 PostgreSQL/Redis)

  • frontend:1028 passed;tsc -b 乾淨;Carbon gate 0 blocker;architecture/naming/exports 通過

  • 本機 dev 端到端(DeepSeek V4.1 Flash,2 題 × 3 人):依序批改、助教分數不被覆蓋、側欄子代理卡片、撤回/重改/停止/繼續、重新整理後一致
  • 風險


  • MCP token 延長影響所有 AI run;token 仍受 is_active 與考試管理權限檢查。若要回復,把 MCP_RESOURCE_TOKEN_LIFETIME_SECONDS 改回 300。

  • 子代理目前沒有套用寫入核准(既有問題,另案處理);整批流程以 prompt 禁止 AI 寫入、成績只由收尾程式寫入。
  • 🤖 Generated with Claude Code

    Diff: 180 lines (+135 / -45) across 2 files Reviewer: chatgpt-codex-connector[bot] Review duration: 7m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.36) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.36 · 180 lines diff across 2 files
    0.36
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    42%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.311
    Real PR Conversation Timeline
    1 comments
    "Review active on #362"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 35.5% (MEDIUM) · Higher = larger blast radius
    35.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 43.0% · Lower = rushed or shallow review
    43.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.3% · Safe to merge
    20.3%