Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(vibey): claim how a hosted call ran and what it found only once it completed, on every surface (#2584)

Call Whitee37305dab489
diff --git a/core/hosted_activity.py b/core/hosted_activity.py
index 799d10abb..cae4450b8 100644
--- a/core/hosted_activity.py
+++ b/core/hosted_activity.py
@@ -76,6 +76,19 @@ class HostedActivity:
# before that row, as the call happened before the text that reads its result.
response_id: Optional[str] = None
+ @property
+ def completed(self) -> bool:
+ """Whether the call finished: the one gate every surface reads.
+
+ Only a completed call claims how it ran (its mode, who ran it, how long it
+ took) and what it produced (counts, sources, images). A cut-off or failed
+ call shows its status instead. A known cost shows whatever the status:
+ a charge stands whatever happened after it. The Web card reads the same
+ rule from ``hostedCompleted`` (``ui/src/lib/hostedActivity.ts``).
+ """
+
+ return self.status == "completed"
+
def to_payload(self) -> dict[str, Any]:
payload: dict[str, Any] = {
"version": HOSTED_ACTIVITY_VERSION,
@@ -291,25 +304,22 @@ def _cost(activity: HostedActivity, lang: str) -> Optional[str]:
def hosted_line(activity: HostedActivity, lang: str, *, escape: Callable[[str], str] = lambda text: text) -> str:
"""The one-line form IM shows per hosted call.
- ``🔎 Web search "query" · native (xAI) · 6 sources · $0.01``. A failed call
- says why instead of counting results it never had. ``escape`` makes the
- quoted subject safe for the destination's markup.
+ ``🔎 Web search "query" · native (xAI) · 6 sources · $0.01``. A call that did
+ not complete says why instead of how it ran or what it found, and keeps a
+ known cost (``HostedActivity.completed``). ``escape`` makes the quoted
+ subject safe for the destination's markup.
"""
emoji = "🖼" if activity.tool == "image_generation" else "🔎"
- parts = [f"{emoji} {i18n_t(f'hostedTools.tool.{activity.tool}', lang)}"]
+ parts: list[Optional[str]] = [f"{emoji} {i18n_t(f'hostedTools.tool.{activity.tool}', lang)}"]
if activity.subject:
parts[0] += " " + i18n_t("hostedTools.quoted", lang, subject=escape(_clip(activity.subject)))
- if activity.status in ("failed", "incomplete"):
+ if activity.completed:
+ vendor = _vendor_label(activity.provider)
+ if vendor:
+ parts.append(i18n_t(f"hostedTools.mode.{activity.mode}", lang, provider=vendor))
+ parts.append(_count(activity, lang))
+ else:
parts.append(i18n_t(f"hostedTools.status.{activity.status}", lang, error=escape(activity.error or "")))
- return " · ".join(parts)
- vendor = _vendor_label(activity.provider)
- if vendor:
- parts.append(i18n_t(f"hostedTools.mode.{activity.mode}", lang, provider=vendor))
- if activity.status == "pending":
- parts.append(i18n_t("hostedTools.status.pending", lang))
- return " · ".join(parts)
- for part in (_count(activity, lang), _cost(activity, lang)):
- if part:
- parts.append(part)
- return " · ".join(parts)
+ parts.append(_cost(activity, lang))
+ return " · ".join(part for part in parts if part)
diff --git a/modules/agents/vibey/agent.py b/modules/agents/vibey/agent.py
index 5f817edb2..fb1c0376a 100644
--- a/modules/agents/vibey/agent.py
+++ b/modules/agents/vibey/agent.py
@@ -1283,7 +1283,9 @@ class VibeyAgent(BaseAgent):
async def _emit_hosted(self, run: _Run, activity: HostedActivity) -> None:
"""One hosted call: its line for IM and its card for the Web (``core.hosted_activity``)."""
- run.hosted_images.extend((image.path, Path(image.path).name) for image in activity.images)
+ # Only a completed call delivers what it produced, as only its image counts as a reply (``has_reply``).
+ if activity.completed:
+ run.hosted_images.extend((image.path, Path(image.path).name) for image in activity.images)
formatter = self._get_formatter(run.request.context)
line = hosted_line(activity, self._language(), escape=formatter.escape_special_chars)
try:
diff --git a/tests/scenarios/model_hub/catalog.yaml b/tests/scenarios/model_hub/catalog.yaml
index 34f10ee2c..0c594313e 100644
--- a/tests/scenarios/model_hub/catalog.yaml
+++ b/tests/scenarios/model_hub/catalog.yaml
@@ -240,6 +240,17 @@ scenarios:
related_tests:
- tests/test_vibey_agent.py::test_a_native_hosted_call_reaches_the_workbench_as_a_card_and_cited_answer
- tests/test_vibey_agent.py::test_a_proxied_hosted_result_shows_once_its_result_is_committed
+ - id: MH-HOSTED-UI-014
+ name: A hosted call that did not complete shows its status and any known charge, and claims neither how it ran nor what it found, on the IM line, the Web card (collapsed or expanded) and image delivery alike
+ status: covered
+ kind: contract
+ layer: unit
+ test:
+ - tests/test_hosted_activity.py::test_the_im_line_claims_how_a_call_ran_and_what_it_found_only_once_it_completed
+ - tests/test_vibey_agent.py::test_an_image_from_a_call_that_did_not_complete_is_not_delivered
+ - ui/src/components/workbench/HostedToolRow.test.tsx::MH-HOSTED-UI-014 (pending)
+ - ui/src/components/workbench/HostedToolRow.test.tsx::MH-HOSTED-UI-014 (failed)
+ - ui/src/components/workbench/HostedToolRow.test.tsx::MH-HOSTED-UI-014 (incomplete)
- id: MH-HOSTED-VIBEY-001
name: Vibey declares a hop's native hosted tool verbatim with its include values and pins that request to the hop's Source; the probe builds the same request
status: covered
diff --git a/tests/test_hosted_activity.py b/tests/test_hosted_activity.py
index 60c23b558..0f1abe6fc 100644
--- a/tests/test_hosted_activity.py
+++ b/tests/test_hosted_activity.py
@@ -58,12 +58,14 @@ def _native(source_id: str) -> HostedNative:
return HostedNative(source_id=source_id, payload=({"type": "provider_item"},))
-def _search(call_id: str, *queries: str, sources=(), source_id="src_relayclaude") -> HostedToolBlock:
+def _search(
+ call_id: str, *queries: str, sources=(), source_id="src_relayclaude", status="completed", error=None
+) -> HostedToolBlock:
return HostedToolBlock(
id=call_id,
tool="web_search",
action=HostedAction(type="search", queries=tuple(queries)),
- record=HostedRecord(status="completed", sources=tuple(sources)),
+ record=HostedRecord(status=status, error=error, sources=tuple(sources)),
native=_native(source_id),
)
@@ -209,6 +211,30 @@ def test_the_im_line_states_tool_query_mode_count_and_known_cost(build, lang, li
assert hosted_line(build(), lang) == line
+ ("status", "error", "line"),
+ [
+ ("completed", None, "🔎 Web search “OpenAI news” · native (Anthropic) · 2 sources · ≈ $0.01"),
+ ("pending", None, "🔎 Web search “OpenAI news” · cut off · ≈ $0.01"),
+ ("failed", "upstream timeout", "🔎 Web search “OpenAI news” · failed: upstream timeout · ≈ $0.01"),
+ ("incomplete", "response ended", "🔎 Web search “OpenAI news” · incomplete: response ended · ≈ $0.01"),
+ ],
+)
+def test_the_im_line_claims_how_a_call_ran_and_what_it_found_only_once_it_completed(status, error, line):
+ """MH-HOSTED-UI-014: a call that did not complete shows its status instead, and its known charge still shows.
+
+ The same records the Web card renders (``HostedToolRow.test.tsx`` reads the rule from ``hostedCompleted``).
+ """
+
+ [activity] = native_activities(
+ _message(
+ _search("srvtoolu_01", "OpenAI news", sources=(DEVDAY, CHANGELOG), status=status, error=error),
+ summary=HostedSummary(cost=HostedCost(basis="list", usd=0.01)),
+ )
+ )
+ assert hosted_line(activity, "en") == line
+
+
def test_the_im_line_names_a_subscription_and_a_shared_response_cost():
included = proxy_activity(
_x_call("call_x3", "from:xai within_time:3d"),
diff --git a/tests/test_vibey_agent.py b/tests/test_vibey_agent.py
index 919df3c48..5cf299cf1 100644
--- a/tests/test_vibey_agent.py
+++ b/tests/test_vibey_agent.py
@@ -3641,3 +3641,34 @@ async def test_an_image_only_final_is_a_reply_and_reaches_the_user(engine, sessi
assert result["content_text"].startswith(i18n_t("info.generatedImagesFallback", "en"))
assert not any(i18n_t("vibeyAgent.error.emptyResponse", "en") in item for item in harness.controller.im_client.sent)
+
+async def test_an_image_from_a_call_that_did_not_complete_is_not_delivered(engine, session, tmp_path, published) -> None:
+ """MH-HOSTED-UI-014: delivery follows the card and ``has_reply``: a call that did not complete shows no image."""
+ image = tmp_path / "partial.png"
+ image.write_bytes(b"\x89PNG\r\n\x1a\npartial")
+ final = AssistantMessage(
+ (
+ HostedToolBlock(
+ id="ig_2",
+ tool="image_generation",
+ action=HostedAction(type="generate", prompt="a laptop at night"),
+ record=HostedRecord(
+ status="incomplete",
+ error="the provider stopped the image",
+ images=(HostedImage(path=str(image), mime="image/png"),),
+ ),
+ native=HostedNative(source_id="src_testsrc1", payload=({"type": "image_generation_call"},)),
+ ),
+ TextBlock(text="The image could not be finished."),
+ ),
+ ORIGIN,
+ "stop",
+ hosted_summary=HostedSummary(),
+ )
+ harness = _Harness(engine, tmp_path, "telegram", [[Done(final)]])
+
+ await harness.agent.handle_message(harness.request("draw a laptop at night"))
+
+ assert harness.controller.terminals[-1]["is_error"] is False
+ assert harness.controller.im_client.uploads == []
+
diff --git a/ui/src/components/workbench/HostedToolRow.test.tsx b/ui/src/components/workbench/HostedToolRow.test.tsx
index 2c3eafc97..54b7ef85d 100644
--- a/ui/src/components/workbench/HostedToolRow.test.tsx
+++ b/ui/src/components/workbench/HostedToolRow.test.tsx
@@ -99,11 +99,24 @@ describe('hosted tool cards', () => {
within(figure).getByText(fixture.native_image.revised_prompt);
});
- it('shows a call cut off with its turn as cut off, never as having run', () => {
- renderGroup([{ ...fixture.native_web_search, status: 'pending', cost: undefined }]);
- const pending = row('srvtoolu_01');
- within(pending).getByText('Cut off');
- expect(within(pending).queryByText('Native · Anthropic')).toBeNull();
+ it.each([
+ ['pending', undefined, 'Cut off'],
+ ['failed', 'upstream timeout', 'Failed'],
+ ['incomplete', 'response ended', 'Incomplete'],
+ ] as const)('MH-HOSTED-UI-014 (%s): shows its status and known charge, collapsed or expanded, never how it ran or what it found', (status, error, label) => {
+ renderGroup([{ ...fixture.native_web_search, status, error }]);
+ const card = row('srvtoolu_01');
+ within(card).getByText(label);
+ within(card).getByText('≈ $0.01');
+ expect(within(card).queryByText('Native · Anthropic')).toBeNull();
+ expect(within(card).queryByText('2 sources')).toBeNull();
+
+ // Expanding it must not bring the claims back.
+ fireEvent.click(within(card).getByRole('button'));
+ expect(card.textContent).not.toMatch(/Ran natively|took \d+ s/);
+ expect(within(card).queryByRole('link')).toBeNull();
+ within(card).getAllByText('≈ $0.01');
+ if (error) within(card).getByText(error);
});
it('keeps the plain tool line for a row whose card this client cannot read', () => {
diff --git a/ui/src/components/workbench/HostedToolRow.tsx b/ui/src/components/workbench/HostedToolRow.tsx
index a76222920..9b20cf3d0 100644
--- a/ui/src/components/workbench/HostedToolRow.tsx
+++ b/ui/src/components/workbench/HostedToolRow.tsx
@@ -9,7 +9,7 @@ import clsx from 'clsx';
import { ChatImage } from '../ui/chat-image';
import { apiKeyVendorPreset } from '../settings/models/apiKeyVendors';
-import type { HostedActivity, HostedActivityImage, HostedToolName } from '../../lib/hostedActivity';
+import { hostedCompleted, type HostedActivity, type HostedActivityImage, type HostedToolName } from '../../lib/hostedActivity';
const TOOL_ICON: Record<HostedToolName, React.ComponentType<{ className?: string }>> = {
web_search: Globe,
@@ -54,24 +54,21 @@ const useHostedCost = (card: HostedActivity): string | null => {
return cost.calls > 1 ? t('chat.agentActivity.hosted.cost.calls', { cost: figure, count: cost.calls }) : figure;
};
-/** 「原生 · Anthropic」 or 「由 xAI 代理」, and the failure state when it failed. */
+/** 「原生 · Anthropic」 or 「由 xAI 代理」 once it completed; until then, its status. */
export const HostedModeChip: React.FC<{ card: HostedActivity }> = ({ card }) => {
const { t } = useTranslation();
- if (card.status === 'failed' || card.status === 'incomplete') {
- return (
- <span className="inline-flex shrink-0 items-center gap-1 rounded-full border border-destructive/40 bg-destructive/10 px-2 py-px text-[11px] font-medium text-destructive-ink">
- <TriangleAlert className="size-3" aria-hidden="true" />
- {t(`chat.agentActivity.hosted.status.${card.status}`)}
- </span>
- );
- }
- if (card.status === 'pending') {
- // Cut off with its turn: it never finished, so it claims no way of having run.
- return (
+ if (!hostedCompleted(card)) {
+ // It did not finish, so it claims no way of having run: cut off with its turn, or failed.
+ return card.status === 'pending' ? (
<span className="inline-flex shrink-0 items-center gap-1 rounded-full border border-gold/40 bg-gold/10 px-2 py-px text-[11px] font-medium text-gold-ink">
<CircleSlash className="size-3" aria-hidden="true" />
{t('chat.agentActivity.hosted.status.pending')}
</span>
+ ) : (
+ <span className="inline-flex shrink-0 items-center gap-1 rounded-full border border-destructive/40 bg-destructive/10 px-2 py-px text-[11px] font-medium text-destructive-ink">
+ <TriangleAlert className="size-3" aria-hidden="true" />
+ {t(`chat.agentActivity.hosted.status.${card.status === 'incomplete' ? 'incomplete' : 'failed'}`)}
+ </span>
);
}
const vendor = vendorLabel(card.provider);
@@ -92,6 +89,7 @@ export const HostedModeChip: React.FC<{ card: HostedActivity }> = ({ card }) =>
/** What the row counts ("1 image · 1536×1024", "2 posts"), when there is anything to count. */
const useCountLabel = (card: HostedActivity): string | null => {
const { t } = useTranslation();
+ if (!hostedCompleted(card)) return null;
if (card.tool === 'image_generation') {
if (card.images.length === 0) return null;
const [first] = card.images;
@@ -142,17 +140,20 @@ export const HostedImageFigure: React.FC<{ card: HostedActivity; image: HostedAc
const HostedDetail: React.FC<{ card: HostedActivity }> = ({ card }) => {
const { t } = useTranslation();
const cost = useHostedCost(card);
- const where = [card.source_name ?? vendorLabel(card.provider), card.model].filter(Boolean).join(' · ');
+ const completed = hostedCompleted(card);
+ const where = completed ? [card.source_name ?? vendorLabel(card.provider), card.model].filter(Boolean).join(' · ') : '';
const facts = [
where && t(card.mode === 'proxy' ? 'chat.agentActivity.hosted.ranProxy' : 'chat.agentActivity.hosted.ranNative', { where }),
- card.duration_ms !== undefined && t('chat.agentActivity.hosted.duration', { seconds: Math.max(1, Math.round(card.duration_ms / 1000)) }),
+ completed && card.duration_ms !== undefined && t('chat.agentActivity.hosted.duration', { seconds: Math.max(1, Math.round(card.duration_ms / 1000)) }),
cost,
].filter(Boolean);
return (
<div className="mx-1.5 mb-1 mt-0.5 flex flex-col overflow-hidden rounded-md border border-border bg-foreground/[0.03]">
{facts.length > 0 && (
<div className="flex items-center gap-1.5 border-b border-border px-2.5 py-1.5 text-[11px] text-muted">
- {card.mode === 'proxy' ? <Waypoints className="size-3 shrink-0 text-cyan-ink" aria-hidden="true" /> : <Check className="size-3 shrink-0 text-mint-ink" aria-hidden="true" />}
+ {completed && (card.mode === 'proxy'
+ ? <Waypoints className="size-3 shrink-0 text-cyan-ink" aria-hidden="true" />
+ : <Check className="size-3 shrink-0 text-mint-ink" aria-hidden="true" />)}
<span className="min-w-0">{facts.join(' · ')}</span>
</div>
)}
@@ -164,7 +165,7 @@ const HostedDetail: React.FC<{ card: HostedActivity }> = ({ card }) => {
{t('chat.agentActivity.hosted.alsoSearched', { queries: card.extra_queries.join(' · ') })}
</p>
)}
- {card.sources.length > 0 && (
+ {completed && card.sources.length > 0 && (
<ol className="flex flex-col">
{card.sources.map((source, index) => (
<li key={`${source.url}:${index}`} className="flex gap-2.5 border-b border-border px-2.5 py-2 last:border-b-0">
@@ -180,7 +181,7 @@ const HostedDetail: React.FC<{ card: HostedActivity }> = ({ card }) => {
))}
</ol>
)}
- {card.images.map((image) => (
+ {completed && card.images.map((image) => (
<div key={image.path} className="p-2"><HostedImageFigure card={card} image={image} /></div>
))}
</div>
@@ -208,7 +209,7 @@ export const HostedToolRow: React.FC<{ card: HostedActivity }> = ({ card }) => {
? <span className="min-w-0 flex-1 truncate"><span className="rounded-md border border-border bg-foreground/[0.03] px-1.5 py-px text-[12px] text-foreground/90" title={card.subject}>{card.subject}</span></span>
: <span className="min-w-0 flex-1" />}
<HostedModeChip card={card} />
- {cost && card.status === 'completed' && <span className="shrink-0 text-[11px] text-muted">{cost}</span>}
+ {cost && <span className="shrink-0 text-[11px] text-muted">{cost}</span>}
{count && <span className="hidden shrink-0 text-[11px] text-muted sm:inline">{count}</span>}
<ChevronRight className={clsx('size-3.5 shrink-0 text-muted transition-transform', open && 'rotate-90')} aria-hidden="true" />
</button>
diff --git a/ui/src/lib/hostedActivity.ts b/ui/src/lib/hostedActivity.ts
index c80cea210..978783e5e 100644
--- a/ui/src/lib/hostedActivity.ts
+++ b/ui/src/lib/hostedActivity.ts
@@ -66,6 +66,15 @@ export const hostedActivityFrom = (raw: unknown): HostedActivity | undefined =>
};
};
+/**
+ * Whether the call finished: the one gate every surface reads. Only a completed
+ * call claims how it ran (its mode, who ran it, how long it took) and what it
+ * produced (counts, sources, images); a cut-off or failed call shows its status
+ * instead. A known cost shows whatever the status: a charge stands whatever
+ * happened after it. The IM line reads the same rule (`HostedActivity.completed`).
+ */
+export const hostedCompleted = (card: HostedActivity): boolean => card.status === 'completed';
+
/** The media token of a proxy URL (``/api/media/<token>?w=&h=``), which joins a card's image to the answer's. */
export const mediaToken = (url: string | undefined): string | null => {
if (!url) return null;