Skip to content

fix: make Start() idempotent when box is already running#496

Closed
nieyy wants to merge 1 commit into
boxlite-ai:mainfrom
nieyy:claude/kind-ritchie-bc2b3a
Closed

fix: make Start() idempotent when box is already running#496
nieyy wants to merge 1 commit into
boxlite-ai:mainfrom
nieyy:claude/kind-ritchie-bc2b3a

Conversation

@nieyy

@nieyy nieyy commented May 8, 2026

Copy link
Copy Markdown

问题

box.start() 在 box 已由 Create() 自动启动的情况下返回 HTTP 404,
但 box 实际上正在运行。影响所有按标准示例调用 create() + start()
的用户。

根因

Create() 加入了自动启动逻辑,但 Start() 没有做幂等处理。当 box
处于 Running 状态时,bx.Start() 在状态转换窗口内触发 ErrInvalidState
runner 将其直接作为错误返回,HTTP 层映射成 404。

改动

提取 startIdempotent() 函数:收到 ErrInvalidState 时先调用
bx.Info() 确认 box 是否真的在 Running,只有确认后才静默忽略,
其他状态(Stopping 等)的错误原样透传。

直接吞掉所有 ErrInvalidState 是错的——该错误码还覆盖 Stopping /
Unknown 等真正需要报错的状态。

验证

cd apps/runner
go test -tags boxlite_dev ./pkg/boxlite/ -run TestStartIdempotent -v

4 个测试全部 PASS。

@DorianZheng

Copy link
Copy Markdown
Member

Hi @nieyy. Please use English only

@nieyy nieyy force-pushed the claude/kind-ritchie-bc2b3a branch from 9352394 to 1971647 Compare May 11, 2026 02:29
## Problem

Start() returns ErrInvalidState when the box was already started by Create(), even though the box is actually running. Affects all users following the standard pattern of calling create() then start().

## Root Cause

Create() was updated to auto-start the box, but Start() was not made idempotent. When the box is already Running, Start() returns ErrInvalidState, which propagates as an error.

## Change

Extract startIdempotent() in the runner client: when ErrInvalidState is received, call Info() to confirm the box is actually Running before suppressing the error. All other states (Stopping, etc.) propagate the error unchanged.

Unconditionally suppressing ErrInvalidState would be wrong — the error code also covers Stopping/Paused states that are genuine failures.

Also adds api_id() to BoxBackend for REST API ID handling and fixes CLI linker issue on Linux.

## Verification

```bash
cd apps/runner
go test -tags boxlite_dev ./pkg/boxlite/ -run TestStartIdempotent -v
```

All 4 tests pass.
@nieyy nieyy force-pushed the claude/kind-ritchie-bc2b3a branch from 1971647 to b5830b1 Compare May 11, 2026 02:39
@nieyy nieyy closed this May 11, 2026
@nieyy

nieyy commented May 11, 2026

Copy link
Copy Markdown
Author

will open another pr later

@nieyy nieyy deleted the claude/kind-ritchie-bc2b3a branch May 12, 2026 14:33
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