77 / 90

第 77 天:整合複習——狀態、重試與故障分類

憑記憶提取本週的控制詞彙,對所有注入故障進行分類,並撰寫一份以軌跡為據的事後複盤。

Agent 480 主動學習分鐘(8 小時)
01 120 分鐘

檢索提取演練:執行狀態與執行限制詞彙

Agent 輔助工程檢查

前置要求

第 76 天的狀態與重試機制;第 73-75 天的工具協定。

學習目標

閉卷回憶本週控制詞彙的定義——步數預算、重試預算、軌跡、終止原因、檢查點、冪等副作用、拋棄式工作區——然後對照程式碼而非憑感覺驗證。

操作指引

1. 閉卷:為以下各項寫一行定義:max_steps、max_retries、trace、termination、checkpoint、idempotent effect、disposable workspace。
2. 對照權威定義自行批改:project.json 的 controls(max_steps=6、max_retries=2、tool_payload_bytes=4096)、agent.py 的 RunResult 欄位、cli.py 的 TemporaryDirectory 工作區。
3. 記錄模糊的詞彙,列入明天的提取計畫(間隔提取勝過重讀)。
4. 區分近似概念:重試預算(容忍的失敗觀測數)與步數預算(允許的總迭代數);檢查點(使復原成為可能的持久狀態)與軌跡(紀錄本身);逾時(單次阻塞等待)與截止期限(端到端上限)。

自主實作與記錄

在查看參考答案之前,先為你的手寫定義按 7 分制評分;把每個錯誤記入提取佇列。

獨立掌握標準

無輔助寫出全部七條定義並在查程式碼前誠實自評;最低 6/7。

權威來源資源與權利證明

linking CC BY-NC-ND 4.0 noncommercial no-derivatives

Site Reliability Engineering, Chapter 22: Addressing Cascading Failures

作者 / 機構: Mike Ulrich, in Site Reliability Engineering (eds. Betsy Beyer, Chris Jones, Jennifer Petoff, Niall Richard Murphy; Google) | 原始出處連結 ↗

對應章節 / 時間戳: Preventing Server Overload: Retries; Latency and Deadlines

驗證版本與日期: O'Reilly 2016 free online edition (Verified: 2026-10-30)

入選理由:

Primary analysis of how unbounded retries amplify partial outages into cascading failures, motivating hard retry budgets and deadlines in agent runtimes.

來源前置條件:

Retries, queueing, and load-shedding basics.

安全回退方案(離線彈性):

The retry-amplification scenario and budget arithmetic are fully reproduced in the lesson's worked example.

對比候選資源與選型分析 (2)
Release It! (Michael Nygard) - Stability patterns ↗ compared_alternative [Commercial book]

Broader stability-pattern catalog (circuit breakers, bulkheads); the SRE chapter is free and directly quantifies retry amplification.

Strong companion article; the SRE chapter frames the failure mode (cascading overload) that the retry budget defends against.

linking Amazon Web Services site content / linked reference noncommercial

Exponential Backoff And Jitter

作者 / 機構: Marc Brooker, AWS Architecture Blog | 原始出處連結 ↗

對應章節 / 時間戳: Adding Backoff; Adding Jitter (Full Jitter, Equal Jitter, Decorrelated Jitter)

驗證版本與日期: AWS Architecture Blog 2015 (Verified: 2026-10-30)

入選理由:

Detailed practitioner reference proving that full jitter (sleep = random_between(0, min(cap, base*2**attempt))) prevents synchronized retry storms and reduces total work during contention.

來源前置條件:

Retries, timeouts, and basic probability of correlated load.

安全回退方案(離線彈性):

The backoff exercise is implemented in pure Python with a local flaky stub; the derivation of jitter benefits is fully reproduced in lesson instructions.

對比候選資源與選型分析 (2)
Google Cloud retry strategy documentation ↗ compared_alternative [CC BY 4.0 / documentation terms]

Product-scoped truncated exponential backoff recipe; Brooker's analysis explains why jitter matters, not just what to configure.

