Skip to content

fix(project): repost the pinned card when Lark's edit window expires - #3873

Merged
deepcoldy merged 4 commits into
deepcoldy:masterfrom
xushulong-solo:fix/project-card-repost-on-expiry
Nov 26, 2026
Merged

deepcoldy merged 4 commits into
deepcoldy:masterfrom
xushulong-solo:fix/project-card-repost-on-expiry

Conversation

@xushulong-solo

Copy link
Copy Markdown
Contributor

Problem

Lark only allows editing a card for 14 days. When a project group's pinned progress card is older than that, updateCard fails with MessageUpdateExpiredError (230031). ProjectCoordinator.publish() only treated withdrawn messages as "repost", so every later project update threw and the pinned card stayed stale forever.

Fix

Treat an expired edit window like a withdrawn message: unpin the stale card, send a fresh card, pin it, and persist the new card.messageId. Unrelated update failures still propagate.

Tests

  • New: recreates and re-pins a projection whose card is past the edit window.
  • New: does not repost on unrelated card update failures.
  • vitest run test/project-group-mode.test.ts → 26 passed.

Verification

Applied the same change to a local release, restarted the daemon, and triggered a project update: the new card was sent and pinned, the stale card was unpinned, and project-groups.json stored the new card id.

🤖 Generated with Claude Code

Lark only allows editing a card for 14 days. When updateCard fails with MessageUpdateExpiredError (230031), the project coordinator previously threw and the pinned progress card stayed stale forever. Treat an expired update like a withdrawn message: unpin the stale card, send a fresh card, pin it, and persist the new card id. Add regression tests for the expired and unrelated-error paths.

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

Copy link
Copy Markdown
Owner

自动评审初步意见(最终以维护者审阅为准)

修复方向认可:230031(超过飞书 14 天编辑窗口)后把旧卡 unpin、重发新卡并持久化新 card.messageId,与 client.ts 中 MessageUpdateExpiredError 的契约("post a fresh message rather than treating it as a transient failure")以及 oncall 卡片的既有处理模式一致。真实组件探针验证正常路径:过期后仅重发一次、旧卡精确 unpin、存储切换到新卡,后续更新打到新卡,自愈闭环成立;无关更新错误仍然抛出,没有 fail-open。

但当前 head 有一项阻断回归和一项设计缺口需要处理:

P1(阻断):破坏 test/project-card-runtime-sync.test.ts 两个既有用例

  • master 基线上该文件 6/6 通过,本 PR 上 2 个失败(vitest run test/project-card-runtime-sync.test.ts):
    • 「卡片过了编辑窗口(永久失败):同一摘要最多试有限次,摘要变化后才再试」
    • 「新摘要获得完整的独立失败预算,不继承旧摘要的失败计数」
  • 根因:ProjectCardRuntimeSync(daemon 30 秒 tick 的运行态刷新,refresh 即 coordinator.run({action:'refresh'}) → publish())原本把 230031 视为永久失败,靠「同一摘要 3 次预算」限频,且测试中有明确契约注释「永久失败不会被当成撤回去另发新卡」(断言 sendCard 始终只有 1 次)。本 PR 在 publish() 内吞掉 230031 并重发后,sync 层再也观测不到该失败,预算机制对它失效,两个断言都不再成立。
  • project-card-runtime-sync.ts 头注释把 230031 列为预算保护对象,也需要同步更新。

P2(设计缺口):持续失败下重发无上限

探针(真实 ProjectCoordinator + 临时存储,模拟 updateCard 对任意卡持续抛 230031、sendCard 正常返回新 id):20 次 refresh 产生 21 次 sendCard、21 次 pin/unpin——每次刷新都重发一张新卡。正常飞书环境下新卡 14 天内可更新、加上 sync 的 digest 去重,不会触发;但在「update 持续失败而 send 仍成功」的窄缝里(或绕过 sync 去重的用户 /project 命令路径),会持续产生置顶卡片垃圾,而旧的预算限频恰好能挡住这个场景。建议重发机制与 sync 层预算协同设计(例如让 sync 能识别并重发限频,而不是在 publish() 单层吞掉错误)。

P3(观察项,不阻断)

  1. 新增的 unpin 内层容错(unpin 抛非 withdrawn 错误时 warn 后继续重发)没有直接测试覆盖。
  2. 真实 unpinMessage 是 fail-soft 返回 false 而非抛错(client.ts),当前不检查返回值:业务失败时无日志,且新卡持久化后旧 messageId 被覆盖,残留置顶再无清理机会。
  3. expired && card.pinned === false 跳过 unpin 的分支没有测试。

验证记录:tsc --noEmit、bun run build 通过;project-group-mode.test.ts 26/26 通过;3 个变异(豁免条件还原 / unpin 块失效 / 全错误吞掉)均被新测试精准咬红;coordinator 直接消费方 8 个测试文件 953/955,仅上述 P1 的 2 个失败。

@xushulong-solo

Copy link
Copy Markdown
Contributor Author

Thanks — addressing the P1/P2 design gap: the expired-card repost will move into the runtime sync's per-digest budget (with a per-chat cooldown) instead of being swallowed in publish(), so the sync layer can still observe 230031 and bound reposts. Also covering P3: unpinMessage return value, unpin failure, and pinned=false. Will push a follow-up commit and re-run the two sync tests plus the coordinator tests.

按卡片和实际渲染摘要核对后台 PATCH 预算,耗尽后才对过期卡限频重发。保留显式恢复路径,记录取消置顶失败并允许对已保存的新卡补置顶。
@xushulong-solo

Copy link
Copy Markdown
Contributor Author

Pushed cd0c9a0b1 on top of d119b7179. The expired-card repost now lives in the runtime sync's PATCH budget instead of being swallowed by publish():

  • 3 PATCH attempts per rendered digest; only after the 230031 budget is exhausted does the sync call repostExpiredCard once.
  • 10-minute per-chat cooldown and at most one repost per digest; 20 persistent-expired ticks produce one repost.
  • Explicit refresh paths (dashboard refresh-card, attachment sync) pass repostOnExpired; association events now feed the same sync budget.
  • P3: unpinMessage false/throw logs the old card id and continues; pinned=false skips unpin; the new card id is persisted before pin, and an unconfirmed pin is retried on the same id.

Tests: 48/48 project-card-runtime-sync + project-group-mode; 63/63 adjacent; tsc --noEmit clean.

@xushulong-solo

Copy link
Copy Markdown
Contributor Author

CI has been queued since 06:58Z (the CI workflow; Sandbox network boundary already passed). If it is waiting for first-time-contributor approval, could you approve the workflow when you have a moment? Thanks!

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

增量复审结论:暂不建议合入(4 个 P2)

复审基于远端 head cd0c9a0b;本地在最新 master 上的 rebase 树 da0ee4b417 验证。原先 project-card-runtime-sync 的 CI 回归已经消失,纯后台持续过期路径也已有预算、冷却、模式切换和并发 tick 覆盖。但以下四条自动路径 / 失败组合仍会使恢复状态机失效;每条都用真实 ProjectCoordinator、真实项目存储及 fenced 探针复现。

1. [P2] 自动 report 仍绕过全部重发限频

src/services/project-coordinator.ts:291-296 以 action !== 'refresh' 判定 repostOnExpired:true。但 report 不只是人工 /project 命令:worker 的自动进展上报也从 src/services/project-workstream-attachments.ts:600-603、:643-649 进入同一 run()。因此这些自动写入完全绕开 runtime sync 的 PATCH 预算、每 digest 去重与 10 分钟冷却。

探针令所有卡的 updateCard 持续抛 230031、send/pin/unpin 正常:在完成 init/dispatch 基线后,20 次自动 report 额外产生 20 张新卡、20 次 pin、20 次 unpin。这与本 PR 要消除的持续重发缺口相同。建议不要按 action 名称推断「人工显式操作」,由调用方明确选择发布策略;自动 report 应复用 sync 预算与冷却。

2. [P2] 第三次是瞬时错误会抹掉已经确认的过期状态

src/services/project-card-runtime-sync.ts:81-88 只在「预算耗尽的这一次错误」为 230031 时设置 awaitingRepost。同一 digest 前两次 PATCH 已返回 230031、第三次遇到网络错误时,状态变成 failures=3, awaitingRepost=false;后续 tick 在 :87-88 直接返回。过期是永久事实,后一次瞬时错误不应撤销重发资格。

真实 sync 探针按「expired → expired → transient」注入错误,随后再跑 20 tick:总计仍只有 3 次 PATCH、0 次 repost、1 张初始卡,旧卡保持陈旧。建议按 digest 记录 sawExpired,预算耗尽时依据整个窗口而非最后一次错误决定重发。

3. [P2] unpin 未确认后仍覆盖旧 ID,旧置顶永久失联

src/services/project-coordinator.ts:562-575 对 unpinMessage=false 或异常仅 warn 并继续;sendAndPinCard() 随后在 :594-600 把存储切到新 ID,没有保存待清理旧 ID。现有 test/project-group-mode.test.ts:448-466 只钉住「仍换卡并 warn」,没有验证旧置顶最终清理。

探针令旧卡过期、unpinMessage(oldId)=false,新卡 send/pin 成功:存储立即变为 om_card_2/pinned:true;继续 20 次成功更新后,旧 om_card_1 的 unpin 调用仍只有第一次,再无恢复入口。建议 unpin 未确认时中止本次重发并保留旧卡状态,或持久化待清理旧 ID,后续限频重试。

4. [P2] 后台重发的新卡 pin 失败后被记为成功,不再补置顶

后台 refreshCard() 固定 repostOnExpired:false,所以 src/services/project-coordinator.ts:555 不会在成功 PATCH 后调用 confirmCardPin()。而 src/services/project-card-runtime-sync.ts:103-107 不检查重发结果的 card.pinned,即使新卡 pin 返回 false 也 rememberPublished() 写入 failures:0,同 digest 后续直接跳过。

真实 sync 探针令旧卡过期、unpin/send 成功、新卡第一次 pin 返回 false:重发后存储为 om_card_2/pinned:false;随后 20 个 tick 没有任何补 pin 调用,旧卡已取消置顶,新卡也一直未置顶。建议把未确认 pin 保留为待恢复状态并限频重试,或让后台成功路径同样执行幂等补置顶。

验证记录

  • 本地相关回归:8 个测试文件 164/164 passed(runtime-sync、group-mode、workstream-attachments、coordinator-runtime、task-event-route、group-command、group-mode-api、import-legacy-route)。
  • bun run typecheck:通过。
  • 远端 cd0c9a0b 的 build、4 个 vitest 分片、4 个 Bun 分片及二进制检查均为 SUCCESS;上述问题位于现有测试未覆盖的行为组合,不是当前 CI 红。
  • 探针均在 bun scripts/fenced-run.ts 下运行,只使用临时 HOME / 存储与假 transport,未触达真实飞书或 fleet。

@xushulong-solo

Copy link
Copy Markdown
Contributor Author

Thanks for the incremental review. Addressing all four P2s: explicit publish policy instead of action-name inference (automatic report will share the sync budget/cooldown), per-digest sawExpired so a later transient error cannot erase a confirmed expiry, abort/persist when unpin is not confirmed instead of overwriting the old card id, and retain/retry an unconfirmed pin after a background repost. Will push a follow-up commit with regression probes for each.

让自动回报只提交业务状态,统一由后台按摘要和冷却发布。累计编辑过期信号,未确认旧卡解除置顶时保留旧 ID,并持久化新卡补置顶的重试窗口。
@xushulong-solo

Copy link
Copy Markdown
Contributor Author

Pushed ca1e3f05c. All four P2s addressed:

  1. Publish policy is explicit. Automatic report only writes business state and queues; the runtime sync performs the PATCH budget/cooldown (20 automatic reports → one repost in both normal and imported-task paths).
  2. Per-digest sawExpired: if any attempt in the window hit 230031, the budget-exhausted repost still happens; a later transient error cannot erase the expiry signal.
  3. An unconfirmed unpinMessage (false/throw) aborts the repost and keeps the old card id.
  4. An unconfirmed new-card pin persists a retry deadline; the background retries the same id at ≥60s, never sends another card.

Tests: 117/117 targeted, 44/44 adjacent, tsc --noEmit clean; 10/10 mutation guards caught.

同一旧卡的替换发送使用稳定 UUID 并转发飞书幂等去重,写库失败或重启后的重试可取回原 messageId;命中去重后 PATCH 最新卡片内容,避免恢复期间业务或运行态变化造成重复卡。重发失败只记录每群冷却,不再把对应摘要永久视为完成,unpin/send 瞬败可在冷却后自动重试。

补充真实写盘失败、同步器与协调器重建、内容变化、对齐 PATCH 瞬败及 unpin/send 冷却回归。独立探针复验覆盖 revision 变化、runtime 变化、重启和部分失败;移除 UUID 或失败冷却记录的变异均咬红。

Co-Authored-By: Claude Code <[email protected]>

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

已在 ca1e3f05c 上追加并 fast-forward 推送 0a3cfb5fc,未改写作者已有提交。

本次补充修复

  • 同一旧卡的替换发送使用稳定 UUID(app、chat、旧 messageId),并透传到现有飞书 sendMessage 幂等协议。send 成功但新 ID 写库失败时,后续重试或进程重建可取回原 messageId,不再永久静默或盲目另发新卡。
  • 命中去重后,对同一 messageId 再 PATCH 最新 cardJson;恢复期间即使用户写入改变 revision、或 owner 显示名等 runtime 内容改变,也只有一张逻辑替换卡,且内容最终收敛到最新版本。
  • unpin/send 瞬败只进入每群 10 分钟冷却,不再把该 digest 永久视为已尝试完成;成功重发才按 digest 去重。冷却后可自动重试。

探针与变异证据

真实 coordinator + runtime sync + 临时 JSON 存储、可控时钟:

  • 写库失败后 revision 改变、仅 runtime Alpha→Beta、Coordinator+Sync 重建:均复用同一 UUID 和原 messageId,只有 1 张替换卡,最终内容为最新版本。
  • 内容对齐 PATCH 瞬败:后续 tick 或重建后仅 PATCH 同一 ID,不再次 send;随后按 pinRetryAt 补置顶。
  • 原四项验收在最终 head 复跑:20 次自动 report 新增 send/pin/unpin 均为 0;混合错误成功重发一次;unpin 失败先中止并保留旧 ID、恢复后清理;pin 到期补成功后 20 tick 不再重复。
  • 隔离变异:移除 send UUID 后 3 条恢复用例咬红;移除失败冷却记录后 unpin/send 两条用例咬红。

验证

  • bun run build:通过。
  • 18 个直接消费方与测试卫生文件:1111/1111 passed。
  • Bun:project-card-runtime-sync 27/27、project-group-mode 32/32、project-workstream-attachments 62/62。
  • git diff --check:通过;推送后 API 确认 head 为 0a3cfb5fc46a551e9ce4215263b97beacda1667e。

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

#109 合并树背书:接受窄例外(仅绑定以下精确提交与树)

结论:接受 #109,无需为同步 master 另出新 head 重跑首跑 CI。 可按既定流程 squash;如果 master 再次前进,本背书失效。

独立核对

  • PR head:0a3cfb5fc46a551e9ce4215263b97beacda1667e,冻结未变。
  • 当前 master:36f11a21e3594b881c2f9737a401661dc74de24f(包含在你给定 b5cff66a 之后新增的 #3883)。
  • git merge-tree --write-tree 36f11a21 0a3cfb5f:无冲突,预测 tree 为 3cfa106c5ecd19dbd73bafe5b9ba94dcb141eca0;本地实际合成合并树后 git write-tree 逐字相等。
  • 先前 b5cff66a 对应的本地合并 commit/tree 0451841d / fbd44b99 也核对一致,但没有用它替代当前 master 的验证。

交集判断

  • #3883 在 daemon.ts 只新增第 244 行 import,以及第 36270 行附近两个 worker-pool 回调;与本 PR 的 project card runtime sync 块没有相邻 hunk、共享标识符或语句交叠。
  • 你列出的 #3876 decisionBoard 块与本 PR projectCardRuntimeSync 块之间仍由 projectImports 和 projectCardContext 两个独立块隔开;dashboard-ipc-server.ts 两侧同样为非相邻机械并集。
  • 自动合并结果与逐文件检查一致,未发现需要人工语义取舍的交叠。

当前树实测

  • bun run build:通过(含完整 TypeScript 编译与 typecheck)。
  • 本 PR 消费方、测试卫生及 #3883 自带测试共 20 文件:1146/1146 passed。
  • 首轮并发运行中 event-dispatcher 的慢插件 ACK 用例出现一次时序失败;随后单用例通过、整文件 767/767 通过,同一 20 文件组合复跑也全部通过,没有稳定失败用例。
  • CI run 45834571700:attempt=1,headSha 精确为 0a3cfb5f,14/14 checks 全部 completed + success,包括聚合 test。

@deepcoldy
deepcoldy merged commit 1789521 into deepcoldy:master Nov 26, 2026
15 checks passed
@deepcoldy

Copy link
Copy Markdown
Owner

感谢贡献,这个修复已合入 master(squash 1789521)。

最终落地的能力:项目群置顶进度卡超过飞书 14 天编辑窗口(updateCard 返回 230031)后,既不会永久停滞,也不会无节制重发——

  • 后台 30 秒同步沿用「同一摘要最多 3 次 PATCH」预算,仅在该预算窗口内确认见过过期错误时才触发重发,并按每群 10 分钟冷却、同一摘要一次限频;混合瞬时失败不会清空过期资格。
  • 真人显式操作(CLI /project、Dashboard 刷新按钮)仍可即时换卡;worker 的自动上报改为只提交业务状态并标记 refreshPending,发卡统一交后台,不再绕过限流。
  • 旧卡取消置顶若飞书未确认,保留原 messageId 并在冷却后重试,不丢失唯一引用;新卡先以 pinned:false + pinRetryAt 落盘再置顶,失败由后续同步自动补置顶且不重发。
  • 换卡发送用由旧卡 ID 确定性派生的稳定 UUID 走飞书 1 小时幂等,写库失败或进程重启后的重试取回同一张卡并 PATCH 到最新内容,不产生重复卡片。

验证:最新主干合并树上 tsc/build 通过,相关 1700+ 单元测试全绿,PR head CI 首跑(attempt=1)15 项 check 全绿。

后续:飞书真机上卡片置顶与重发的实际视觉效果,留待版本发布后验证。欢迎继续贡献。

@github-actions

Copy link
Copy Markdown

🚀 Released in v3.59.35

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