Skip to content

feat(bots): accept and forward conversation attachments - #469

Merged
nixuuu merged 1 commit into
devfrom
feat/bot-attachments-1
Nov 10, 2026
Merged

nixuuu merged 1 commit into
devfrom
feat/bot-attachments-1

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 10, 2026

Copy link
Copy Markdown
Member

Bot conversations now accept the same files as threads. A bot can read text and PDFs without filesystem tools, then pass selected conversation attachment references to start_thread or send_message. The gateway copies references to the existing blobs and uses the normal thread delivery pipeline.

Forwarding validates the owner, current bot conversation, duplicates and current limits before approval and again during execution. It shares the action's existing approval; the card lists filenames, types and sizes. File copies, thread input, bot attribution, durable confirmation and tool result commit together. The read-only list_attachments tool exposes only sent files in that conversation.

File type Claude Codex Grok
Images Native image parts Native image parts Native image parts; CLI image capability required
UTF-8 text, Markdown, code, JSON, CSV Bounded turn text Bounded turn text Bounded turn text
PDF Native document blocks Extracted text Extracted text
Archives and other binary files Metadata and forwardable references Metadata and forwardable references Metadata and forwardable references

Text is capped at 64,000 characters per file and 128,000 per turn, with truncation notes. PDF extraction reads at most 50 pages, without OCR; unreadable or image-only PDFs retain their original forwardable references. Nonimage bot input requires worker capability bot_files_v1; images retain bot_images_v1. No wire fields or migrations were added.

Web/desktop retain the common picker, paste, drop, chips and previews. Mobile changes are TypeScript only, including ordinary attachment previews under bot-attributed thread input. The bot conversation records “Sent report.md to ‘Thread’”. Forwarding to another linked computer is explicitly refused before approval; users can choose a thread on the bot's computer.

Validation:

  1. bun install, bun run gen:check, bun run typecheck, bun run lint, bun run format:check and the web build pass.
  2. Focused tests pass: bot-files.test.ts (9), bot-composer.test.ts (7), bots-remote.test.ts (7), and the four affected harness adapter/stop files (10). Coverage includes real gateway/worker transport with fake provider CLIs, native versus extracted input, shared blobs and worker paths, ownership/conversation refusal, approval denial and execution-time revalidation, old-worker refusal and linked-target refusal. Multi-gateway files ran separately.
  3. Real-browser check on isolated fixture services: attach MD/PDF/PNG, inspect Markdown/image previews and PDF file controls, fake-harness forwarding, durable bot confirmation, normal thread attachment preview and bot attribution. Checked light/dark at desktop and phone widths, including a long filename. No UI test suite was added.
  4. Requested EAS CLI 27.4.1 production fingerprints equal current dev: iOS 6ddec9ef559ee0095ac33e94ff9418a942053b17; Android 5f6eae3ab278f1cd543e9ed763f923a319b65ec9.

Copy audit (§8): “Attach images” → “Attach files” and “Drop images to attach” → “Drop files to attach”, matching the accepted input. New forwarding confirmation names the file and destination; refusal and limit errors state the problem and next action. Existing file vocabulary, verb-led controls and accessible labels are reused; no new empty state or decorative copy. Short, typical and long filenames were checked on desktop and phone. Long file chips and previews truncate or wrap within the viewport.

Remaining gate: CI runs the full suite, including check:tmp; it was intentionally not run locally. Live provider inference and native mobile device interaction were not exercised.

Related: #449, #398, #421, #429

@nixuuu
nixuuu merged commit 76d814d into dev Nov 10, 2026
9 checks passed
@nixuuu
nixuuu deleted the feat/bot-attachments-1 branch November 10, 2026 07:47
nixuuu added a commit that referenced this pull request Nov 10, 2026
The forwarding integration test can see `FIXTURE_OK` as the last message
after `list_attachments`: finishing the forwarded worker turn schedules
a separate bot follow-up, whose reply can follow the listing response.
CI run 42784104536 attempt 1 failed on that assumption.

Wait for the bot-authored `TOOL_RESULT` containing this attachment ID,
using the existing bounded `eventually` helper. Keep the assertion after
the wait so a missing result still fails. The immediate
forwarding-notice assertion and the blob, worker-path and attribution
checks remain intact.

This is a test race:

- Conversation reads already order messages by the unique
`bot_messages.seq`; equal timestamps do not make the returned order
unstable.
- `forwardedNotice` runs inside the fenced `botAction` transaction,
before the forwarding tool completes. `botQueue.finish` inserts the
answer and settles its turn in one transaction.
- `botDeliveries.deliver` schedules a distinct bot turn when the worker
turn finishes. The scripted CLI replies `FIXTURE_OK` to that
notification. `settled()` can correctly return an idle conversation with
that follow-up as its last message.

Validation:

1. Before: 30 sequential runs of `TMPDIR=/var/tmp bun run check:tmp
tests/integration/bot-files.test.ts`; 29 passed, run 8 reproduced the
exact CI failure (`Received: "FIXTURE_OK"`).
2. After: the same 30 sequential runs all passed (270 test cases). Every
run reported `check:tmp: nothing left in the temp dir`.
3. `bun install`, `bun run typecheck`, `bun run lint`, `bun run
format:check`, and `git diff --check` pass.

Only the requested integration file and allowed static checks were run
locally; the full suite remains for CI. No product, protocol, schema or
UI behavior changes.

Related: #469
nixuuu added a commit that referenced this pull request Nov 10, 2026
Hovering an attachment in the bot composer could briefly flash a preview
and close it while the pointer stayed on the chip. Keep the selected
attachment and anchor stable when pointerover reaches the same chip
again.

Bot and thread composers already use the same `EditorAttachmentPreview`
and `AttachmentPreview`. When loaded content increases the card's
height, the card can briefly cross the pointer before repositioning.
Returning to the chip recreated `selected`, reran the anchor effect and
closed the preview during cleanup. Pointer movement between the chip's
icon and text had the same failure path. The shared component now
updates selection only for a different chip or attachment key. Existing
300 ms open / 180 ms close delays, keyboard focus, Escape, viewers and
motion tokens are preserved.

Validation:

1. `bun install --frozen-lockfile`, `bun run typecheck`, `bun run lint`,
`bun run format`, `bun run format:check`, and `bun run --filter
@canopy/web build` passed. No UI tests were added or run.
2. Real Chromium browser with an isolated gateway, database and scripted
model: Markdown, PDF metadata and PNG previews in the bot composer, sent
messages and actual bot-forwarded thread messages, light/dark at desktop
width. Verified pointer transfer to the card, keyboard focus and Escape.
Phone-width clicks open the Markdown viewer, PDF metadata actions and
image lightbox in both themes. Long filenames remain within the
viewport. The thread composer also retains its preview while moving
repeatedly between the chip's icon and text; leaving closes it at the
existing delay.
3. Hover evidence includes eight sampled screenshot frames per theme and
100 ms visibility samples showing the card remaining open for at least
two seconds. Evidence is outside the repository under
`/var/tmp/canopy-bot-attachment-hover/`.
4. Requested EAS CLI 27.4.1 production fingerprints are byte-identical
before/after: iOS `6ddec9ef559ee0095ac33e94ff9418a942053b17`; Android
`5f6eae3ab278f1cd543e9ed763f923a319b65ec9`. Native mobile already shares
`AttachmentChips` between bots and threads. No native or mobile source
changes.

Native device interaction remains unverified: device support twice
returned “Could not communicate with device support. Try refreshing
devices.” Phone-width browser interaction was checked. Full
integration/temporary-directory checks and generated-contract checks
were left to CI; this change only touches the shared web editor preview.
Copy audit: no UI copy changed.

The faulty selection assignment was introduced by the attachment-preview
implementation in #398; verified in its original diff. Bot attachment
PRs reused that component.

Fixes: #398
Related: #449, #469
nixuuu added a commit that referenced this pull request Nov 12, 2026
## Change

A file sent once could be presented to the bot again when its hidden
harness session was rebuilt. The gateway collected historical
attachments into `historyAttachments`, and the worker flattened them
into the newest native user input. The generic “Canopy attached files”
note did not distinguish the original message. This originated in #449;
#469 extended the same path to other file types.

Send file bytes only with their original message, for both resumed and
rebuilt Claude, Codex and Grok sessions. Historical messages retain
dated, forwardable references and explicitly say they are earlier
attachments. The current message is supplied once, separately from
history. Workers ignore the legacy historical binary field, and the
session context key changes once to discard previously mixed attachment
context.

The server already clears the sent draft revision atomically with
message acceptance and attachment binding. A separate race in the shared
web/desktop/mobile synchronizer allowed a draft read started before
acknowledgement to restore the old client draft afterward. Ignore stale
reads and reload the current revision after clearing. Newer device
edits, failed-send drafts and idempotency remain preserved.

Connector accounts expose MCP tools; there is no automatic inbound
Slack/thread-file ingestion path in this flow. Owner/conversation checks
and attachment forwarding authorization remain in the gateway.

## Verification

- Added gateway → real WorkerHost → fake CLI regressions for all three
providers: two images, three text-only follow-ups across resume/rebuild,
then one fresh image. Assert both durable command attachment IDs and
native harness parts.
- Added delayed-read regression using the shared client synchronizer
against real draft/send RPCs; retained restart durability, failed-send,
idempotency, revision-conflict and owner-scoping coverage.
- Extended PDF/text/image coverage to ensure rebuilt sessions receive
references without old binary or extracted content. Added worker
compatibility coverage for legacy historical attachments and
session-cache invalidation.
- `bun install --frozen-lockfile`, targeted spacing autofix and
formatting, full `bun run lint`, `git diff --check`, and the Angular
commit-message hook passed.
- Focused `check:tmp` run passed: 44 tests, 371 assertions across bot
composer, bot files, harness context, harness durability/restarts and
worker attachment compatibility. No files remained in the temporary
directory.
- **Not run locally:** browser, typecheck, generation checks, web build
or fingerprint generation. CI covers the remaining
static/build/full-suite checks. No RED/GREEN reproduction is claimed. No
real provider or connector APIs were called.

