Skip to content

fix(drive): stop realtime cursor writes from warning during a sync#82

Merged
yurenju merged 1 commit into
mainfrom
claude/drive-realtime-lock-warn
Jul 14, 2026
Merged

fix(drive): stop realtime cursor writes from warning during a sync#82
yurenju merged 1 commit into
mainfrom
claude/drive-realtime-lock-warn

Conversation

@yurenju

@yurenju yurenju commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

問題

wspc drive watch 每次上傳週期(syncing 0 / 1)約 1 秒後都會噴一行 realtime warning: realtime error,看起來像出錯但其實沒事。

連鎖反應:存檔觸發一次 sync,sync 握著 .wspc-drive/sync.lock 並改寫 state.json;同一時間 server 回傳自己造成的 own-echo library_changed,只需推進 cursor。但推 cursor 的 writeDriveRealtimeStatewithDriveLock 要搶同一把鎖,撞到 sync 正握著,於是丟 sync lock already exists。這個 best-effort 錯誤被 redactedRealtimeError 壓成毫無資訊的 realtime error

兩層問題:cursor 寫入在 sync 進行中會失敗(本來只是暫時撞鎖),且失敗訊息被 redact 到看不出原因。

修正

  • withDriveLock 新增選用的 DriveLockOptions,支援 bounded retry。預設 retries: 0,所以 sync 與 ensureDriveRealtimeState 行為不變(撞鎖仍 fail-fast)。
  • writeDriveRealtimeState opt-in 重試約 2 秒,讓這個 best-effort cursor 寫入等 sync 放鎖後成功,而不是噴警告。
  • 撞鎖錯誤帶上 code: WSPC_DRIVE_LOCK_HELD,任何殘餘警告會 redact 成 realtime error (WSPC_DRIVE_LOCK_HELD),一眼可診斷。

cursor 推進本來就是 best-effort、idempotent:就算漏一次,下一個 realtime 訊息或重連 replay 會補回,不掉資料,所以不需要把 realtime 與 sync 寫入全域序列化。

測試

TDD:先寫 4 個紅測試(帶 code、retry 撞鎖後成功、retry 用完仍失敗、cursor 等 sync 放鎖後成功)確認失敗,再實作到全綠。整個 drive 測試 242 passed,typecheck 乾淨。

`drive watch` logged a bare "realtime warning: realtime error" ~1s after
every upload cycle: the own-echo library_changed arrives mid-sync, so
writeDriveRealtimeState's withDriveLock collides with the sync still
holding sync.lock and throws "sync lock already exists". redaction then
flattened that undiagnosable message to "realtime error".

- withDriveLock gains an opt-in bounded retry (DriveLockOptions); sync and
  ensureDriveRealtimeState keep fail-fast (retries default 0)
- writeDriveRealtimeState opts into ~2s of retry so a tiny best-effort
  cursor write waits out a sync instead of surfacing a warning
- lock-contention error now carries code WSPC_DRIVE_LOCK_HELD, so any
  residual warning redacts to "realtime error (WSPC_DRIVE_LOCK_HELD)"
@yurenju yurenju merged commit f2b5d88 into main Jul 14, 2026
2 checks passed
@yurenju yurenju deleted the claude/drive-realtime-lock-warn branch July 14, 2026 06:31
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.

1 participant