Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions crates/goose/src/acp/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2356,22 +2356,14 @@ impl GooseAcpAgent {

let run_id = format!("run_{}", Uuid::new_v4());
let cancel_token = CancellationToken::new();
let agent = self.get_session_agent(&session_id, None).await?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Register prompt cancellation before agent activation

In the desktop ACP path, sessions are loaded via the existing resumeAgent flow and the first client.prompt can reach this lazy get_session_agent activation before start_active_run stores the cancel_token. If the user presses Stop while that activation is still loading the agent/extensions, on_cancel has no token/session run to cancel, so the prompt continues as soon as activation finishes. Register the run or otherwise store the cancellation token before the awaitable activation work.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is planned to handle in a separate PR

self.start_active_run(&session_id, run_id.clone(), cancel_token.clone())
.await?;
if let Err(error) = Self::send_active_run_update(cx, &args.session_id, Some(&run_id)) {
self.clear_active_run(&session_id, &run_id).await;
return Err(error);
}

let agent = match self.get_session_agent(&session_id, None).await {
Ok(agent) => agent,
Err(error) => {
self.clear_active_run(&session_id, &run_id).await;
let _ = Self::send_active_run_update(cx, &args.session_id, None);
return Err(error);
}
};

let user_message = Self::convert_acp_prompt_to_message(&args.prompt);

let message_text = user_message.as_concat_text();
Expand Down
48 changes: 48 additions & 0 deletions ui/desktop/src/acp/__tests__/errors.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { describe, expect, it } from 'vitest';
import { parseAcpCreditsExhaustedError } from '../errors';

describe('parseAcpCreditsExhaustedError', () => {
it('parses structured ACP credits exhausted errors', () => {
expect(
parseAcpCreditsExhaustedError({
code: -32603,
message: 'Please add credits to your account, then resend your message to continue.',
data: {
reason: 'credits_exhausted',
url: 'https://router.tetrate.ai/billing',
},
})
).toEqual({
message: 'Please add credits to your account, then resend your message to continue.',
url: 'https://router.tetrate.ai/billing',
});
});

it('parses wrapped JSON-RPC errors', () => {
expect(
parseAcpCreditsExhaustedError({
error: {
code: -32603,
message: 'Add credits to continue.',
data: {
reason: 'credits_exhausted',
},
},
})
).toEqual({
message: 'Add credits to continue.',
});
});

it('ignores non-credits-exhausted errors', () => {
expect(
parseAcpCreditsExhaustedError({
code: -32603,
message: 'Something failed.',
data: {
reason: 'provider_error',
},
})
).toBeNull();
});
});
42 changes: 42 additions & 0 deletions ui/desktop/src/acp/__tests__/prompt.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { describe, expect, it } from 'vitest';
import type { Message } from '../../api';
import { messageToAcpPromptContent } from '../prompt';

describe('messageToAcpPromptContent', () => {
it('converts text and image content into ACP prompt blocks', () => {
const message: Message = {
id: 'message-1',
role: 'user',
created: 123,
content: [
{ type: 'text', text: 'Describe this' },
{ type: 'image', data: 'abc123', mimeType: 'image/png' },
],
metadata: { userVisible: true, agentVisible: true },
};

expect(messageToAcpPromptContent(message)).toEqual([
{ type: 'text', text: 'Describe this' },
{ type: 'image', data: 'abc123', mimeType: 'image/png' },
]);
});

it('omits empty text content and unsupported content blocks', () => {
const message: Message = {
id: 'message-1',
role: 'user',
created: 123,
content: [
{ type: 'text', text: ' ' },
{
type: 'toolResponse',
id: 'tool-1',
toolResult: { status: 'success', value: [] },
},
],
metadata: { userVisible: true, agentVisible: true },
} as Message;

expect(messageToAcpPromptContent(message)).toEqual([]);
});
});
Loading
Loading