Long-Horizon Task Test: Building a Video Generation SaaS Platform in Three Hours

    A practical evaluation of AI coding for system-level development: building an e-commerce video generation SaaS with asynchronous rendering, multi-tenant isolation, quota billing, observability, and long-running task management. The experiment shows why agentic capabilities, specification-driven development, and architectural consistency matter more than isolated code generation or visual polish.

    1. The Bottom Line: AI Coding Has Moved Beyond Code Generation

    Over the past two years, intelligent coding tools have often been judged by whether they can generate attractive pages or produce runnable code in a single file. After conducting a long-running, several-hour automation experiment, I believe the evaluation criteria have changed.

    The real dividing line now consists of three capabilities: agentic behavior, long-horizon task execution, and systems engineering. The first two determine whether a model can decompose requirements, call tools, validate its own work, and preserve context over several hours of continuous development. The third determines whether the output is merely a demonstrable demo or a system capable of going live and serving paying users.

    The gap between these capabilities is not linear. A polished landing page only requires local attention from the model. A commercially viable SaaS product requires the model to maintain a consistent mental model across dozens of files, hundreds of interfaces, and multiple database tables. Naming conventions must remain consistent, error handling must follow the same rules, permission boundaries must be preserved, and billing logic must not be quietly rewritten in the third module.

    Context consistency is the real challenge in long-horizon tasks.

    2. Why Use E-Commerce Video Generation as the Test Case?

    The choice of project was based on an initially counterintuitive observation.

    I had previously focused on workflow orchestration, showing how visual canvases could connect images, copywriting, voice-over, and subtitles into a video pipeline. However, user feedback made one thing clear: target users do not want to learn how to build workflows.

    Small and mid-sized merchants, as well as cross-border sellers, care about return on investment:

    • Does each video cost a few cents or several dollars?
    • Can the system reliably produce thousands of videos per day?
    • After uploading the source material, can users generate a finished video with one click?
    • If something goes wrong, is there an operational process for handling it, and can the billing records be reconciled?

    In other words, as generative capabilities become increasingly accessible, the value of “teaching users how to fish” is declining, while the value of delivering the finished product directly is increasing. This means the product should be an end-to-end SaaS platform rather than a collection of tools.

    At the same time, continued progress in video generation models and the expansion of content commerce channels have created a clear need for converting batches of source materials into batches of finished videos.

    The experiment therefore had a defined goal:

    Users upload product images and basic product information. The system automatically generates scripts, voice-overs, subtitles, and final compositions, producing short-form product marketing videos ready for distribution. The platform must also support accounts, quotas, billing, and task observability.

    3. Breaking Down the System Requirements: Complexity Grows Exponentially

    If the goal is only to build a frontend, the complexity remains relatively limited. Once the system must be commercially usable, the requirement list expands rapidly.

    Ingress Layer and Frontend

    Uploading large images and media requires multipart uploads and resumable transfer support. Since generation may take several minutes, the frontend must handle polling, timeouts, retries, and progress updates. Weak network conditions and mobile browser compatibility also need to be considered.

    Service Layer

    The platform needs an asynchronous web framework to host its APIs. Interfaces must be idempotent, and write operations must prevent duplicate submissions. After files are uploaded, the system also needs extension points for malware scanning and content compliance checks.

    Data Layer

    The relational database must include core tables for users, media assets, tasks, rendered videos, quota ledgers, and billing records. Multi-tenant isolation cannot rely solely on application-level filtering. Row-level security (RLS) must be enabled so that unauthorized access is rejected at the database layer.

    Asynchronous Tasks and Scheduling

    Video rendering can take several minutes or even more than ten minutes, so it must never occupy a request thread. A message queue is required for traffic smoothing, while a task state machine must represent states such as queued, rendering, succeeded, failed, and timed out.

    The system also needs failure retries, dead-letter handling, and idempotency keys to prevent duplicate charges.

    Authentication and Billing

    The authentication layer needs phone-based verification-code login, token issuance and refresh, and token revocation. The quota system must support a “reserve first, settle later, release on failure” model. Every step must produce an auditable ledger entry.

    Observability

    The system needs structured logs, distributed tracing, task-duration distributions, failure-rate monitoring, and cost dashboards. Without this layer, a long-running task system becomes a black box.

    My conclusion was that this was not primarily a code-writing problem. It was a systems architecture problem. Previously, I would have assumed that such a project required a team of at least five people. In this experiment, a single AI coding tool completed the full workflow.

    4. The Key Method: Using Specification-Driven Development to Constrain Long-Horizon Tasks

    The most common reason long-horizon tasks fail is not necessarily insufficient model capability. More often, the problem is that acceptance criteria were not defined early enough.

    I used specification-driven development (SDD), enforcing a three-stage process:

    Research → Architecture → Development

    The output of each stage was captured in documentation, so later stages depended on explicit documents rather than on the model’s memory.

    The prompt structure can be summarized as follows:

    1. Role: Senior full-stack architect responsible for designing and implementing a commercially viable SaaS product.
    2. Process constraints: Proceed strictly through three stages:
    3. Research -> Architecture -> Development.
    4. At each stage, produce documentation and wait for confirmation before moving to the next stage.
    5. Stage 1 - Research:
    6. List target users, core scenarios, and non-functional requirements
    7. (concurrency, latency, cost, and compliance).
    8. Mark unresolved questions clearly. Do not make assumptions.
    9. Stage 2 - Architecture:
    10. Produce a system-layer diagram, database DDL, and an API inventory
    11. (including idempotency requirements and error codes).
    12. Define the task state machine, permission matrix, and billing ledger design.
    13. Stage 3 - Development:
    14. Implement the system in the following order:
    15. data layer -> service layer -> task layer -> ingress layer.
    16. After completing each layer, provide a minimal verification method.
    17. Global constraints:
    18. 1. Multi-tenant isolation must use row-level security at the database layer.
    19. Application-level filtering alone is not allowed.
    20. 2. Every write API requires an idempotency key.
    21. Billing must use a reserve-settle-release model with ledger records.
    22. 3. Do not introduce unexplained external dependencies.
    23. Centralize configuration, and never hard-code secrets.
    24. 4. After completing each layer, perform a self-check for:
    25. naming consistency, error-handling consistency, and privilege-escalation paths.

    The value of this approach is that it externalizes the information the model needs to remember into documents and turns the rules it must follow into verifiable checklist items.

    Long-horizon reliability comes from constraint design, not wishful thinking.

    5. Final Architecture and Key Design Points

    The final system used a layered structure based on technology-neutral, widely adopted patterns:

    • Ingress layer: Handles authentication, rate limiting, direct-upload signing, and progress queries.
    • Service layer: Runs as stateless containers that can scale horizontally. APIs are organized by resource and use standardized error codes.
    • Data layer: Combines a relational database, object storage for source media and finished videos, and a cache for sessions and frequently accessed data.
    • Task layer: Uses message-queue-driven workers. Rendering workers scale independently, with automatic scaling based on queue backlog.
    • Observability layer: Includes logging, monitoring and alerting, and cost dashboards.

    Example of Database Isolation

    1. ALTER TABLE render_task ENABLE ROW LEVEL SECURITY;
    2. CREATE POLICY tenant_isolation ON render_task
    3. USING (tenant_id = current_setting('app.tenant_id')::uuid);

    Example of the Billing Lifecycle

    1. Create task -> Reserve quota (write ledger entry) -> Publish message -> Render
    2. ├─ Success: settle the ledger entry and consume the reserved quota
    3. ├─ Failure: release the reservation and record the failure reason
    4. └─ Timeout: mark as timed out, release the reservation,
    5. and allow retry with idempotency-key deduplication

    When deployed in the cloud, the system can use standard infrastructure categories such as object storage, message queues, container platforms, logging services, monitoring and alerting, and secrets management.

    Baidu AI Cloud provides these types of general-purpose infrastructure capabilities. In this architecture, the model is responsible for generating code coupled to the business logic, while the infrastructure is integrated through configuration and declarative definitions.

    6. Lessons from the Experiment

    1. Context Drift

    When development reached the ingress layer, an inconsistent naming convention appeared in the task layer. The issue was resolved by documenting naming standards and the error-code table, then performing a consistency check after completing each layer.

    2. Duplicate Charges

    In an early version, retries could reserve quota more than once. Adding idempotency keys and a task state machine resolved the problem.

    3. False Failures in Long-Running Tasks

    The polling timeout was initially too short, causing the frontend to mark tasks as failed even though rendering was still in progress. The solution was to treat backend state as authoritative and use exponential backoff for polling.

    4. Compute Queues

    During peak periods, tasks spent a long time waiting in the queue. The complete experiment ran from morning into the evening, and under normal conditions the full workflow took approximately three hours.

    This also demonstrated an important point: as long-horizon task capabilities improve, compute capacity increasingly becomes the bottleneck.

    7. Conclusion and Practical Recommendations

    The experiment did not primarily prove that one model runs faster than another. It demonstrated a change in the development paradigm.

    When tools can handle system-level decomposition and maintain consistency across files, the output ceiling for individual developers expands significantly.

    For anyone planning a similar project, I have four recommendations:

    • Write the specification before writing the code. Define acceptance criteria, permission matrices, and billing rules in advance.
    • Treat non-functional requirements as first-class concerns. Isolation, idempotency, and observability must be decided during architecture design. Retrofitting them later is extremely expensive.
    • Validate incrementally and deliver by layer. Provide a minimal verification method for each layer instead of waiting until the end of a long task to discover that the direction was wrong.
    • Keep product judgment in human hands. Tools can build the system, but only people can determine what users are actually willing to pay for.

    AI coding has entered its next level. The entry ticket for that level is architectural capability.