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(hosted): close four hosted activity edges from the #2573 review (#2821)

Call Whiteb20c34cf4ee4
diff --git a/core/agent_core/agent/loop.py b/core/agent_core/agent/loop.py
index d0ead7639..781925f9d 100644
--- a/core/agent_core/agent/loop.py
+++ b/core/agent_core/agent/loop.py
@@ -136,6 +136,7 @@ from core.agent_core.messages import (
Usage,
UserMessage,
has_reply,
+ image_deliverable,
message_to_dict,
text,
usage_to_dict,
@@ -1307,7 +1308,8 @@ class Agent:
# The committed result, which a settlement race may have taken from another writer, not this execution's.
committed = row.message.hosted if isinstance(row.message, ToolResultMessage) else None
if committed is not None and committed.record.status == "completed":
- self._generated_images.extend(committed.record.images or ())
+ # Only an image a surface can deliver counts toward the reply, and is carried with it.
+ self._generated_images.extend(image for image in committed.record.images or () if image_deliverable(image))
await emit(
ToolFinished,
tool_call_id=call.id,
diff --git a/core/agent_core/messages.py b/core/agent_core/messages.py
index 051065e17..3f25b3fd5 100644
--- a/core/agent_core/messages.py
+++ b/core/agent_core/messages.py
@@ -9,6 +9,7 @@ rows, so the field names here are a shipped surface.
from __future__ import annotations
import copy
+import os
import re
from dataclasses import dataclass, field
from typing import Any, Literal, Mapping, Optional, Union
@@ -361,6 +362,17 @@ class HostedImage:
raise ValueError(f"image {name} is at least 1")
+def image_deliverable(image: HostedImage) -> bool:
+ """Whether a surface can send this generated image: its path names a file absolutely. A relative path, from a
+ restored or foreign record, names no file anyone can attach.
+
+ The one rule for both decisions a generated image takes part in: whether the turn's final response counts as a
+ reply (``has_reply``), and which images are delivered with it. Kept in one place so a reply is never counted for
+ an image delivery then skips.
+ """
+ return os.path.isabs(image.path)
+
+
@dataclass(frozen=True)
class HostedRecord:
"""Per-call facts. ``images`` is set exactly for ``image_generate`` (possibly empty).
diff --git a/core/citations.py b/core/citations.py
index aafe1d08e..31a9b8b26 100644
--- a/core/citations.py
+++ b/core/citations.py
@@ -1095,6 +1095,14 @@ def register_text_citations(
blocks - and a citation whose place it removed, or that falls in code, is
left out rather than written as a stray marker.
"""
+ blocks = list(blocks)
+ # Each ref this call inserts carries a nonce the text does not contain, so no marker the text itself
+ # carries (a literal one in a code example, say) can name an annotation's ref, at registration or at
+ # cleanup.
+ arrived = "".join(separator + text for separator, text, _ in blocks)
+ nonce = secrets.token_hex(_TOKEN_NONCE_BYTES)
+ while nonce in arrived:
+ nonce = secrets.token_hex(_TOKEN_NONCE_BYTES)
sources: dict[str, CitationSource] = {}
joined = ""
for block_index, (separator, text, citations) in enumerate(blocks):
@@ -1104,7 +1112,7 @@ def register_text_citations(
if not transform(text).strip():
citations = ()
for citation_index, citation in enumerate(citations or ()):
- ref = f"t{block_index}c{citation_index}"
+ ref = f"{nonce}:t{block_index}c{citation_index}"
sources[ref] = CitationSource(ref_id=ref, title=citation.title or "", url=citation.url)
end = len(text) if citation.end is None else min(max(citation.end, 0), len(text))
at.setdefault(end, []).append(ref)
@@ -1118,7 +1126,14 @@ def register_text_citations(
if not sources:
return joined, None
registered, bundle = register_citations(joined, sources, unresolved_label=unresolved_label)
- return CITATION_MARKER_RE.sub("", registered or ""), bundle
+ # Only the markers inserted here for annotations whose place was left out (in code, or removed by the
+ # display rules) go: only they name this call's refs. A marker the text itself carries, such as a literal
+ # one in a code example that registration deliberately left alone, stays as written.
+ def drop_synthetic(match: re.Match[str]) -> str:
+ refs = [ref for ref in match.group(1).split(_SEP) if ref]
+ return "" if refs and all(ref in sources for ref in refs) else match.group(0)
+
+ return CITATION_MARKER_RE.sub(drop_synthetic, registered or ""), bundle
def materialize_citations(
diff --git a/core/hosted_activity.py b/core/hosted_activity.py
index 6d4cd397f..33ff84ccc 100644
--- a/core/hosted_activity.py
+++ b/core/hosted_activity.py
@@ -31,6 +31,7 @@ from core.agent_core.messages import (
ProxyExecution,
ToolCallBlock,
)
+from core.citations import safe_url
from core.message_output import plain_untrusted_text
from vibe.i18n import t as i18n_t
@@ -148,11 +149,16 @@ class HostedActivity:
def _source_payload(source: HostedSource) -> dict[str, Any]:
- out: dict[str, Any] = {"url": source.url}
+ """A source as the card links it: only a URL a browser should open, held to the rule citation links are
+ (``safe_url``). Any other string a provider gave stays readable as the source's title, never a link."""
+ url = safe_url(source.url)
+ out: dict[str, Any] = {"url": url} if url else {}
for name in ("title", "snippet", "page_age"):
value = getattr(source, name)
if value:
out[name] = value
+ if not url and not source.title:
+ out["title"] = source.url
return out
diff --git a/core/message_mirror.py b/core/message_mirror.py
index 0c4586fa8..db91d033d 100644
--- a/core/message_mirror.py
+++ b/core/message_mirror.py
@@ -233,6 +233,7 @@ def _hosted_card(conn, context: MessageContext, hosted: dict, *, scope_id, sessi
images = hosted.get("images") if isinstance(hosted.get("images"), list) else []
if context.platform != "avibe" or not session_id or not images:
return hosted
+ from core.agent_core.messages import IMAGE_MIME_TYPES
from core.workbench_media import register_agent_reply_media
from storage import media_service
@@ -245,6 +246,7 @@ def _hosted_card(conn, context: MessageContext, hosted: dict, *, scope_id, sessi
try:
# Canonical, as the transcript's rewrite registers it, so both share one token.
canonical = str(Path(path).resolve())
+ mime = image.get("mime")
token = register_agent_reply_media(
conn,
scope_id=scope_id,
@@ -252,6 +254,8 @@ def _hosted_card(conn, context: MessageContext, hosted: dict, *, scope_id, sessi
kind="image",
local_path=canonical,
file_name=os.path.basename(canonical),
+ # The record names the image's type; a path need not carry a suffix that says it.
+ content_type=mime if mime in IMAGE_MIME_TYPES else None,
)
row = media_service.get_by_token(conn, token) or {}
except Exception:
diff --git a/core/workbench_media.py b/core/workbench_media.py
index b7e63ed3e..cd533cf07 100644
--- a/core/workbench_media.py
+++ b/core/workbench_media.py
@@ -264,8 +264,10 @@ def register_agent_reply_media(
kind: str,
local_path: str,
file_name: str,
+ content_type: str | None = None,
) -> str:
- """Register a local agent-reply file under the shared media proxy."""
+ """Register a local agent-reply file under the shared media proxy. ``content_type`` is a type the producer
+ knows; without one, the path's suffix decides."""
return media_service.register(
conn,
scope_id=scope_id,
@@ -274,6 +276,7 @@ def register_agent_reply_media(
source="agent_reply",
local_path=local_path,
file_name=file_name,
+ content_type=content_type,
)
diff --git a/modules/agents/vibey/agent.py b/modules/agents/vibey/agent.py
index d4b458a34..0d7d34319 100644
--- a/modules/agents/vibey/agent.py
+++ b/modules/agents/vibey/agent.py
@@ -70,6 +70,7 @@ from core.agent_core.messages import (
ToolResultMessage,
UserMessage,
has_reply,
+ image_deliverable,
message_from_dict,
text as text_block,
)
@@ -1463,7 +1464,9 @@ class VibeyAgent(BaseAgent):
"""One hosted call: its line for IM and its card for the Web (``core.hosted_activity``)."""
# 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)
+ run.hosted_images.extend(
+ (image.path, Path(image.path).name) for image in activity.images if image_deliverable(image)
+ )
formatter = self._get_formatter(run.request.context)
line = hosted_line(activity, self._language(), escape=formatter.escape_special_chars)
try:
diff --git a/tests/agent_core/agent/test_loop.py b/tests/agent_core/agent/test_loop.py
index 4205b1fe3..0dde9b6f1 100644
--- a/tests/agent_core/agent/test_loop.py
+++ b/tests/agent_core/agent/test_loop.py
@@ -186,6 +186,35 @@ async def test_resume_preserves_images_committed_by_an_earlier_tool_call():
assert agent._generated_images == [HostedImage(path="/media/winner.png", mime="image/png")]
+ ("path", "reason"),
+ [("/media/winner.png", "completed"), ("media/winner.png", "error")],
+ ids=["deliverable", "relative-path"],
+)
+async def test_only_an_image_a_surface_can_deliver_makes_a_silent_final_a_reply(path, reason):
+ """MH-HOSTED-UI-012: a final that says nothing after an image call is a reply only if the image can be delivered.
+ A relative path names no file a surface can attach, so counting it would end the turn as a success with nothing
+ delivered; it is the empty-reply error instead (``image_deliverable``, shared with delivery)."""
+ from core.agent_core.messages import HostedResult, ProxyExecution
+
+ hosted = HostedResult(
+ HostedRecord(status="completed", images=(HostedImage(path=path, mime="image/png"),)),
+ ProxyExecution(ORIGIN, "src_executor01", "metered", mode="direct"),
+ )
+ tool = FakeTool("image_generate", result=ToolResult((text("saved"),), hosted=hosted))
+ provider = ScriptedProvider(
+ [
+ [Done(assistant("", calls=[ToolCallBlock("call_img", "image_generate", {})]))],
+ [Done(assistant(""))],
+ ]
+ )
+ agent = make_agent(provider, tools=[tool])
+
+ events = await collect(agent, value="make an image")
+
+ assert events[-1].reason == reason
+
+
async def test_C1_tool_set_is_captured_per_request_and_unavailable_calls_are_errors():
old, new = FakeTool("old"), FakeTool("new")
entered, release = asyncio.Event(), asyncio.Event()
diff --git a/tests/scenarios/model_hub/catalog.yaml b/tests/scenarios/model_hub/catalog.yaml
index ef49314da..78dab429d 100644
--- a/tests/scenarios/model_hub/catalog.yaml
+++ b/tests/scenarios/model_hub/catalog.yaml
@@ -253,6 +253,7 @@ scenarios:
- 'ui/src/components/workbench/HostedToolRow.test.tsx::MH-HOSTED-UI-008: shows a direct image call by its model and Source, with its size, file and prompt, and no cost when none is known'
- 'ui/src/components/workbench/HostedToolRow.test.tsx::MH-HOSTED-UI-008: shows a total an unpriced attempt left only as a lower bound'
- 'ui/src/components/workbench/HostedToolRow.test.tsx::MH-HOSTED-UI-008: says why a search ran by proxy when the turn''s Source refused it, and how to undo that'
+ - 'ui/src/components/workbench/HostedToolRow.test.tsx::MH-HOSTED-UI-008: names a source without a web URL but links nothing'
- id: MH-HOSTED-UI-009
name: A hosted call's card payload is projected from the canonical C-1 records in the shape the Web renders
status: covered
@@ -261,8 +262,10 @@ scenarios:
test: tests/test_hosted_activity.py::test_payloads_match_the_shape_the_web_card_renders
related_tests:
- tests/test_hosted_activity.py::test_a_response_scoped_summary_is_shown_once
+ - tests/test_hosted_activity.py::test_a_source_no_browser_should_open_is_named_but_not_linked
- tests/test_agent_activity_service.py::test_a_hosted_tool_row_carries_its_card
- tests/test_message_mirror.py::test_a_hosted_card_rides_on_its_toolcall_row_and_its_image_joins_the_answer
+ - tests/test_message_mirror.py::test_a_hosted_image_without_an_image_suffix_is_served_as_its_recorded_type
- id: MH-HOSTED-UI-010
name: IM shows one line per hosted call with tool, query, mode, count and a cost only when known
status: covered
@@ -281,6 +284,7 @@ scenarios:
related_tests:
- tests/test_agent_transcript.py::test_a_final_commits_as_the_loops_reply_decision_says
- tests/agent_core/agent/test_loop.py::test_a_reply_counts_the_images_of_the_tool_result_that_committed_not_the_writer_that_lost
+ - tests/agent_core/agent/test_loop.py::test_only_an_image_a_surface_can_deliver_makes_a_silent_final_a_reply
- id: MH-HOSTED-UI-011
name: Vibey delivers a native hosted call as its IM line and Web card, and its answer with provider citations as links, an answer split into adjacent text blocks reading as written
status: covered
diff --git a/tests/test_citations.py b/tests/test_citations.py
index 2b530a2f0..118e50a01 100644
--- a/tests/test_citations.py
+++ b/tests/test_citations.py
@@ -1585,6 +1585,21 @@ class TestTextBlockCitations:
assert body == "Visible.\n\nRun `vibe status` now."
assert citations == []
+ def test_a_literal_marker_in_code_survives_beside_a_provider_citation(self):
+ """A code example quoting the marker grammar is the reply's own text: only the markers inserted for
+ annotations go, never one the text itself carries."""
+ # The ref this block's first annotation would have, were refs named by position alone.
+ literal = "\ue200cite\ue202t0c0\ue201"
+ text = f"Codex writes `{literal}` for a citation. Filters shipped."
+ registered, bundle = register_text_citations(
+ [("", text, [self.cite(self.FILTERS, "Changelog", len(text) - 1, len(text))])],
+ unresolved_label=UNRESOLVED,
+ )
+ body, citations = finalize_citations(registered, bundle)
+
+ assert f"`{literal}`" in body
+ assert [row["url"] for row in citations] == [self.FILTERS]
+
def test_a_block_the_display_rules_remove_takes_its_citations_with_it(self):
"""An unranged citation sits after its block; when the whole block is silent, nothing is left to cite."""
registered, bundle = register_text_citations(
diff --git a/tests/test_hosted_activity.py b/tests/test_hosted_activity.py
index 1d1aba5d5..08630b561 100644
--- a/tests/test_hosted_activity.py
+++ b/tests/test_hosted_activity.py
@@ -216,6 +216,33 @@ def test_payloads_match_the_shape_the_web_card_renders(build):
assert build().to_payload() == FIXTURE[build.__name__]
+def test_a_source_no_browser_should_open_is_named_but_not_linked():
+ """MH-HOSTED-UI-009: a source URL is linked only if a citation could link it (``safe_url``); any other string a
+ provider gave is kept as the source's name, so the count still matches the IM line."""
+
+ activity = proxy_activity(
+ ToolCallBlock(id="call_w8", name="web_search", arguments={"query": "devday"}),
+ HostedResult(
+ record=HostedRecord(
+ status="completed",
+ sources=(
+ DEVDAY,
+ HostedSource(url="/docs/changelog", title="Responses API changelog"),
+ HostedSource(url="openai.com/index/devday-2026"),
+ ),
+ ),
+ execution=XAI,
+ ),
+ source_names=NAMES,
+ )
+
+ assert activity.to_payload()["sources"] == [
+ {"url": DEVDAY.url, "title": DEVDAY.title, "page_age": DEVDAY.page_age},
+ {"title": "Responses API changelog"},
+ {"title": "openai.com/index/devday-2026"},
+ ]
+
+
def test_a_response_scoped_summary_is_shown_once():
"""The response's cost covers all its calls, and xAI's cited posts belong to its X search."""
diff --git a/tests/test_message_mirror.py b/tests/test_message_mirror.py
index f7a643a14..9c0294026 100644
--- a/tests/test_message_mirror.py
+++ b/tests/test_message_mirror.py
@@ -40,7 +40,7 @@ from core.message_mirror import (
persist_silent_terminal,
)
from modules.im import MessageContext
-from storage import messages_service
+from storage import media_service, messages_service
from storage.agent_session_rows import SESSION_VISIBILITIES
from storage.db import create_sqlite_engine
from storage.importer import ensure_sqlite_state
@@ -1699,6 +1699,47 @@ def test_a_hosted_card_rides_on_its_toolcall_row_and_its_image_joins_the_answer(
assert json.loads(event["metadata_json"])["precedes_message_id"] == "msg_response"
+def test_a_hosted_image_without_an_image_suffix_is_served_as_its_recorded_type(isolated_state, tmp_path):
+ """MH-HOSTED-UI-009: the record's ``mime`` decides the served type, so a suffixless image still renders inline
+ (a guessed ``application/octet-stream`` is served as an attachment the card cannot show)."""
+ image = tmp_path / "image-3f2a"
+ image.write_bytes(b"\x89PNG\r\n\x1a\nimage")
+ engine = create_sqlite_engine()
+ now = "2026-10-14T00:00:00Z"
+ with engine.begin() as conn:
+ scope_id = upsert_scope(conn, platform="avibe", scope_type="project", native_id="proj_hosted", now=now)
+ conn.execute(
+ agent_sessions.insert().values(
+ id="ses_hosted",
+ scope_id=scope_id,
+ agent_name="vibey",
+ agent_backend="vibey",
+ agent_variant="default",
+ session_anchor="anchor_ses_hosted",
+ native_session_id="",
+ status="active",
+ metadata_json="{}",
+ created_at=now,
+ updated_at=now,
+ last_active_at=now,
+ )
+ )
+ ctx = MessageContext(
+ user_id="workbench",
+ channel_id="ses_hosted",
+ platform="avibe",
+ platform_specific={"agent_session_id": "ses_hosted"},
+ )
+
+ persist_agent_message(ctx, "toolcall", "🖼 Image generation · 1 image", hosted=_hosted_card(str(image)))
+
+ with engine.connect() as conn:
+ event = conn.execute(select(agent_events).where(agent_events.c.session_id == "ses_hosted")).mappings().one()
+ [stored] = json.loads(event["content_json"])["hosted"]["images"]
+ row = media_service.get_by_token(conn, stored["media_url"].split("?")[0].removeprefix("/api/media/"))
+ assert row["content_type"] == "image/png"
+
+
def test_an_im_hosted_card_keeps_its_file_paths(isolated_state, tmp_path):
"""Only the Workbench serves media URLs; an IM row stores the card as given."""
ctx = _slack_ctx()
diff --git a/ui/src/components/workbench/HostedToolRow.test.tsx b/ui/src/components/workbench/HostedToolRow.test.tsx
index 3660446c0..ab8c494f8 100644
--- a/ui/src/components/workbench/HostedToolRow.test.tsx
+++ b/ui/src/components/workbench/HostedToolRow.test.tsx
@@ -77,6 +77,18 @@ describe('hosted tool cards', () => {
within(proxy).getByText('x.com · 2 days ago');
});
+ it('MH-HOSTED-UI-008: names a source without a web URL but links nothing', () => {
+ // As the producer sends a source whose URL failed `safe_url`, and as a row stored before it did holds one.
+ renderGroup([{ ...fixture.native_web_search, sources: [{ title: 'openai.com/index/devday-2026' }, { url: '/docs/changelog', title: 'Responses API changelog' }] }]);
+
+ const native = row('srvtoolu_01');
+ within(native).getByText('2 sources');
+ fireEvent.click(within(native).getByRole('button'));
+ within(native).getByText('openai.com/index/devday-2026');
+ within(native).getByText('Responses API changelog');
+ expect(within(native).queryAllByRole('link')).toEqual([]);
+ });
+
it('says why a call failed instead of counting results it never had', () => {
renderGroup(['proxy_failed']);
const failed = row('call_x2');
diff --git a/ui/src/components/workbench/HostedToolRow.tsx b/ui/src/components/workbench/HostedToolRow.tsx
index c4b08831b..3588ec2fe 100644
--- a/ui/src/components/workbench/HostedToolRow.tsx
+++ b/ui/src/components/workbench/HostedToolRow.tsx
@@ -43,6 +43,17 @@ const domainOf = (url: string): string => {
}
};
+/** A source's link, only to a web page. The producer sends only such URLs; rows stored before it did may hold any string. */
+const webUrl = (url: string | undefined): string | undefined => {
+ if (!url) return undefined;
+ try {
+ const { protocol } = new URL(url);
+ return protocol === 'https:' || protocol === 'http:' ? url : undefined;
+ } catch {
+ return undefined;
+ }
+};
+
const fileName = (path: string): string => path.split(/[\\/]/).pop() || path;
const formatBytes = (bytes: number): string =>
@@ -212,18 +223,24 @@ const HostedDetail: React.FC<{ card: HostedActivity }> = ({ card }) => {
)}
{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">
- <span className="mt-px inline-flex size-[18px] shrink-0 items-center justify-center rounded border border-mint/30 bg-mint/[0.08] text-[10px] font-semibold text-mint-ink">{index + 1}</span>
- <span className="flex min-w-0 flex-col gap-0.5">
- <span className="flex min-w-0 flex-wrap items-baseline gap-x-2">
- <a href={source.url} target="_blank" rel="noopener noreferrer" className="min-w-0 truncate text-[12px] font-medium text-foreground hover:underline" title={source.title ?? source.url}>{source.title || domainOf(source.url)}</a>
- <span className="shrink-0 text-[11px] text-muted">{[domainOf(source.url), source.page_age].filter(Boolean).join(' · ')}</span>
+ {card.sources.map((source, index) => {
+ const href = webUrl(source.url);
+ const name = source.title || (href ? domainOf(href) : source.url);
+ return (
+ <li key={`${source.url ?? source.title}:${index}`} className="flex gap-2.5 border-b border-border px-2.5 py-2 last:border-b-0">
+ <span className="mt-px inline-flex size-[18px] shrink-0 items-center justify-center rounded border border-mint/30 bg-mint/[0.08] text-[10px] font-semibold text-mint-ink">{index + 1}</span>
+ <span className="flex min-w-0 flex-col gap-0.5">
+ <span className="flex min-w-0 flex-wrap items-baseline gap-x-2">
+ {href
+ ? <a href={href} target="_blank" rel="noopener noreferrer" className="min-w-0 truncate text-[12px] font-medium text-foreground hover:underline" title={source.title ?? href}>{name}</a>
+ : <span className="min-w-0 truncate text-[12px] font-medium text-foreground" title={name}>{name}</span>}
+ <span className="shrink-0 text-[11px] text-muted">{[href && domainOf(href), source.page_age].filter(Boolean).join(' · ')}</span>
+ </span>
+ {source.snippet && <span className="text-[11px] leading-relaxed text-muted">{source.snippet}</span>}
</span>
- {source.snippet && <span className="text-[11px] leading-relaxed text-muted">{source.snippet}</span>}
- </span>
- </li>
- ))}
+ </li>
+ );
+ })}
</ol>
)}
{completed && card.images.map((image) => (
diff --git a/ui/src/lib/hostedActivity.ts b/ui/src/lib/hostedActivity.ts
index dea648072..455404395 100644
--- a/ui/src/lib/hostedActivity.ts
+++ b/ui/src/lib/hostedActivity.ts
@@ -6,7 +6,8 @@
export type HostedToolName = 'web_search' | 'x_search' | 'image_generate';
export type HostedActivitySource = {
- url: string;
+ /** Only a URL a browser should open; a source without one is named by its title. */
+ url?: string;
title?: string;
snippet?: string;
page_age?: string;
@@ -68,7 +69,7 @@ export const hostedActivityFrom = (raw: unknown): HostedActivity | undefined =>
if (typeof card.status !== 'string' || !STATUSES.includes(card.status)) return undefined;
return {
...(card as unknown as HostedActivity),
- sources: Array.isArray(card.sources) ? (card.sources as HostedActivitySource[]).filter((s) => typeof s?.url === 'string') : [],
+ sources: Array.isArray(card.sources) ? (card.sources as HostedActivitySource[]).filter((s) => typeof s?.url === 'string' || typeof s?.title === 'string') : [],
images: Array.isArray(card.images) ? (card.images as HostedActivityImage[]).filter((i) => typeof i?.path === 'string') : [],
};
};