Mobile is affected only through shared TypeScript. No native
configuration, dependencies, assets, lockfiles or fingerprint inputs
were changed; fingerprints were not recalculated locally. No UI markup
or UI text changed; copy audit §8 is not applicable to the model-facing
provenance notes. Polish bot docs describe the resulting behavior.

Fixes: #449
Related: #469
nixuuu added a commit that referenced this pull request Nov 13, 2026
Describe default-on Web access and Files, per-conversation workspaces,
bounded downloads and outgoing attachments before changing runtime
behavior. The Polish design covers SSRF/DNS rebinding, path traversal
and symlinks, disk exhaustion, cross-conversation exfiltration, owner
scoping and gateway approvals.

This is the bottom layer of the five-stage stack. Keep every layer draft
until the complete implementation and verification are finished; do not
merge individual layers.

Validation: read architecture, bot/harness, worker and connector
documentation and the existing #469/#581 attachment behavior. `bun
install --frozen-lockfile`, `bun run format` and `git diff --check`
passed. No runtime changes or local integration/browser tests in this
layer. CI runs required checks. Copy audit §8: no UI copy changed.
nixuuu added a commit that referenced this pull request Nov 13, 2026
Bots can use Claude WebSearch/WebFetch, Codex native live web search and
Grok web_search/web_fetch while local tools remain disabled. Add the
owner-controlled, default-on webAccess setting to the existing JSON
configuration, preserve explicit false across unrelated saves, and
require worker capability bot_web_v1. No database migration is needed.

Every adapter receives the resolved permission; changing it rebuilds the
hidden session. Tool-free handoffs keep web access disabled. Add
provider schema-capture coverage for both toggle states and gateway
settings persistence coverage, using only local fixtures. Grok's MCP
search_tool is not confused with native web search.

Validation: on the authorized review host, gen:check, typecheck, lint,
format:check and the web build passed. Official Claude, Codex and Grok
CLIs captured their tool schemas against local inference fixtures: both
Web access states passed for every provider (8 isolation tests). Gateway
settings persistence (6 tests) and harness integration (24 tests)
passed. No real provider APIs or external test URLs were called. CI is
green for this layer.

Copy audit §8: the new update-worker error names the missing capability
and tells the user to update or choose another worker. No settings UI is
added until the final layer; prompt text is model-facing.

Related: #469, #581
nixuuu added a commit that referenced this pull request Nov 13, 2026
Bots can download public HTTP(S) files into their conversation workspace
and send generated/downloaded files as ordinary Canopy attachments.
download_file and send_attachment are gated by current Files permission,
owner, worker, active turn and gateway approval policy. A new
bot_outgoing_files_v1 capability prevents dispatch to older workers;
protobuf extensions are additive and no migration is needed.

Downloads block private/loopback/link-local/metadata/reserved addresses
after DNS and on every redirect, pin the checked literal IP and preserve
HTTPS hostname verification. Limits: 50 MiB, five redirects, 60 seconds
total, 10 seconds idle; Content-Length and streamed bytes are checked
separately. No credentials, cookies, inherited proxy, execution or
unpacking. Files is the download permission, independent of native Web
access.

Outgoing transfers use bounded chunks and an immutable worker snapshot
with SHA-256. Existing gateway attachment validation/storage, message,
audit and durable tool result commit in the fenced/idempotent action.
Replayed call IDs return the stored result; revoked Files and
stopped/foreign turns cannot publish. Existing web/desktop/mobile APIs
and attachment renderers provide download and supported previews. This
repository has MCP connector accounts, but no automatic Telegram/Slack
chat delivery adapters; external delivery needs its separately granted
connector tool.

Fourth draft layer of stack #598. Do not merge separately.

Validation: authorized review-host checks passed: gen:check, typecheck,
lint, format:check and web build. All download security tests passed (3
tests): SSRF private/reserved ranges, redirects, DNS pinning/rebinding,
declared/streamed size, DNS/body timeouts and MIME. All gateway↔worker
outgoing-file tests passed (6 tests): every provider, attachment
retrieval, replay without duplicate delivery/audit, owner refusal
through core/storage, completed turns, approval refusal, Files
revocation and restarts. Local HTTP/inference fixtures only. The final
UI layer was reviewed in one Chromium session at desktop/phone widths,
light/dark, including actual Markdown/image previews and downloads.

Copy audit §8: errors name public-URL, size, timeout or permission
failures with a recovery action. Tool descriptions distinguish
downloading from sending and Canopy delivery from connector delivery.
Prompt states files/web boundaries, retention and limits. No new UI
controls in this layer; final-layer visual verification passed.

Related: #469, #581
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant