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.