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

    This article reports a prototype-level experiment that used a long-horizon agent to build a content-commerce UGC video generation platform from scratch. It covers specification-driven requirements, architecture, data models, tenant isolation, async task state machines, authentication and credit billing, deployment and observability, plus the risks that still require human review.

    Recent model releases that emphasize agent capability, long-horizon tasks, and systems engineering have drawn developer attention. The discussion has moved beyond “can it generate a polished page” to a harder question: can a model act like a senior architect, break down system-level requirements on its own, and stay coherent across hours of automated work? To probe that capability, I ran an engineering-oriented experiment: building a UGC video generation platform for content commerce from scratch.

    The boundary should be stated first. This was a prototype-level full-stack experiment, not a production delivery. The goal was to test how efficiently a long-horizon agent can collaborate across requirements research, architecture, development and integration, and deployment verification—and to surface real engineering risks.

    Why a Systems Architecture Problem, Not a Page Demo

    A static page reduces the problem to assembling components and adjusting styles. A video generation platform that could be used commercially grows in complexity much faster.

    The backend must cover uploads, authentication, task creation, status queries, callback notifications, error retries, rate limiting, and audit logs. The database needs multi-tenant user tables, credit-account tables, asset tables, generation-task tables, and billing ledgers, plus row-level security and tenant isolation. Video generation often takes minutes, so requests cannot block synchronously. An async queue, a task state machine, and polling or callbacks are required. Authentication must cover phone verification codes, standard token auth, session refresh, permission boundaries, and credit charges. Object storage, content-safety review, cost budgets, monitoring and alerting, and failure recovery also belong in the design.

    This is systems engineering, not simply “writing code.” The experiment used specification-driven development. The agent had to follow research, architecture, development, and verification, and leave reviewable artifacts at each step: a requirements list, architecture decision records, API contracts, data models, test cases, and deployment notes.

    The Key to Long Tasks: Specs First, Traceable Context

    The most common failure of a long-horizon agent is not that it cannot write, but that it drifts from the goal while writing. The first step was therefore not code. It was a specification.

    Requirements were split into four groups: user capabilities, generation-task capabilities, billing and permissions, and operations and security.

    • User side: sign-up and login, image upload, template selection, task progress, and finished-video download.
    • Generation tasks: asset validation, enqueueing, status queries, failure retries, and result storage.
    • Billing and permissions: credit holds, settlement on success, refunds on failure, and tenant isolation.
    • Operations and security: rate limits, audit, alerts, logs, and data-retention policy.

    The architecture boundaries were explicit. The access layer handles authentication and rate limiting. Business services handle users, tasks, and billing. An async execution layer consumes the queue and calls the generation capability. Object storage keeps source images and finished videos. A relational database stores business metadata. Logs, monitoring, and alerts watch queue backlog, task failure rate, and API latency.

    To limit context drift, the agent maintained a requirements traceability matrix: each requirement mapped to an API, table fields, test cases, and acceptance criteria. Even as the conversation grew, the matrix could pull the work back to the original goal.

    Core Data Model and Tenant Isolation

    The data model should center on users, accounts, tasks, and ledgers. A schematic structure:

    1. CREATE TABLE generation_task (
    2. id UUID PRIMARY KEY,
    3. tenant_id UUID NOT NULL,
    4. user_id UUID NOT NULL,
    5. input_uri TEXT NOT NULL,
    6. status TEXT NOT NULL,
    7. cost_credits INT NOT NULL,
    8. idempotency_key TEXT UNIQUE,
    9. created_at TIMESTAMP NOT NULL,
    10. updated_at TIMESTAMP NOT NULL
    11. );

    The task table must include tenant ID, user ID, input asset URI, status, credit cost, an idempotency key, and timestamps. The idempotency key prevents duplicate charges from repeated frontend submits or network retries. The billing ledger records three actions—hold, settlement, and refund—so the books stay traceable.

    The core of row-level security is that no query can bypass the tenant and user boundary. A pseudo-policy:

    1. policy: row.tenant_id == session.tenant_id
    2. policy: row.user_id == session.user_id

    Every read and write should inject tenant and user identity from the session context, not trust parameters sent by the client. An admin console needs its own role policy and audit log so ordinary business policies are not reused by mistake.

    Async Tasks and the State Machine

    Because generation takes a long time, it must be asynchronous. A recommended state machine:

    1. PENDING -> QUEUED -> RUNNING -> SUCCEEDED
    2. \-> FAILED -> RETRY_QUEUED

    On task creation, validate parameters and place a credit hold, then write the task record and publish to the message queue. The consumer marks the task RUNNING, calls the generation capability, and on success writes the output URI and settles credits. On failure it records an error code and retries with backoff. After the retry limit, the message goes to a dead-letter queue, a refund is triggered, and an alert fires.

    A schematic flow:

    1. task = create_task(user_id, input_uri, idempotency_key)
    2. charge_credits(user_id, task.cost) # hold
    3. enqueue("video_generation", task.id, idempotency_key=task.id)

    The query side can combine short polling with callback notification: the client polls task status, and the server refreshes state through a callback or message when the task finishes. Poll frequency must be rate-limited so many users refreshing at once do not overload the database. Queue consumption must be idempotent. Check task status before processing so generation and charges are not repeated.

    Authentication, Verification Codes, and Credit Charges

    A practical auth path is verification-code login, then issuance of a short-lived access token and a long-lived refresh token, with the server checking permissions. Verification codes need rate limits, an expiry, and a failure-count limit. Tokens need a reasonable lifetime and a way to revoke them. Sensitive operations should be written to an audit log.

    Credit charging should follow a consistent hold–settle–refund model. Creating a task holds credits and writes a ledger entry inside a transaction. Success settles under an idempotency condition. Failure or timeout refunds. Concurrent charges need database transactions, row locks, or atomic updates so balances cannot go negative. Under high concurrency, an account-balance snapshot and a ledger reconciliation job can be added.

    Deployment and Observability

    Business services can run on a container platform, source assets and finished videos in object storage, and generation tasks decoupled through a message queue. Logging plus monitoring and alerting should watch API error rate, queue backlog, task success rate, and average duration. On a general cloud platform such as Baidu AI Cloud, resources can be composed from common categories—object storage, message queues, a container platform, logging, and monitoring and alerting—without heavy customization at the prototype stage.

    Observability needs at least three metric groups:

    • Business: task creation volume, success rate, and refund rate.
    • System: API latency, queue backlog, and consume-failure rate.
    • Cost: credits per task, storage growth, and generation resource use.

    Without these, a long-running task system is hard to diagnose for where it is slow, wrong, or expensive.

    Results and Risk List

    In this experiment, the end-to-end prototype took about three hours, including requirements, architecture, main APIs and pages, the task queue, auth and billing, and local verification. Actual time depends on compute, network, model response, and human review. It should not be treated as a production performance commitment.

    The more useful outcome was the risk list. The model may produce APIs that look reasonable but are unverified. Long tasks can drift in configuration. Row-level security policies are easy to omit. Concurrent credit charges need dedicated tests. Duplicate queue consumption needs an idempotency key. Failure retries must be paired with refunds and alerts. Mitigations are specification-driven work, API contracts, automated tests, static checks, least privilege, audit logs, and budget alerts.

    Conclusion

    A long-horizon agent can already speed up a full-stack prototype substantially. It behaves more like a highly productive engineering collaborator than an unreviewed replacement. What still determines system quality is a clear specification, traceable architecture decisions, strict permission boundaries, and an observable operations setup. For teams that want to validate a video-generation business quickly, a sound path is to build a reviewable prototype in a specification-driven way, then fill in security, billing, and stability before moving toward production.