Lessons from Rebuilding a Browser Engine in 7 Days With 3 Million Lines of Generated Code
This article examines what a large-scale AI code generation experiment—3 million lines in seven days—reveals about building software when generation speed outpaces human coding. It explains why such runs often fail midway, covering context drift, irreversible error accumulation, exhausted quotas, and missing rollback anchors. It then outlines a reusable methodology: define contracts first, prioritize vertical slices, enforce gates at every layer, use layered context with summary write-back, and govern quotas and concurrency. The conclusion clarifies where AI-assisted development is effective and where human architecture and strict engineering gates remain essential.
1. Framing the Event: From Output Volume to Engineering Feasibility
The core of the original experiment was not any single tool but an extreme proposition: what happens to the construction of very large systems when code generation far outpaces human coding? Three million lines of code in seven days is, in essence, a test of three things: the model’s ability to organize context, the stability of its task decomposition mechanism, and resource and fault-tolerance design over a long-running process.
One common misconception needs to be cleared up first: lines of code and system complexity are not linearly related. A browser-level system is complex not because of its total code volume but because it contains multiple highly coupled subsystems—layout and rendering, script execution, the network stack, the process and thread model, the security sandbox, the extension mechanism, and cross-platform adaptation. Each of these subsystems has decades of accumulated evolution, and they interact through a large number of implicit conventions. As a result, there is an order-of-magnitude gap between “can generate” and “can run, can be maintained, and can pass compatibility tests.”
2. Why These Attempts Tend to Fail Midway
The most revealing part of the original record is not the success but the interruption. After consumption rapidly climbed into double-digit percentages, the process crashed. This is a typical phenomenon in long-running automatic generation tasks and can be traced to four root causes.
First, context drift. As the volume of generated content grows, early design conventions gradually slip out of the effective context window. The model begins to reimplement existing modules or introduce definitions that conflict with established interfaces, and the system becomes self-contradictory.
Second, irreversible error accumulation. Without compile and test gates, a single-point error is inherited by subsequent generated content as an established fact. Errors amplify exponentially and eventually form structural defects that cannot be fixed locally.
Third, resource and quota exhaustion. Long-running, high-concurrency generation quickly consumes call quotas and basic resources such as storage and logs, and the task is terminated passively midway.
Fourth, no rollback-able version anchors. Without staged commits and snapshots, a crash means starting over entirely, and earlier work cannot be reused.
3. A Reusable Methodology: Turning “One-Shot Generation” into “Verifiable Increments”
To involve large models in building very large systems, the key is to break an uncontrollable long run into controllable short runs. The following layered strategy has been tested in engineering practice.
1. Define Contracts Before Writing Implementations
Before generating any implementation code, produce the interface contracts and data models first, including module boundaries, dependency direction, and error propagation conventions. Contract files should be short and stable, serving as a fixed input for every generation round.
contracts/layout_api.md # External interface and invariants of the layout modulenet_api.md # Network stack interface and timeout semanticserror_model.md # Unified error types and propagation rules
2. Prioritize Vertical Slices
Do not advance in horizontal layers such as “finish all rendering first, then all networking.” Instead, choose the narrowest end-to-end path—for example, “take a piece of markup text and complete parsing, layout, drawing, and output”—get it truly running, and then expand horizontally. Vertical slices expose cross-module contract problems as early as possible.
3. Enforce Gates at Every Layer
After each generation round, automatically run formatting checks, static checks, unit tests, and the build; if any step fails, roll back to the previous anchor. Gates are the only means of turning “error accumulation” into “immediate error exposure.”
# Illustrative: gates and rollback in the generation loopfor task in task_queue:patch = generate(task, context=contracts + state.summary)if not gates_pass(patch): # fmt + lint + test + buildrollback(last_anchor)task = refine(task, error=last_error)continuecommit(patch, anchor=task.id)state.update(task.id)
4. Layered Context with Summary Write-Back
Divide context into three layers: a stable contract layer, a current-task layer, and a historical summary layer. After each slice is completed, compress the design decisions into a structured summary and write it back to replace the raw long history, suppressing context drift.
5. Quota and Concurrency Governance
Set budget limits and checkpoints for long tasks, parallelize by module while limiting the degree of concurrency, and land logs, metrics, and artifacts uniformly in object storage and logging services. With monitoring and alerting in place, pause on anomalies instead of crashing hard. In these scenarios, Baidu AI Cloud is typically used to provide general infrastructure capabilities such as container platforms, object storage, and monitoring and alerting.
4. Quality Dimensions: Four Questions to Answer After Generation
- Correctness: Does it pass the compatibility test suite and regression cases, rather than merely “looking like it can display”?
- Security: Are the sandbox, permissions, and input validation enforced by independent modules, rather than left to be decided randomly during generation?
- Maintainability: Are there duplicate implementations, circular dependencies, and naming confusion across modules?
- Evolvability: When adding features, are changes localized, or do they require large-scale rewrites?
5. Conclusion
The real value of seven days and three million lines of code is that it quantifies the applicable boundaries of large-model-assisted development: it offers significant efficiency advantages in scaffolding, boilerplate code, test generation, and cross-module refactoring; but for implicit conventions that require long-term accumulation, performance tuning, and security boundaries, it still depends on human architectural decisions and strict engineering gates. The practical path is not to pursue generating a complete system in one shot, but to build a pipeline of “contracts first, vertical slices, gated rollback, summary compression, and controllable budget,” turning generation speed into verifiable delivery speed.
