Skip to content

Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.

fix(transcribe): start jobs IN_PROGRESS rather than QUEUED (#1690)

ppettitaub1816e35c8db
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 010df17d..9eec2308 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,11 @@ All notable changes to MiniStack will be documented here.
Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
Versioning follows [Semantic Versioning](https://semver.org/).
+## [Unreleased]
+
+### Fixed
+- **Transcribe — `StartTranscriptionJob` returns a job already `IN_PROGRESS`** — the start response reported `QUEUED` with no `StartTime`, and the job reached `IN_PROGRESS` only from the background worker, after the response had been sent. A caller that reads the status off the start response and then waits for the terminal `Transcribe Job State Change` event, rather than polling, therefore never saw an in-progress state at all: the job went straight from queued to complete. Jobs now start `IN_PROGRESS` with `StartTime` set, matching the response the AWS CLI walkthrough documents, and `TRANSCRIBE_JOB_RUN_SECONDS` covers the whole run rather than half of it. `QUEUED`, which AWS reaches only for a request that opted into job queueing through `JobExecutionSettings.AllowDeferredExecution` while the account is at its concurrent job limit, stays reachable through the new `TRANSCRIBE_JOB_QUEUE_SECONDS` (default `0`); both knobs are settable at runtime through `/_ministack/config`. Contributed by @ppettitau.
+
## [1.5.10] — 2026-09-10
### Added
diff --git a/README.md b/README.md
index afb7fd47..fcfc7e14 100644
--- a/README.md
+++ b/README.md
@@ -427,7 +427,7 @@ subnet = ec2.create_subnet(
| **Bedrock Agent** | 72 operations — agents (versions, aliases, action groups, collaborators, agent knowledge bases, PrepareAgent), knowledge bases (data sources, ingestion jobs — `StartIngestionJob` reads the S3 data source and reports real statistics, `FAILED` with `failureReasons` when the source is unreadable — documents), flows (aliases, versions, ValidateFlowDefinition, PrepareFlow), prompts with versions, tagging | All 72 operations verified against botocore `bedrock-agent-2023-06-05` |
| **Bedrock Agent Runtime** | InvokeAgent, InvokeInlineAgent, GetAgentMemory, DeleteAgentMemory, Retrieve, RetrieveAndGenerate, RetrieveAndGenerateStream, Rerank, CreateSession, GetSession, UpdateSession, DeleteSession, EndSession, ListSessions, CreateInvocation, ListInvocations, PutInvocationStep, GetInvocationStep, ListInvocationSteps, InvokeFlow, StartFlowExecution, StopFlowExecution, GetFlowExecution, ListFlowExecutions, ListFlowExecutionEvents, GetExecutionFlowSnapshot, OptimizePrompt | All 31 operations verified against botocore `bedrock-agent-runtime-2023-07-26`; eventstream responses on streaming operations; `Retrieve` searches the documents Knowledge Base ingestion stored (lexical scoring — no embeddings) and returns content, `s3Location` and score; `InvokeAgent` answers a canned reply without orchestration and emits no trace events — it never fabricates an `ORCHESTRATE` trace |
| **Bedrock AgentCore** | Control plane (`bedrock-agentcore-control`): CreateAgentRuntime, GetAgentRuntime, ListAgentRuntimes, UpdateAgentRuntime, DeleteAgentRuntime, ListAgentRuntimeVersions, CreateAgentRuntimeEndpoint, GetAgentRuntimeEndpoint, ListAgentRuntimeEndpoints, UpdateAgentRuntimeEndpoint, DeleteAgentRuntimeEndpoint. Data plane (`bedrock-agentcore`): InvokeAgentRuntime | Agent-runtime lifecycle with `CREATING`/`UPDATING`→`READY` transitions, versioned ARNs (`agent/{uuid}:{version}`, `agentEndpoint/{uuid}`); request/response shapes verified against botocore `bedrock-agentcore-control` / `bedrock-agentcore`; account- and region-scoped state; `InvokeAgentRuntime` is a deterministic echo (no model inference), matching the requested emulation scope |
-| **Transcribe** | StartTranscriptionJob, GetTranscriptionJob, ListTranscriptionJobs, DeleteTranscriptionJob | Batch transcription jobs only; streaming is a separate endpoint (`transcribestreaming`). All four operations verified against botocore `transcribe-2017-10-26`. Jobs walk `QUEUED` → `IN_PROGRESS` → `COMPLETED` over `TRANSCRIBE_JOB_RUN_SECONDS` (default 2, `0` completes immediately); the media object is read from MiniStack S3 via an `s3://`, path-style or virtual-hosted HTTPS URI, and an unreadable URI fails the job with a `FailureReason` rather than erroring at `Start`, as on AWS; the transcript is written back to S3 in the real result format (`results.transcripts`, word-level `results.items`, `results.audio_segments`, plus `results.segments` and `results.speaker_labels` when the matching `Settings` are set) at `OutputBucketName`/`OutputKey`, or to an auto-created `ministack-transcribe-output` bucket. `IdentifyLanguage` and `IdentifyMultipleLanguages` resolve a language on completion, `ContentRedaction` controls whether a `redacted-` copy replaces or accompanies the transcript, and `Subtitles` writes WebVTT and SubRip files, redacted alongside the transcript when redaction is on. Reaching a terminal state publishes a `Transcribe Job State Change` event, so EventBridge rules downstream of a job fire. There is no speech recognition, so the transcript is deterministic canned text keyed on a digest of the media URI |
+| **Transcribe** | StartTranscriptionJob, GetTranscriptionJob, ListTranscriptionJobs, DeleteTranscriptionJob | Batch transcription jobs only; streaming is a separate endpoint (`transcribestreaming`). All four operations verified against botocore `transcribe-2017-10-26`. A job starts `IN_PROGRESS` with `StartTime` set, as on AWS, and reaches `COMPLETED` over `TRANSCRIBE_JOB_RUN_SECONDS` (default 2, `0` completes immediately); `QUEUED`, which AWS reaches only for a request that opted into job queueing while the account is at its concurrent job limit, is reachable by setting `TRANSCRIBE_JOB_QUEUE_SECONDS`; the media object is read from MiniStack S3 via an `s3://`, path-style or virtual-hosted HTTPS URI, and an unreadable URI fails the job with a `FailureReason` rather than erroring at `Start`, as on AWS; the transcript is written back to S3 in the real result format (`results.transcripts`, word-level `results.items`, `results.audio_segments`, plus `results.segments` and `results.speaker_labels` when the matching `Settings` are set) at `OutputBucketName`/`OutputKey`, or to an auto-created `ministack-transcribe-output` bucket. `IdentifyLanguage` and `IdentifyMultipleLanguages` resolve a language on completion, `ContentRedaction` controls whether a `redacted-` copy replaces or accompanies the transcript, and `Subtitles` writes WebVTT and SubRip files, redacted alongside the transcript when redaction is on. Reaching a terminal state publishes a `Transcribe Job State Change` event, so EventBridge rules downstream of a job fire. There is no speech recognition, so the transcript is deterministic canned text keyed on a digest of the media URI |
| **Translate** | StartTextTranslationJob, DescribeTextTranslationJob, ListTextTranslationJobs, StopTextTranslationJob | Batch text translation jobs only; the synchronous `TranslateText` / `TranslateDocument` pair and the custom terminology / parallel data families are not implemented. All four operations verified against botocore `translate-2017-07-01`. Jobs walk `SUBMITTED` → `IN_PROGRESS` → `COMPLETED` over `TRANSLATE_JOB_RUN_SECONDS` (default 2, `0` completes immediately); every document under `InputDataConfig.S3Uri` is read from MiniStack S3 and written back to the rewritten output location AWS uses — `OutputDataConfig.S3Uri` is reported as `s3://<bucket>/<prefix><account-id>-TranslateText-<JobId>/` — as `<target-code>.<input name>`, with a `details/<code>.auxiliary-translation-details.json` summary per target language. `text/plain` is translated line by line, `text/html` keeps its markup and translates only text nodes, `application/x-xliff+xml` gets a populated `<target>` in every `<trans-unit>` plus `target-language` on every `<file>`, and the three Office ZIP types are copied through. A document that can't be read as its content type is counted in `JobDetails` and the job ends `COMPLETED_WITH_ERROR`; an empty or unreadable input location fails the job with a `Message` rather than erroring at `Start`. `ClientToken` is idempotent, `StopTextTranslationJob` reaches a running worker, and reaching a terminal state publishes a `Translate TextTranslationJob State Change` event, so EventBridge rules downstream of a job fire. There is no machine translation, so the output is deterministic canned text derived from the source |
| **MSK** | CreateCluster, ListClusters, DescribeCluster, DeleteCluster, GetBootstrapBrokers, ListNodes, CreateConfiguration, ListConfigurations, DescribeConfiguration, ListConfigurationRevisions, DescribeConfigurationRevision, BatchAssociateScramSecret, BatchDisassociateScramSecret, ListScramSecrets, TagResource, UntagResource, ListTagsForResource | Kafka control plane; `GetBootstrapBrokers` honors `MINISTACK_MSK_BOOTSTRAP` so clients route to a real broker you bring (Redpanda, Kafka, KRaft) — the Kafka wire protocol itself is not emulated |
| **WAF v2** | CreateWebACL, GetWebACL, UpdateWebACL, DeleteWebACL, ListWebACLs, AssociateWebACL, DisassociateWebACL, GetWebACLForResource, ListResourcesForWebACL, CreateIPSet, GetIPSet, UpdateIPSet, DeleteIPSet, ListIPSets, CreateRuleGroup, GetRuleGroup, UpdateRuleGroup, DeleteRuleGroup, ListRuleGroups, TagResource, UntagResource, ListTagsForResource, CheckCapacity, DescribeManagedRuleGroup | LockToken enforced on Update/Delete; resource associations tracked |
@@ -863,7 +863,8 @@ end-to-end without any client config.
| `MINISTACK_MSK_BOOTSTRAP_TLS` | _(unset)_ | TLS bootstrap string (`BootstrapBrokerStringTls`) |
| `MINISTACK_MSK_BOOTSTRAP_SASL_SCRAM` | _(unset)_ | SASL/SCRAM bootstrap string (`BootstrapBrokerStringSaslScram`) |
| `MINISTACK_MSK_BOOTSTRAP_SASL_IAM` | _(unset)_ | SASL/IAM bootstrap string (`BootstrapBrokerStringSaslIam`) |
-| `TRANSCRIBE_JOB_RUN_SECONDS` | `2` | Wall-clock time a Transcribe job spends between `QUEUED` and `COMPLETED`. Set `0` to complete immediately, or raise it when a test needs to observe `IN_PROGRESS` |
+| `TRANSCRIBE_JOB_RUN_SECONDS` | `2` | Wall-clock time a Transcribe job spends between `IN_PROGRESS` and `COMPLETED`. Set `0` to complete immediately, or raise it when a test needs to observe `IN_PROGRESS`. Also settable without a restart by posting `{"transcribe._JOB_RUN_SECONDS": 10}` to `/_ministack/config` |
+| `TRANSCRIBE_JOB_QUEUE_SECONDS` | `0` | Wall-clock time a Transcribe job sits `QUEUED` before it starts. On AWS a job is queued only if the request opted in through `JobExecutionSettings.AllowDeferredExecution` and the account is at its concurrent job limit, so the default is `0` and `StartTranscriptionJob` returns `IN_PROGRESS` as it does on AWS. Raise it to exercise a caller that handles `QUEUED`. Also settable through `/_ministack/config` |
| `TRANSLATE_JOB_RUN_SECONDS` | `2` | Wall-clock time a Translate batch job spends between `SUBMITTED` and `COMPLETED`. Set `0` to complete immediately, or raise it when a test needs to observe `IN_PROGRESS` or stop a running job. Also settable without a restart by posting `{"translate._JOB_RUN_SECONDS": 10}` to `/_ministack/config` |
### API Gateway HTTP proxy execution model
diff --git a/ministack/app.py b/ministack/app.py
index cb662bde..943dc84e 100644
--- a/ministack/app.py
+++ b/ministack/app.py
@@ -1232,6 +1232,8 @@ async def _handle_admin_config_request(path: str, method: str, body: bytes):
"stepfunctions._sfn_mock_config",
"stepfunctions._SFN_WAIT_SCALE",
"translate._JOB_RUN_SECONDS",
+ "transcribe._JOB_RUN_SECONDS",
+ "transcribe._JOB_QUEUE_SECONDS",
"lambda_svc.LAMBDA_EXECUTOR",
"cloudtrail._recording_enabled",
"alb.TARGET_CONNECT_TIMEOUT",
@@ -1253,7 +1255,12 @@ async def _handle_admin_config_request(path: str, method: str, body: bytes):
mod_name, var_name = key.rsplit(".", 1)
try:
mod = __import__(f"ministack.services.{mod_name}", fromlist=[var_name])
- if key in ("stepfunctions._SFN_WAIT_SCALE", "translate._JOB_RUN_SECONDS"):
+ if key in (
+ "stepfunctions._SFN_WAIT_SCALE",
+ "translate._JOB_RUN_SECONDS",
+ "transcribe._JOB_RUN_SECONDS",
+ "transcribe._JOB_QUEUE_SECONDS",
+ ):
try:
float_value = float(value)
except (ValueError, TypeError):
diff --git a/ministack/services/transcribe.py b/ministack/services/transcribe.py
index 3a2f635b..56dbe8b3 100644
--- a/ministack/services/transcribe.py
+++ b/ministack/services/transcribe.py
@@ -10,8 +10,13 @@ Implemented:
StartTranscriptionJob, GetTranscriptionJob, ListTranscriptionJobs,
DeleteTranscriptionJob.
-Jobs run as a background task that walks QUEUED -> IN_PROGRESS -> COMPLETED
-over ``TRANSCRIBE_JOB_RUN_SECONDS`` (0 completes immediately), reads the media
+StartTranscriptionJob returns the job already IN_PROGRESS with StartTime set,
+as the documented AWS response does. QUEUED is reached on AWS only by a
+request that opted into job queueing while the account is at its concurrent
+job limit; here it is reachable by setting ``TRANSCRIBE_JOB_QUEUE_SECONDS``.
+A background task
+walks the job to COMPLETED or FAILED over ``TRANSCRIBE_JOB_RUN_SECONDS``
+(0 completes immediately), reads the media
object out of MiniStack's S3 store, and writes a transcript document back to
S3 in the real Transcribe result format. Entering a terminal state publishes a
``Transcribe Job State Change`` event so EventBridge rules downstream of a
@@ -74,11 +79,18 @@ from ministack.core.responses import (
logger = logging.getLogger("transcribe")
-# How long a job spends between QUEUED and COMPLETED. Same knob shape as
-# GLUE_CRAWLER_RUN_SECONDS: tests that assert on IN_PROGRESS need a non-zero
-# value, tests that just want a result set it to 0.
+# How long a job spends between IN_PROGRESS and COMPLETED. Same knob shape as
+# GLUE_CRAWLER_RUN_SECONDS: tests that want to observe a job mid-flight need a
+# non-zero value, tests that just want a result set it to 0.
_JOB_RUN_SECONDS = float(os.environ.get("TRANSCRIBE_JOB_RUN_SECONDS", "2"))
+# How long a job sits QUEUED before it starts. On AWS a job is queued only if
+# the request opted into queueing (JobExecutionSettings.AllowDeferredExecution)
+# and the account is at its concurrent job limit, so the default is 0 and the
+# start response reports IN_PROGRESS. Raise it to exercise a caller that
+# handles QUEUED. Also settable at runtime through /_ministack/config.
+_JOB_QUEUE_SECONDS = float(os.environ.get("TRANSCRIBE_JOB_QUEUE_SECONDS", "0"))
+
# Where transcripts land when the caller supplies no OutputBucketName. Real
# Transcribe uses a service-managed bucket and hands back a presigned URL; the
# local equivalent is a bucket MiniStack owns, so the URI is always fetchable.
@@ -221,7 +233,7 @@ def load_persisted_state(data):
def _fail_orphaned_jobs():
"""A job that was mid-flight when the process stopped has no worker any
- more. Leaving it QUEUED or IN_PROGRESS strands every caller polling
+ more. Leaving it in a non-terminal state strands every caller polling
GetTranscriptionJob forever, so it is failed the way AWS fails a job it
cannot finish."""
for job in _jobs.all_values():
@@ -609,13 +621,13 @@ def _live_job(job_name, run_id):
return job
-async def _run_job(job_name, run_id, account_id, region, netloc):
+async def _run_job(job_name, run_id, account_id, region, netloc, queue_seconds):
"""Walk a job to a terminal state. Runs as a background task, so it pins
the account and region it was started for rather than inheriting whatever
request happens to be in flight."""
with request_scope(account_id, region):
try:
- await _run_job_inner(job_name, run_id, netloc)
+ await _run_job_inner(job_name, run_id, netloc, queue_seconds)
except Exception:
logger.exception("Transcribe: job %s crashed", job_name)
job = _live_job(job_name, run_id)
@@ -626,21 +638,23 @@ async def _run_job(job_name, run_id, account_id, region, netloc):
_emit_state_change(job_name, "FAILED")
-async def _run_job_inner(job_name, run_id, netloc):
- half = _JOB_RUN_SECONDS / 2 if _JOB_RUN_SECONDS > 0 else 0
-
- if half:
- await asyncio.sleep(half)
+async def _run_job_inner(job_name, run_id, netloc, queue_seconds):
+ # queue_seconds is passed in rather than read here: the start handler
+ # decided on it when it chose the job's initial status, and /_ministack/config
+ # can change the module value in between, which would otherwise leave a
+ # QUEUED job with no worker to start it.
+ if queue_seconds > 0:
+ await asyncio.sleep(queue_seconds)
- job = _live_job(job_name, run_id)
- if job is None:
- return
+ job = _live_job(job_name, run_id)
+ if job is None:
+ return
- job["TranscriptionJobStatus"] = "IN_PROGRESS"
- job["StartTime"] = time.time()
+ job["TranscriptionJobStatus"] = "IN_PROGRESS"
+ job["StartTime"] = time.time()
- if half:
- await asyncio.sleep(half)
+ if _JOB_RUN_SECONDS > 0:
+ await asyncio.sleep(_JOB_RUN_SECONDS)
job = _live_job(job_name, run_id)
if job is None:
@@ -819,16 +833,21 @@ def _start_transcription_job(data):
location_type = "SERVICE_BUCKET"
run_id = new_uuid()
+ queue_seconds = _JOB_QUEUE_SECONDS
+ queued = queue_seconds > 0
+ # One timestamp for both members: a job that starts immediately has not
+ # started before it was created, and two time.time() calls can skew.
+ created = time.time()
job = {
"TranscriptionJobName": name,
- "TranscriptionJobStatus": "QUEUED",
+ "TranscriptionJobStatus": "QUEUED" if queued else "IN_PROGRESS",
"LanguageCode": language_code,
"MediaSampleRateHertz": data.get("MediaSampleRateHertz"),
"MediaFormat": data.get("MediaFormat"),
"Media": copy.deepcopy(media),
"Transcript": None,
- "StartTime": None,
- "CreationTime": time.time(),
+ "StartTime": None if queued else created,
+ "CreationTime": created,
"CompletionTime": None,
"FailureReason": None,
"Settings": copy.deepcopy(data.get("Settings")) if data.get("Settings") else None,
@@ -855,7 +874,9 @@ def _start_transcription_job(data):
_jobs[name] = job
asyncio.create_task(
- _run_job(name, run_id, get_account_id(), get_region(), _external_netloc())
+ _run_job(
+ name, run_id, get_account_id(), get_region(), _external_netloc(), queue_seconds
+ )
)
return json_response({"TranscriptionJob": _public_job(job)})
diff --git a/tests/test_transcribe.py b/tests/test_transcribe.py
index b93a2892..e3f28a61 100644
--- a/tests/test_transcribe.py
+++ b/tests/test_transcribe.py
@@ -60,7 +60,7 @@ def test_transcribe_job_completes_and_writes_a_transcript(transcribe, s3, media)
)["TranscriptionJob"]
assert started["TranscriptionJobName"] == job_name
- assert started["TranscriptionJobStatus"] == "QUEUED"
+ assert started["TranscriptionJobStatus"] == "IN_PROGRESS"
assert started["LanguageCode"] == "en-US"
assert started["Media"] == {"MediaFileUri": media_uri}
# AWS omits Transcript until the job completes.
@@ -81,6 +81,58 @@ def test_transcribe_job_completes_and_writes_a_transcript(transcribe, s3, media)
assert document["results"]["items"][0]["alternatives"][0]["content"] == text.split()[0]
+def test_transcribe_start_returns_a_job_already_in_progress(transcribe, media):
+ """AWS starts a job IN_PROGRESS with StartTime set; QUEUED is reached only
+ by a request that opted into job queueing while the account is at its
+ concurrent job limit. A caller that reads status off the start response and
+ then waits for the terminal event, rather than polling, sees that one value
+ for the whole life of the job, so returning QUEUED here loses the
+ in-progress state entirely."""
+ _, _, media_uri = media
+ job_name = _unique("job")
+
+ started = transcribe.start_transcription_job(
+ TranscriptionJobName=job_name,
+ LanguageCode="en-US",
+ Media={"MediaFileUri": media_uri},
+ )["TranscriptionJob"]
+
+ assert started["TranscriptionJobStatus"] == "IN_PROGRESS"
+ assert started["StartTime"] >= started["CreationTime"]
+
+
+def test_transcribe_queue_seconds_puts_a_job_through_queued_first(transcribe, media):
+ """QUEUED is off by default because AWS reaches it only for a request that
+ opted into job queueing while the account is at its concurrent job limit,
+ but a caller that handles the state still needs a way to exercise it. With
+ TRANSCRIBE_JOB_QUEUE_SECONDS set, the job starts QUEUED with no StartTime
+ and the worker moves it to IN_PROGRESS."""
+ from conftest import _ministack_config
+
+ _, _, media_uri = media
+ job_name = _unique("job")
+
+ _ministack_config({"transcribe._JOB_QUEUE_SECONDS": 3})
+ try:
+ started = transcribe.start_transcription_job(
+ TranscriptionJobName=job_name,
+ LanguageCode="en-US",
+ Media={"MediaFileUri": media_uri},
+ )["TranscriptionJob"]
+
+ assert started["TranscriptionJobStatus"] == "QUEUED"
+ # AWS omits StartTime until the job leaves the queue.
+ assert "StartTime" not in started
+
+ running = _wait_for_status(transcribe, job_name, statuses=("IN_PROGRESS",))
+ assert running["StartTime"] >= running["CreationTime"]
+ finally:
+ _ministack_config({"transcribe._JOB_QUEUE_SECONDS": 0})
+
+ job = _wait_for_status(transcribe, job_name)
+ assert job["TranscriptionJobStatus"] == "COMPLETED"
+
+
def test_transcribe_transcript_is_deterministic_per_media(transcribe, s3, media):
"""There is no ASR here, so the value of the mock rests entirely on being
reproducible. The same media must transcribe identically on every run or
@@ -277,7 +329,7 @@ def test_transcribe_identify_language_without_options_falls_back_to_a_default(tr
IdentifyLanguage=True,
Media={"MediaFileUri": media_uri},
)["TranscriptionJob"]
- assert started["TranscriptionJobStatus"] == "QUEUED"
+ assert started["TranscriptionJobStatus"] == "IN_PROGRESS"
assert "LanguageCode" not in started
job = _wait_for_status(transcribe, job_name)
@@ -835,7 +887,7 @@ def test_transcribe_recreating_a_deleted_job_name_emits_one_event(
Media={"MediaFileUri": media_uri},
)
transcribe.start_transcription_job(**start)
- # Delete while still QUEUED, then immediately reuse the name.
+ # Delete while still running, then immediately reuse the name.
transcribe.delete_transcription_job(TranscriptionJobName=job_name)
transcribe.start_transcription_job(**start)