mirror of
https://wget.la/https://github.com/leookun/cursor-byok
synced 2026-12-01 01:05:10 +08:00
fix: repair stream lifecycle reliability
This commit is contained in:
1 parent
370f120b8a
commit
59379f1f72
7 files changed
+108
-106
No files matched your search
@@ -21,7 +21,7 @@ use crate::{
|
||||
store::Store,
|
||||
};
|
||||
|
||||
use super::{inbox::OrderedInbox, CursorCommand, CursorSessionHandle};
|
||||
use super::{inbox::OrderedInbox, lifecycle, CursorCommand, CursorSessionHandle};
|
||||
|
||||
pub struct CursorActor;
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ pub fn fail(handle: &CursorSessionHandle, error: &Error) -> Result<()> {
|
||||
}
|
||||
|
||||
pub fn cancel(handle: &CursorSessionHandle) -> Result<()> {
|
||||
handle.cancel();
|
||||
// Always close the output even if encoding fails, to prevent silent hangs.
|
||||
match encode_error_end_stream(&ConnectStreamError {
|
||||
code: ConnectCode::Canceled,
|
||||
|
||||
@@ -316,6 +316,8 @@ impl CursorSessionRegistry {
|
||||
// Create the notification future BEFORE checking state to avoid
|
||||
// a race where a notification fires between state check and await.
|
||||
let changed = self.inner.route_changed.notified();
|
||||
tokio::pin!(changed);
|
||||
changed.as_mut().enable();
|
||||
if self.inner.runs.lock().await.contains_key(request_id) {
|
||||
return CursorRoute::Local;
|
||||
}
|
||||
|
||||
@@ -54,8 +54,10 @@ pub(super) async fn start(
|
||||
let call = normalized_call.as_ref().unwrap_or(call);
|
||||
|
||||
match normalized(&call.name).as_str() {
|
||||
"shell" | "bash" | "read" | "delete" | "grep" | "glob" | "readlints" | "task" | "callmcptool"
|
||||
| "fetchmcpresource" | "getmcptools" => exec::start(runtime, call, context).await,
|
||||
"shell" | "bash" | "read" | "delete" | "grep" | "glob" | "readlints" | "task"
|
||||
| "callmcptool" | "fetchmcpresource" | "getmcptools" => {
|
||||
exec::start(runtime, call, context).await
|
||||
}
|
||||
"write" | "strreplace" | "editnotebook" => edit::start(runtime, call, context).await,
|
||||
"askquestion" | "websearch" | "webfetch" | "switchmode" | "createplan"
|
||||
| "generateimage" => interaction::start(runtime, call).await,
|
||||
@@ -66,7 +68,7 @@ pub(super) async fn start(
|
||||
}
|
||||
|
||||
fn normalize_block_until_ms(call: &ToolCall) -> Result<Option<ToolCall>> {
|
||||
if normalized(&call.name) != "shell" {
|
||||
if !is_shell_tool(&call.name) {
|
||||
return Ok(None);
|
||||
}
|
||||
let Some(value) = call.arguments.get("block_until_ms") else {
|
||||
@@ -133,6 +135,10 @@ pub(super) async fn resume_interaction(
|
||||
interaction::resume(results, search, fetch, pending, response).await
|
||||
}
|
||||
|
||||
fn is_shell_tool(name: &str) -> bool {
|
||||
matches!(normalized(name).as_str(), "shell" | "bash")
|
||||
}
|
||||
|
||||
pub(super) fn normalized(name: &str) -> String {
|
||||
name.chars()
|
||||
.filter(|character| character.is_ascii_alphanumeric())
|
||||
@@ -167,6 +173,18 @@ mod tests {
|
||||
assert_eq!(call.arguments["block_until_ms"].as_i64(), Some(45_000));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bash_accepts_integer_valued_float_timeout() {
|
||||
let call = tool(
|
||||
"Bash",
|
||||
serde_json::json!({"command": "echo ok", "block_until_ms": 45_000.0}),
|
||||
);
|
||||
|
||||
let call = normalize_block_until_ms(&call).unwrap().unwrap();
|
||||
|
||||
assert_eq!(call.arguments["block_until_ms"].as_i64(), Some(45_000));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shell_rejects_fractional_timeout() {
|
||||
let call = tool(
|
||||
|
||||
Reference in new issue
Block a user