diegosouzapw/OmniRoute · error · Error

Trae create_session

Error message

Trae create_session: ${JSON.stringify(json)}

What it means

Trae /chat_sessions returned HTTP 200 but the JSON envelope carried a non-zero business code (json.code !== 0), signaling an application-level failure (e.g. quota exhausted, model unavailable) that Trae reports in-band rather than via HTTP status. The full JSON is embedded for diagnosis.

Solutions

  1. Map known Trae error codes to specific recovery actions (token refresh, model switch)
  2. Log the embedded JSON for unsupported codes
  3. Fall back to another provider if the error indicates capacity limits
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at open-sse/executors/trae.ts:156 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of diegosouzapw/OmniRoute@a179ffed5b (2026-08-25). Data as JSON: /api/errors/899c66ddbcdf0b90. Report an issue: GitHub.

Appendix: source

Thrown at open-sse/executors/trae.ts:156

        model_name: modelName,
        agent_type: "solo_agent_remote",
        model_selection_strategy: strategy,
        common_params: this.commonParams(psd, mode),
      },
      env: "remote",
      auto_create_project: false,
      origin: "web",
    };
    const res = await fetch(`${this.base()}/chat_sessions`, {
      method: "POST",
      headers,
      body: JSON.stringify(body),
      signal: signal || undefined,
    });
    const text = await res.text();
    if (!res.ok) throw new Error(`[${res.status}] ${text}`);
    const json = JSON.parse(text);
    if (json?.code !== 0) throw new Error(`Trae create_session: ${JSON.stringify(json)}`);
    return { sessionId: json.data.chat_session_id, messageId: json.data.message_id };
  }

  /**
   * GET /events SSE → invoke onEvent(eventType, dataObj) per frame.
   * Resolves when `done`/`error` arrives, the stream ends, or timeout fires.
   */
  private async streamEvents(
    headers: Record<string, string>,
    sessionId: string,
    replyTo: string,
    onEvent: (ev: string | null, data: JsonRecord) => boolean,
    signal?: AbortSignal | null
  ): Promise<void> {
    const url = `${this.base()}/chat_sessions/${sessionId}/events?reply_to_message_id=${encodeURIComponent(replyTo)}`;
    const ctrl = new AbortController();
    // If the caller's signal is already aborted, abort upfront so we don't open
    // a network request the consumer no longer wants.

View on GitHub (pinned to a179ffed5b)