Repository navigation
Description
Summary
The current file attachment pipeline has three gaps that make it unreliable from a user's perspective:
-
Files are lost on turn yield/resume —
replyFilesis an in-memory array local torespond(). If the turn yields cooperatively (timeout or auth pause), any files accumulated viaattachFileare silently dropped. The resumed turn starts with an emptyreplyFiles. -
imageGeneratenever writes to disk — generated image bytes live only in the in-memorygeneratedFilesarray. If a yield happens betweenimageGenerateandattachFile, the resolved artifact is gone. There is no path from which to recover it. -
followupdelivery mode is dead code —ReplyFileDeliveryincludes"followup"andplanSlackReplyPostshandles it, butbuildReplyDeliveryPlannever returns it. This is low-priority but should be removed or wired up.
The Sentry alert JUNIOR-4B — "agent turn execution failure: assistant returned no text" — is likely related: a resumed continuation with no queued files and no text produces an empty reply, which throws.
Current pipeline
imageGenerate → onGeneratedArtifactFiles → generatedFiles[] (in-memory)
attachFile → reads generatedFiles[] or sandbox disk → replyFiles[] (in-memory)
turn end → buildTurnResult(replyFiles) → AssistantReply.files
delivery → filesUploadV2({ file_uploads: [...] }) — one batched Slack call
Everything is in-memory. Nothing is checkpointed. Any yield drops all of it.
Desired behavior
- Multiple files → one Slack message (no reply spam). Already works in the happy path.
- File-only posts (no text required). Slack allows this; we should too.
- Files survive yield/resume. A user who asked for images should get them even if the turn takes multiple slices.
Recommended design: durable sandbox refs
Core idea
Replace in-memory buffer accumulation with durable path references checkpointed at every yield boundary. Buffers are only materialized once, at Slack upload time.
Two ref lists are needed — both must survive yields:
| List | Written by | Purpose |
|---|---|---|
generatedArtifactRefs |
imageGenerate |
Registry so attachFile can resolve filenames after resume |
pendingAttachmentRefs |
attachFile |
Files selected for delivery in the final reply |
Changes required
imageGenerate
- Write generated bytes to sandbox disk at a stable path, e.g.
/tmp/junior/generated-artifacts/{unique-name}.{ext}— before returning the tool result. - Register the path in
generatedArtifactRefs. - Continue returning
attachment_path: filenamefor model compatibility;attachFileresolves via the registry.
attachFile
- For generated images: resolve filename →
generatedArtifactRefsby filename → push{ path, filename, mimeType }topendingAttachmentRefs. - For real sandbox files: resolve to absolute path → push to
pendingAttachmentRefs. - Validation (file exists, size check) still happens at call time for immediate feedback.
- Stop pushing
FileUploadbuffers toreplyFiles; refs are now canonical.
AgentTurnSessionRecord
generatedArtifactRefs?: Array<{ id: string; filename: string; path: string; mimeType?: string; createdAt: string }>
pendingAttachmentRefs?: Array<{ id: string; filename: string; path: string; mimeType?: string; source: "sandbox" | "generated"; createdAt: string }>All checkpoint functions (persistYieldSessionRecord, persistTimeoutSessionRecord, persistAuthPauseSessionRecord, persistRunningSessionRecord)
- Pass through both ref arrays when calling
upsertAgentTurnSessionRecord.
agent-continue-runner
- On resume, restore both arrays from session record and pass into
respond(). respond()pre-populates the running ref state from restored arrays.
Delivery / buildTurnResult
- Materialize
pendingAttachmentRefs → FileUpload[]by re-reading from sandbox just before assemblingAssistantReply.files. - Existing
planSlackReplyPostsandfilesUploadV2batching behavior is unchanged.
Sandbox durability
The sandbox already tries to reconnect by ID on resume via Sandbox.get({ name: sandboxId, resume: true }) and sandboxId is persisted in thread state. For typical resumes (minutes), the sandbox container is alive and files are readable.
Failure mode: if the sandbox has expired, paths become unreadable. Degrade gracefully:
- Deliver the text reply without files.
- Log a structured warning with the unresolvable paths.
- Do not crash the continuation.
- Do not claim "attached" in the reply if the files couldn't be recovered.
If stronger durability is needed beyond sandbox lifetime, add short-TTL object storage (R2/S3) as a follow-up — do not serialize 10MB buffers into session records.
Test cases
imageGenerate→attachFile→ response, no yield (baseline compat)imageGenerate→ yield → resume →attachFile→ responseimageGenerate→attachFile→ yield → resume → response- Two generated images, both attached, single
filesUploadV2call with both files - Real sandbox file + generated image in same reply
- File-only reply (no text)
- Sandbox expired on resume → no crash, structured warning, text delivered
- Resume replay doesn't duplicate files (dedupe by id or
path+filename) - Filename collision between two generated images resolves correctly via registry
- Non-yield turns behave identically to today
Out of scope / follow-ups
followupdelivery mode cleanup (#dead-code)- Object storage upgrade for sandbox-expiry durability
- Immediate mid-turn file delivery (intentionally deferred — complicates batching)
--
Activity
fix(github-issues): ban conventional commit prefixes in issue titles (#…
fix(chat): Treat empty sendMessage turns as success
feat(chat): Add file-capable Slack sendMessage
fix(chat): Treat empty sendMessage turns as success
feat(chat): Add file-capable Slack sendMessage
fix(chat): Treat empty sendMessage turns as success
feat(slack): Add file-capable sendMessage (#744)
fix(slack): Send files through active conversation messages (#760)
fix(slack): Remove attachFile delivery path
fix(slack): Remove attachFile delivery path
fix(slack): Remove attachFile delivery path
fix(slack): Remove attachFile delivery path (#761)