Skip to content

fix(bots): send attachments only with their original message - #581

Merged
nixuuu merged 2 commits into
devfrom
fix/bot-stale-attachments
Nov 12, 2026
Merged

nixuuu merged 2 commits into
devfrom
fix/bot-stale-attachments

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

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

Keep historical files as dated references instead of native content on rebuilt harness turns. Reject draft reads that started before successful send acknowledgement across the shared web, desktop and mobile synchronizer.

Fixes: #449

Related: #469
@nixuuu
nixuuu marked this pull request as ready for review November 12, 2026 17:08
Extract attachment input assembly and capability validation from the harness runner. Apply the spacing rule to the changed attachment code and regression tests.
@nixuuu
nixuuu merged commit 3525107 into dev Nov 12, 2026
10 checks passed
@nixuuu
nixuuu deleted the fix/bot-stale-attachments branch November 12, 2026 19:11
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