Skip to content

fix(feedback): 共享有效鉴权缓存并隔离新卡发送 - #3274

Merged
deepcoldy merged 6 commits into
deepcoldy:masterfrom
chaozuo-cpu:fix/feedback-auth-cache-latency-1109
Nov 9, 2026
Merged

deepcoldy merged 6 commits into
deepcoldy:masterfrom
chaozuo-cpu:fix/feedback-auth-cache-latency-1109

Conversation

@chaozuo-cpu

@chaozuo-cpu chaozuo-cpu commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

问题

动态 BytePG 鉴权在每次连接池 checkout 前读取凭据;多个来源只共享 generation,不共享可复用的凭据,返回 token 变化会不断失效各进程缓存。历史反馈刷新在预算检查之前查询数据库,旧卡慢查询会阻塞同一后台循环中的新反馈卡。

修改

  • 用受保护的 0600 credential 文件跨来源复用已取得凭据,限制缓存寿命并受 token 到期前安全余量约束;明确拒绝先撤销旧 generation,保留失败与清理边界。
  • 将鉴权取得移到新连接 startup,已建立的连接不因普通查询重复取得 token;不自动重放 SQL。
  • 新卡发送和后台旧卡刷新使用独立循环;数据库查询纳入原有刷新预算和每消息在途协调。
  • 保留发送回执、未知结果不重发、历史状态、动作授权、撤销和配置写入边界;增加不含凭据和内容的慢循环耗时日志。
  • 仍有效但已进入到期余量的 token 允许当前握手使用,后续调用重新取得凭据;只拒绝真正到期值。
  • 将存储初次打开纳入 webhook worker 的周期恢复,冷鉴权失败不会永久停用后台;同一 worker 只有一次打开/轮询在途,维护暂停和退出禁止迟到打开启动发送。
  • 同步原始 token 落盘、非加密和备份保护说明;明确连接超时包含冷鉴权等待。独立 lane 不绕过 SQLite 的单队列,SQLite 只保证慢网络 PATCH 不阻塞新卡。
  • 移除动态刷新后已无读者的 pool credential 赋值及重复校验。
  • 异常时序探针复现并补齐三项边界:周期存储打开失败不再拒绝 shutdown drain;hard stop 后返回的已认领行以原 claim token 标记为请求前停止并重新待处理,不虚构 transport unknown;鉴权拒绝后的 refresh 使用首尝试剩余预算,晚完成不能启动原调用的 reconnect/SQL。
  • SQLite-BUSY探针暴露请求前release失败仍留inflight;SQLite/PG在原outbox字段持久化请求阶段,claim时标记请求前、token-fenced请求准入后标记started。请求前stale恢复不虚构unknown;started及老版本未知claim仍保守unknown,历史unknown经过新claim、准入、成功发送仍保留。不新增表或迁移。

验证

  • 新增回归先在基线复现:交替来源重复 mint、复用连接重复读凭据、旧卡耗尽预算仍查询、旧卡阻塞新卡。
  • 上一发布 head f97baadb83dad7ae56b013667594a35c9887ea8a:36个反馈文件、390项通过;本轮最终全部反馈与 skill-feedback:39个文件、494项通过。
  • 本轮准确head:e200035a881b7228dc0d08f4eca8252f247ab36d(base=9d202b2ca3b7b444ea7f17e77f00acd5ac67f200)。
  • bun test 分进程执行 credential、BytePG、webhook:25+17+30=72项通过;test-hygiene及vitest围栏33项通过。
  • bun run build 通过;当前本地缺少 TypeScript native 依赖,使用仓库明确支持的 TypeScript 5.9 fallback;没有修改 package.json 或锁文件。
  • 跨进程清理、鉴权拒绝只重连一次、SQL失败不重放、安全文件、token过期、预算及慢查询重入用真实组件/隔离测试覆盖。
  • 生命周期真实组件+受控时钟:late-open在stop/quiesce后不发送;周期open跨21次poll仅一次在途;真实SQLite claim在hard stop后不发送且实际freeze通过;stop(0)面对真正pending open立即返回;失败drain清理timer不打断退出。共享凭据6种初取/续期/refresh的rename前后部分失败均可恢复,清理不重复。移除late-open守卫使2项咬红,移除single-flight造成22次open,验证边界测试同时保护并发与停止。
  • 上一 head 本地全量 unit:49705 passed、139 failed、197 skipped(44个失败文件),不声明全量通过。干净准确 upstream 的44文件对照已完成:42 failed/1 passed/1 skipped,119项失败;单独复跑 lead-only-guard再复现相同21项失败。原139项中133项在准确基线复现;plugin-mcp-sandbox的6项因宿主环境跳过,未证明该6项同源。
  • 本轮全量unit完成:2532 passed/54 failed/14 skipped files;49658 passed/190 failed/202 skipped tests。该运行跨本轮增量编辑,不作为最终提交验收:其中2项webhook是在修复前被读取的红测试,后续已在最终反馈回归单独通过;新增宿主Bun/version/voice/session等失败未全部归因,不声明均为基线失败或全量通过。
  • SQLite-BUSY+stale恢复+真实freeze的现有用例通过;Bun outbox4和webhook30通过。PostgreSQL同契约扩展既有e2e,准确e200的CI PostgreSQL15/17成功(run42657389949);本地未配置PG endpoint且无服务端工具,未声称本地PG集成通过。
  • 准确e200的CI build、network-boundary、Linux/musl/Darwin binary通过;四个unit分片及Bun仍运行,不声明完整CI全绿。

追加测试(b804596e4,只改测试)

  • 从 e200035 快进,只改 test/feedback-webhook-dispatcher.test.ts、test/feedback-outbox.test.ts、test/feedback-extension-host.test.ts,src/ 未动。
  • 钉住之前摘掉守卫仍全绿的几道新防线:请求准入失败(busy 或已被重新认领)不发请求;认领返回途中、准入之后到发请求之前硬停时行回到待发并标为确定未发;SQLite 重新认领、准入、送达都保留更早的未知标记;新卡 lane 不碰旧卡刷新和内联清理。对应变异在 vitest 腿全部变红。
  • 本地(master 907c58c 合并树,预测落地 tree 62f385c14):bun run build 通过;vitest 改动的 3 个文件加 test-hygiene 92 条通过;bun 腿 dispatcher 34、outbox 5 条通过。
  • CI:e200035a8 的 CI 是同 SHA 重跑第 3 次才全绿(首跑 bun-test 红在无关的 test/loopback-fetch.test.ts,见 test(loopback-fetch): bun-test 偶发未处理的 ECONNRESET,记在「gives a HEAD response a null body」头上 #3287),以 b804596 首跑结果为准。

范围与限制

基于 9d202b2ca3b7b444ea7f17e77f00acd5ac67f200;不包含私有群规则、卡片外观、内部人员或生产 token。
仅代码与隔离组件/CI验证;没有部署、重启服务、改变生产存储或补发消息。准确e200已完成15文件最终复核,原五项建议解决,无阻塞结论;不自动合并。

shutdown 等待期间的异常(r4515464057):探针核实 drain 期在途 tick 的失败仍经 onError 上报,stop() 里的 catch 只用于等待竞速,与文档“reported”一致,不再列为限制。连接超时实际按凭据等待/握手阶段分别受限,单次总时间不能等同单阶段阈值。JWT到期解析支持三段token且expireTime/exp为秒;不宣称覆盖任意TTL格式。完整CI及本地全量失败限制如上。

Created-by: Polaris

@chaozuo-cpu

Copy link
Copy Markdown
Contributor Author

AI Code Review · Aegis

  • 被审版本:head f97baadb83dad7ae56b013667594a35c9887ea8a / base 9d202b2ca3b7b444ea7f17e77f00acd5ac67f200
  • 覆盖:8 个文件(+305/−36)全部读取并核对 diff;本地 worktree HEAD 与 head 一致
  • 结论:未发现 P0/P1/P2 阻塞问题;5 项 P3 非阻塞建议;3 项待确认
  • 验证(我实际执行):vitest run --project unit test/feedback-doas.test.ts test/feedback-bytepg.test.ts test/feedback-extension-host.test.ts → 63 passed;node scripts/tsc.mjs -p tsconfig.typecheck.json → exit 0(TypeScript 5.9 fallback)。我未运行全量 unit;PR 描述的 139 项失败不在本次 8 个文件内,基线对照仍以作者数据为准。
  • 不 Approve;PR 保持 Draft。

P3(非阻塞)

  1. 短寿命 token 在 mint 路径被直接拒绝 — src/services/feedback-doas-token.ts:156(throw 在 :35)。触发:doas 返回 expireTime/exp 距现在 <30s 的 token。影响:get() 抛 feedback_doas_token_expired,池只对 28000/28P01 重试,新连接直接失败;30s 余量本意是限制缓存复用而非拒绝仍可完成握手的 token。建议:mint 路径 deadline <= now 时不缓存但仍使用该 token,仅对真正过期的 token 拒绝。
  2. 文档仍声明 token 只驻留内存 — docs/feedback-storage.md:182(新段落)与 :89 旧句冲突。本 PR 在 credential.json 持久化原始 token(0600)。建议同步更新 :89/:85。
  3. connectTimeoutMs 同时约束鉴权获取,影响一次性 bootstrap — src/services/feedback-postgres-schema.ts:58。触发:doas 冷启动/文件锁等待超过 connectTimeoutMs(默认 5000;锁等待上限 35s、命令上限 55s)。运行期只跳过该次连接,但 daemon 启动的 getSkillFeedbackStore(src/daemon.ts:33011-33025)失败会把 webhook/indexing 置为 disabled 直到重启/维护恢复。建议:bootstrap 重试或使用更长的凭据等待,并在文档说明该字段同时约束鉴权。
  4. lane 独立性测试绕过生产 SQLite 串行队列 — test/feedback-extension-host.test.ts:109(mock 在 :11-12)。getFeedbackStorage 对 SQLite store 的所有方法用单条 promise 队列串行化(src/services/feedback-storage.ts:58-80),surface lane 的 readFeedbackEventsAfter 仍会排在后台慢读之后;该保证目前只对 PostgreSQL 连接池成立。建议:测试走真实 getFeedbackStorage,或明确文档限定 PostgreSQL。
  5. pool 级 credential 赋值已无读者 — src/services/feedback-postgres-schema.ts:99-100。token 模式下新客户端在 connect 内自行 password.get();credential 仅静态字符串密码路径读取。建议保留 await password.refresh(generation),删除赋值/校验或注释说明。

待确认

  • credentialCacheDeadline 假设 3 段 JWT 且 expireTime/exp 为秒;若实际为毫秒或其他字段,30s 余量失效,缓存可能超过真实有效期(依赖 28000 拒绝后刷新,可恢复但多一次 generation bump)。需确认 doas token 格式/TTL。
  • src/services/feedback-doas-token.ts:131 在外部删除 generation.json 时对持有 cached 的进程 fail-closed 到重启;确认是否有意,及是否需要自愈/测试。
  • 全量 unit 的 139 项失败/44 个文件:我未运行全量,无法独立确认与干净基线一致;该结论不影响本次 8 文件 scope 的静态结论。

if (!token || token.length > 65536 || /[\s\0]/.test(token)) throw new Error('feedback_doas_output_invalid');
if (rejectedHash === createHash('sha256').update(token).digest('hex')) throw new Error('feedback_doas_refresh_failed');
const nextHash = createHash('sha256').update(token).digest('hex');
const validUntil = credentialCacheDeadline(token, Date.now());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Code Review · Aegis — 被审 SHA f97baadb83dad7ae56b013667594a35c9887ea8a

[P3] mint 路径把 <30s 剩余寿命的 token 直接判为过期

  • 触发:doas 返回的 token expireTime/exp 距现在 <30s(例如 doas 返回其缓存 token 的临近过期值)。
  • 影响:credentialCacheDeadline 在 :35 抛 feedback_doas_token_expired,get() 失败;池级重试只处理 28000/28P01,因此新连接直接失败,直到拿到剩余寿命 >30s 的 token。30s 余量的本意是限制缓存复用,不是拒绝仍可完成握手的 token。
  • 证据:本行 const validUntil = credentialCacheDeadline(token, Date.now());;:35 if (deadline <= now) throw;现有测试只覆盖“已过期结果”(test/feedback-doas.test.ts:39-50),未覆盖 20–25s 剩余寿命。
  • 建议:mint 路径在 deadline <= now 时不写缓存/不设 cachedUntil,但仍返回该 token 完成本次连接;仅对真正过期(或明确要求)的 token 拒绝。补一个 20s 剩余寿命的测试:首次 get() 成功,第二次 get() 重新 mint 而非复用。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已在 e200035 修复:只拒绝真正过期值;剩余寿命20秒的token当前get可用,但第二次get重新取得凭据。真实doas回归Node/Bun通过,过期与共享cache安全边界保持。

Comment thread docs/feedback-storage.md
## Dynamic Credential Reuse

BytePG dynamic credentials are shared through an owned private cache directory.
The credential file is a single regular file with mode `0600`; generation metadata

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Code Review · Aegis — 被审 SHA f97baadb83dad7ae56b013667594a35c9887ea8a

[P3] 新段落与旧文档冲突:token 现在会落盘

  • 触发:运维/审计按 docs/feedback-storage.md:89 的旧句判断 token 不落盘。
  • 影响:旧句仍写 “Token values remain in process memory; BotMux persists only generation metadata and credential hashes”,但本 PR 在 credential.json 写入原始 token(0600,src/services/feedback-doas-token.ts:160-161)。备份、权限与审计假设可能错误。
  • 证据:本段落只说明 credential 文件存在;:89 未同步更新;:85 的 “No TTL is assumed” 也与新的 60s/到期前 30s 缓存上限不一致。
  • 建议:更新 :85/:89,明确 credential 文件保存原始 token(0600、0700 目录)、缓存上限与到期余量。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已在 e200035 同步旧文档:原始token在0600 credential.json持久保存,私有目录和备份按凭据保护,非加密;明确opaque token本地缓存上限和JWT到期余量,不再写仅内存或无本地TTL。

current = await Promise.race([
password.get(),
new Promise<never>((_, reject) => {
timer = setTimeout(() => reject(new Error('feedback_bytepg_credentials_timeout')), target.connectTimeoutMs);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Code Review · Aegis — 被审 SHA f97baadb83dad7ae56b013667594a35c9887ea8a

[P3] 鉴权等待复用 connectTimeoutMs,一次性 bootstrap 可能被跳过

  • 触发:doas 冷启动或跨进程 refresh 锁等待超过 connectTimeoutMs(默认 5000,最小 100;feedback-doas-token.ts 的锁等待上限 35s、命令上限 55s)。
  • 影响:运行期只是本次连接失败(pending mint 完成后下一 tick 复用);但 daemon 启动的 getSkillFeedbackStore(src/daemon.ts:33011-33025)若首次取 token 超时,会走 fail-soft 分支把 webhook/indexing 置为 disabled,直到重启或维护恢复。
  • 证据:本行 timeout 使用 target.connectTimeoutMs;src/daemon.ts:33011-33025 的 bootstrap catch 只记录并继续。
  • 建议:bootstrap 路径重试一次或使用独立的更长凭据等待;并在 docs/feedback-storage.md 说明 connectTimeoutMs 同时约束凭据获取。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已在 e200035 修复:daemon把storage opening置入lazy worker,首次失败仍安装正常5秒poll,opening与reset/claim单次在途;维护及shutdown迟到open不启动发送,失败drain不打断退出。connectTimeoutMs冷鉴权与refresh剩余预算明确,晚refresh不触发弃用调用的reconnect/SQL。Node/Bun真实回归通过;PG15/17新head CI待执行。

await new Promise<void>(resolve => { release = resolve; });
return original(deliveryId);
});
const background = tickFeedbackExtensions(data.directory, 'app', 'background');

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Code Review · Aegis — 被审 SHA f97baadb83dad7ae56b013667594a35c9887ea8a

[P3] lane 独立性测试绕过生产 SQLite 串行队列

  • 触发:SQLite 后端下后台 lane 的 findDeliveryById 变慢(大表、磁盘抖动)。
  • 影响:getFeedbackStorage 对 SQLite store 的所有方法用单条 promise 队列串行化(src/services/feedback-storage.ts:58-80),surface lane 的 readFeedbackEventsAfter 仍会排在后台慢读之后;“旧卡慢查询不能阻塞新卡 lane”目前只对 PostgreSQL 连接池成立。
  • 证据:本测试的 getSkillFeedbackStore 被 mock 成裸 SkillFeedbackStore(本文件 :11-12),未经过生产代理;skill-feedback-store.ts:1078-1081 的 getSkillFeedbackStore 实际走 getFeedbackStorage。
  • 建议:让该测试走真实 getFeedbackStorage(或在文档中明确该保证仅适用于 PostgreSQL);若 SQLite 也要独立,给后台 lane 单独的 store 句柄/队列。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已在 e200035 更正:现有lane用例用真实getFeedbackStorage SQLite selector,阻塞边界是旧卡网络PATCH,surface新卡成功落绑定;文档明确SQLite仍单队列,不宣称慢数据库操作能被独立lane绕过。没有拆SQLite队列或放宽维护门禁。

chaozuo-cpu and others added 3 commits November 10, 2026 00:27
修正短寿命凭据使用与缓存边界,同步凭据安全及SQLite并发说明,恢复首次存储打开失败后的周期轮询并清理动态刷新死赋值。

Created-by: Polaris
Co-authored-by: TRAE CLI <[email protected]>
隔离后台打开失败对退出清理的影响,硬停止后以原claim恢复请求前状态,对鉴权刷新使用首尝试剩余预算并禁止迟到重连。

Created-by: Polaris
Co-authored-by: TRAE CLI <[email protected]>
为写锁下未完成的请求前释放保留可恢复阶段,SQLite与PostgreSQL使用原outbox字段并保持旧未知结果及claim token门禁。

Created-by: Polaris
Co-authored-by: TRAE CLI <[email protected]>
@chaozuo-cpu

Copy link
Copy Markdown
Contributor Author

本轮更新 head e200035:五项P3均修正(四个行内已回复);第5项删除dynamic refresh无读者的credential赋值及重复校验。补充真实时序探针修正stop失败、late claim、refresh无界及SQLite-BUSY请求前恢复,原outbox字段持久阶段与PG同契约。最终39文件494反馈通过、Bun相关76项通过、完整build/typecheck通过。全量运行54失败文件/190失败测试,跨增量编辑,不认为最终全量通过;PG15/17等待新head CI。PR仍Draft,当前请求准确新head的复核,不用旧head结论解除Draft。

@chaozuo-cpu

Copy link
Copy Markdown
Contributor Author

AI Code Review · Aegis(复审)

  • 被审版本:head e200035a881b7228dc0d08f4eca8252f247ab36d / base 9d202b2ca3b7b444ea7f17e77f00acd5ac67f200
  • 范围:15 个文件(+587/−64)全量读取;增量 f97baadb8→e200035a8 逐文件核对
  • 结论:未发现 P0/P1/P2 阻塞问题;新增 1 项 P3 非阻塞(shutdown drain 错误未上报);3 项待确认
  • 验证(我实际执行):vitest run --project unit 定向 179 项通过(doas 25、bytepg 17、extension-host 24、webhook-dispatcher 30、outbox 4、recovery 12、maintenance 8+8+40、storage-api 5、pg-optional-load 1、store-v3 5);node scripts/tsc.mjs -p tsconfig.typecheck.json → exit 0(TS 5.9 fallback)。PG e2e 未在本地运行(无 PG endpoint);全量 unit 未由我运行,作者数据中的失败文件不在本次 15 文件静态结论内。
  • 不 Approve;PR 保持 Draft。

五项 P3 复核(逐项)

  1. 短寿命 token — 已解决。feedback-doas-token.ts:23-41 只在真正过期时抛错;:160 mint 返回可用 token,cachedUntil 可落在过去,后续 get() 重新 mint。新测试 "uses an unexpired short-lived credential..." 通过。
  2. token 落盘文档 — 已解决。docs/feedback-storage.md:89 明确 0600 credential.json 持久原始 token、非加密、需按凭据保护;:85 与 :197-198 同步缓存/过期语义。
  3. connectTimeoutMs/bootstrap — 已解决。daemon.ts:33009-33017 改为 lazy store factory;dispatcher :155-166 懒加载、:207-220 ready 始终安装 5s 轮询;:226-241 stop 用剩余预算且不再让 pending rejection 打断退出。新增 dispatcher 测试覆盖 bootstrap 重试、late open、single-flight、stop(0)。仅余 1 项 P3(见下)。
  4. SQLite lane 测试/文档 — 已解决。test/feedback-extension-host.test.ts 改用真实 getFeedbackStorage selector,阻塞点改为旧卡网络 PATCH;docs:205-212 明确 SQLite 单队列、lane 不绕过数据库停滞。测试通过。
  5. 死赋值 — 已解决。feedback-postgres-schema.ts:32 改为 const credential;:93-111 retry 不再赋值/重复 validate,改由 waitForCredential 约束首尝试与 refresh 预算。

P3(新增,非阻塞)

  1. shutdown drain 的在途 tick 错误被静默吞掉 — src/services/feedback-webhook-dispatcher.ts:237。pending.catch(() => {}) 让 stop 不抛错(正确),但也没有调用 options.onError;docs/feedback-storage.md:91 声称 "Shutdown drain failures are reported by the worker",实际不可见。触发:stop 等待期间在途 tick 因 reset/claim/reschedule 抛错。影响:仅观测性(durable outbox 仍保留行,下一次 reset 恢复),但文档承诺的上报缺失。建议:pending.catch(error => options.onError?.(error))(race 仍 resolve),或改文档;补一个 onError spy 的 stop 测试。

待确认

  • credentialCacheDeadline 仍假设 3 段 JWT 且 expireTime/exp 为秒(feedback-doas-token.ts:26-38)。若实际为毫秒,30s 余量失效,缓存可能超过真实有效期;依赖 28000 拒绝后的 refresh 恢复(可恢复,但会多一次 generation bump)。现有测试只覆盖秒。
  • connectTimeoutMs 文档称 "bounds each pool connection attempt, including cold doas acquisition ... and its handshake";代码对凭据等待与 pg 握手分别使用该值(feedback-postgres-schema.ts:63,89),单次尝试总时长可达约 2×。行为可接受,建议文档明确“每阶段”。
  • 全量 unit 的失败文件我未运行/未归因;PG15/17 e2e 等待新 head CI。这两项不改变本次 15 文件静态结论,但属于验证缺口。

let deadlineTimer: ReturnType<typeof setTimeout> | undefined;
try {
await Promise.race([
pending.catch(() => {}),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Code Review · Aegis — 被审 SHA e200035a881b7228dc0d08f4eca8252f247ab36d

[P3] stop 静默吞掉在途 tick 的错误,文档却承诺上报

  • 触发:stop() 等待期间,在途 tick 在 reset/claim/reschedule 阶段抛错(例如存储连接/关闭错误)。
  • 影响:pending.catch(() => {}) 让 stop 不抛错(保证 daemon 后续清理继续,正确),但错误没有进入 options.onError;docs/feedback-storage.md:91 的 "Shutdown drain failures are reported by the worker" 与实际不符。durable outbox 行仍保留,下一次 reset 可恢复,因此是观测性缺口而非数据丢失。
  • 证据:本行 pending.catch(() => {});stop 的其他路径(interval 的 .catch、ready 的 catch)会调用 onError,唯独 stop 等待中的 rejection 被吞。
  • 建议:改为 pending.catch(error => options.onError?.(error))(race 仍 resolve,stop 仍不抛错),或修正文档;补一个 stop 期间 store 抛错 + onError spy 的测试。

@chaozuo-cpu
chaozuo-cpu marked this pull request as ready for review November 9, 2026 17:02
补齐本 PR 新防线的回归用例,删掉对应守卫时这些用例会失败:
- 请求准入被拒(忙或已被别的 worker 重新认领)时不得发请求
- 认领返回途中、准入之后到发请求之间硬停时,行回到待发且标为确定未发
- SQLite 重新认领、准入和送达都保留更早的结果未知标记
- 新卡 lane 不碰旧卡刷新和内联清理

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@deepcoldy

Copy link
Copy Markdown
Owner

追加测试提交 b804596(只改测试)

在作者 head e200035 上快进追加了一个只改测试的提交:src/ 没动,已有提交也没有改写。

为什么加: 逐一摘掉本 PR 新增的守卫(每次只改一处,跑完还原),下面几处摘掉后,原有测试仍然全绿:

  • 请求准入没通过(SQLite busy,或这一行已被别的 worker 重新认领)时仍照发请求
  • 准入之后、发请求之前没再检查硬停
  • 认领返回后没检查硬停(和上一条一起摘掉)
  • SQLite 重新认领、请求准入时覆盖了更早的 webhook_outcome_unknown:* 标记
  • surface lane 落到旧卡刷新,或拿到了真实的刷新预算

加了什么: 6 条用例:test/feedback-webhook-dispatcher.test.ts 4 条,test/feedback-outbox.test.ts 1 条,test/feedback-extension-host.test.ts 1 条。硬停类用例用桩在 store 调用中途触发 stop(0),确定能命中这个窗口,不靠计时。加上之后,上面这些变异在 vitest 腿全部变红;dispatcher 和 outbox 两个文件在 bun 腿也变红。

还有两处变异不会变红,都不影响行为:

  • 只摘「认领返回后」那一处硬停检查时,准入之后的检查会兜住,结果一样。
  • 鉴权 refresh 返回后的截止时间复查,只有 refresh 恰好在截止那一刻完成时才会起作用,属于边界上的纵深防御。

验证:

  • master 907c58c 之后新进的提交和本 PR 的文件没有交集;git merge-tree 无冲突,预测落地 tree 为 62f385c14。
  • bun run build(含 typecheck)通过。
  • vitest:在合并树上跑反馈相关 10 个文件,153 条通过;加测试后,改过的 3 个文件加 test-hygiene 共 92 条通过。
  • bun 腿逐文件跑:bytepg 17、doas 25、outbox 5、webhook-dispatcher 34、extension-runtime 8,全部通过。

描述里保留的 shutdown 限制实际不存在

用真实的 dispatcher 加受控 store 跑了三种情形:bootstrap tick 在 drain 期间开库失败、周期 tick 的 SQL 在 drain 期间失败、stop 的等待预算先到期之后才失败。三种情形下错误都经 onError 上报。stop() 里的 pending.catch(() => {}) 只用在等待的竞速上,原 tick 的拒绝仍会被 ready 的 catch 或定时器的 .catch(onError) 接住,和文档里的 "Shutdown drain failures are reported by the worker" 一致。我已把描述里的这一条改掉。

不阻断,建议后续处理

  1. doas 自己的缓存返回过期 token 时无法自愈。 用假 doas 做对比:它在 clean 之前一直输出 exp 已过的 JWT。本 PR 的 get() 每次都抛 feedback_doas_token_expired,一直不会触发 doas clean;base 版本会先拿这个 token 去连库,被服务端以 28P01 拒绝后走 refresh、clean,再取到新 token。这只在 doas 真会返回过期缓存值时才会发生,本机没有凭据,没法用真 doas 验证,所以不挡合码。建议:取到已过期的 token 时,按「这一 generation 被拒绝」处理,执行一次 clean 后再取。
  2. 运行中删掉私有缓存目录要重启才能恢复。 进程已持有缓存凭据时,删掉 <dataDir>/feedback-doas/<hash> 后,这个进程之后所有的新连接都会以 feedback_doas_state_invalid 失败,直到重启;新建的 token source 不受影响。这是有意的 fail-closed(有用例钉住),但运维排障时手动删这个目录,会让共享这个目录的所有 daemon 都连不上 PG。建议在 docs/feedback-storage.md 里写明:删掉后要重启。

CI

e200035 的 CI 首跑时,bun-test 红在 test/loopback-fetch.test.ts 一个没人接住的 ECONNRESET 上(和本 PR 无关),在同一 SHA 上重跑到第 3 次才全绿。按合码标准,同一 SHA 重跑转绿不能放行,已开 #3287 跟踪根治。是否放行以 b804596 的首跑结果为准。

@deepcoldy
deepcoldy merged commit 26d564f into deepcoldy:master Nov 9, 2026
13 checks passed
@deepcoldy

Copy link
Copy Markdown
Owner

感谢贡献,已 squash 合入 master(落地提交 26d564f,作者署名保留)。

双审与 CI 均通过:当前 head 的 13 项 check-run 首跑全绿(含 bun-test、四个 unit 分片、PostgreSQL 15/17、三平台二进制)。

两个非阻断 follow-up(不影响本次合入,供后续处理):

  1. 当 doas 自身缓存返回已过期 token 时,get() 会持续抛 feedback_doas_token_expired 且不触发 doas clean;建议后续把「取到已过期 token」按该 generation 被拒绝处理,执行一次 clean 后再取。目前仅用假 doas 复现,真实 doas 是否会返回过期缓存尚未验证。
  2. 进程已持有凭据时若手动删除私有缓存目录,该进程的新连接会 fail-closed 直到重启;这是有意行为,建议在 docs/feedback-storage.md 补一句「删除该目录后需重启相关进程」。

再次感谢,欢迎继续贡献。

deepcoldy pushed a commit to chaozuo-cpu/botmux that referenced this pull request Nov 9, 2026
同步 deepcoldy#3274(反馈卡双 lane / 共享鉴权缓存)。唯一冲突在
test/feedback-extension-host.test.ts:两边在 describe 开头同位各增用例,
保留并集(本 PR 的计数范围用例 + deepcoldy#3274 的 3 条 lane 用例);
feedback-extension-host.ts 自动合并,lane 开关与本 PR 的 send 签名、
beforeWrite 计数范围复验互不相交。

Co-Authored-By: Claude Fable 5 <[email protected]>
@github-actions

Copy link
Copy Markdown

@chaozuo-cpu @deepcoldy 合入 master 后的 Midscene E2E 失败:Feishu live Midscene 失败。

这次运行覆盖 7a1438f…38ec82937(4 个提交),同批合入的还有 #3262 #3285 #3283,失败不一定由本 PR 引起。

用例 跑道 状态 失败信息
OpenCode basic bot flow feishu-core-clis failed waitFor timeout: Based on the screenshot, the main content area displays a conversation thread. I am looking for a specific text bubble from "OpenCode" containing the string "ACK-e2e-opencode-1794267…

@github-actions

Copy link
Copy Markdown

🚀 Released in v3.59.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants