Skip to content

Workspace lock deadlock: unconfirmable MCP tool side effects permanently stall the session #1249

Closed as duplicate

Description

@guolvlin-cn

摘要

当某个 MCP 工具(典型是 Playwright 的 browser_navigate)产生的副作用无法被工作区日志(workspace journal)确认落地时,整个会话会进入永久死锁:此后每一次输入都返回 Workspace execution could not be confirmed stopped,不再执行任何工具,且无任何恢复路径。

环境

  • astra v0.2.13(~/.local/bin/astra)
  • macOS(Darwin 25.6.0)
  • Playwright MCP @playwright/[email protected](事发时配置为 @latest)
  • 模型:glm-5.3-flash

复现步骤

  1. 启动 astra,让它通过 Playwright MCP 打开一个 URL(browser_navigate)。

  2. 该工具拉起一个持久 Chrome 实例(--user-data-dir=…/ms-playwright-mcp/mcp-chrome-…),navigate 完成后浏览器进程不退出。

  3. astra 报错:

    Failed Mcp Playwright Browser Navigate
    Error: Tool 'mcp__playwright__browser_navigate' returned before its workspace effects were proven se…
    Workspace execution could not be confirmed stopped. The available result is preserved as unverified.
    
  4. 此后任何输入都返回同样提示,不再跑工具(ttft ~2s,无工具执行):

    Workspace execution could not be confirmed stopped. The available result is preserved as unverified.
    ⚠ Warning · Some work remains unverified. Continue this session to resolve what remains.
    

根因分析

astra 的日志式工作区(journaled workspace,带 journal_event_seq / canonical_root_hash / branch main)在「证实」工具副作用时卡住。对于一个会拉起长期存活外部进程的工具,其副作用无法被确认完成,调用状态停留在 running,工作区锁永不释放:

  • ~/.astra/sessions/v1/.../sessions/<session_id>/.workspace.lock 一直残留(0 字节,不释放)。
  • ~/.astra/edge-invocations/*.json.wal 末尾是 {"tool":"bash","state":"running"},从未 finalize。

会话内那句 "Continue this session to resolve what remains" 永远不会自行解决——唯一出路是手动 kill -9 进程并删除残留锁。

影响范围(系统性)

排查发现 ~/.astra/sessions/v1/users/*/sessions/ 下共 21 个会话残留 .workspace.lock。说明每次异常退出/强杀的会话都会泄漏工作区锁,锁文件越积越多。

期望行为

  • 副作用无法被确认的工具应超时并释放锁(或将变异标记为 failed/aborted),而不是永久停在 running。
  • "Continue this session to resolve what remains" 应提供真正可用的恢复路径,而非无限循环。

建议修复方向

  1. 给 workspace-effect 确认加超时 + watchdog,超时后把 invocation 标记为 failed/aborted 并释放 .workspace.lock。
  2. 会话启动时对残留 .workspace.lock 做 liveness/PID 检查并回收。
  3. MCP 工具(尤其会拉起持久进程的)副作用超时后,应降级为「未验证」而非阻塞整个会话。

