Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(platform): record why the brain-dump gate rejected a take, and retry it when its judge failed (#15932)

Reinier van der Leerb4f71cfacd92
diff --git a/autogpt_platform/backend/backend/api/features/onboarding_dump/EVAL.md b/autogpt_platform/backend/backend/api/features/onboarding_dump/EVAL.md
index 66c6e0cd10..5a324ff685 100644
--- a/autogpt_platform/backend/backend/api/features/onboarding_dump/EVAL.md
+++ b/autogpt_platform/backend/backend/api/features/onboarding_dump/EVAL.md
@@ -56,8 +56,10 @@ Every scored file's machine transcript is pushed through the real
hallucinates — the gate must reject the result, whatever it is. One wrong
verdict fails the run, exactly like a WER breach: a garbage dump that
personalizes and a real dump that bounces are both release blockers. The
-LLM half of the gate needs the usual chat key (`OPEN_ROUTER_API_KEY` or an
-OpenAI key) on top of the STT key.
+LLM half of the gate needs `OPEN_ROUTER_API_KEY` on top of the STT key; an
+OpenAI key alone gives the judge no client. A file the judge could not be asked
+about (no key, a timeout, an error) scores as wrong even where a reject was
+expected, so an outage can fail the run but never pass it.
## The committed baseline corpus
diff --git a/autogpt_platform/backend/backend/api/features/onboarding_dump/brain_dump_gate_eval.py b/autogpt_platform/backend/backend/api/features/onboarding_dump/brain_dump_gate_eval.py
index 3b0296a303..19bdd5d879 100644
--- a/autogpt_platform/backend/backend/api/features/onboarding_dump/brain_dump_gate_eval.py
+++ b/autogpt_platform/backend/backend/api/features/onboarding_dump/brain_dump_gate_eval.py
@@ -35,6 +35,7 @@ class GateFileResult(BaseModel):
expected: GateExpectation
outcome: GateExpectation
error_code: str | None = None
+ reason: str | None = None
correct: bool
transcript_preview: str = ""
transcription_error: str | None = None
@@ -73,14 +74,20 @@ def build_report(
async def evaluate_transcript(
name: str, expected: GateExpectation, transcript: str
) -> GateFileResult:
- error_code = await quality.check_transcript_quality(transcript)
- outcome: GateExpectation = "pass" if error_code is None else "reject"
+ rejection = await quality.check_transcript_quality(transcript)
+ outcome: GateExpectation = "pass" if rejection is None else "reject"
+ # A judge that could not be asked made no call, so it confirms nothing,
+ # not even an expected reject.
+ judged = (
+ rejection is None or rejection.error_code != quality.QUALITY_CHECK_UNAVAILABLE
+ )
return GateFileResult(
name=name,
expected=expected,
outcome=outcome,
- error_code=error_code,
- correct=outcome == expected,
+ error_code=rejection.error_code if rejection else None,
+ reason=rejection.reason if rejection else None,
+ correct=judged and outcome == expected,
transcript_preview=transcript.strip()[:TRANSCRIPT_PREVIEW_CHARS],
)
@@ -156,7 +163,11 @@ def render_gate_report(report: GateReport) -> list[str]:
def _gate_detail(result: GateFileResult) -> str:
- detail = result.error_code or result.transcript_preview or "(empty transcript)"
+ detail = (
+ f"{result.error_code} ({result.reason})"
+ if result.error_code
+ else result.transcript_preview or "(empty transcript)"
+ )
if result.transcription_error:
detail += f" [stt error: {result.transcription_error[:40]}]"
return detail
diff --git a/autogpt_platform/backend/backend/api/features/onboarding_dump/brain_dump_gate_eval_test.py b/autogpt_platform/backend/backend/api/features/onboarding_dump/brain_dump_gate_eval_test.py
index 2f79b774ca..3bd1303b55 100644
--- a/autogpt_platform/backend/backend/api/features/onboarding_dump/brain_dump_gate_eval_test.py
+++ b/autogpt_platform/backend/backend/api/features/onboarding_dump/brain_dump_gate_eval_test.py
@@ -23,6 +23,9 @@ from backend.api.features.onboarding_dump.transcription import TranscriptionResu
GOOD_TRANSCRIPT = "I run a bakery and want the weekly order emails handled."
GARBAGE_TRANSCRIPT = "Thank you for watching."
+JUDGED_UNUSABLE = quality.QualityRejection(
+ error_code=quality.INSUFFICIENT_CONTENT, reason="judge_unusable"
+)
def _result(text: str) -> TranscriptionResult:
@@ -38,8 +41,8 @@ def _write_manifest(directory: Path, entries: dict[str, str]) -> None:
def _gate_by_transcript(monkeypatch) -> None:
"""A stand-in gate: rejects the known garbage transcript, passes the rest."""
- async def check(transcript: str) -> str | None:
- return "insufficient_content" if transcript == GARBAGE_TRANSCRIPT else None
+ async def check(transcript: str) -> quality.QualityRejection | None:
+ return JUDGED_UNUSABLE if transcript == GARBAGE_TRANSCRIPT else None
monkeypatch.setattr(quality, "check_transcript_quality", check)
@@ -178,8 +181,14 @@ async def test_gate_only_transcription_failure_counts_as_empty_transcript(
),
)
- async def check(transcript: str) -> str | None:
- return None if transcript else "no_usable_speech"
+ async def check(transcript: str) -> quality.QualityRejection | None:
+ return (
+ None
+ if transcript
+ else quality.QualityRejection(
+ error_code=quality.NO_USABLE_SPEECH, reason="deterministic"
+ )
+ )
monkeypatch.setattr(quality, "check_transcript_quality", check)
@@ -206,6 +215,26 @@ async def test_evaluate_transcript_compares_outcome_to_expectation(
assert result.correct is outcome_correct
+async def test_a_judge_outage_confirms_no_expected_reject(monkeypatch):
+ """A judge that could not be asked made no call, so an outage can fail
+ the run but never pass it on the clips it happens to reject."""
+
+ async def check(transcript: str) -> quality.QualityRejection:
+ return quality.QualityRejection(
+ error_code=quality.QUALITY_CHECK_UNAVAILABLE, reason="judge_timeout"
+ )
+
+ monkeypatch.setattr(quality, "check_transcript_quality", check)
+
+ result = await brain_dump_gate_eval.evaluate_transcript(
+ "gate-reject-silence", "reject", GARBAGE_TRANSCRIPT
+ )
+
+ assert result.outcome == "reject"
+ assert result.reason == "judge_timeout"
+ assert result.correct is False
+
+
# --- shipped corpus consistency (pure filesystem, no credentials) ---------
EVAL_DATA_DIR = Path(__file__).parent / "eval_data"
diff --git a/autogpt_platform/backend/backend/api/features/onboarding_dump/db.py b/autogpt_platform/backend/backend/api/features/onboarding_dump/db.py
index aefd8faa17..b094cd7637 100644
--- a/autogpt_platform/backend/backend/api/features/onboarding_dump/db.py
+++ b/autogpt_platform/backend/backend/api/features/onboarding_dump/db.py
@@ -102,6 +102,7 @@ async def start_dump(
"status": BrainDumpStatus.recording_uploaded,
"inputMode": input_mode,
"errorCode": None,
+ "errorReason": None,
**(_TAKE_OWNED_RESET if is_new_take else {}),
}
return await OnboardingBrainDump.prisma().upsert(
@@ -161,10 +162,20 @@ async def claim_transition(
return updated == 1
-async def mark_failed(user_id: str, recording_id: str, error_code: str) -> None:
- """Record a terminal failure without ever dropping the stored audio."""
+async def mark_failed(
+ user_id: str, recording_id: str, error_code: str, reason: str | None = None
+) -> None:
+ """Record a terminal failure without ever dropping the stored audio.
+
+ ``reason`` says what decided a quality-gate rejection; any other failure
+ clears the one an earlier attempt left.
+ """
await update_dump(
- user_id, recording_id, status=BrainDumpStatus.failed, errorCode=error_code
+ user_id,
+ recording_id,
+ status=BrainDumpStatus.failed,
+ errorCode=error_code,
+ errorReason=reason,
)
diff --git a/autogpt_platform/backend/backend/api/features/onboarding_dump/db_test.py b/autogpt_platform/backend/backend/api/features/onboarding_dump/db_test.py
index 5af5d33b06..d53667c110 100644
--- a/autogpt_platform/backend/backend/api/features/onboarding_dump/db_test.py
+++ b/autogpt_platform/backend/backend/api/features/onboarding_dump/db_test.py
@@ -168,7 +168,13 @@ async def test_retrying_the_same_take_keeps_what_that_take_produced(
update = upsert.await_args.kwargs["data"]["update"]
assert create["recommendedProviders"] == Json(None)
assert create["recommendedExperts"] == Json(None)
- assert set(update) == {"recordingId", "status", "inputMode", "errorCode"}
+ assert set(update) == {
+ "recordingId",
+ "status",
+ "inputMode",
+ "errorCode",
+ "errorReason",
+ }
@pytest.mark.asyncio
diff --git a/autogpt_platform/backend/backend/api/features/onboarding_dump/failure_reason_db_test.py b/autogpt_platform/backend/backend/api/features/onboarding_dump/failure_reason_db_test.py
new file mode 100644
index 0000000000..57dcd9b1ab
--- /dev/null
+++ b/autogpt_platform/backend/backend/api/features/onboarding_dump/failure_reason_db_test.py
@@ -0,0 +1,53 @@
+"""A quality rejection's reason against Postgres.
+
+The service and route tests fake ``mark_failed`` and ``start_dump``, so only
+the database shows the column is written, and cleared once it stops applying.
+"""
+
+import uuid
+from collections.abc import AsyncGenerator
+
+import pytest_asyncio
+from prisma.enums import BrainDumpInputMode
+from prisma.models import User
+
+from backend.api.features.onboarding_dump import db
+
+RECORDING_ID = "rec-1"
+
+
+@pytest_asyncio.fixture(loop_scope="session")
+async def user_id(server) -> AsyncGenerator[str, None]:
+ user_id = str(uuid.uuid4())
+ await User.prisma().create(data={"id": user_id, "email": f"{user_id}@example.com"})
+ yield user_id
+ await User.prisma().delete(where={"id": user_id})
+
+
+async def test_a_rejection_stores_its_reason_until_the_take_is_retried(user_id: str):
+ await db.start_dump(user_id, RECORDING_ID, BrainDumpInputMode.voice)
+ await db.mark_failed(
+ user_id, RECORDING_ID, "quality_check_unavailable", "judge_timeout"
+ )
+
+ rejected = await db.get_dump(user_id)
+ assert rejected is not None
+ assert rejected.errorReason == "judge_timeout"
+
+ await db.start_dump(user_id, RECORDING_ID, BrainDumpInputMode.voice)
+
+ retried = await db.get_dump(user_id)
+ assert retried is not None
+ assert retried.errorReason is None
+
+
+async def test_a_failure_outside_the_gate_clears_an_earlier_reason(user_id: str):
+ await db.start_dump(user_id, RECORDING_ID, BrainDumpInputMode.voice)
+ await db.mark_failed(
+ user_id, RECORDING_ID, "insufficient_content", "judge_unusable"
+ )
+ await db.mark_failed(user_id, RECORDING_ID, "transcription_failed")
+
+ failed = await db.get_dump(user_id)
+ assert failed is not None
+ assert (failed.errorCode, failed.errorReason) == ("transcription_failed", None)
diff --git a/autogpt_platform/backend/backend/api/features/onboarding_dump/models.py b/autogpt_platform/backend/backend/api/features/onboarding_dump/models.py
index a3b1f822ea..55c341c17e 100644
--- a/autogpt_platform/backend/backend/api/features/onboarding_dump/models.py
+++ b/autogpt_platform/backend/backend/api/features/onboarding_dump/models.py
@@ -86,6 +86,10 @@ class FinalizeResponse(BaseModel):
input_mode: BrainDumpInputMode
transcript_preview: str | None = None
error_code: str | None = None
+ error_reason: str | None = None
+ """What decided a quality-gate rejection (``quality.QualityRejection``)."""
+ transcript_words: int | None = None
+ """A rejected transcript's length as the gate counts words; the text is not sent."""
class DumpStatusResponse(BaseModel):
diff --git a/autogpt_platform/backend/backend/api/features/onboarding_dump/quality.py b/autogpt_platform/backend/backend/api/features/onboarding_dump/quality.py
index 99da1d3c21..cef2532589 100644
--- a/autogpt_platform/backend/backend/api/features/onboarding_dump/quality.py
+++ b/autogpt_platform/backend/backend/api/features/onboarding_dump/quality.py
@@ -29,6 +29,8 @@ import os
import zlib
from typing import Literal
+from pydantic import BaseModel
+
from backend.api.features.onboarding_dump.parsing import parse_response_json
from backend.util.clients import get_openai_client
@@ -38,7 +40,12 @@ logger = logging.getLogger(__name__)
# enum migration) and read by the frontend to show the recovery screen.
NO_USABLE_SPEECH = "no_usable_speech"
INSUFFICIENT_CONTENT = "insufficient_content"
-QUALITY_ERROR_CODES = frozenset({NO_USABLE_SPEECH, INSUFFICIENT_CONTENT})
+# Not a verdict: the judge could not be asked, so the frontend offers a
+# retry of the same take instead of telling the user they said too little.
+QUALITY_CHECK_UNAVAILABLE = "quality_check_unavailable"
+QUALITY_ERROR_CODES = frozenset(
+ {NO_USABLE_SPEECH, INSUFFICIENT_CONTENT, QUALITY_CHECK_UNAVAILABLE}
+)
_MODEL = os.environ.get("BRAIN_DUMP_QUALITY_MODEL", "anthropic/claude-haiku-5.5")
# The gate runs inside the finalize request, after transcription already
@@ -90,8 +97,22 @@ Transcript:
"""
-async def check_transcript_quality(transcript: str) -> str | None:
- """Return an error code when ``transcript`` can't support personalization.
+class QualityRejection(BaseModel):
+ """Why the gate refused a transcript.
+
+ ``error_code`` decides what the user is shown. ``reason`` records what
+ decided it, stored as ``OnboardingBrainDump.errorReason``: one of
+ ``deterministic``, ``judge_unusable``, ``judge_timeout``,
+ ``judge_malformed``, ``judge_unconfigured`` or
+ ``judge_failed:<ExceptionClass>``.
+ """
+
+ error_code: str
+ reason: str
+
+
+async def check_transcript_quality(transcript: str) -> QualityRejection | None:
+ """Return why ``transcript`` can't support personalization, if it can't.
``None`` means the dump is usable and the personalized pipeline may
run. Deterministic answers are preferred in both directions; only the
@@ -100,17 +121,22 @@ async def check_transcript_quality(transcript: str) -> str | None:
text = transcript.strip()
verdict = _deterministic_verdict(text)
if verdict == "reject":
- return NO_USABLE_SPEECH
+ return QualityRejection(error_code=NO_USABLE_SPEECH, reason="deterministic")
if verdict == "pass":
return None
return await _semantic_verdict(text)
+def count_words(transcript: str) -> int:
+ """How many words the gate sees in ``transcript``, for ``CLEAR_PASS_WORDS``."""
+ return len(_words(transcript))
+
+
def _deterministic_verdict(text: str) -> Literal["pass", "reject", "ambiguous"]:
if not text or not any(ch.isalnum() for ch in text):
return "reject"
- words = [word for word in text.split() if any(ch.isalnum() for ch in word)]
+ words = _words(text)
if not words:
return "reject"
if len(words) >= REPETITION_MIN_WORDS:
@@ -132,26 +158,29 @@ def _deterministic_verdict(text: str) -> Literal["pass", "reject", "ambiguous"]:
return "ambiguous"
+def _words(text: str) -> list[str]:
+ return [word for word in text.split() if any(ch.isalnum() for ch in word)]
+
+
def _compression_ratio(text: str) -> float:
"""How far zlib collapses ``text`` — high means the decoder was looping."""
raw = text.encode("utf-8")
return len(raw) / len(zlib.compress(raw))
-async def _semantic_verdict(text: str) -> str | None:
+async def _semantic_verdict(text: str) -> QualityRejection | None:
"""One cheap LLM call for the short-but-nonempty middle band.
- Every failure path here — no client, timeout, malformed output —
- resolves to ``INSUFFICIENT_CONTENT`` rather than a silent pass: an
- ambiguous dump must never produce confident personalized output just
- because the judge was unavailable. The outcome is recoverable by
- design (the user is offered retry / type / skip), which is the safe
- documented behavior for a quality-model outage.
+ Every failure path here — no client, timeout, error, malformed output —
+ rejects rather than silently passing: an ambiguous dump must never
+ produce confident personalized output just because the judge was
+ unavailable. It rejects as ``QUALITY_CHECK_UNAVAILABLE`` rather than as
+ a verdict, so the user is offered a retry instead of being told they
+ said too little.
"""
client = get_openai_client(prefer_openrouter=True)
if client is None:
- logger.warning("Brain dump quality check: no LLM client configured")
- return INSUFFICIENT_CONTENT
+ return _judge_unavailable("judge_unconfigured")
try:
response = await asyncio.wait_for(
@@ -163,13 +192,22 @@ async def _semantic_verdict(text: str) -> str | None:
),
timeout=_TIMEOUT_SECONDS,
)
- content = response.choices[0].message.content or ""
+ except TimeoutError as e:
+ return _judge_unavailable("judge_timeout", e)
except Exception as e:
- logger.warning("Brain dump quality check failed: %s", e)
- return INSUFFICIENT_CONTENT
+ return _judge_unavailable(f"judge_failed:{type(e).__name__}", e)
- data = parse_response_json(content)
+ content = response.choices[0].message.content if response.choices else None
+ data = parse_response_json(content or "")
if not isinstance(data, dict) or not isinstance(data.get("usable"), bool):
- logger.warning("Brain dump quality check: malformed verdict")
- return INSUFFICIENT_CONTENT
- return None if data["usable"] else INSUFFICIENT_CONTENT
+ return _judge_unavailable("judge_malformed")
+ if data["usable"]:
+ return None
+ return QualityRejection(error_code=INSUFFICIENT_CONTENT, reason="judge_unusable")
+
+
+def _judge_unavailable(reason: str, error: Exception | None = None) -> QualityRejection:
+ # ERROR, not WARNING: only ERROR raises a Sentry event, and an outage
+ # rejects every ambiguous dump, so it has to be seen.
+ logger.error(f"Brain dump quality check unavailable: {reason}", exc_info=error)
+ return QualityRejection(error_code=QUALITY_CHECK_UNAVAILABLE, reason=reason)
diff --git a/autogpt_platform/backend/backend/api/features/onboarding_dump/quality_test.py b/autogpt_platform/backend/backend/api/features/onboarding_dump/quality_test.py
index a381c7221f..9731c3d8d3 100644
--- a/autogpt_platform/backend/backend/api/features/onboarding_dump/quality_test.py
+++ b/autogpt_platform/backend/backend/api/features/onboarding_dump/quality_test.py
@@ -3,10 +3,11 @@
The layering is the contract under test: unmistakable garbage and clearly
substantial dumps must be decided without a model call, only the ambiguous
middle may pay for one, and every judge failure resolves to a recoverable
-rejection rather than a silent pass.
+rejection rather than a silent pass, recorded as an outage and not a verdict.
"""
import asyncio
+import logging
from unittest.mock import AsyncMock, MagicMock
import pytest
@@ -32,6 +33,13 @@ SPANISH_DUMP = (
"campañas nuevas."
)
+DETERMINISTIC = quality.QualityRejection(
+ error_code=quality.NO_USABLE_SPEECH, reason="deterministic"
+)
+JUDGED_UNUSABLE = quality.QualityRejection(
+ error_code=quality.INSUFFICIENT_CONTENT, reason="judge_unusable"
+)
+
def _llm_client(content: str) -> MagicMock:
response = MagicMock()
@@ -68,9 +76,7 @@ async def test_empty_and_symbol_only_transcripts_reject_without_llm(
llm, transcript: str
):
client_factory = llm(_llm_client('{"usable": true}'))
- assert (
- await quality.check_transcript_quality(transcript) == quality.NO_USABLE_SPEECH
- )
+ assert await quality.check_transcript_quality(transcript) == DETERMINISTIC
client_factory.assert_not_called()
@@ -78,7 +84,7 @@ async def test_empty_and_symbol_only_transcripts_reject_without_llm(
async def test_repeated_word_loop_rejects_without_llm(llm):
client_factory = llm(_llm_client('{"usable": true}'))
looped = "you " * 30
- assert await quality.check_transcript_quality(looped) == quality.NO_USABLE_SPEECH
+ assert await quality.check_transcript_quality(looped) == DETERMINISTIC
client_factory.assert_not_called()
@@ -86,7 +92,7 @@ async def test_repeated_word_loop_rejects_without_llm(llm):
async def test_repeated_phrase_loop_rejects_without_llm(llm):
client_factory = llm(_llm_client('{"usable": true}'))
looped = "thank you for watching " * 12
- assert await quality.check_transcript_quality(looped) == quality.NO_USABLE_SPEECH
+ assert await quality.check_transcript_quality(looped) == DETERMINISTIC
client_factory.assert_not_called()
@@ -96,7 +102,7 @@ async def test_compressible_character_garbage_rejects_without_llm(llm):
# compression check is what catches a decoder stuck on a character.
client_factory = llm(_llm_client('{"usable": true}'))
garbage = "a" * 200
- assert await quality.check_transcript_quality(garbage) == quality.NO_USABLE_SPEECH
+ assert await quality.check_transcript_quality(garbage) == DETERMINISTIC
client_factory.assert_not_called()
@@ -161,7 +167,7 @@ async def test_exactly_clear_pass_words_passes_without_llm(llm):
async def test_one_word_below_clear_pass_still_asks_the_llm(llm):
llm(_llm_client('{"usable": false}'))
text = " ".join(_DISTINCT_WORDS[: quality.CLEAR_PASS_WORDS - 1])
- assert await quality.check_transcript_quality(text) == quality.INSUFFICIENT_CONTENT
+ assert await quality.check_transcript_quality(text) == JUDGED_UNUSABLE
@pytest.mark.asyncio
@@ -169,7 +175,7 @@ async def test_unique_ratio_just_below_threshold_rejects(llm):
client_factory = llm(_llm_client('{"usable": true}'))
# 20 words, 5 unique → 0.25, just under MIN_UNIQUE_WORD_RATIO.
text = " ".join(["ab", "cd", "ef", "gh", "ij"] * 4)
- assert await quality.check_transcript_quality(text) == quality.NO_USABLE_SPEECH
+ assert await quality.check_transcript_quality(text) == DETERMINISTIC
client_factory.assert_not_called()
@@ -193,8 +199,8 @@ async def test_compression_seam_separates_looping_from_prose(llm):
# Self-check the fixtures actually straddle the threshold.
assert quality._compression_ratio(looping) > quality.MAX_COMPRESSION_RATIO
assert quality._compression_ratio(prose) <= quality.MAX_COMPRESSION_RATIO
- assert await quality.check_transcript_quality(looping) == quality.NO_USABLE_SPEECH
- assert await quality.check_transcript_quality(prose) == quality.INSUFFICIENT_CONTENT
+ assert await quality.check_transcript_quality(looping) == DETERMINISTIC
+ assert await quality.check_transcript_quality(prose) == JUDGED_UNUSABLE
# --- the ambiguous middle: one LLM call decides ---------------------------
@@ -211,9 +217,7 @@ async def test_short_meaningful_request_passes_via_llm(llm):
async def test_short_filler_rejects_via_llm(llm):
llm(_llm_client('{"usable": false}'))
filler = "Uh hello hello, testing, can you hear me?"
- assert (
- await quality.check_transcript_quality(filler) == quality.INSUFFICIENT_CONTENT
- )
+ assert await quality.check_transcript_quality(filler) == JUDGED_UNUSABLE
@pytest.mark.asyncio
@@ -221,7 +225,7 @@ async def test_hallucinated_outro_rejects_via_llm(llm):
llm(_llm_client('{"usable": false}'))
assert (
await quality.check_transcript_quality("Thank you for watching.")
- == quality.INSUFFICIENT_CONTENT
+ == JUDGED_UNUSABLE
)
@@ -231,64 +235,69 @@ async def test_llm_verdict_tolerates_markdown_fence(llm):
assert await quality.check_transcript_quality("Automate my invoices.") is None
-# --- judge failures: never a silent pass ----------------------------------
+def test_count_words_skips_tokens_without_a_letter_or_digit():
+ assert quality.count_words(" Uh... -- I run 2 shops !!! ") == 5
-async def test_no_llm_client_rejects_ambiguous_input(llm):
- llm(None)
- assert (
- await quality.check_transcript_quality("Automate my invoices.")
- == quality.INSUFFICIENT_CONTENT
- )
+# --- judge failures: an outage, never a verdict or a silent pass ----------
-async def test_no_llm_client_still_passes_clear_input(llm):
- llm(None)
- assert await quality.check_transcript_quality(SUBSTANTIAL_DUMP) is None
+def _hanging_client() -> MagicMock:
+ async def hang(**_kwargs):
+ await asyncio.Event().wait()
+ client = MagicMock()
+ client.chat.completions.create = hang
+ return client
[email protected]("content", ["not json at all", '{"usable": "yes"}', "{}"])
-async def test_malformed_llm_verdict_rejects(llm, content: str):
- llm(_llm_client(content))
- assert (
- await quality.check_transcript_quality("Automate my invoices.")
- == quality.INSUFFICIENT_CONTENT
- )
+
+def _raising_client() -> MagicMock:
+ client = MagicMock()
+ client.chat.completions.create = AsyncMock(side_effect=RuntimeError("boom"))
+ return client
-async def test_empty_choices_rejects(llm):
+def _no_choices_client() -> MagicMock:
response = MagicMock()
response.choices = []
client = MagicMock()
client.chat.completions.create = AsyncMock(return_value=response)
- llm(client)
- assert (
- await quality.check_transcript_quality("Automate my invoices.")
- == quality.INSUFFICIENT_CONTENT
- )
+ return client
@pytest.mark.asyncio
-async def test_llm_timeout_rejects(llm):
- client = MagicMock()
- client.chat.completions.create = AsyncMock(side_effect=asyncio.TimeoutError())
- llm(client)
- assert (
- await quality.check_transcript_quality("Automate my invoices.")
- == quality.INSUFFICIENT_CONTENT
+ "make_client,reason",
+ [
+ (lambda: None, "judge_unconfigured"),
+ (_hanging_client, "judge_timeout"),
+ (_raising_client, "judge_failed:RuntimeError"),
+ (lambda: _llm_client("not json at all"), "judge_malformed"),
+ (lambda: _llm_client('{"usable": "yes"}'), "judge_malformed"),
+ (lambda: _llm_client("{}"), "judge_malformed"),
+ (_no_choices_client, "judge_malformed"),
+ ],
+)
+async def test_a_judge_failure_rejects_as_unavailable_and_logs_an_error(
+ llm, caplog, monkeypatch, make_client, reason: str
+):
+ """The user must not be told they said too little, and the outage must
+ be seen: only an ERROR record becomes a Sentry event."""
+ llm(make_client())
+ monkeypatch.setattr(quality, "_TIMEOUT_SECONDS", 0.05)
+
+ with caplog.at_level(logging.WARNING, logger=quality.logger.name):
+ rejection = await asyncio.wait_for(
+ quality.check_transcript_quality("Automate my invoices."), timeout=5
+ )
+
+ assert rejection == quality.QualityRejection(
+ error_code=quality.QUALITY_CHECK_UNAVAILABLE, reason=reason
)
+ assert [record.levelno for record in caplog.records] == [logging.ERROR]
@pytest.mark.asyncio
-async def test_llm_error_rejects(llm):
- client = MagicMock()
- client.chat.completions.create = AsyncMock(side_effect=RuntimeError("boom"))
- llm(client)
- assert (
- await quality.check_transcript_quality("Automate my invoices.")
- == quality.INSUFFICIENT_CONTENT
- )
+async def test_no_llm_client_still_passes_clear_input(llm):
+ llm(None)
+ assert await quality.check_transcript_quality(SUBSTANTIAL_DUMP) is None
diff --git a/autogpt_platform/backend/backend/api/features/onboarding_dump/routes_test.py b/autogpt_platform/backend/backend/api/features/onboarding_dump/routes_test.py
index 201990469c..f92dac1254 100644
--- a/autogpt_platform/backend/backend/api/features/onboarding_dump/routes_test.py
+++ b/autogpt_platform/backend/backend/api/features/onboarding_dump/routes_test.py
@@ -15,7 +15,7 @@ from prisma.enums import BrainDumpInputMode, BrainDumpStatus
from prisma.models import OnboardingBrainDump
from pytest_mock import MockerFixture
-from backend.api.features.onboarding_dump import routes
+from backend.api.features.onboarding_dump import quality, routes
from backend.api.features.onboarding_dump.models import (
MAX_DURATION_SECS,
MAX_PART_BYTES,
@@ -42,6 +42,12 @@ RECOMMENDED_EXPERTS_URL = "/onboarding/brain-dump/recommended-experts"
RECORDING_ID = "rec-1"
TRANSCRIPT = "I run a small bakery and I want the weekly order emails handled."
+JUDGED_UNUSABLE = quality.QualityRejection(
+ error_code=quality.INSUFFICIENT_CONTENT, reason="judge_unusable"
+)
+# Taken before the autouse fixture below replaces it, for the one test
+# that drives the real gate.
+_REAL_QUALITY_GATE = quality.check_transcript_quality
GREETING = "Let's get those weekly order emails off your plate."
@@ -131,13 +137,18 @@ class DumpStore:
return True
async def mark_failed(
- self, user_id: str, recording_id: str, error_code: str
+ self,
+ user_id: str,
+ recording_id: str,
+ error_code: str,
+ reason: str | None = None,
) -> None:
await self.update_dump(
user_id,
recording_id,
status=BrainDumpStatus.failed,
errorCode=error_code,
+ errorReason=reason,
)
async def mark_greeting_seen(self, user_id: str) -> None:
@@ -456,7 +467,7 @@ def test_quality_rejected_voice_finalize_reports_the_error_code(
it went once the transcript was stored, and a re-record starts a new
take from the browser."""
upload_part()
- quality_gate.return_value = "insufficient_content"
+ quality_gate.return_value = JUDGED_UNUSABLE
response = finalize()
@@ -475,7 +486,7 @@ def test_quality_rejected_voice_finalize_reports_the_error_code(
def test_quality_rejected_typed_finalize_reports_the_error_code(
dumps: DumpStore, quality_gate: AsyncMock, extraction: dict[str, AsyncMock]
):
- quality_gate.return_value = "insufficient_content"
+ quality_gate.return_value = JUDGED_UNUSABLE
response = finalize(input_mode="typed", text="hello hello testing")
@@ -486,6 +497,35 @@ def test_quality_rejected_typed_finalize_reports_the_error_code(
extraction["upsert_business_understanding"].assert_not_awaited()
+def test_a_judge_outage_reports_its_own_code_and_reason(
+ dumps: DumpStore,
+ quality_gate: AsyncMock,
+ extraction: dict[str, AsyncMock],
+ mocker: MockerFixture,
+):
+ """Through the real gate: a judge that times out is reported as an
+ outage the frontend offers a retry for, never as "not enough", and the
+ row and the response both say what decided it."""
+ quality_gate.side_effect = _REAL_QUALITY_GATE
+ judge = MagicMock()
+ judge.chat.completions.create = AsyncMock(side_effect=TimeoutError())
+ mocker.patch.object(quality, "get_openai_client", return_value=judge)
+ upload_part()
+
+ response = finalize()
+
+ assert response.status_code == 200
+ body = response.json()
+ assert body["status"] == BrainDumpStatus.failed
+ assert body["error_code"] == "quality_check_unavailable"
+ assert body["error_reason"] == "judge_timeout"
+ assert body["transcript_words"] == 13
+ assert dumps.row is not None
+ assert dumps.row.errorCode == "quality_check_unavailable"
+ assert dumps.row.errorReason == "judge_timeout"
+ extraction["upsert_business_understanding"].assert_not_awaited()
+
+
def test_a_duration_past_the_ceiling_is_rejected(stt_create: AsyncMock):
"""``duration_secs`` is not just metadata — it bounds the split loop.
@@ -517,6 +557,8 @@ def test_skipped_finalize_records_the_skip_without_a_transcript(dumps: DumpStore
"input_mode": BrainDumpInputMode.skipped,
"transcript_preview": None,
"error_code": None,
+ "error_reason": None,
+ "transcript_words": None,
}
assert dumps.row is not None
assert dumps.row.inputMode == BrainDumpInputMode.skipped
diff --git a/autogpt_platform/backend/backend/api/features/onboarding_dump/service.py b/autogpt_platform/backend/backend/api/features/onboarding_dump/service.py
index bc2f2bb082..d85793e62e 100644
--- a/autogpt_platform/backend/backend/api/features/onboarding_dump/service.py
+++ b/autogpt_platform/backend/backend/api/features/onboarding_dump/service.py
@@ -215,10 +215,10 @@ async def finalize_voice_dump(
# its text for debugging — the gate only decides whether the
# personalized pipeline below may run on it. The recording is not kept
# for a rejected take either: the user re-records from the browser.
- quality_error = await quality.check_transcript_quality(result.text)
- if quality_error is not None:
+ rejection = await quality.check_transcript_quality(result.text)
+ if rejection is not None:
return await _quality_rejection(
- user_id, recording_id, quality_error, BrainDumpInputMode.voice
+ user_id, recording_id, rejection, result.text, BrainDumpInputMode.voice
)
# Finalize only does the audio work. Extraction and the Sonnet
# greeting are LLM calls that can outlive the frontend proxy's 30s
@@ -295,10 +295,10 @@ async def finalize_typed_dump(
# produce "asdf asdf asdf" just as easily as a silent mic produces a
# hallucinated transcript. Only the claim winner reaches this point,
# so concurrent retries never run duplicate quality checks.
- quality_error = await quality.check_transcript_quality(text)
- if quality_error is not None:
+ rejection = await quality.check_transcript_quality(text)
+ if rejection is not None:
return await _quality_rejection(
- user_id, recording_id, quality_error, BrainDumpInputMode.typed
+ user_id, recording_id, rejection, text, BrainDumpInputMode.typed
)
background_tasks.add_task(
@@ -347,23 +347,26 @@ async def _admit_processing(user_id: str, recording_id: str) -> None:
async def _quality_rejection(
user_id: str,
recording_id: str,
- error_code: str,
+ rejection: quality.QualityRejection,
+ transcript: str,
input_mode: BrainDumpInputMode,
) -> FinalizeResponse:
"""Mark the row failed with the gate's verdict and build the response.
Shared by the voice and typed paths so the reject contract (log, mark
- failed, surface the error code) cannot drift between them.
+ failed, surface the error code and reason) cannot drift between them.
"""
logger.info(
- f"Brain dump ({input_mode}) rejected by quality gate "
- f"for user {user_id} ({error_code})"
+ f"Brain dump ({input_mode}) rejected by quality gate for user "
+ f"{user_id} ({rejection.error_code}, {rejection.reason})"
)
- await db.mark_failed(user_id, recording_id, error_code)
+ await db.mark_failed(user_id, recording_id, rejection.error_code, rejection.reason)
return FinalizeResponse(
status=BrainDumpStatus.failed,
input_mode=input_mode,
- error_code=error_code,
+ error_code=rejection.error_code,
+ error_reason=rejection.reason,
+ transcript_words=quality.count_words(transcript),
)
diff --git a/autogpt_platform/backend/backend/api/features/onboarding_dump/service_test.py b/autogpt_platform/backend/backend/api/features/onboarding_dump/service_test.py
index cd53411806..ed1dfb6986 100644
--- a/autogpt_platform/backend/backend/api/features/onboarding_dump/service_test.py
+++ b/autogpt_platform/backend/backend/api/features/onboarding_dump/service_test.py
@@ -22,6 +22,7 @@ from backend.api.features.onboarding_dump import (
db,
intro,
prompts,
+ quality,
service,
transcription,
)
@@ -46,8 +47,16 @@ _NEW_TAKE_COLUMNS: dict[str, Any] = {
"recommendedProviders": None,
"recommendedExperts": None,
"errorCode": None,
+ "errorReason": None,
}
+DETERMINISTIC = quality.QualityRejection(
+ error_code=quality.NO_USABLE_SPEECH, reason="deterministic"
+)
+JUDGED_UNUSABLE = quality.QualityRejection(
+ error_code=quality.INSUFFICIENT_CONTENT, reason="judge_unusable"
+)
+
class DumpStore:
"""In-memory stand-in for the one-row-per-user brain dump table."""
@@ -92,6 +101,7 @@ class DumpStore:
self.row.status = BrainDumpStatus.recording_uploaded
self.row.inputMode = input_mode
self.row.errorCode = None
+ self.row.errorReason = None
else:
# model_construct skips defaults, so every column the code
# under test reads has to be seeded explicitly — otherwise a
@@ -141,13 +151,18 @@ class DumpStore:
return True
async def mark_failed(
- self, user_id: str, recording_id: str, error_code: str
+ self,
+ user_id: str,
+ recording_id: str,
+ error_code: str,
+ reason: str | None = None,
) -> None:
await self.update_dump(
user_id,
recording_id,
status=BrainDumpStatus.failed,
errorCode=error_code,
+ errorReason=reason,
)
async def mark_greeting_seen(self, user_id: str) -> None:
@@ -1115,7 +1130,7 @@ async def test_quality_rejected_voice_dump_keeps_its_transcript_and_queues_nothi
storage_mocks: dict[str, AsyncMock],
):
await start_voice_take(dumps)
- quality_gate.return_value = "no_usable_speech"
+ quality_gate.return_value = DETERMINISTIC
background = BackgroundTasks()
response = await service.finalize_voice_dump(
@@ -1125,9 +1140,12 @@ async def test_quality_rejected_voice_dump_keeps_its_transcript_and_queues_nothi
assert response.status == BrainDumpStatus.failed
assert response.error_code == "no_usable_speech"
+ assert response.error_reason == "deterministic"
+ assert response.transcript_words == 11
assert dumps.row is not None
assert dumps.row.status == BrainDumpStatus.failed
assert dumps.row.errorCode == "no_usable_speech"
+ assert dumps.row.errorReason == "deterministic"
# The transcript survives the rejection for debugging. The recording
# does not: it went once the transcript was stored, and the user
# re-records from the browser rather than from it.
@@ -1144,7 +1162,7 @@ async def test_quality_rejected_voice_dump_keeps_its_transcript_and_queues_nothi
async def test_quality_rejected_typed_dump_records_the_error(
dumps: DumpStore, quality_gate: AsyncMock, extraction: dict[str, AsyncMock]
):
- quality_gate.return_value = "insufficient_content"
+ quality_gate.return_value = JUDGED_UNUSABLE
background = BackgroundTasks()
response = await service.finalize_typed_dump(
@@ -1154,9 +1172,12 @@ async def test_quality_rejected_typed_dump_records_the_error(
assert response.status == BrainDumpStatus.failed
assert response.error_code == "insufficient_content"
+ assert response.error_reason == "judge_unusable"
+ assert response.transcript_words == 3
assert dumps.row is not None
assert dumps.row.status == BrainDumpStatus.failed
assert dumps.row.errorCode == "insufficient_content"
+ assert dumps.row.errorReason == "judge_unusable"
assert dumps.row.transcript == "hello hello testing"
assert background.tasks == []
extraction["upsert_business_understanding"].assert_not_awaited()
@@ -1173,7 +1194,7 @@ async def test_repeating_finalize_after_quality_rejection_does_not_rerun_the_gat
the row's failure instead, without a second quality check.
"""
await start_voice_take(dumps)
- quality_gate.return_value = "no_usable_speech"
+ quality_gate.return_value = DETERMINISTIC
await finalize_voice()
response = await finalize_voice()
@@ -1188,7 +1209,7 @@ async def test_a_new_take_after_quality_rejection_runs_the_pipeline(
dumps: DumpStore, quality_gate: AsyncMock, extraction: dict[str, AsyncMock]
):
await start_voice_take(dumps)
- quality_gate.return_value = "insufficient_content"
+ quality_gate.return_value = JUDGED_UNUSABLE
await finalize_voice()
quality_gate.return_value = None
@@ -1207,16 +1228,23 @@ async def test_a_new_take_after_quality_rejection_runs_the_pipeline(
@pytest.mark.asyncio
-async def test_intro_card_takes_path_b_for_a_quality_rejected_dump(dumps: DumpStore):
+ "error_code",
+ ["no_usable_speech", "insufficient_content", "quality_check_unavailable"],
+)
+async def test_intro_card_takes_path_b_for_a_quality_rejected_dump(
+ dumps: DumpStore, error_code: str
+):
"""The preserved transcript of a rejected dump must never leak into a
- Path A greeting — the gate already decided it isn't worth reflecting."""
+ Path A greeting, even one the judge was unavailable for: the gate
+ fails closed."""
await dumps.start_dump(USER_ID, RECORDING_ID, BrainDumpInputMode.voice)
await dumps.update_dump(
USER_ID,
RECORDING_ID,
status=BrainDumpStatus.failed,
transcript="Thank you for watching.",
- errorCode="insufficient_content",
+ errorCode=error_code,
)
card = await service.get_intro_card(USER_ID)
diff --git a/autogpt_platform/backend/migrations/20261022000000_add_brain_dump_error_reason/migration.sql b/autogpt_platform/backend/migrations/20261022000000_add_brain_dump_error_reason/migration.sql
new file mode 100644
index 0000000000..1e01b7d065
--- /dev/null
+++ b/autogpt_platform/backend/migrations/20261022000000_add_brain_dump_error_reason/migration.sql
@@ -0,0 +1,4 @@
+-- What decided a quality-gate rejection, beside errorCode
+-- (quality.QualityRejection.reason). NULL for every other failure.
+ALTER TABLE "OnboardingBrainDump"
+ ADD COLUMN "errorReason" TEXT;
diff --git a/autogpt_platform/backend/schema.prisma b/autogpt_platform/backend/schema.prisma
index 75848befcb..3168e2ae6e 100644
--- a/autogpt_platform/backend/schema.prisma
+++ b/autogpt_platform/backend/schema.prisma
@@ -498,6 +498,8 @@ model OnboardingBrainDump {
transcript String?
transcriptLang String?
errorCode String?
+ /// What decided a quality-gate rejection (`quality.QualityRejection.reason`).
+ errorReason String?
/// Written once when the dump is processed, read by the copilot home's
/// greeting. Generated up-front rather than on page load so the greeting
diff --git a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/__tests__/brain-dump.test.tsx b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/__tests__/brain-dump.test.tsx
index 71fb00f143..f57a848cdb 100644
--- a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/__tests__/brain-dump.test.tsx
+++ b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/__tests__/brain-dump.test.tsx
@@ -829,6 +829,64 @@ describe("onboarding brain dump — failure", () => {
// The wizard must not advance on failure.
expect(screen.queryByTestId("step-hire")).toBeNull();
});
+
+ it("retries a typed take with its text and sends no recording", async () => {
+ const partUploads: string[] = [];
+ server.use(
+ getUploadBrainDumpPartMockHandler200(() => {
+ partUploads.push("part");
+ return {
+ recording_id: "r",
+ part_index: 0,
+ received_bytes: 9,
+ total_bytes: 9,
+ };
+ }),
+ );
+ const responses = [
+ { status: "failed" as const, error_code: "quality_check_unavailable" },
+ { status: "completed" as const },
+ ];
+ const finalizeBodies: unknown[] = [];
+ server.use(
+ getFinalizeBrainDumpMockHandler200(async (info) => {
+ finalizeBodies.push(await info.request.json());
+ return {
+ ...responses[finalizeBodies.length - 1],
+ input_mode: "typed" as const,
+ };
+ }),
+ );
+ landOnPainPointsStep();
+
+ render(<OnboardingPage />);
+ await screen.findByText(DUMP_HEADLINE);
+ await userEvent.click(screen.getByRole("button", { name: "Write" }));
+ await userEvent.type(
+ await screen.findByPlaceholderText(
+ "What repeats every week? What would you hand off first?",
+ ),
+ "I run a bakery",
+ );
+ await userEvent.click(screen.getByRole("button", { name: "I'm done" }));
+
+ expect(
+ await screen.findByText("Your text is safe. Try again."),
+ ).toBeDefined();
+ expect(
+ screen.queryByRole("button", { name: "Download recording" }),
+ ).toBeNull();
+
+ await userEvent.click(screen.getByRole("button", { name: "Try again" }));
+
+ expect(await screen.findByTestId("step-hire")).toBeDefined();
+ expect(finalizeBodies).toHaveLength(2);
+ expect(finalizeBodies[1]).toMatchObject({
+ input_mode: "typed",
+ text: "I run a bakery",
+ });
+ expect(partUploads).toHaveLength(0);
+ });
});
describe("onboarding brain dump — insufficient content", () => {
@@ -878,6 +936,20 @@ describe("onboarding brain dump — insufficient content", () => {
expect(recordingStoreState.parts).toHaveLength(1);
});
+ it("offers a retry of the same take when the quality check was unavailable", async () => {
+ finalizeReturns({
+ status: "failed",
+ error_code: "quality_check_unavailable",
+ });
+
+ await recordAndSend();
+
+ expect(await screen.findByText("That didn't go through.")).toBeDefined();
+ expect(screen.getByRole("button", { name: "Try again" })).toBeDefined();
+ expect(screen.queryByText("We didn't catch enough of that.")).toBeNull();
+ expect(recordingStoreState.parts).toHaveLength(1);
+ });
+
it("moves on from 'Continue without it' before the skip is recorded", async () => {
const skip = holdSkipRecord();
diff --git a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/BrainDumpStep.tsx b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/BrainDumpStep.tsx
index a862db29b2..c02409adfa 100644
--- a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/BrainDumpStep.tsx
+++ b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/BrainDumpStep.tsx
@@ -165,6 +165,7 @@ export function BrainDumpStep() {
{dump.screen === "failed" && (
<RevealItem>
<FailureState
+ mode={dump.submittedMode}
onDownload={dump.handleDownloadRecording}
onSkip={dump.handleSkip}
/>
@@ -195,7 +196,9 @@ export function BrainDumpStep() {
onClick={dump.showTyping}
className="underline underline-offset-4"
>
- type instead
+ {dump.submittedMode === "typed"
+ ? "edit your text"
+ : "type instead"}
</Button>
)}
{isTyping && !dump.isMicBlocked && (
diff --git a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/__tests__/useBrainDumpStep.test.ts b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/__tests__/useBrainDumpStep.test.ts
index 56b84d3e73..3c57785c59 100644
--- a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/__tests__/useBrainDumpStep.test.ts
+++ b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/__tests__/useBrainDumpStep.test.ts
@@ -771,6 +771,33 @@ describe("useBrainDumpStep — retry", () => {
});
});
+ it("retries the recording, not earlier typed text, when sending it failed", async () => {
+ finalizeBrainDump.mockRejectedValueOnce(new Error("offline"));
+ const { result } = await renderStep();
+ act(() => {
+ result.current.setTypedText("notes");
+ });
+ await act(async () => {
+ await result.current.handleSubmitTyped();
+ });
+ recorderState.recordingId = "rec-1";
+ recorderState.stop.mockRejectedValueOnce(new Error("stop failed"));
+ await act(async () => {
+ await result.current.handleDone();
+ });
+ finalizeBrainDump.mockClear();
+
+ await act(async () => {
+ await result.current.handleRetry();
+ });
+
+ expect(recorderState.resendAllParts).toHaveBeenCalledWith("rec-1");
+ expect(finalizeBody()).toMatchObject({
+ recording_id: "rec-1",
+ input_mode: "voice",
+ });
+ });
+
it("does not replay parts when there is no recording to retry", async () => {
recorderState.recordingId = null;
const { result } = await renderStep();
diff --git a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/components/FailureState.tsx b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/components/FailureState.tsx
index 39f7655de8..08f8ba8fad 100644
--- a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/components/FailureState.tsx
+++ b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/components/FailureState.tsx
@@ -4,6 +4,7 @@ import { Button } from "@/components/atoms/Button/Button";
import { Text } from "@/components/atoms/Text/Text";
interface Props {
+ mode: "voice" | "typed";
onDownload: () => void;
onSkip: () => void;
}
@@ -14,17 +15,22 @@ interface Props {
// inconvenience, not a loss — the copy and the download button both have to
// make that obvious. Download and retry both read the
// browser's copy. Retrying is the orb itself, so only the secondary exits
-// live here.
-export function FailureState({ onDownload, onSkip }: Props) {
+// live here. A typed take has no recording, so it gets neither the download
+// nor that promise; its text stays in the composer.
+export function FailureState({ mode, onDownload, onSkip }: Props) {
return (
<div className="flex flex-col items-center gap-4 text-center">
<Text variant="body" tone="muted">
- Your recording is safe. Try again.
+ {mode === "voice"
+ ? "Your recording is safe. Try again."
+ : "Your text is safe. Try again."}
</Text>
<div className="flex items-center gap-3">
- <Button variant="primary" size="small" onClick={onDownload}>
- Download recording
- </Button>
+ {mode === "voice" && (
+ <Button variant="primary" size="small" onClick={onDownload}>
+ Download recording
+ </Button>
+ )}
<Button variant="ghost" size="small" onClick={onSkip}>
Continue without it
</Button>
diff --git a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/helpers.ts b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/helpers.ts
index 09865f41b7..7d7d2d1a32 100644
--- a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/helpers.ts
+++ b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/helpers.ts
@@ -98,6 +98,8 @@ export const BRAIN_DUMP_HEADLINE = "Talk to me about your work";
// transcription succeeded but carried nothing to personalize from —
// silence, filler, or an STT hallucination. Distinct from a transcription
// failure: the take went through fine, it just didn't say enough.
+// `quality_check_unavailable` is left out on purpose: the judge never ruled,
+// so the take gets the failure screen, whose retry can still pass.
const INSUFFICIENT_DUMP_ERROR_CODES = [
"no_usable_speech",
"insufficient_content",
diff --git a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/useBrainDumpStep.ts b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/useBrainDumpStep.ts
index ee0f9dcebc..5cd8661b29 100644
--- a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/useBrainDumpStep.ts
+++ b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/useBrainDumpStep.ts
@@ -44,6 +44,11 @@ export function useBrainDumpStep() {
const [insufficientMode, setInsufficientMode] = useState<"voice" | "typed">(
"voice",
);
+ // Which kind of take was last sent: the failure screen retries that one,
+ // and a typed take has no recording to resend.
+ const [submittedMode, setSubmittedMode] = useState<"voice" | "typed">(
+ "voice",
+ );
const [typedText, setTypedText] = useState("");
const [reachedTimeLimit, setReachedTimeLimit] = useState(false);
@@ -123,6 +128,7 @@ export function useBrainDumpStep() {
}
async function handleDone() {
+ setSubmittedMode("voice");
setScreen("processing");
// Duration comes back from `stop()` for the same reason the id is
// passed in below — `recorder.elapsedSeconds` here is this render's
@@ -168,6 +174,7 @@ export function useBrainDumpStep() {
recordingId: string | null,
durationSecs: number,
) {
+ setSubmittedMode("voice");
const actionToken = recordingId
? claimTakeAction(recordingId, "submit")
: null;
@@ -271,6 +278,10 @@ export function useBrainDumpStep() {
async function handleRetry() {
retryCountRef.current += 1;
trackBrainDump("brain_dump_retry", { attempt: retryCountRef.current });
+ if (submittedMode === "typed") {
+ await handleSubmitTyped();
+ return;
+ }
setScreen("processing");
const recordingId = recorder.recordingId;
if (recordingId) await recorder.resendAllParts(recordingId);
@@ -300,6 +311,7 @@ export function useBrainDumpStep() {
}
async function submitTyped(text: string) {
+ setSubmittedMode("typed");
setScreen("processing");
const recordingId = recorder.recordingId ?? crypto.randomUUID();
try {
@@ -471,6 +483,7 @@ export function useBrainDumpStep() {
headline: BRAIN_DUMP_HEADLINE,
screen,
insufficientMode,
+ submittedMode,
typedText,
setTypedText,
elapsedSeconds: recorder.elapsedSeconds,
diff --git a/autogpt_platform/frontend/src/app/api/openapi.json b/autogpt_platform/frontend/src/app/api/openapi.json
index 7906a5b226..a9cffcae39 100644
--- a/autogpt_platform/frontend/src/app/api/openapi.json
+++ b/autogpt_platform/frontend/src/app/api/openapi.json
@@ -26251,6 +26251,14 @@
"error_code": {
"anyOf": [{ "type": "string" }, { "type": "null" }],
"title": "Error Code"
+ },
+ "error_reason": {
+ "anyOf": [{ "type": "string" }, { "type": "null" }],
+ "title": "Error Reason"
+ },
+ "transcript_words": {
+ "anyOf": [{ "type": "integer" }, { "type": "null" }],
+ "title": "Transcript Words"
}
},
"type": "object",