[Bug]: First message with an attachment on a new session fails with "Session not found"

Author: JohnnyCjyCreated Sep 25, 2026Updated Sep 26, 2026
Labelsbug

Ekko Studio Version

v0.7.24

Agent Runtime and Version (if applicable)

N/A (Studio-only issue)

Bug Description

In a brand-new session, the very first message fails with Error: Session not found whenever it contains an attachment. The same message works if any plain-text message has been sent first in that session. 100% reproducible. This is a regression: sessions created around June 2026 accepted an attachment as the first message; it appears to have been introduced with the session-uploads share-access hardening.

Steps to Reproduce

  1. Create a new chat session (do not send anything yet).
  2. Attach a file (or paste an image) and send it together with any text.
  3. The run fails immediately with Error: Session not found.

Workaround: send a plain-text message first, then send the attachment.

Expected Behavior

The first message of a new session can carry attachments.

Actual Behavior

run.failed with error Session not found is emitted before the run starts. Nothing is persisted server-side (no session row, no messages), so the failed attempt leaves no trace in the Studio session database.

Root Cause

In packages/server/src/modules/studio/sockets/chat-run.ts, the socket run handler:

typescript
try {
  runProfile = resolveRunProfile(data.session_id, data.profile)
  if (!shared && data.session_id && Array.isArray(data.input)) {
    requireSocketSessionAccess(data.session_id)   // <-- throws for new sessions
    await recordSessionUploadAttachments(data.session_id, runProfile, data.input)
  }
} catch (err) {
  socket.emit('run.failed', { ..., error: err.message })  // 'Session not found'
  return
}

Two facts collide:

  1. Array.isArray(data.input) is true only when the message has attachments — with attachments the client sends a ContentBlock[]; a plain-text message sends a string and skips this block entirely. This is exactly why the bug needs an attachment to trigger.
  2. requireSocketSessionAccess calls getSession(sessionId) and throws Session not found when there is no row. But the session row for a brand-new session is only created later in this same run — in handle-bridge-run.ts (createSession(...) around lines 616/638). So the check runs before the record it checks can possibly exist.

Note that recordSessionUploadAttachments already tolerates a missing session (if (!session || session.profile !== profile) return) — it is the hard requireSocketSessionAccess call in front of it that kills the run.

Proposed Fix

Only enforce the access check for sessions that already exist; a session that does not exist yet cannot be owned by anyone else, and it is created moments later under runProfile (which resolveRunProfile has already authorized):

diff
       try {
         runProfile = resolveRunProfile(data.session_id, data.profile)
         if (!shared && data.session_id && Array.isArray(data.input)) {
-          requireSocketSessionAccess(data.session_id)
+          // A brand-new session has no row yet (it is created later in
+          // handle-bridge-run when the run starts), so ownership can only be
+          // enforced for sessions that already exist.
+          if (getSession(data.session_id)) requireSocketSessionAccess(data.session_id)
           await recordSessionUploadAttachments(data.session_id, runProfile, data.input)
         }
       } catch (err) {

getSession is already imported in this module.

Additional Notes

  • With the fix, recordSessionUploadAttachments still no-ops for a brand-new session, so first-message uploads are not recorded in session_uploads. Share-recipient download authorization still works through the legacyContents fallback in isSessionUploadAttachment. If you want first-message uploads recorded as well, the recording could be re-run after createSession in handle-bridge-run.ts.
  • A regression test could extend tests/server/chat-run-bridge-readiness.test.ts: a run with Array.isArray(input) for a session id that has no row must not emit run.failed with Session not found.

Steps to Reproduce

  1. Create a new chat session (do not send anything yet).
  2. Attach a file (or paste an image) and send it together with any text.
  3. The run fails immediately with Error: Session not found.

Note: sending a plain-text message first, then the attachment, always works — this is the accepted workaround and points at the root cause (the input array vs string difference).

Expected Behavior

The first message of a new session can carry attachments; the run starts normally.

Actual Behavior

run.failed is emitted before the run starts with error Session not found. Nothing is persisted server-side (no session row, no messages in the Studio session database), so the failed attempt leaves no trace. The error shows in the chat as Error: Session not found.

Image

Logs / Error Messages

bash

Environment

Docker

Node Version

v24.15.0

Additional Context

  • Deployment: Docker Compose on Synology DSM, image ekkoye8888/hermes-web-ui:latest, no local modifications.
  • An attachment as the first message worked in builds from June 2026, so this is a regression rather than a long-standing limitation.
  • The failed run leaves no trace in hermes-web-ui.db (no session row, no messages), consistent with the check failing before session creation.

Source: EKKOLearnAI/hermes-studio