Skip to content

fix(backend): replace sunset Assistants file-chat with Chat Completions - #12284

Open
Git-on-my-level wants to merge 4 commits into
BasedHardware:mainfrom
Git-on-my-level:fix/sca-362-file-chat-completions
Open

fix(backend): replace sunset Assistants file-chat with Chat Completions#12284
Git-on-my-level wants to merge 4 commits into
BasedHardware:mainfrom
Git-on-my-level:fix/sca-362-file-chat-completions

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

OpenAI retired the Assistants API on 2026-08-26. Production Cloud Run backend /v2/messages file-chat has been 100% down on the non-vision path since 20:02Z: every POST /v1/threads is 404, wrapped as RuntimeError('failed to create OpenAI thread').

This PR replaces that retired surface with the already-healthy direct Chat Completions lane (SCA-361 RCA):

  • Images stay on gpt-5.6-luna as base64 image_url (live-verified).
  • PDFs use Chat Completions file parts {"type":"file","file":{"file_id":…}} on gpt-4.1 (documented file-input contract; luna is not pinned for an untested file-part capability).
  • Upload: images purpose=vision; PDFs purpose=user_data; other docs rejected at attach as UnsupportedChatFileError.
  • Assistants thread/assistant create/persist/delete is gone. Legacy openai_thread_id / openai_assistant_id remain readable on old session docs.
  • File-chat 4xx is classified at the graph boundary (unsupported_attachment / provider_rejected vs stream_failure) with status_code + sanitized param only.
  • search_files_tool rides the same replacement and still returns a soft error string.

Closes #3361
Closes SCA-362

RCA (SCA-361)

Last-24h chat_response failures were the Assistants file-chat lane. Historical ~2% were Assistants 400s (message-create / run-create). The hard break is the sunset: 8/8 thread creates 404 after 2026-08-26 20:02Z. Files API and chat/completions 200 on the same key. Agentic search_files_tool 404s were swallowed as journey success.

Test plan

  • Sunset: PDF chat via fake completions client; zero Assistants calls; no thread/assistant ids persisted
  • Stale/deleted file_id → typed unsupported_attachment error frame + journey failure
  • Completion stream error after first token → error frame + journey failure
  • Upload: non-PDF doc → 400 UnsupportedChatFileError; PDF → purpose=user_data
  • search_files_tool provider failure returns soft error string without raising
  • Do not merge until review; merge later is merge-commit only (never squash)

Verification

Focused backend unit tests for the file-chat / graph / upload / tool / inventory surfaces passed locally (25 passed on the new Completions suite plus the updated neighbors).

Failure-Class: FC-pinned-vendor-request-contract-retired

Review in cubic

Git-on-my-level and others added 4 commits August 28, 2026 00:53
OpenAI retired Assistants on 2026-08-26, so every /v1/threads create 404s
and non-vision file chat is down. Stream PDFs as Chat Completions file
parts on gpt-4.1 (documented file-input contract) and keep images on the
verified gpt-5.6-luna vision lane.

Failure-Class: FC-pinned-vendor-request-contract-retired
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: multica-agent <github@multica.ai>
Unpacking a token-budget dict into create() is untyped and fails pyright.

Failure-Class: FC-pinned-vendor-request-contract-retired
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: multica-agent <github@multica.ai>
CI ran each unit file in its own process; incomplete BYOK/LLM stubs and a
duration-guard race on desktop transcribe failed the backend suite.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: multica-agent <github@multica.ai>
Upstream 7c900a9 moved the Soniox client into utils.stt.soniox but left
SafeSonioxSocket / process_audio_soniox imported in streaming.py without a
re-export marker; receiver.py and test_soniox_streaming.py import them through
utils.stt.streaming, so strict pyright fails main and every PR merge ref.

Carry the one-line marker so this backend CI lane can go green; matches the
existing SafeDeepgramSocket compat re-export convention on the previous line.

Co-authored-by: multica-agent <github@multica.ai>
@Git-on-my-level
Git-on-my-level force-pushed the fix/sca-362-file-chat-completions branch from 4f6d9f1 to ebd3618 Compare August 27, 2026 18:02
@Git-on-my-level

Copy link
Copy Markdown
Collaborator Author

Backend unit suite unblocked — the failure was not in this PR's diff. Upstream main has been failing its own Backend Unit Tests since the Soniox module refactor (7c900a9383) left SafeSonioxSocket / process_audio_soniox imported in backend/utils/stt/streaming.py without a re-export marker; strict pyright flags both as unused even though receiver.py and test_soniox_streaming.py import them through utils.stt.streaming. Since this lane evaluates the merge ref, every open PR inherited the break.

  • Rebased onto current origin/main (932e2f5f06) and marked the Soniox imports as intentional re-exports (# pyright: ignore[reportUnusedImport], matching the existing SafeDeepgramSocket compat line). Net-zero line count (1707 → 1707) so the line-count ratchet stays clean.
  • Verification: enforced backend/scripts/typecheck.sh 0 errors (pinned pyright 1.1.403; was 2 errors); repo-runner unit suites for test_soniox_streaming.py (11 passed), the five file-chat suites (all passed) post-rebase; full pre-push gate passed.
  • Note for maintainers: main itself is still red on this lane (latest main run at 2026-08-27T16:49Z fails with the same 2 errors) — the marker fix or equivalent should land on main separately to unblock other PRs.

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.

Change file upload purpose to user_data according to official recommendation

1 participant