amos 9d633e9e67 Batch 15 (20261023-C-hwe-scale-15): 320 HWE-derived repair tasks
One user-space repair task per eligible HWE debug-diag / compile-deploy base
ID: 320 admitted (C 218, C++ 97, build scripts 5), 1 skipped by the content
filter. Each ships a public spec with a check-to-basis table, at least two
defects with single-fix fixtures, a symptom-masking fixture and an alternative
correct implementation. Claude re-checked all 320: structure, the HWE quality
items and trace6 Docker calibration receipts against current digests
(320/320 USABLE). Difficulty is unmeasured. Known follow-up: 212 tasks use 120
ad-hoc family names; the next batch maps them to the canonical list.
The batch's 1,256-line progress log stays in its factory report and the
36-local branch batch15-hwe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 01:55:56 +08:00

14 lines
4.8 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Reader Cache Service 合同
1. 范围:C++17、Linux、无网络与真实硬件。`Cache` 通过 `Pool` 管理动态容器内的读写资源;这是一套可控软件替身。资源初始化成功后需先结束使用,再 destroy,再归还容器;不假设 POSIX 的任何具体内部内存分配。
2. API:cache_api.hpp 定义的 public 接口有效。每个 Cache 起始为空,handle、ticket 的合法创建范围都是 1..1000000。initial/value 是绝对值不超过 10^12 的有符号整数。成功创建分配一个单调递增资源编号,从 1 开始,成功初始 version=0。相同 handle 不得重复;可在彻底关闭后重建。缓存最多 128 个,票据最多 512 个;调用者不越过这两个上限。
3. 返回码:0 成功、1 非法参数/没有写事务、2 资源忙、3 重复标识、4 不存在、5 初始化失败、6 关闭中、7 Pool 拒绝有效调用。校验优先顺序:create 先 handle 范围再重复;begin 先 handle 存在、关闭中,再 ticket 范围、ticket 重复、writer 忙;start_write 先存在、关闭中,再 readers/writer 忙;commit/abort 先存在,再检查 writer。其他未提及参数对不存在标识返回 4。除 begin 成功写入输出参数外,输出参数保持调用前值。失败不改变任何缓存、票据或资源状态,但第 5 条的失败初始化按该条记录。
4. 读写:begin 进入一个 Pool reader 并保存当前 value/version 的只读票据;多个 reader 可以共存。end 按 ticket 结束恰好一个 reader 并删除票据;重复 end 返回 4。start_write 在没有 readers/writer 时进入一个 writer。commit 更新 value、version 加 1,退出 writer;abort 只退出 writer,不改 value/version。write 等价于成功 start_write 随即 commit,失败不产生写入。
5. 初始化失败注入:fail_next_initialization 将一个标志置真;重复注入不累计。下一次真正调用 Pool.initialize 消耗标志并失败,记录分配、失败初始化、归还容器;没有创建缓存,不 destroy 未初始化资源,资源编号照常消耗。重复 handle 或非法 handle 不调用 Pool,亦不消耗标志。
6. 关闭:close 对存在的缓存总成功且进入关闭中;重复 close 幂等。没有使用者时立即完成关闭,否则保留对象和已有使用者。关闭中拒绝新的 begin/start_write/write(返回 6),已有 end/commit/abort 仍正常完成。最后一个使用者结算后立即 destroy 再 release 并移除缓存,不能提前归还。对已移除 handle 的 close 返回 4。Cache 析构不属于回放观测;调用者负责结束其保留的对象。
7. Pool 行为及事件:pool.cpp 是公开的确定性设备。allocate=事件 1;initialize 成功=2、注入失败=3;enter_reader=4(argument 为进入后 readers)、leave_reader=5(argument 为离开后 readers);enter_writer=6、leave_writer=7、destroy=8、release=9(未列出 argument 都是 0)。非法设备调用产生 20..27 事件并增加 violations;release 即使发现还在初始化/使用,也会记录违规然后归还容器,因此不能靠归还掩盖遗漏。不同缓存按各操作的自然执行顺序记录,禁止无业务请求的额外 Pool 调用。
8. 观测:views 按 handle 升序,每项为 handle/phase(0可用1关闭中)/resource/value/version/readers/writer(0或1);tickets 按 ticket 升序,每项 ticket/handle/value/version。Pool counters 为累计 allocated/released/initialized/destroyed/violations 和当前 allocated容器/initialized资源/readers/writers 九项。
9. 控制台:observe.cpp 只调用接口、打印原始观测。每行一个命令:C handle initial、W handle value、B handle ticket、E ticket、X handle、S handle、K handle value、A handle、F、Q。F 注入初始化失败,Q 只观测。空行、未知命令、多/少参数返回 1 不改状态。参数以 ASCII space/TAB/CR 分隔,范围均在 C++ int/long long 内;命令首尾允许水平空白。输入中的数可以带 +/- 与前导 0。测试不输入超出第2条计数上限的序列。
10. stdout 每个输入行输出一个十进制整数 token 行;行内 token 以一个或多个 ASCII space/TAB/CR 分隔,首尾允许这些水平空白;token 可带 +/- 和任意前导0,负零与0等价。顺序为 status、begin输出value、begin输出version、九项counters、views数量和各view的7项、tickets数量和各ticket的4项、events数量和各event的3项。begin未成功的两个输出哨兵是 -777/-888。没有其他 stdout;stderr 允许任意诊断字节,不参与业务判定。
11. 提交只修改 cache.cpp;可采用其他内部数据组织、算法或控制方式,只要全部外部行为保持上述合同。公开构建使用 make 或 `g++ -std=c++17 -O2 cache.cpp pool.cpp observe.cpp -o reader-cache`,评分从干净候选与冻结公开支撑重建,不评分本地构建产物。