Skip to content

Conversation

@kcze
Copy link
Contributor

@kcze kcze commented Nov 13, 2025

Make onboarding task completion backend-authoritative which prevents cheating (previously users could mark all tasks as completed instantly and get rewards) and makes task completion more reliable. Completion of tasks is moved backend with exception of introductory onboarding tasks and visit-page type tasks.

Changes 🏗️

  • Move incrementing run counter backend and make webhook-triggered and scheduled task execution count as well
  • Use user timezone for calculating run streak
  • Frontend task completion is moved from update onboarding state to separate endpoint and guarded so only frontend tasks can be completed
  • Graph creation, execution and add marketplace agent to library accept source, so appropriate tasks can be completed
  • Replace client.ts api calls with orval generated and remove no longer used functions from client.ts
  • Add resolveResponse helper function that unwraps orval generated call result to 2xx response

Small changes&bug fixes:

  • Make Redis notification bus serialize all payload fields
  • Fix confetti when group is finished
  • Collapse finished group when opening Wallet
  • Play confetti only for tasks that are listed in the Wallet UI

Checklist 📋

For code changes:

  • I have clearly listed my changes in the PR description
  • I have made a test plan
  • I have tested my changes according to the test plan:
    • Onboarding can be finished
    • All tasks can be finished and work properly
    • Confetti works properly

@github-actions
Copy link
Contributor

This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.

@github-actions github-actions bot removed the conflicts Automatically applied to PRs with merge conflicts label Nov 17, 2025
@github-actions
Copy link
Contributor

Conflicts have been resolved! 🎉 A maintainer will review the pull request shortly.

@AutoGPT-Agent
Copy link

Thanks for implementing the backend support for onboarding tasks! This looks like a solid improvement that will help track and reward user progress automatically.

However, before this PR can be merged, you need to address these issues:

Missing PR Description

  • Please add a clear description of the changes made in this PR
  • Complete the checklist in the PR description, particularly the test plan

Technical Implementation

The implementation looks good overall! Here are some observations:

  • Great work adding the timezone-aware tracking for consecutive run days
  • Good job handling onboarding notifications and rewards consistently
  • The automatic milestone tracking will improve the user experience
  • The serializer fix for notification payloads is a nice catch

