Long-Context Agentic Coding in Practice: Building a Full-Stack Video Generation SaaS in 3 Hours

    A hands-on test of whether a long-horizon coding agent can deliver a working full-stack SaaS product rather than scattered code snippets. The task: build a short-video generation platform for cross-border e-commerce sellers, covering a React App Router frontend, a FastAPI backend, PostgreSQL with row-level security, a message-queue-based asynchronous generation pipeline, and JWT authentication with credit-based billing. The article walks through the spec-driven development (SDD) workflow used—research, architecture, then implementation—and documents what actually went wrong: latency spikes and the need to resume from checkpoints, unhandled edge cases in the async task state machine, and a billing consistency gap that required compensation logic. It closes with practical takeaways on why task complexity must match the agent's capability boundary, why a written spec is the anchor that keeps multi-hour runs from drifting, and how the shift from code completion to system delivery changes the human role.

    1. Background: AI Coding Is Moving from “Completing Code” to “Delivering Systems”

    Over the past two years, the dominant form of AI-assisted coding has been conversational completion: you describe a function and it generates the code; you paste an error and it suggests a fix. This mode solves problems at the code-snippet level. But what actually consumes engineering effort in real projects is system-level decision-making and integration:

    • How technology choices constrain one another (the frontend framework determines the shape of the backend API).
    • How module dependencies are ordered (create the tables first, or write the service layer first).
    • How context stays coherent across a long task without “losing memory.”

    The marketing emphasis of the new generation of coding models has shifted away from “does the generated page look good” toward three harder dimensions: agentic capability, long-horizon tasks, and systems engineering. A long-horizon task means the model can, over hours of automated execution, decompose requirements on its own, plan steps, maintain context consistency, and ultimately deliver a running system rather than a pile of disconnected files.

    Does that claim hold up? Talk is cheap, so I designed an experiment complex enough to test it: build a short-video generation SaaS platform for cross-border e-commerce sellers.

    2. Why This Topic: The Complexity Has to Qualify

    To test long-horizon capability, the task itself must carry a high order of complexity. A single-page demo proves nothing, while a commercially viable video generation SaaS naturally covers the entire full-stack development chain.

    2.1 System Decomposition

    Frontend layer: a React full-stack framework using the modern App Router pattern. The typical problems to handle include drawing the boundary between server and client components, route groups and middleware-based authentication, and using streaming rendering to improve the experience of generation-style interactions. This looks routine, but cross-component state design (task in progress / failed retry / insufficient credits) is very easy to get wrong.

    Backend layer: services built with Python’s FastAPI. The core is not writing a few endpoints but the systemic design of API contracts: video generation is a long-running operation, so the API must split into two asynchronous endpoints—“submit task” and “query status”—returning a unified task ID and state machine definition.

    Data layer: the PostgreSQL schema must cover four entity types: users, credit ledger, generation tasks, and artifact storage. In a multi-tenant scenario, row-level security (RLS) is mandatory so that user A can never query user B’s tasks—this is the security baseline for a SaaS:

    1. ALTER TABLE generation_tasks ENABLE ROW LEVEL SECURITY;
    2. CREATE POLICY tenant_isolation ON generation_tasks
    3. FOR ALL USING (user_id = current_setting('app.current_user_id')::uuid);

    Task scheduling layer: this is the core difficulty of the video generation business. Generating a single video often takes several minutes, and an HTTP request cannot wait synchronously. The standard approach is an asynchronous pipeline built on a message queue: the API writes the request to the queue, an independent worker consumes it and calls the model service, and the frontend subscribes to task status via polling or WebSocket. This also involves retry policies, idempotency, dead-letter handling, and a series of related engineering details.

    Auth and billing layer: phone-number verification-code login, JWT issuance and refresh, and transactional credit deduction. “Charge first or generate first” looks like a business question but is really a distributed consistency question: if the charge succeeds and generation fails, how do you refund? That requires compensation logic.

    2.2 Conclusion Up Front

    By conventional estimation, this is a project that needs a team of 3–5 people over several weeks. The goal of this experiment: rely solely on a coding agent with long-horizon capability and compress the main development into roughly 3 hours.

    3. Methodology: Spec-Driven Development (SDD)

    Throwing a one-line requirement at the model is the most common cause of long-task failure. My approach was spec-driven development, forcing the model through a three-stage process—research → architecture → development—instead of writing code immediately.

    Stage 1: Research. Have the agent first produce a requirements spec: user roles, core use cases, and non-functional requirements (concurrency level, cost constraints). The value here is translating a vague “I want to build a video generation site” into executable acceptance criteria, such as “a single video generation takes no more than X minutes” and “credit deduction must be strongly consistent with task status.”

    Stage 2: Architecture. Based on the spec, produce architecture decision records: technology stack choices and rationale, the database ER diagram, the state machine design for the task queue, and module dependencies. I required architecture before implementation; this stage produces the project’s skeleton, and all subsequent code must conform to it.

    Stage 3: Development. Proceed in dependency order: database schema → backend services → task queue → frontend pages → integration. At the end of each stage, run a self-check: endpoints callable, RLS policies enforced, billing logic rollback-able.

    The key insight of this model: move “system architecture capability” explicitly out of a person’s head and into a spec document, so the model works against the spec throughout a long task instead of relying on decaying conversational memory.

    4. Real Pitfalls Along the Way

    The experiment was not smooth sailing. A few typical problems are worth recording.

    Compute and queueing. Load was extremely high right after the new model’s release, and single-response latency fluctuated noticeably. This itself points to a reality: long tasks demand far more service stability than Q&A scenarios, and any interruption in the middle requires the agent to be able to resume from a checkpoint.

    Edge cases in the async state machine. The model’s initial task polling did not handle the state where “the generation service times out but the task is stuck in processing.” When I flagged this during acceptance, it correctly located the worker’s timeout fallback logic and added the failure transition. This shows the model’s repair capability is adequate, but autonomously enumerating edge conditions still has gaps—human acceptance review is not optional.

    Refactoring billing consistency. In the first version, credit deduction and the generation call were two independent transactions, leaving a window where the charge succeeded but the task failed—a direct financial loss. The model had actually flagged this risk during the architecture stage but omitted the compensation task during implementation. This is exactly why the spec document must include non-functional requirements such as “failure compensation.”

    5. Observations and Conclusions

    Having run the entire experiment, my core judgment is that AI coding has genuinely entered its next phase.

    In terms of capability, the model can already take on the combined role of “architect + junior engineering team”: requirement decomposition, technology selection, code implementation, and self-testing and repair can form a complete loop within a single long task. The human role shifts from “the person who writes code” to “the person who writes specs and does acceptance.”

    In terms of method, two lessons are directly reusable:

    1. Task complexity must match the capability boundary: toy projects cannot validate long-horizon capability; only real systems expose real weaknesses.
    2. SDD is the key to long-task stability: the spec document is the model’s anchor during hours of execution. Without it, a long task will almost inevitably drift.

    One business-side insight is also worth mentioning. The original motivation came from a counterintuitive observation: many target users (for example, cross-border e-commerce sellers) do not want to learn any workflow tool—they care only about cost, throughput, and “click once and get the result.” So in the AI era, rather than teaching people to fish, put the fish in front of them; packaging technology into a product is often more valuable than teaching the technology.

    If you want to test the real level of these long-horizon agents yourself, I suggest following the three-stage SDD process described here and picking a full-stack scenario you know well. You will likely reach your own conclusions.