Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

fix(hooks): drop Cursor's empty-draft placeholder session

AkitaOnRails7292c3b809df
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 62b7fcaa..779c81a7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
`tool_name`/`tool_input` fields, but Cursor was missing from the tool-capture
mapping, so every Cursor tool observation reached the store empty. They now
get the same tool-family title and output summary as Claude Code's.
+- Fixed every Cursor window adding a session to memory before any
+ conversation: Cursor fires `sessionStart` for its empty draft composer with
+ the placeholder id `empty-state-draft` and no workspace, and each launch
+ appended another observation to that one empty session. The server now
+ acknowledges and drops that placeholder.
- Corrected the Claude Desktop documentation: Linux is an Anthropic beta for
Debian-based distributions with its config at
`~/.config/Claude/claude_desktop_config.json` (pass it to
diff --git a/crates/ai-memory-hooks/src/router.rs b/crates/ai-memory-hooks/src/router.rs
index 1b511435..ee8b86fb 100644
--- a/crates/ai-memory-hooks/src/router.rs
+++ b/crates/ai-memory-hooks/src/router.rs
@@ -664,6 +664,10 @@ async fn handle_hook(
HookProcessingOutcome::DroppedPolicy.record(&state.ingest_metrics);
return (StatusCode::ACCEPTED, "capture policy dropped");
};
+ if is_cursor_draft_placeholder(&env) {
+ HookProcessingOutcome::DroppedInvalid.record(&state.ingest_metrics);
+ return (StatusCode::ACCEPTED, "cursor draft placeholder dropped");
+ }
// Accept-but-drop subagent captures (incl. the unmarked tail of tracked
// subagent sessions) when the operator opts in. Returning 202 (not an error)
// means the client treats the event as delivered and never retries/spools
@@ -932,6 +936,15 @@ async fn handle_hook_batch(
accepted_indices.push(idx);
continue;
};
+ if is_cursor_draft_placeholder(&env) {
+ HookProcessingOutcome::DroppedInvalid.record(&state.ingest_metrics);
+ results.push(HookBatchResult {
+ index: idx,
+ outcome: HookProcessingOutcome::DroppedInvalid,
+ });
+ accepted_indices.push(idx);
+ continue;
+ }
// Accept-but-drop subagent captures (see `handle_hook`): count the item
// as committed so the client clears it from its spool, but do not store
// it. Keeps the contiguous-prefix ack contract intact.
@@ -1281,6 +1294,15 @@ const fn canonical_tool_name(family: ToolFamily) -> &'static str {
}
}
+/// Cursor fires `sessionStart` for the empty draft composer of every window it
+/// opens, before any conversation exists, always with this placeholder id and
+/// no workspace. Kept, it piles up as one session that never holds work.
+const CURSOR_DRAFT_SESSION_ID: &str = "empty-state-draft";
+
+fn is_cursor_draft_placeholder(env: &HookEnvelope) -> bool {
+ env.agent == AgentKind::Cursor && env.session_id.as_deref() == Some(CURSOR_DRAFT_SESSION_ID)
+}
+
/// Decide whether to accept-but-drop this event under `drop_subagent_captures`,
/// maintaining the subagent-session set. Returns `true` to drop. Seeds the
/// session on `SubagentStart` and on any marker-bearing event; keeps it through
@@ -7971,6 +7993,77 @@ mod tests {
);
}
+ #[tokio::test]
+ async fn cursor_draft_placeholder_is_dropped_before_any_capacity_is_spent() {
+ let tmp = TempDir::new().unwrap();
+ let mut state = make_state(&tmp).await;
+ // One token, no refill: a placeholder that reached the limiter would
+ // leave nothing for the real conversation that follows.
+ state.ingest_rate = Arc::new(tokio::sync::Mutex::new(IngestRateLimiter::new(0.001, 1.0)));
+ let state = Arc::new(state);
+ async fn hit(state: Arc<HookState>, sid: &str) -> (StatusCode, String) {
+ let response = handle_hook(
+ State(state),
+ Query(HookQuery {
+ event: "session-start".into(),
+ agent: Some("claude-code".into()),
+ ..Default::default()
+ }),
+ None,
+ None,
+ None,
+ HeaderMap::new(),
+ Json(serde_json::json!({
+ "conversation_id": sid, "session_id": sid,
+ "hook_event_name": "sessionStart", "cursor_version": "3.24.9",
+ "workspace_roots": [], "transcript_path": null,
+ })),
+ )
+ .await
+ .into_response();
+ let status = response.status();
+ let body = axum::body::to_bytes(response.into_body(), 1024)
+ .await
+ .unwrap();
+ (status, String::from_utf8(body.to_vec()).unwrap())
+ }
+
+ for _ in 0..2 {
+ assert_eq!(
+ hit(state.clone(), "empty-state-draft").await,
+ (
+ StatusCode::ACCEPTED,
+ "cursor draft placeholder dropped".into()
+ )
+ );
+ }
+ // Control: a real Cursor conversation is queued.
+ assert_eq!(
+ hit(state.clone(), "17689370-2e8e-4dfd-bcd0-7e5bb9cd19ed").await,
+ (StatusCode::ACCEPTED, "queued".into())
+ );
+ // A Claude Code session that happens to use the same id is not Cursor's.
+ let claude = handle_hook(
+ State(state),
+ Query(HookQuery {
+ event: "session-start".into(),
+ agent: Some("claude-code".into()),
+ ..Default::default()
+ }),
+ None,
+ None,
+ None,
+ HeaderMap::new(),
+ Json(serde_json::json!({ "session_id": "empty-state-draft" })),
+ )
+ .await
+ .into_response();
+ let body = axum::body::to_bytes(claude.into_body(), 1024)
+ .await
+ .unwrap();
+ assert_eq!(&body[..], b"queued");
+ }
+
#[tokio::test]
async fn handle_hook_rate_limits_a_flooding_source_but_not_others() {
let tmp = TempDir::new().unwrap();