Please update the PR description with details about:

  1. The purpose of these changes
  2. Which onboarding steps are now automatically tracked
  3. How the reward system works
  4. Your test plan (how you've verified these changes)

Once you've addressed these documentation issues, this PR should be ready for another review.

@AutoGPT-Agent
Copy link

Thanks for this PR that improves the security of the onboarding process by moving task completion to the backend!

What looks good

  • The code changes are well-structured and maintain proper user_id checks
  • The PR description clearly explains the changes and intent
  • You've maintained backward compatibility while adding important security improvements
  • The timezone handling for run streaks is a nice improvement

What needs attention

The PR needs a completed checklist as per our requirements. Please fill out the test plan section and check off the boxes in the PR description. Since this is a significant change touching both backend and frontend, having a clear test plan is important.

Suggested test plan could include:

  • Testing completion of different types of onboarding tasks (frontend vs backend-controlled)
  • Verifying timezone-based run streak calculation
  • Testing that webhook-triggered executions properly count toward run counts
  • Verifying that task rewards are correctly applied
  • Testing that frontend can't complete backend-protected tasks

Once you've added and checked off the test plan items, this PR should be good to go!

@AutoGPT-Agent
Copy link

Thanks for your PR on making onboarding task completion backend-authoritative! The changes look well thought out and should effectively prevent users from cheating by marking all tasks as completed instantly.

I noticed a few items to address before this can be merged:

  1. Your checklist indicates you haven't fully tested that onboarding can be completed from start to finish. This seems like an important test to complete given the significance of the changes to the onboarding flow.

  2. Consider completing all the checkboxes in your test plan to confirm you've verified all aspects of the functionality.

  3. The PR includes a helpful helper function resolveResponse for unwrapping orval generated call results, which improves code readability throughout the frontend changes.

  4. The timezone-aware streak calculation is a nice improvement that will make the feature more reliable for users in different regions.

Once you've completed testing the full onboarding flow and updated your checklist accordingly, this PR should be ready for final review and merging. The code changes themselves look well-structured and maintain proper security patterns with user_id checks.

@kcze kcze requested review from 0ubbe, Pwuts and majdyz November 17, 2025 11:21
@kcze kcze marked this pull request as ready for review November 17, 2025 11:21
@kcze kcze requested a review from a team as a code owner November 17, 2025 11:21
@qodo-merge-pro
Copy link

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Type Validation

The POST /onboarding/step handler validates the 'step' argument using get_args on FrontendOnboardingStep. FastAPI/Orval may coerce values differently; ensure the request body schema strictly restricts values and that invalid enum strings are rejected as intended.

async def onboarding_complete_step(
    user_id: Annotated[str, Security(get_user_id)], step: FrontendOnboardingStep
):
    if step not in get_args(FrontendOnboardingStep):
        raise HTTPException(status_code=400, detail="Invalid onboarding step")
    return await complete_onboarding_step(user_id, step)
Concurrency

increment_runs reads onboarding then updates counters and computes milestones based on old completedSteps. In concurrent executions, milestones or counters might race. Consider doing the update and step computation in a transaction or re-fetching state after update to avoid duplicate or missed completions.

async def increment_runs(user_id: str):
    """
    Increment a user's run counters and trigger any onboarding milestones.
    """
    user_timezone = await _get_user_timezone(user_id)
    onboarding = await get_user_onboarding(user_id)
    new_run_count = onboarding.agentRuns + 1
    last_run_at, consecutive_run_days = _calculate_consecutive_run_days(
        onboarding.lastRunAt, onboarding.consecutiveRunDays, user_timezone
    )

    await UserOnboarding.prisma().update(
        where={"userId": user_id},
        data={
            "agentRuns": new_run_count,
            "lastRunAt": last_run_at,
            "consecutiveRunDays": consecutive_run_days,
        },
    )

    milestones = _get_run_milestone_steps(new_run_count, consecutive_run_days)
    new_steps = [step for step in milestones if step not in onboarding.completedSteps]

    for step in new_steps:
        await complete_onboarding_step(user_id, step)
Backward Compatibility

Notification payload now enforces event type and OnboardingNotificationPayload.step as OnboardingStep and allows extras via model_config. Verify all producers/consumers (WS, Redis serializer) handle this shape and that older clients expecting string step don't break.

    type: str
    event: str

    model_config = pydantic.ConfigDict(extra="allow")


class OnboardingNotificationPayload(NotificationPayload):
    step: OnboardingStep

Comment on lines +18 to +21
@field_serializer("payload")
def serialize_payload(self, payload: NotificationPayload):
"""Ensure extra fields survive Redis serialization."""
return payload.model_dump()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This makes all fields of NotificationPayload subclasses serialized (in this case OnboardingNotificationPayload)

Comment on lines +38 to +48
FrontendOnboardingStep = Literal[
OnboardingStep.WELCOME,
OnboardingStep.USAGE_REASON,
OnboardingStep.INTEGRATIONS,
OnboardingStep.AGENT_CHOICE,
OnboardingStep.AGENT_NEW_RUN,
OnboardingStep.AGENT_INPUT,
OnboardingStep.CONGRATS,
OnboardingStep.MARKETPLACE_VISIT,
OnboardingStep.BUILDER_OPEN,
]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a subset of OnboardingStep with only the step that are allowed to be completed frontend-side.

async def update_user_onboarding(user_id: str, data: UserOnboardingUpdate):
update: UserOnboardingUpdateInput = {}
onboarding = await get_user_onboarding(user_id)
if data.completedSteps is not None:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Step completion has now dedicated endpoint.

Comment on lines +225 to +228
mock_complete_onboarding = mocker.patch(
"backend.server.v2.library.routes.agents.complete_onboarding_step",
new_callable=AsyncMock,
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This makes sure we don't actually call onboarding function (and try to access db)

Comment on lines +39 to +40
GraphCreationSource = Literal["builder", "upload"]
GraphExecutionSource = Literal["builder", "library", "onboarding"]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need sources to know if an onboarding step should be completed; for example running agent from library shouldn't be completed when running onboarding agent or in the builder.

CREDENTIALS_FIELDS: dict[str, str] = get_credentials_blocks()


def _normalize_datetime(value: datetime | None) -> datetime | None:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The following functions are to calculate run streak for the user for running agent, i.e. keep increasing by one every day and if one day is missed reset. The time is calculated in the user timezone.

@github-actions github-actions bot added the conflicts Automatically applied to PRs with merge conflicts label Nov 19, 2025
@github-actions
Copy link
Contributor

This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.

@github-actions github-actions bot removed the conflicts Automatically applied to PRs with merge conflicts label Nov 20, 2025
@github-actions
Copy link
Contributor

Conflicts have been resolved! 🎉 A maintainer will review the pull request shortly.

return get_user_timezone_or_utc(user.timezone if user else None)


async def increment_runs(user_id: str):
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know how far are we trying to be careful with this,
It's safer to just increment the integer field than do this see Updating Atomic Fields in https://prisma-client-py.readthedocs.io/en/v0.1.0/reference/operations/#integer-fields_1

@github-project-automation github-project-automation bot moved this from 🆕 Needs initial review to 👍🏼 Mergeable in AutoGPT development kanban Nov 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

platform/backend AutoGPT Platform - Back end platform/frontend AutoGPT Platform - Front end Review effort 4/5 size/xl

Projects

Status: 👍🏼 Mergeable
Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants