refactor: update cursor request handling and improve parent request management

- Changed `run_id` to `request_id` in `CursorParent` struct for clarity.
- Enhanced the `prepare` function to handle parent requests asynchronously, ensuring proper error handling for active runs.
- Updated database interactions to include `cursor_request_id` for better tracking of requests.
- Added tests to verify the behavior of reused cursor request IDs and their mapping to distinct executions.
This commit is contained in:
leookun committed 2026-08-26 01:46:30 +08:00
1 parent ae31757635
commit 847e92c7ea
20 files changed
+271 -57

No files matched your search

+19 -2
View File
@@ -88,12 +88,13 @@ impl Store {
run_kind_columns(&prepared.kind);
sqlx::query(
"INSERT INTO runs
(run_id, conversation_id, base_revision_id, head_revision_id,
(run_id, cursor_request_id, conversation_id, base_revision_id, head_revision_id,
parent_run_id, parent_tool_call_id, run_kind, subagent_kind,
status, created_at_ms, updated_at_ms)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, 'running', ?, ?)",
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 'running', ?, ?)",
)
.bind(prepared.run_id.as_str())
.bind(prepared.cursor_request_id.as_deref())
.bind(prepared.conversation_id.as_str())
.bind(prepared.base_revision_id.0)
.bind(prepared.base_revision_id.0)
@@ -128,6 +129,22 @@ impl Store {
})
}
pub async fn active_run_for_cursor_request(
&self,
cursor_request_id: &str,
) -> Result<Option<RunId>> {
let run_id: Option<String> = sqlx::query_scalar(
"SELECT run_id FROM runs
WHERE cursor_request_id = ? AND status = 'running'
ORDER BY created_at_ms DESC
LIMIT 1",
)
.bind(cursor_request_id)
.fetch_optional(&self.pool)
.await?;
Ok(run_id.map(RunId))
}
pub async fn begin_provider_call(&self, run_id: &RunId) -> Result<u64> {
let index: Option<i64> = sqlx::query_scalar(
"UPDATE runs SET provider_call_index = provider_call_index + 1, updated_at_ms = ?