[Bug Bash] Guest operations (read/write/shell/MCP) on a deleted or non-existent environment fail with Unimplemented instead of NotFound

未关闭
#121 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
74/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
go, grpc
领域
api, backend

调研方向

Start in internal/apiservice/wakeretry.go, especially ensureAwake around lines 80–92, and trace how the wake probe handles gRPC status codes and deleting actor state. Reproduce with a deleted or non-existent environment using read, write, shell, or MCP tools/call; finish when these requests report NotFound and deleting actors fail without waiting for the full wake budget.

由索引模型根据 Issue 内容生成。

描述

Summary & Root Cause

Running read, write, shell, or MCP tools/call against a deleted or non-existent environment fails with gRPC code Unimplemented (ate-env: env: rpc error: code = Unimplemented desc = actor ate-env/<id> not found) instead of NotFound (ate-env: env: not found: ...).

Root Cause
  1. In internal/apiservice/wakeretry.go:80-89, ensureAwake probes the guest via atenet-router and assumes any error code other than codes.Unavailable came from a live guest:
    _, err := probe.GetProcess(ctx, &ateenvv1alpha.GetProcessRequest{ProcessId: "ate-env-wake-probe"})
    if status.Code(err) != codes.Unavailable {
        // Anything else, NotFound for the probe id included, came from
        // the guest itself.
        return nil
    }
    state, serr := s.actorState(ctx, atespace, id)
    
  2. When an actor does not exist (or has finished deleting), atenet-router responds with a plain HTTP 404 Not Found (actor <atespace>/<id> not found) without a grpc-status trailer.
  3. Per the gRPC over HTTP/2 specification, grpc-go maps an HTTP 404 response without grpc-status to codes.Unimplemented (12), not codes.Unavailable or codes.NotFound.
  4. Because status.Code(err) == codes.Unimplemented != codes.Unavailable, ensureAwake returns nil immediately without calling s.actorState(ctx, atespace, id) (whose doc comment at :122-124 explicitly notes: "A deleted environment surfaces here as NotFound (through toGRPCError), which is the right answer to a caller still holding its handle").
  5. The caller's subsequent RPC (ReadFile, WriteFile, StartProcess) then hits the same HTTP 404 from atenet-router and surfaces raw codes.Unimplemented to the client.

Versions

  • agent-substrate/env: 40a6c63 (also present on main @ d579fd0)
  • agent-substrate/substrate: ddb46651

Steps to Reproduce

Test Case 1: Read from a deleted environment (Bug Bash Flow — Step 9: Delete)
ate-env create $USER
echo "hello $(date)" | ate-env $USER write /data/note.txt

# Step 9 from the bug bash doc:
ate-env delete $USER
ate-env $USER read /data/note.txt
  • Expected: Fails with NotFound:
    ate-env: env: not found: environment "chenyiwang" not found
    
  • Actual: Fails with codes.Unimplemented (exit code 1):
    ate-env: env: rpc error: code = Unimplemented desc = actor ate-env/chenyiwang not found
    
Test Case 2: Run read, write, or shell on a non-existent environment (Bad Inputs)
ate-env does-not-exist read /data/note.txt
echo "hi" | ate-env does-not-exist write /data/note.txt
ate-env does-not-exist shell 'echo hi'
  • Expected: All three commands fail with NotFound (ate-env: env: not found: ...).
  • Actual: All three commands fail with codes.Unimplemented (exit code 1):
    ate-env: env: rpc error: code = Unimplemented desc = actor ate-env/does-not-exist not found
    
Test Case 3: Call MCP tools/call on a deleted or non-existent environment
curl -s http://localhost:7777/v1alpha/envs/does-not-exist/mcp \
  -H 'Content-Type: application/json' \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"shell","arguments":{"command":"echo hi"}}}'
  • Expected: Error message indicates the environment was not found (not found).
  • Actual: Tool result reports code = Unimplemented:
    {"jsonrpc":"2.0","id":1,"result":{"content":[{"type":"text","text":"env: rpc error: code = Unimplemented desc = actor ate-env/does-not-exist not found"}],"isError":true}}
    

Suggested Fix

  1. In ensureAwake (internal/apiservice/wakeretry.go:80-89), do not treat codes.Unimplemented from the wake probe as a live guest response (since atenet-router returns HTTP 404 -> codes.Unimplemented when the target actor is unknown, and GetProcess is implemented by ate-env-guest), or fall through to s.actorState(ctx, atespace, id) so a missing/deleted actor surfaces as codes.NotFound.
  2. In ensureAwake (internal/apiservice/wakeretry.go:90-92), also fail fast when state == ateapipb.ActorState_ACTOR_STATE_DELETING instead of polling until DefaultWakeBudget (2m) expires.
主要语言
Go
星标
71
派生
17
平均合并
21 小时 36 分钟
30 天内合并 PR
19

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

agent-substrate/env 的其他 Issue

查看 agent-substrate/env 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。