03 / 90

第 03: 恢复演练:诊断失败的环境

恢复演练:诊断失败的环境。每项活动都保留预测、观察、复盘与恢复证据。

自学方法与 Python 工程基础 480 分钟(8 小时专注学习)
01 120 分钟

恢复演练:诊断失败的环境

独立掌握检查 — 评估作业期间不得使用 AI 辅助。如接受任何辅助必须如实申报,但接受辅助的作业只计为补救练习:在声称掌握之前,必须完成一次新的无辅助检查。

前置要求

完成第 02 学习日各活动。评估路径需要 Bash;已验证的执行范围是 Linux Bash。需要可用的 `python3`;不安装软件包、不做机器级更改。

学习目标

用预测、最小复现和恢复笔记,诊断一个被故意破坏的虚拟环境或路径假设。

操作指引

本演练在一次性 env-drill 目录内提供一个故意破坏但无害的装置。运行前预测症状,复现它,收集诊断证据,应用可论证的最小修正,然后复查。全程留在装置目录内;不做任何机器级更改(不安装、不编辑 env-drill 以外的内容、不做持久环境改动——下面的修复只作用于单次命令调用)。 各代码块在失败即停的子 shell 中运行:设置阶段先验证新建的 mktemp 私有根目录,失败会在写入前中止;还会通过一个不执行模块代码的 importlib.util.find_spec 检查来确认环境 Python 配置是否已能解析 helper,若能解析也会中止(预期失败需要这一前提;该探针不导入也不运行模块)。最后的代码块会打印一条字面 rm -r -- <private-root> 清理行,只指向所创建的根目录。后续代码块之前先粘贴打印的 export SBX_ROOT= 行;并记录shell 原本 PYTHONPATH 的设置与否及其取值——未设置、空、非空都是有效证据。 请在 Bash 中运行这些代码块——打印的 export/rm -r -- 行使用 Bash 的 %q 引用,实际执行范围为 Linux Bash;zsh/dash/Windows 未执行。

自主演练与记录

构建损坏的装置并复现失败(整块粘贴;若设置失败,或不执行模块的检查发现 helper 已可解析,会在写入前中止):

(
set -e
SBX_ROOT=$(mktemp -d "${TMPDIR:-/tmp}/d03env.XXXXXX")
[ -n "$SBX_ROOT" ]
[ -d "$SBX_ROOT" ]
[ -w "$SBX_ROOT" ]
[ -x "$SBX_ROOT" ]
probe_rc=0
python3 -c "import sys, importlib.util
try:
    spec = importlib.util.find_spec('helper')
except Exception:
    sys.exit(4)
sys.exit(3 if spec is not None else 0)" || probe_rc=$?
if [ "$probe_rc" -ne 0 ]; then
  if [ "$probe_rc" -eq 3 ]; then
    echo "abort: ambient Python config already resolves 'helper' - the intended failure cannot be demonstrated"
  else
    echo "abort: helper-resolvability probe failed (rc=$probe_rc) - cannot verify the precondition safely"
  fi
  exit 1
fi
mkdir "$SBX_ROOT/env-drill"
cd "$SBX_ROOT/env-drill"
mkdir tools
printf 'def greet():\n    return "ok"\n' > tools/helper.py
printf 'from helper import greet\nprint(greet())\n' > app.py
rc=0
python3 app.py 2>err.txt || rc=$?
cat err.txt
grep -q "ModuleNotFoundError: No module named 'helper'" err.txt
echo "expected failure observed (rc=$rc)"
printf 'export SBX_ROOT=%q\n' "$SBX_ROOT"
)

运行前预测错误。粘贴打印的 export SBX_ROOT= 行,然后收集证据:

(
set -e
: "${SBX_ROOT:?run the setup block first, then paste its printed export line}"
[ -d "$SBX_ROOT/env-drill" ]
cd "$SBX_ROOT/env-drill"
python3 -c "import sys, os; print([os.path.abspath(p or '.') for p in sys.path])"
ls tools
)

仅对本次调用应用可论证的最小修正并复查,将 PYTHONPATH 与记录的原始值比较——代码块会打印明确的 set/unset 标记和取值,因此未设置、空、非空的原始状态都可区分地证明未改变:

(
set -e
: "${SBX_ROOT:?run the setup block first, then paste its printed export line}"
[ -d "$SBX_ROOT/env-drill" ]
cd "$SBX_ROOT/env-drill"
pp_state() { if [ "${PYTHONPATH+x}" = x ]; then printf 'PYTHONPATH %s: set value=<%s>\n' "$1" "$PYTHONPATH"; else printf 'PYTHONPATH %s: unset\n' "$1"; fi }
pp_state before
PYTHONPATH=tools python3 app.py
pp_state after
printf 'rm -r -- %q\n' "$SBX_ROOT"
)

记录症状、证据、修复、为何最小的理由,以及复查结果。

独立掌握标准

在无辅助条件下满足以下全部即通过:(a) 运行前预测了 `ModuleNotFoundError` 症状;(b) 记录了诊断证据(缺少 `tools/` 的解析后 `sys.path` 列表,以及显示文件存在的 `ls tools` 结果);(c) 所应用的修复限定在单次调用内,并书面说明了为何最小;(d) 记录了成功的复查和无持久化检查——限定修复后的 `PYTHONPATH` 与记录的原始值(未设置、空、或不变的非空值)一致。辅助只计为补救练习,在声称掌握之前必须完成一次新的无辅助检查。

权威源资源与权利证明

linking PSF License Version 2

The Python Tutorial: Virtual Environments and Packages

作者 / 机构: Python Software Foundation | 原始出处链接 ↗

对应章节 / 时间戳: Section 12 (creating venvs, pip installs, requirements files)

验证版本与日期: Python 3.12 (Verified: 2026-10-30)

入选理由:

Primary reference for python -m venv, interpreter isolation, and requirements files used by the wrong-environment drills.

来源前置条件:

Basic Python syntax from Study Days 01-09

安全回退方案(离线弹性):

The drill needs no network: venv creation, sys.executable inspection, and ModuleNotFoundError reproduction all run offline.

对比候选资源与选型分析 (2)
pip documentation ↗ compared_alternative [MIT]

Primary reference for pip commands, but the tutorial presents the create-activate-install loop as one beginner-friendly narrative.

virtualenv documentation ↗ compared_alternative [MIT License]

Mature third-party environment tool with overlapping behavior; the stdlib venv tutorial was selected to avoid an extra dependency for first-time setup.

linking PSF License Version 2

The Python Tutorial: Errors and Exceptions

作者 / 机构: Python Software Foundation | 原始出处链接 ↗

对应章节 / 时间戳: Sections 8.3-8.6 (handling exceptions, else, finally, cleanup actions)

验证版本与日期: Python 3.12 (Verified: 2026-10-30)

入选理由:

Primary reference for try/except/else/finally semantics and the with statement as predefined cleanup for Day 11.

来源前置条件:

Basic Python syntax from Study Days 01-09

安全回退方案(离线弹性):

Every clause behavior in the lesson is demonstrated by runnable local snippets.

对比候选资源与选型分析 (2)
MIT OCW 6.0001 Lecture on Exceptions ↗ compared_alternative [CC BY-NC-SA 4.0]

Solid lecture treatment but paced for a semester course and requires video viewing; the tutorial section matches the exercise scope directly.

Python Standard Library: Built-in Exceptions ↗ compared_alternative [PSF License Version 2]

Reference-style exception hierarchy listing rather than the tutorial narrative; retained as lookup material for the recovery drills.

02 120 分钟

智能体辅助工程审查与修正

智能体辅助工程检查 — 须声明所选轨道、权限和审查边界;智能体的输出不构成独立证据。若无已授权的工具可用,须将实操部分标记为"受阻 — 未执行":下面预先编写的坏补丁是离线示例,不是从真实服务商观察到的输出。

前置要求

完成 day-03-act-01,以及已选定的智能体工具轨道。

学习目标

审查智能体产出的改动,运行检查,发现失败,并要求修正而不是盲目接受输出。

操作指引

在新建的 agent-review-sandbox 内,创建包含 def add(a, b): return a + b 的 calc.py,以及下面的独立检查 check_clamp.py——这是你自己的检查,独立于智能体的任何声称。然后请选定的智能体精确执行此改动:"在 agent-review-sandbox/calc.py 中添加函数 clamp(x, lo, hi):返回被限制在 [lo, hi] 区间内的 x,当 lo > hi 时抛出 ValueError。不要修改 add 或任何其他文件。"写入前必须批准;沙箱之外禁止一切操作。 声明的权限是约定,不是操作系统沙箱——范围必须由你自行验证。 预算:智能体轮次或重试最多 3 次;停止条件:检查通过、预算耗尽、或发生任何越界操作。若首次运行即通过,这本身就是有效证据——不要编造缺陷;记录通过输出并完成实质性评审。带标签的操练补丁可另行用于练习修正流程(记为操练证据)。对产出的代码运行你的检查。若没有已授权工具,用参考解答中带标签的预编写补丁练习该流程——它是示例,不是实操证据。

自主演练与记录

独立行为检查(自己编写,保存为 check_clamp.py):

from calc import clamp
assert clamp(5, 0, 10) == 5
assert clamp(-3, 0, 10) == 0
assert clamp(99, 0, 10) == 10
try:
    clamp(2, 10, 0)
except ValueError:
    pass
else:
    raise AssertionError('clamp must reject lo > hi')
print('clamp checks passed')

对产出的代码运行 python3 check_clamp.py。若失败,写出精确反馈(哪个用例、预期值与实际值、疑似原因),要求修正,捕获差异(git diff 或对所存副本 diff -u),并重跑检查。需记录:失败输出、你的反馈、差异、通过的复查。若首次即通过,记录通过输出和实质性证据评审(逐条追踪各 assert、验证 lo > hi 的 ValueError 路径、确认 add 及其他文件未改动);仍可用带标签操练补丁练习反馈流程,但记为操练证据,绝不得作为智能体输出。

独立掌握标准

满足以下全部即通过:(a) 学习者自写的 `check_clamp.py` 存在并已对产出代码运行;(b) 记录了真实失败路径(失败输出、点名失败用例及预期/实际值与疑似原因的反馈、修正差异、通过复查),或记录了首次通过(通过输出加逐条追踪各检查、`lo > hi` 路径、范围合规的实质性证据评审)。不得改动有效结果来编造智能体缺陷;带标签操练补丁仅作为注明身份的 optional 练习证据。若无已授权工具,实操部分标记为受阻/未执行,流程在带标签示例上演示——绝不得作为真实智能体输出出示。

权威源资源与权利证明

linking Open Access / CC BY 4.0

SWE-agent: Agent-Computer Interfaces Enable Automated Software Engineering

作者 / 机构: John Yang, Carlos E. Jimenez, Alexander Wettig, Kilian Lieret, Shunyu Yao, Karthik Narasimhan, Ofir Press | 原始出处链接 ↗

对应章节 / 时间戳: Section 2 The Agent-Computer Interface and Section 3 SWE-agent: Designing an ACI for Software Engineering

验证版本与日期: NeurIPS 2024 / arXiv:2405.15793v2 (Verified: 2026-10-30)

入选理由:

Primary literature on agent-computer interfaces showing that bounded tool commands, trajectory inspection, and environment constraints determine whether an agent can carry an engineering task to verifiable completion.

来源前置条件:

Agent loops, tool protocols, and basic software engineering workflow vocabulary.

安全回退方案(离线弹性):

The permission/budget control profile, tool contract schema, and trace audit procedure are fully implemented in the local bounded agent fixture (projects/agent_learning).

对比候选资源与选型分析 (2)

Broader generalist agent platform; SWE-agent isolates the agent-computer interface design principles most relevant to bounded task delivery.

AutoCodeRover: Autonomous Program Improvement ↗ compared_alternative [Open Access / CC BY 4.0]

Focuses on autonomous program repair via code search; SWE-agent better matches the curriculum's bounded-tool and human-verification emphasis.

linking Open Access / CC BY 4.0

Reflexion: Language Agents with Verbal Reinforcement Learning

作者 / 机构: Noah Shinn, Federico Cassano, Ashwin Gopinath, Karthik Narasimhan, Shunyu Yao | 原始出处链接 ↗

对应章节 / 时间戳: Section 2 & 3 (Reflexion Architecture and Memory Buffer)

验证版本与日期: NeurIPS 2023 / arXiv:2303.11366v4 (Verified: 2026-10-30)

入选理由:

Rigorous framework analyzing dynamic error feedback, memory buffering of execution failures, and controlled self-reflection loops without updating model weights.

来源前置条件:

Reinforcement learning concepts, agent evaluation loops, and error feedback handling.

安全回退方案(离线弹性):

Error recovery state diagrams and retry budget algorithms are detailed in curriculum materials.

对比候选资源与选型分析 (2)

Single-turn generative text refinement; Reflexion operates across multi-turn external environment action-observation failures.

Domain-specific LLM-based agent for open-world Minecraft; Reflexion establishes domain-general verbal feedback control loops.

03 120 分钟

独立掌握:文件系统成果物检查

独立掌握检查 — 评估作业期间不得使用 AI 辅助。如接受任何辅助必须如实申报,但接受辅助的作业只计为补救练习:在声称掌握之前,必须完成一次新的无辅助检查。

前置要求

完成 day-03-act-02。评估路径需要 Bash;已验证的执行范围是 Linux Bash。

学习目标

用一个全新任务和可检查的成果物,展示终端/文件系统的独立掌握。

操作指引

全新的迁移任务——不是第 02 学习日序列的重复。运行每个检查之前先写预测,再记录观察输出。一切都在新建的一次性 report-sandbox 内进行,不碰外部任何内容。 代码块在受控的失败即停子 shell 中运行:先验证新建的 mktemp 私有根目录,mkdir/cd 失败会在写入前中止——绝不会写入当前目录。末尾会打印一条字面的 rm -r -- <private-root> 清理命令(Bash %q 引用),只指向本次创建的私有根目录;仅在想删除该目录时才运行它。 请在 Bash 中运行该代码块;实际执行范围为 Linux Bash,zsh/dash/Windows 未执行。

自主演练与记录

在新的 Bash shell 中运行下面整个代码块(作为一整块),在每个 wc、diff、find 之前写下预测。设置失败会中止子 shell,当前目录不会被写入任何内容。末尾会打印一条只指向所创建根目录的字面 rm -r -- <private-root> 清理命令;仅在想删除时才运行:

(
set -e
SBX_ROOT=$(mktemp -d "${TMPDIR:-/tmp}/d03rpt.XXXXXX")
[ -n "$SBX_ROOT" ]
[ -d "$SBX_ROOT" ]
[ -w "$SBX_ROOT" ]
[ -x "$SBX_ROOT" ]
mkdir "$SBX_ROOT/report-sandbox"
cd "$SBX_ROOT/report-sandbox"
mkdir data archive
printf 'month,total\njan,10\nfeb,20\n' > data/sales-q1.csv
wc -l data/sales-q1.csv
cp data/sales-q1.csv archive/sales-q1.bak
diff data/sales-q1.csv archive/sales-q1.bak
printf 'draft note\n' > data/readme.txt
mv data/readme.txt archive/notes.txt
find . -type f | sort
printf 'rm -r -- %q\n' "$SBX_ROOT"
)

须满足的成果物检查:备份与原文件逐字节一致;移动后 data/readme.txt 不再存在;最终 find 输出恰好列出 ./archive/notes.txt、./archive/sales-q1.bak、./data/sales-q1.csv 三项。

独立掌握标准

在无辅助条件下满足以下全部即通过:(a) 每个 `wc`/`diff`/`find` 的预测都在执行前写下且观察输出已记录;(b) 三项成果物检查全部成立——`diff` 结果一致、`data/` 中无 `readme.txt`、恰好三个文件的 `find` 列表;(c) 工作未超出 `report-sandbox`。辅助只计为补救练习,在声称掌握之前必须完成一次新的无辅助检查。

权威源资源与权利证明

linking PSF License Version 2

Python Standard Library: pathlib

作者 / 机构: Python Software Foundation | 原始出处链接 ↗

对应章节 / 时间戳: Path.exists, Path.cwd, and anchoring paths to __file__

验证版本与日期: Python 3.12 (Verified: 2026-10-30)

入选理由:

Normative reference for the exists()/cwd() evidence that separates an absent file from a wrong working directory.

来源前置条件:

Basic Python syntax from Study Days 01-09

安全回退方案(离线弹性):

Path.exists() and Path.cwd() are exercised directly in the local drill, so no online page is required.

对比候选资源与选型分析 (2)
os.path documentation ↗ compared_alternative [PSF License Version 2]

Functionally equivalent for exists() checks; pathlib keeps the beginner syntax object-oriented and consistent across the block.

shutil — High-level file operations ↗ compared_alternative [PSF License Version 2]

Covers copying and moving whole trees rather than path modeling; pathlib remains the right reference for the filesystem checks these days rehearse.

linking PSF License Version 2

Python Standard Library: tempfile

作者 / 机构: Python Software Foundation | 原始出处链接 ↗

对应章节 / 时间戳: TemporaryDirectory for disposable on-disk fixtures

验证版本与日期: Python 3.12 (Verified: 2026-10-30)

入选理由:

Normative reference for creating and auto-removing fixture files inside tests without touching real user files.

来源前置条件:

Basic Python syntax from Study Days 01-09

安全回退方案(离线弹性):

TemporaryDirectory is part of the installed standard library and needs no page access.

对比候选资源与选型分析 (2)
pytest tmp_path fixture ↗ compared_alternative [MIT]

Equivalent capability scoped to the pytest runner; deferred until the curriculum adopts pytest.

io — Core tools for working with streams ↗ compared_alternative [PSF License Version 2]

Lower-level file-object interface without automatic cleanup semantics; tempfile was selected for the safe scratch-file pattern the drills require.

04 120 分钟

间隔复习与下一步计划

独立掌握检查 — 评估作业期间不得使用 AI 辅助。如接受任何辅助必须如实申报,但接受辅助的作业只计为补救练习:在声称掌握之前,必须完成一次新的无辅助检查。

