← Back to Pull requests

fix(workspace): 暂存写操作对有界瞬时 index.lock 竞争自动重试 #869

Closed
unknown closed this pull request without merging on Nov 29, 2026 07:38 UTC
View on GitHub
unknown unknown commented on Nov 28, 2026 10:31 UTC
Author

Summary

修复 main CI 的 E2E flake(git-workbench-line-smart.spec.ts 在 chromium-mobile 上因 [busy_locked] 中止而失败,触发 failOnFlakyTests 使整分片变红):

  • 根因:Git 遇到 index.lock 时立即失败、自身没有任何宽限期。WebMux 的使用场景中 CLI agent、编辑器与后台刷新会在同一仓库并发执行 Git 命令,亚秒级的瞬时锁竞争就会把暂存操作中止为用户可见错误。E2E 失败快照确认了这一点:逐行暂存请求因外部 index.lock 被「安全中止」且未重试。

  • 修复:gitInputOutput 对 ErrLocked(锁竞争)在 2.5 秒预算内以 150ms 间隔自动重试。Git 在任何修改之前先取锁,锁失败的尝试未产生任何变更,重放同一命令是安全的。持续存在的锁(真实外部进程)在预算耗尽后仍返回 ErrLocked/409 busy,且不删除锁文件——既有语义不变。

  • stdin 处理:只有 update-index 会写索引,其 --index-info 输入为小体量元数据,重试前缓冲以便重放;流式输入(hash-object 等不会碰到索引锁的命令)保持单次执行。

  • 用户故事:更新 US-J19(git-workbench/core.md)锁竞争行为描述。
  • Test plan

  • 新增 TestStageRetriesTransientIndexLockAndFailsPersistentOne:瞬时锁 600ms 后释放 → 暂存成功且内容正确;持续锁 → 预算内重试后仍报 ErrLocked,锁文件不被删除 — 通过(race)

  • go test -race ./internal/workspace/ 全量通过(38.7s)

  • go test -race -run 'TestGitWrite|TestStage|TestWire' ./internal/api/ 通过(既有 409 busy API 语义测试不受影响)

  • golangci-lint run ./internal/workspace/... 0 issues;make docs-check 通过

  • 本地 stress:该 spec 连跑 12 轮全部通过(flake 为 CI 低帧率时序问题,本地无法复现,已从 CI artifacts 的页面快照确认根因)

  • CI 全绿
  • 备注

  • TestEmbeddedRendererFontLicense 在本地干净 main 上同样失败(前端产物未完整构建的环境问题),与本改动无关。

  • 昨日另一次 flake(worktrees.spec.ts 批量清理断言)性质不同,本次未覆盖;若再现需单独跟进。
  • Generated with Devin

    Diff: 168 lines (+126 / -42) across 2 files Reviewer: mzdluo123 Review duration: 1267m
    All Vouch review confidence checks passed
    Residual risk 0.14 = Change Risk (0.35) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.35 · 168 lines diff across 2 files
    0.35
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.307
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #869"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 35.1% (MEDIUM) · Higher = larger blast radius
    35.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 13.9% · Safe to merge
    13.9%