Skip to content

feat(stepfunctions): real activity worker pool#770

Merged
vieiralucas merged 2 commits intomainfrom
worktree-batch3-stepfunctions-activities
Apr 26, 2026
Merged

feat(stepfunctions): real activity worker pool#770
vieiralucas merged 2 commits intomainfrom
worktree-batch3-stepfunctions-activities

Conversation

@vieiralucas
Copy link
Copy Markdown
Member

@vieiralucas vieiralucas commented Apr 26, 2026

Summary

Replaces the synthetic GetActivityTask shortcut with a real worker pool: a Task state inserts a PENDING token, GetActivityTask long-polls for the oldest pending task, SendTaskSuccess/Failure unblocks the interpreter. Heartbeat + timeout windows enforced. New introspection endpoint lets tests inject pending tasks directly.

  • Extends TaskTokenState with input/created_at/last_heartbeat_at/heartbeat_seconds/timeout_seconds
  • Interpreter `invoke_activity` polls until the worker resolves the token, with HeartbeatSeconds and TimeoutSeconds enforced
  • GetActivityTask returns empty taskToken after FAKECLOUD_SFN_GET_ACTIVITY_TIMEOUT_SECS (default 5s) when no task is queued, matching AWS
  • SendTaskHeartbeat now refreshes last_heartbeat_at instead of mutating status
  • New POST /_fakecloud/stepfunctions/enqueue-activity-task introspection endpoint
  • Conformance test sfn_task_token_round_trip rewired to use the introspection endpoint (old shortcut no longer applies)
  • New E2E tests cover round-trip success + worker failure propagation

Test plan

  • cargo test -p fakecloud-stepfunctions --lib (137 pass)
  • cargo test -p fakecloud-conformance --test stepfunctions sfn_task_token_round_trip
  • cargo test -p fakecloud-e2e --test stepfunctions sfn_activity_worker_pool_round_trip + sfn_activity_failure_propagates_to_execution
  • cargo clippy --workspace --all-targets -- -D warnings
  • CI green
  • Cubic clean

Summary by cubic

Implements a real Step Functions activity worker pool: Task states enqueue pending work, workers long‑poll GetActivityTask, and executions resolve via SendTaskSuccess/SendTaskFailure with HeartbeatSeconds/TimeoutSeconds enforced. Adds a test-only endpoint to enqueue tasks directly (uses the default account).

  • New Features

    • Real worker pool for activities: oldest pending task is dequeued by GetActivityTask (long-polls up to FAKECLOUD_SFN_GET_ACTIVITY_TIMEOUT_SECS, default 5s; returns empty token on timeout).
    • Heartbeat/timeout enforcement in the interpreter; SendTaskHeartbeat now updates last_heartbeat_at only; emits States.HeartbeatTimeout or States.Timeout when windows close.
    • Introspection: POST /_fakecloud/stepfunctions/enqueue-activity-task inserts a pending task for an activity (accepts activityArn, optional input, heartbeatSeconds, timeoutSeconds; returns taskToken). Tasks are enqueued in the default account namespace.
    • TaskTokenState extended with input, created_at, last_heartbeat_at, heartbeat_seconds, timeout_seconds; tokens are cleaned up on completion.
  • Migration

    • Code relying on synthetic GetActivityTask tokens must handle empty tokens and poll until a task is available.
    • Tests that exercised SendTask* without a state machine should use /_fakecloud/stepfunctions/enqueue-activity-task or start a real execution; for multi-account setups, switch the default account or create the activity in the default account.
    • When HeartbeatSeconds is set, workers must call SendTaskHeartbeat periodically.
    • Adjust long‑poll window via FAKECLOUD_SFN_GET_ACTIVITY_TIMEOUT_SECS if needed.

Written for commit c70cb0b. Summary will update on new commits.

Activities now have a real worker pool. A Task state with an activity
ARN inserts a PENDING token, and GetActivityTask long-polls for the
oldest pending task (FAKECLOUD_SFN_GET_ACTIVITY_TIMEOUT_SECS, default 5s,
empty token returned on timeout to match AWS).

SendTaskSuccess unblocks the interpreter with the worker's output.
SendTaskFailure unblocks with an error+cause. SendTaskHeartbeat refreshes
last_heartbeat_at; the interpreter watches HeartbeatSeconds and
TimeoutSeconds and fails the task with States.HeartbeatTimeout or
States.Timeout when the windows close.

Adds a /_fakecloud/stepfunctions/enqueue-activity-task introspection
endpoint that lets tests insert pending tasks without a state-machine
execution. Updates the conformance round-trip test to use it (the old
synthetic-token shortcut was non-conformant with AWS, which returns an
empty token when no task is queued).

- TaskTokenState gains input/created_at/last_heartbeat_at/heartbeat_seconds/timeout_seconds
- New invoke_activity in interpreter polls until the worker resolves
  the token, then cleans it up
- New E2E tests cover round-trip success + failure paths
- Docs updated to describe the worker pool + introspection endpoint
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 8 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="crates/fakecloud-server/src/main.rs">

<violation number="1" location="crates/fakecloud-server/src/main.rs:3886">
P2: Don’t derive Step Functions account state from the request ARN in this introspection route; use the emulator’s default account state so task injection targets the same account namespace as the rest of Step Functions endpoints.

(Based on your team's feedback about treating FakeCloud as single-account by default and avoiding account derivation from arbitrary ARNs.) [FEEDBACK_USED]</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread crates/fakecloud-server/src/main.rs Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 26, 2026

Codecov Report

❌ Patch coverage is 3.28638% with 206 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/fakecloud-stepfunctions/src/interpreter.rs 6.54% 100 Missing ⚠️
crates/fakecloud-stepfunctions/src/service.rs 0.00% 65 Missing ⚠️
crates/fakecloud-server/src/main.rs 0.00% 39 Missing ⚠️
crates/fakecloud-stepfunctions/src/state.rs 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@vieiralucas vieiralucas merged commit a35c99f into main Apr 26, 2026
48 checks passed
@vieiralucas vieiralucas deleted the worktree-batch3-stepfunctions-activities branch April 26, 2026 04:55
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.

1 participant