前置要求

完成 day-03-act-03,以及你自己记录的第 01–03 学习日证据。

学习目标

提取三天方法的记忆,将证据与掌握标准对比,并为每个遗漏概念安排补救。

操作指引

制定一份与你实际的第 01–03 学习日证据挂钩的间隔提取计划——不是再写一份通用量规。对每个概念记录:证据状态(已验证/已陈旧/缺失)、将要执行的下一次无辅助检查、具体日期、该检查失败时的补救行动。明确列出你可执行的证据缺口(例如 Windows 命令从未执行、实操智能体证据待补)——或者,若你声明的第 01–03 学习日范围内已有完整的当前证据,可记录一条有依据的“声明范围内未发现”,并引用实际证据、附带带日期的复查。不得编造缺口或隐藏未执行的声称。承诺一次带日期的无辅助下次检查。

自主演练与记录

产出一份覆盖至少四个第 01–03 学习日概念的补救计划。每行记录:概念|证据状态|下一次无辅助检查|日期|遗漏时的补救行动。然后列出你记录中全部可执行的证据缺口(你相信但未验证的事);若声明范围内没有,只有引用实际当前证据并承诺带日期的新无辅助复查的明确“声明范围内未发现”才可接受——已有缺口必须披露,不得隐藏。最后以一次预定的新检查收尾:在该日期无辅助预测一个新的修改/同一性代码片段并验证。

独立掌握标准

计划包含至少四个第 01–03 学习日概念,每个都有具名证据状态、可执行的无辅助检查、具体日期和补救行动;列出至少一个可执行的证据缺口,或有引用声明范围内实际当前证据的有依据的明确“未发现”;并承诺了一次带日期的无辅助下次检查,即通过。辅助只计为补救练习,在声称掌握之前必须完成一次新的无辅助检查。

权威源资源与权利证明

linking Journal publisher copyright (all rights reserved) - lawful external linking only

Test-Enhanced Learning: Taking Memory Tests Improves Long-Term Retention

作者 / 机构: Henry L. Roediger III, Jeffrey D. Karpicke | 原始出处链接 ↗

对应章节 / 时间戳: Psychological Science 17(3): 249-255, Experiments 1-2

验证版本与日期: Psychological Science, 2006 (Verified: 2026-10-30)

入选理由:

Foundational experimental evidence that retrieval practice (testing) outperforms repeated study for long-term retention; grounds the Day 88 AI-free retrieval checks in peer-reviewed learning science rather than folk advice.

来源前置条件:

Basic understanding of study sessions, retention intervals, and experimental design vocabulary.

安全回退方案(离线弹性):

The curriculum restates the experimental design and effect sizes in original prose; every sealed task runs without the paper.

对比候选资源与选型分析 (2)

Strong meta-analytic coverage of spacing effects but addresses scheduling rather than the retrieval effect itself; retained as support for the Day 90 spaced-review schedule.

Equally foundational follow-up demonstrating repeated retrieval vs repeated study; the 2006 paper is cited as the standard first controlled demonstration.

linking Journal publisher copyright (all rights reserved) - lawful external linking only

Improving Students' Learning With Effective Learning Techniques: Promising Directions From Cognitive and Educational Psychology

作者 / 机构: John Dunlosky, Katherine A. Rawson, Elizabeth J. Marsh, Mitchell J. Nathan, Daniel T. Willingham | 原始出处链接 ↗

对应章节 / 时间戳: Psychological Science in the Public Interest 14(1): 4-58; practice testing and distributed practice sections

验证版本与日期: Psychological Science in the Public Interest, 2013 (Verified: 2026-10-30)

入选理由:

Detailed comparative review rating practice testing and distributed practice as high-utility techniques while rating highlighting and rereading low-utility; anchors the retrieval, correction, and spaced-review design of Days 88-90.

来源前置条件:

None beyond general academic reading.

安全回退方案(离线弹性):

Curriculum restates the utility ratings and application conditions in original prose; every task remains runnable offline.

对比候选资源与选型分析 (2)
Pashler et al. Learning Styles: Concepts and Evidence ↗ compared_alternative [Publisher copyright (originally Wiley; now SAGE Publications)]

Important negative result on learning-styles matching but narrower scope; Dunlosky et al. rates a broader set of techniques directly usable for this curriculum.

Brown, Roediger & McDaniel: Make It Stick: The Science of Successful Learning ↗ compared_alternative [Publisher copyright (Harvard University Press)]

Strong trade-book synthesis of the same evidence base; the peer-reviewed review is preferred for citation precision and technique-by-technique utility ratings.