Recover interrupted runs and commit terminal state once
ci / vet-and-test (pull_request) Successful in 43s

Why: A hard kill left runs in pending, running, or waiting_hitl, a busy send stored a message before the 409, finishRun could mark a run completed without an assistant message, and a full SSE buffer dropped events without closing the stream.
Evidence: GOWORK=off go vet ./... and GOWORK=off go test -count=1 ./... passed, including store, runmgr, bus, and server recovery tests.
Impact: Migration v14 adds runs.instance_id and messages.request_id. Startup reconciliation and shutdown share one seal. Turn and workflow sends claim a slot before writing. Duplicate request ids return the existing message. SettleRun updates the run and appends the assistant message in one transaction. A full subscriber buffer closes the channel so SSE can replay from the cursor.
Refs: Dev feature/pi-durable-borrow
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-03 14:37:49 +00:00
co-authored by Cursor
parent 8fb3cae987
commit 44aa764b56
16 changed files with 1188 additions and 80 deletions
+21
View File
@@ -369,6 +369,27 @@ func init() {
`DROP TABLE IF EXISTS plugin_grants`,
},
}},
migration{version: 14, name: "run_instance_and_request_id",
// 启动对账按实例收口在途 run;发消息按 request_id 去重。
// 空 request_id 不参与唯一约束,旧消息与命令路径仍可重复追加。
up: map[string][]string{"sqlite": {
`ALTER TABLE runs ADD COLUMN instance_id TEXT NOT NULL DEFAULT ''`,
`ALTER TABLE messages ADD COLUMN request_id TEXT NOT NULL DEFAULT ''`,
`CREATE UNIQUE INDEX IF NOT EXISTS uq_messages_conv_request ON messages(conversation_id, request_id) WHERE request_id <> ''`,
}, "postgres": {
`ALTER TABLE runs ADD COLUMN instance_id TEXT NOT NULL DEFAULT ''`,
`ALTER TABLE messages ADD COLUMN request_id TEXT NOT NULL DEFAULT ''`,
`CREATE UNIQUE INDEX IF NOT EXISTS uq_messages_conv_request ON messages(conversation_id, request_id) WHERE request_id <> ''`,
}},
down: map[string][]string{"sqlite": {
`DROP INDEX IF EXISTS uq_messages_conv_request`,
`ALTER TABLE messages DROP COLUMN request_id`,
`ALTER TABLE runs DROP COLUMN instance_id`,
}, "postgres": {
`DROP INDEX IF EXISTS uq_messages_conv_request`,
`ALTER TABLE messages DROP COLUMN request_id`,
`ALTER TABLE runs DROP COLUMN instance_id`,
}}},
)
}