Polly resilience library retry policies (.NET) ↗ compared_alternative [BSD-3-Clause]

Library implementation reference; the AWS article supplies the comparative evidence (with/without jitter) that anchors the lesson.

02 120 分鐘

故障分類演練:為每個注入故障歸類

獨立掌握檢查(無 AI 輔助)

前置要求

第 76 天三種故障模式的實際執行結果。

學習目標

把每個觀測到的故障歸入「重試後修正」「重試預算耗盡」或「步數預算耗盡」,並指出強制產生該結果的計數器。

操作指引

1. 建立分類表(欄:fault | observation error | 消耗的計數器 | status | termination | 類別)。
2. 來自真實執行的列:invalid_arguments('../outside.txt' 被拒,retries=1,隨後修正)-> 重試後修正;missing_note(not_found 三次,retries=3 > 2)-> 重試預算耗盡 tool_failure;loop(六次相同 list_notes,retries=0)-> 步數預算耗盡;超大 write_report(>4096 位元組 -> size_limit)-> 只有縮小載荷後才可重試。
3. 暫時 vs 永久:invalid_arguments、not_found、size_limit 對同一引數是永久的——盲目重試純屬浪費;配接器修正下一動作才讓重試產生價值。
4. 映射到正式環境:只有暫時故障(逾時、503)才值得帶退避的盲目重試;永久故障需要修正或去重(Stripe 的冪等重播不是失敗重試)。

自主實作與記錄

完成 4 列分類表,再預測一個假想 network_timeout 故障的類別與終止狀態,並用計數器給出理由。

獨立掌握標準

僅憑故障描述預測終止狀態與被消耗的預算,並用實際執行驗證。

權威來源資源與權利證明

linking Amazon Web Services site content / linked reference noncommercial

Exponential Backoff And Jitter

作者 / 機構: Marc Brooker, AWS Architecture Blog | 原始出處連結 ↗

對應章節 / 時間戳: Adding Backoff; Adding Jitter (Full Jitter, Equal Jitter, Decorrelated Jitter)

驗證版本與日期: AWS Architecture Blog 2015 (Verified: 2026-10-30)

入選理由:

Detailed practitioner reference proving that full jitter (sleep = random_between(0, min(cap, base*2**attempt))) prevents synchronized retry storms and reduces total work during contention.

來源前置條件:

Retries, timeouts, and basic probability of correlated load.

安全回退方案(離線彈性):

The backoff exercise is implemented in pure Python with a local flaky stub; the derivation of jitter benefits is fully reproduced in lesson instructions.

對比候選資源與選型分析 (2)
Google Cloud retry strategy documentation ↗ compared_alternative [CC BY 4.0 / documentation terms]

Product-scoped truncated exponential backoff recipe; Brooker's analysis explains why jitter matters, not just what to configure.

Polly resilience library retry policies (.NET) ↗ compared_alternative [BSD-3-Clause]

Library implementation reference; the AWS article supplies the comparative evidence (with/without jitter) that anchors the lesson.

linking Stripe site content / linked reference noncommercial

Stripe API Documentation: Idempotent Requests

作者 / 機構: Stripe, Inc. | 原始出處連結 ↗

對應章節 / 時間戳: Idempotent requests (Idempotency-Key header; keys can be removed after at least 24 hours)

驗證版本與日期: Stripe API documentation (Verified: 2026-10-30)

入選理由:

Standard production definition of idempotency keys: Stripe guarantees safe client retries by deduplicating POST requests on a caller-supplied key, the exact mechanism that turns at-least-once retries into effectively-once effects.

來源前置條件:

HTTP APIs, retries, and side-effect semantics.

安全回退方案(離線彈性):

Idempotency semantics are demonstrated locally with repeated write_report calls and a sha256 dedupe key, no Stripe account needed.

對比候選資源與選型分析 (2)
IETF draft: The Idempotency-Key HTTP Header Field ↗ compared_alternative [IETF Trust / open access]

Standardization-track header specification; Stripe's live documentation is the more concrete deployed example.

AWS Builder's Library: Making retries safe with idempotent APIs ↗ compared_alternative [Amazon site content]

Deep design treatment of idempotent server design; Stripe provides the tighter client-visible contract cited in the exercise.

03 120 分鐘

不究責的事後複盤:卡死迴圈執行

Agent 輔助工程檢查

前置要求

第 77 天活動 2 的分類;軌跡檢查。

學習目標

為 loop 故障執行撰寫不究責的事後複盤:從軌跡重建的時間線、精確的預算算術、促成原因,以及可稽核的防範行動項。

操作指引

1. 按 SRE 複盤結構:Summary、Impact、Root cause、Timeline(每條軌跡一步一行)、What went well、Action items。
2. 只寫事實:六次相同的 list_notes 動作;零條錯誤觀測;retries 維持 0;執行在第 6 步以 budget_exhausted/step_budget 結束;未產生 report.txt。
3. 促成原因:配接器 fault='loop' 無視歷史重複發出 list_notes;run_task 沒有重複動作或進展偵測器。
4. 行動項必須可稽核:「偵測連續 k 次相同動作並中止」或「在 evaluate() 中對工具多樣性評分」——不接受「讓模型更聰明」。
5. 保持不究責:系統恰好允許了它被設計允許的有限浪費——六步,然後安全終止。

自主實作與記錄

起草 postmortem.md,引用軌跡步驟編號(如「第 1-6 步:list_notes 以相同 files 清單回傳 ok」)。每條論斷必須引用軌跡步驟或組態常數。

獨立掌握標準

交付一份每條論斷都可溯源到已記錄步驟或已宣告常數的事後複盤——零猜測。

權威來源資源與權利證明

linking CC BY-NC-ND 4.0 noncommercial no-derivatives

Site Reliability Engineering, Chapter 15: Postmortem Culture: Learning from Failure

作者 / 機構: John Lunney and Sue Lueder (ed. Gary O'Connor), in Site Reliability Engineering (eds. Betsy Beyer, Chris Jones, Jennifer Petoff, Niall Richard Murphy; Google) | 原始出處連結 ↗

對應章節 / 時間戳: Chapter 15: blameless postmortems, trigger conditions, action items

驗證版本與日期: O'Reilly 2016 free online edition (Verified: 2026-10-30)

入選理由:

Standard blameless post-mortem structure (summary, impact, root cause, timeline, action items) applied to the bounded agent's stuck-loop run.

來源前置條件:

Incident timelines, root-cause analysis, and action items.

安全回退方案(離線彈性):

A complete post-mortem template is embedded in the lesson; learners need only the recorded trace to fill it.

對比候選資源與選型分析 (2)
Etsy Code as Craft: Blameless PostMortems ↗ compared_alternative [Blog content / linked reference]

Facilitation guide for live debriefs; the SRE chapter provides the written artifact structure the exercise reproduces.

Atlassian Incident Postmortem templates ↗ compared_alternative [Vendor site content]

Product-oriented templates; the SRE chapter emphasizes evidence-linked claims, which matches the trace-backed drill.

linking CC BY-NC-ND 4.0 noncommercial no-derivatives

Site Reliability Engineering, Chapter 22: Addressing Cascading Failures

作者 / 機構: Mike Ulrich, in Site Reliability Engineering (eds. Betsy Beyer, Chris Jones, Jennifer Petoff, Niall Richard Murphy; Google) | 原始出處連結 ↗

對應章節 / 時間戳: Triggering Conditions for Cascading Failures

驗證版本與日期: O'Reilly 2016 free online edition (Verified: 2026-10-30)

入選理由:

Primary analysis of how unbounded retries amplify partial outages into cascading failures, motivating hard retry budgets and deadlines in agent runtimes.

來源前置條件:

Retries, queueing, and load-shedding basics.

安全回退方案(離線彈性):

The retry-amplification scenario and budget arithmetic are fully reproduced in the lesson's worked example.

對比候選資源與選型分析 (2)
Release It! (Michael Nygard) - Stability patterns ↗ compared_alternative [Commercial book]

Broader stability-pattern catalog (circuit breakers, bulkheads); the SRE chapter is free and directly quantifies retry amplification.

Strong companion article; the SRE chapter frames the failure mode (cascading overload) that the retry budget defends against.

04 120 分鐘

整合與評量複習:有界執行證據包

獨立掌握檢查(無 AI 輔助)

前置要求

第 76-77 天全部活動。

學習目標

組裝本週證據包——全新 CLI 執行產物、故障分類表、遷移稽核輸出與誠實的掌握清單——使審閱者可在乾淨目錄中重現。

操作指引

1. 一切重新產生:在全新暫時目錄中重跑 CLI evaluate;重跑三個故障配接器;重跑遷移稽核。
2. 組裝 evidence_pack.json:{run_report, taxonomy_table, audit_rows, checklist}。
3. 清單項(誠實標註 met/not-met):說出三種終止狀態;重播一個檢查點前綴;為每個故障分類;解釋冪等寫入;約束重試策略;如實陳述終止邊界。
4. 沒有可重現產物的論斷保持 not-met——這是誠實的複習,不是失敗。

自主實作與記錄

產出 evidence_pack.json 和一份 README 命令清單,讓審閱者兩分鐘內重新產生所有產物。

獨立掌握標準

審閱者可重跑所列命令重現每條論斷;不允許任何憑記憶的斷言。

權威來源資源與權利證明

linking PSF License Version 2

Python Standard Library: subprocess - Subprocess Management

作者 / 機構: Python Software Foundation | 原始出處連結 ↗

對應章節 / 時間戳: Using the subprocess Module (subprocess.run timeout) and Notes: Timeout Behavior

驗證版本與日期: Python 3.13 documentation (Verified: 2026-10-30)

入選理由:

Normative reference for subprocess.run(timeout=...), TimeoutExpired, DEVNULL stdin, and the documented kill scope: timeout terminates the child process; it does not define process-tree cleanup semantics.

來源前置條件:

Processes, arguments, exit codes, and context managers.

安全回退方案(離線彈性):

The kill-boundary experiment runs entirely in the standard library, so the documented semantics are exercised offline.

對比候選資源與選型分析 (2)
POSIX standard: process creation and termination ↗ compared_alternative [IEEE/Open Group standard]

Formal POSIX semantics; the Python docs map directly onto the commands learners type.

psutil process-tree utilities ↗ compared_alternative [BSD-3-Clause]

Third-party tree enumeration; the exercise deliberately demonstrates the stdlib boundary before reaching for helpers.

linking MIT (LangGraph project) / documentation site terms

LangGraph Persistence: Checkpoints, Threads, and State Snapshots

作者 / 機構: LangChain / LangGraph Documentation Team | 原始出處連結 ↗

對應章節 / 時間戳: N/A

驗證版本與日期: LangGraph documentation (Verified: 2026-10-30)

入選理由:

Primary reference for agent-run checkpointing: LangGraph checkpointers persist graph state at every super-step so interrupted runs resume from the last committed snapshot, the production analogue of this project's action/observation trace.

來源前置條件:

Agent loop fundamentals, tool calling, and JSON state serialization.

安全回退方案(離線彈性):

The checkpoint/replay exercise is implemented directly against the projects/agent_learning trace JSON; no framework installation is required.

對比候選資源與選型分析 (2)
Temporal Durable Execution documentation ↗ compared_alternative [MIT / documentation terms]

Temporal persists event histories for replay-based recovery of arbitrary workflows; LangGraph targets agent graphs specifically and stays closer to the learner's tool-loop mental model.

OpenAI Agents SDK session/state documentation ↗ compared_alternative [MIT / documentation terms]

Provider-scoped SDK sessions; LangGraph's explicit checkpoint model exposes the underlying state-transition semantics more transparently.