Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(ai): timeouts, prompt, throbber (#1828)

Eric Hayes0bfe3905dab1
diff --git a/.claude/skills/debug-service/SKILL.md b/.claude/skills/debug-service/SKILL.md
new file mode 100644
index 0000000000..c22213386e
--- /dev/null
+++ b/.claude/skills/debug-service/SKILL.md
@@ -0,0 +1,10 @@
+You are going to help me interactively debug the rust binary
+that's in this crate.
+
+Use this command to start the service with debug logging
+
+RUST_LOG=<name_of_bin>=debug,info
+ just run > /tmp/<name_of_bin>.log 2>&1 & tail -f /tmp/<name_of_bin>.log
+
+Use the log tail to answer questions as appropriate
+
diff --git a/js/app/packages/core/component/AI/component/message/ChatMessages.tsx b/js/app/packages/core/component/AI/component/message/ChatMessages.tsx
index cbbe460e3d..3a629c02a1 100644
--- a/js/app/packages/core/component/AI/component/message/ChatMessages.tsx
+++ b/js/app/packages/core/component/AI/component/message/ChatMessages.tsx
@@ -141,19 +141,6 @@ export function ChatMessages(props: ChatMessagesProps) {
return message;
};
- const generatingAfterToolCall = () => {
- const streamAccessor = streamTuple?.[0];
- if (!streamAccessor) return;
- const stream = streamAccessor();
- if (!stream || stream.isDone()) return;
- const message = asChatMessage(stream.data());
- if (!message || typeof message.content === 'string') return;
- const last = message.content.at(-1);
- if (!last) return;
- if (last.type === 'toolCallResponseJson') return true;
- return;
- };
-
const isStream = () => {
const streamSignal = streamTuple?.[0];
if (!streamSignal) return false;
@@ -391,12 +378,7 @@ export function ChatMessages(props: ChatMessagesProps) {
);
}}
</Show>
- {/* this works for most cases */}
- <Show
- when={
- !generatingMessage() && (isStream() || chat.waitingForStream())
- }
- >
+ <Show when={isStream() || chat.waitingForStream()}>
<OnMount
onShow={() =>
scrollToBottom(isNearBottom() ? 'instant' : 'smooth')
@@ -405,12 +387,6 @@ export function ChatMessages(props: ChatMessagesProps) {
<PulsingStar kind="streamIndicator" animate />
</OnMount>
</Show>
- {/*
- This shows a spinner after a tool call
- */}
- <Show when={generatingAfterToolCall()}>
- <PulsingStar kind="streamIndicator" animate />
- </Show>
</div>
</Show>
</div>
diff --git a/rust/cloud-storage/ai/src/prompts/mod.rs b/rust/cloud-storage/ai/src/prompts/mod.rs
index d7bf33c503..4c49b4a2d3 100644
--- a/rust/cloud-storage/ai/src/prompts/mod.rs
+++ b/rust/cloud-storage/ai/src/prompts/mod.rs
@@ -1,4 +1,4 @@
//! Default prompts for the AI crate.
/// Base prompt for AI interactions.
-pub const BASE_PROMPT: &str = include_str!("base.md");
+pub const CLI_PROMPT: &str = include_str!("base.md");
diff --git a/rust/cloud-storage/ai/src/tool/tool_loop/cli.rs b/rust/cloud-storage/ai/src/tool/tool_loop/cli.rs
index 6438c7f5c9..32ca6a9982 100644
--- a/rust/cloud-storage/ai/src/tool/tool_loop/cli.rs
+++ b/rust/cloud-storage/ai/src/tool/tool_loop/cli.rs
@@ -44,7 +44,7 @@
//! }
//! ```
-use crate::prompts::BASE_PROMPT;
+use crate::prompts::CLI_PROMPT;
use crate::tool::ToolLoop;
use crate::tool::types::{AsyncToolSet, RequestContext, StreamPart, ToolResponse};
use crate::types::{ChatMessage, MessageBuilder, Model, RequestBuilder, Role};
@@ -74,7 +74,7 @@ impl Default for Cli<(), fn() -> RequestContext> {
Self {
toolset: AsyncToolSet::new(),
service_context: (),
- system_prompt: BASE_PROMPT.to_string(),
+ system_prompt: CLI_PROMPT.to_string(),
model: Model::Claude45Opus,
#[allow(deprecated)]
request_context_fn: || RequestContext {
diff --git a/rust/cloud-storage/ai_tools/src/prompts/all_tools.md b/rust/cloud-storage/ai_tools/src/prompts/all_tools.md
index 4c334efcde..447885506c 100644
--- a/rust/cloud-storage/ai_tools/src/prompts/all_tools.md
+++ b/rust/cloud-storage/ai_tools/src/prompts/all_tools.md
@@ -1,9 +1,12 @@
# Tone and Style
-- Be correctness-obsessed, precise, and confident.
+- Be precise, and confident.
- Use a casual, natural tone, but avoid hedging (no “maybe”, “perhaps”).
- Do not be whiny. Do not use the word “however.”
- Always use Markdown for formatting.
+- Write casual, test-message style pros
+- Avoid using formal formatting like bullet points, tables, and headings
+- Use short paragraphs
---
@@ -119,6 +122,11 @@ If no inline or node ids are present:
using mentions. Use the above mention format. Always use a mention if the tool
returns anything relavent. IMPORTANT
+- IMPORTANT: The code execution tools (`bash_code_execution`, and `text_editor_code_execution`) should only be used
+when the user asks you to _execute_ code or asks you to do a task that is best done with code ie compute std dev,
+draw a chart, create a pdf, or some other task that can't be completed with any other tool. DO NOT confuse `text_editor_code_execution` tool
+(which creates a file for the code execution environment) for the `CreateDocument` tool which creates a document in the
+users workspace. If the user asks you to create a document, write a code file, or create any file you should use the `CreateDocument` tool.
## Tool usage patterns:
diff --git a/rust/cloud-storage/document_cognition_service/src/api/stream/chat_message.rs b/rust/cloud-storage/document_cognition_service/src/api/stream/chat_message.rs
index 1292fb1f1d..74ac8710b0 100644
--- a/rust/cloud-storage/document_cognition_service/src/api/stream/chat_message.rs
+++ b/rust/cloud-storage/document_cognition_service/src/api/stream/chat_message.rs
@@ -397,8 +397,21 @@ fn stream_and_save_message(
};
let mut is_first_token = false;
+ let idle_timeout = std::time::Duration::from_secs(3 * 60);
- while let Some(response) = ai_stream.next().await {
+ while let Some(response) = match tokio::time::timeout(idle_timeout, ai_stream.next()).await {
+ Ok(item) => item,
+ Err(_) => {
+ tracing::error!("AI stream idle timeout: no token received within {idle_timeout:?}");
+ let stream_error = StreamError::InternalError {
+ stream_id: stream_id.clone(),
+ };
+ if let Ok(json) = serde_json::to_value(&stream_error) {
+ yield json;
+ }
+ None
+ }
+ } {
tracing::trace!("{:#?}", response);
// Log time to first token
@@ -523,6 +536,6 @@ fn stream_and_save_message(
ctx_outer.stream_repo.clone().from_async_stream(
durable_stream_id,
Box::pin(payload_stream),
- None,
+ Some(std::time::Duration::from_secs(30 * 60)),
);
}