临时 workaround(已在本机执行)

  • 强杀卡死的 astra 会话及其 MCP 子进程。
  • 删除全部残留 .workspace.lock 与 edge-invocations/*.lock|*.wal。
  • 将 ~/.astra/mcp.json 中 Playwright MCP 从 @playwright/mcp@latest 锁定为 @playwright/[email protected]。

Activity

  1. guolvlin-cn commented on Nov 9, 2026

    @guolvlin-cn
    Author

    根因修正(重要,比最初的本地锁判断更准确)

    进一步排查确认,真正的阻塞点不在本地 .workspace.lock / edge-invocations 文件,而在 astra serve 网关进程的内存状态。

    真实根因

    1. 每个 astra CLI 会话在服务端登记为一个 edge agent(edge_id 形如 edge-materialization-...-process-<PID>)。

    2. 当某个工具调用卡住(典型是 Playwright browser_navigate 拉起一个不退出的常驻 Chrome),该 edge agent 的 tool request 永远不会完成,服务端把它记为 pending:

      WARN edge heartbeat with active pending tool requests
        edge_id="edge-materialization-...-process-78786"  pending=1
      WARN edge heartbeat with active pending tool requests
        edge_id="edge-materialization-...-process-22977"  pending=1
      
    3. 这个 pending 状态残留服务端内存里(astra serve 跑了 4+ 天)。CLI 进程被 kill 后,pending 变成孤儿,永远不会被清理。

    4. 此后所有新会话(包括全新 event_count=0 的会话)都收到服务端返回的:

      run failed mid-stream (run_error)
        domain_error_code="execution_incomplete"  retryable=false
        error="Some work remains unverified. Continue this session to resolve what remains."
      

      日志目标 astra_runtime::sse 证实这是服务端产生的错误,不是 CLI 端。

    修复验证

    • 重启 astra serve(kill PID,launchd KeepAlive 自动拉起)后,内存 pending 状态被清空。
    • 重启时间戳 07:54 UTC Starting API server on 127.0.0.1:17001;此后日志中不再出现 execution_incomplete。
    • astra chat 实测:4 MCP servers connected: MiniMax · memoria · playwright · r-matrix,run 能正常走过 execution 阶段。

    结论与修复方向(更正)

    • 本地清锁只是症状缓解,真正需要修的 bug 在服务端:edge agent 的 pending tool request 没有超时/回收机制,一旦工具调用卡死,pending 永久残留并全局阻塞所有会话。
    • 建议修复:给 edge agent 的 tool request 加超时 + 心跳失效回收(heartbeat 超时 → 自动 abandon pending request),而不是让一个卡死的工具调用永久污染整个服务。
  2. guolvlin-cn commented on Nov 9, 2026

    @guolvlin-cn
    Author

    完整技术排查(补充根因,纠正前两次判断)

    前两次判断(本地锁 / serve 内存)都不对。下面是完整的排查结论。

    一、真实根因链

    1. 触发点:服务端日志 07:11 出现

      WARN provider tool batch was not fully admitted
        rejected_names=["web_fetch"]  rejected_error_kinds=["deferred_tool_descriptor_stale"]
      

      web_fetch / web_search 的工具 schema 描述符过期(deferred_tool_descriptor_stale)。

    2. 由此产生第一个失败(07:13):

      WARN run failed mid-stream (run_error)
        domain_error_code="execution_incomplete"  retryable=false
        error="Some work remains unverified. Continue this session to resolve what remains."
        target="astra_runtime::sse"
      

      对应二进制内的真实文案是 request wall deadline ended without root execution settlement。

    3. 这次失败在服务端留下「未结算的根执行 / unverified work」,且没有超时回收机制。之后所有在同一 workspace 的新会话(包括只发一个 hi、event_count=0 的全新会话)都在跑完 1 个 turn 后被 execution_incomplete 打断,interruption.resume_action=continue_immediately 但 "continue" 永远不会真正解决,形成死循环。

    二、关键发现:materialization 按 worktree_path 确定性派生

    edge_agent_registry 里 materialization_id 与 worktree_path 一一对应:

    worktree_path materialization_id 状态
    /Users/guolvlin e8f1b1a7… 卡死(unverified work)
    /private/tmp 0e7736e5… 正常
    /Users/guolvlin/repo/git/mo/Astra d575ecff… 正常
    /Users/guolvlin/.astra/r-matrix-tool 198e9616… 正常

    本地 ~/.astra/edge-materializations/<checkout-hash>.id 文件内容正是 materialization-e8f1b1a7…,而 <checkout-hash>.checkout 内容是 checkout-<hash>——这是服务端内容寻址 blob 的引用,真实数据不在本地 git 仓库(本地无对应 .git)。

    三、"unverified work" 状态不在任何可查询的 DB 表

    逐表排查(astra_runtime_v119 库,60+ 表),所有相关表要么 0 行要么正常:

    • edge_pending_dispatch:6 行全 completed(后变为 0 行)
    • edge_agent_registry:e8f1b1a7 有 30 条历史注册,但 registration_state=1、registration_claim_id=NULL(无卡住的 claim)
    • session_execution_bindings:全 state=ready
    • session_execution_switches:0 行
    • agent_session_lifecycle_fences:全干净
    • inference_invocation_settlement_debts:0 行
    • agent_session_memory_work:0 行
    • session_context_heads:无 active_writer / active_reservation
    • session_context_operation_receipts / session_context_authority_events / tool_invocation_ledger:全 0 行
    • agent_runs:失败 run 都是 depth=0、parent_run_id=NULL(自身即 root,无卡住的父 run);owner_pod_id 全 NULL
    • sweeper_leases:runtime_sweepers 租约在正常续期(expires_at 会前移),非卡死

    结论:unverified work 状态存在服务端的内容寻址 blob 存储里(checkout-<hash> 指向的 blob),不在可查询的表里。

    四、尝试过但无效的修复

    1. SIGKILL 全部卡死进程(35 astra + 24 playwright-mcp + mcp-chrome)
    2. 清本地 .workspace.lock(21 个)+ edge-invocations/*.lock|*.wal
    3. 锁 playwright MCP 版本(@latest → @0.0.84)
    4. 重启 astra serve(launchd 拉起新进程)——状态从 DB/内容存储重新加载,无效
    5. astra session cancel 全部 active 会话——对有 run 的会话能 execution_settled=true,但无 run 的僵尸 active 会话无法 cancel,且不影响全局 unverified work

    五、workaround

    因 materialization 按 worktree_path 派生,换目录跑 astra 即绕开(用全新 materialization):

    cd ~/Agent && astra   # 或任何子目录

    /Users/guolvlin 这个 workspace 的 materialization 已永久卡死,只能靠服务端修复。

    六、建议修复方向(按优先级)

    1. execution settlement 超时回收:根执行无法结算时,加 watchdog 超时并标记 failed/aborted,释放 ownership boundary,而不是永久 running/unverified。
    2. deferred_tool_descriptor_stale 自愈:工具描述符过期时应自动重取 schema,而不是让 run 进入无法结算的状态。
    3. 提供 materialization 重置命令:需要一个 astra admin / astra session 级的操作,能清空指定 worktree 的 materialization 状态(含内容寻址 blob),否则用户无法自救。

    补充证据(供定位):失败 run 的 terminal_receipt_json 里 interruption.kind="execution_incomplete"、resume_action="continue_immediately"、remaining_turns=24、tool_ledger.attempted=0、outcome.status="failed"、context.disposition="advanced"、cursor.completed_turn=1(说明 run 推进了 1 个 turn 后才被打断,非启动即失败)。

  3. guolvlin-cn commented on Nov 9, 2026

    @guolvlin-cn
    Author

    补充确认:workaround 已由用户实测有效——换个目录跑 astra 即恢复正常,证实「materialization 按 worktree_path 确定性派生、unverified work 绑定在 /Users/guolvlin 的 materialization 上」这一根因判断成立。卡死的 materialization 仍需服务端修复。

  4. XuPeng-SH commented on Nov 15, 2026

    @XuPeng-SH
    Collaborator

    已合并追踪至 #1302 的第 2 节。原 macOS/Playwright 与 materialization 事故尚未重放;未知副作用不会因为超时而被视为已结算。

    此关闭仅表示将追踪入口合并,不表示原问题已全部修复。原报告、讨论和尚未满足的验收条件继续作为新 issue 的证据与验收来源。

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions