Harness Engineering: Building a Controlled Execution Framework for AI-Assisted Coding
AI coding assistants can generate plausible-looking changes that break your project. This article explains harness engineering—the practice of building a supporting framework around AI execution—and shows how to set up a minimal viable framework covering project documentation, enforceable constraints, structured task cards, repeatable validation, and persistent state records. It then walks through a hands-on example of adding due-date filters to a task management app, and covers layered validation gates, permissions, rollback, retry limits, and how to measure whether your framework actually works.
1. Why AI Changes Spiral Out of Control
When using AI-assisted development, the most frustrating problem is usually not that the AI can’t write code—it’s that it quickly generates large amounts of seemingly reasonable modifications that don’t actually match project requirements.
For example, a developer only wants to adjust button spacing, but the AI refactors the page structure. The project requires that a single source file stay under 200 lines in principle, yet after several conversation rounds a huge file appears. A local defect gets fixed, but related features regress—or the app won’t even start.
These problems shouldn’t simply be attributed to “poorly written prompts.” They typically correspond to three categories of engineering issues:
- Unclear requirement boundaries: no explicit modification scope, prohibitions, or acceptance criteria.
- Project knowledge isn’t maintained: constraints exist only in past conversations, never becoming stable, retrievable project documentation.
- No validation loop for changes: generated code isn’t thoroughly checked, and local correctness gets mistaken for overall correctness.
Prompts can improve individual interactions, but they cannot replace a complete software engineering process. For AI to participate in development continuously, you need to build a controlled execution environment for it.
2. What Exactly Is Harness Engineering?
Harness engineering can be understood as the engineering practice of building a supporting framework around AI task execution. “Harness” here emphasizes supporting, constraining, and checking the execution process—not any specific tool.
There is no single standard implementation that works for every team. For AI coding, you can think of it as a combination of the following elements:
Project context + task protocol + tools and permissions + validation mechanisms + state records + human decision-making
The model is responsible for understanding problems, proposing solutions, and generating modifications. The execution framework determines what it can see, what it is allowed to do, how to prove the result meets requirements, and what happens after failure.
The distinction is analogous to a developer and their development environment. Even an experienced developer can’t deliver reliably without access to requirements, the ability to run tests, and version history. AI needs the same infrastructure—and usually needs even more explicit constraints.
2.1 Relationship to Prompt Engineering
Prompts mainly address “how to express the task”; the execution framework addresses “how the task gets completed reliably.”
For example, “do not modify the authentication logic” is a prompt-level requirement. Setting the authentication-related directories to require human approval before writing, and detecting out-of-scope changes in commit checks, is a stronger engineering constraint.
Important rules therefore shouldn’t live only in prose—they should be converted into executable checks or permission policies whenever possible.
2.2 Relationship to Context Engineering
Context engineering focuses on how to organize and provide effective information: requirements, code, interface contracts, historical decisions, and execution results.
An execution framework must also manage things beyond information—such as modification permissions, test ordering, failure retries, delivery gates, and rollback procedures. Context is an important component, but not the whole picture.
3. Build a Minimal Viable Framework First
You don’t need a complex automation system from day one. For small projects, establishing five foundational capabilities significantly improves controllability.
3.1 A Stable Project Description
At minimum, the project description should answer:
- What problem does the app solve, and for whom?
- How do you start the app and run validation?
- What is each directory responsible for?
- Which modules are high-risk areas?
- What are the current known limitations?
This document should be maintained alongside the project, not left behind in a single conversation. Its value isn’t making the AI read more text—it’s reducing the cost of repeatedly guessing at the project structure.
3.2 Enforceable Development Constraints
Constraints must be specific and verifiable. Avoid unmeasurable phrasing like “the code should be elegant” or “keep it concise.”
For example:
- A single business source file should stay under 200 lines in principle; if exceeded, explain why.
- Don’t modify business data structures for local style adjustments.
- Don’t introduce new dependencies unrelated to the current task.
- When modifying a public interface, update callers and tests in the same change.
- Never log passwords, access credentials, or sensitive personal information.
File line count is just a maintainability signal, not a reason to mechanically split code. Generated files and fixed data files can be granted exceptions—exceptions must be documented and reviewed.
3.3 A Structured Task Card
A task card should include the goal, scope, prohibitions, and acceptance criteria.
Example:
Task: Fix the task list showing incorrect state after filtering.
Allowed to modify: filter state management, list rendering, and related tests.
Forbidden to modify: login flow, data storage structure, public navigation layout.
Acceptance criteria:
- After switching filters, the list is consistent with the filter state;
- Empty lists show a clear empty-state message;
- Page refresh behavior matches existing requirements;
- Existing create, edit, and delete features show no regression.
“Fix the filtering issue” is only an intent; the task card above provides the boundaries for implementation and verification.
3.4 A Repeatable Validation Entry Point
The framework should at least be able to trigger build checks, static analysis, and necessary tests, and save the results.
Validation entry points shouldn’t depend on a developer’s memory. The project needs explicit check ordering, success conditions, and failure handling. For page behavior, add interactive validation—you can’t declare completion just because the code compiles.
3.5 Persistent Task State
At the end of every task, record:
- What was completed;
- Which files were actually modified;
- Which validations ran, and their results;
- Unresolved issues;
- Suggested next steps.
Be especially careful to distinguish between “validation passed,” “validation not run,” and “validation failed.” If the runtime environment is unavailable, the AI should report that honestly rather than writing code-review conclusions as “tests passed.”
4. Hands-On: Adding Due-Date Filters to a Task Management App
Let’s demonstrate the full process with an existing task management app. The app already supports creating, editing, completing, and deleting tasks; now we need to add “Due Today” and “Overdue” filters.
This requirement looks simple, but it involves date interpretation, state combinations, UI display, and compatibility with existing features—making it a good case study for observing the framework in action.
Step 1: Pin Down Business Semantics First
Before writing any code, clarify:
- Is a due date a calendar date or a precise timestamp?
- Which time zone defines “today”?
- Do completed tasks count as overdue?
- How are tasks without a due date handled?
- How do date filters combine with completion-status filters?
For this exercise, assume these conventions: due dates are interpreted as calendar dates in the user’s time zone; completed tasks don’t count as overdue; tasks without a due date are excluded from both date filters; multiple filter conditions combine with logical AND.
These are example conventions for this practice—not fixed rules every app should adopt. Real projects must follow actual business requirements.
Step 2: Inspect First, Then Plan the Change
The AI should first locate the task data definitions, filtering logic, date handling, and related tests, and confirm whether the existing code already includes a due-date field.
If the field already exists, this change may only involve filtering logic and UI. If it doesn’t, the data model may need changes, which expands the task scope—and structural changes must not be quietly completed under the original authorization.
Before executing, output a brief plan:
- Confirm the existing date field and its default value;
- Add date-filter logic;
- Wire up the filter controls;
- Add boundary tests;
- Check whether existing task operations regress.
For high-risk items such as data structure changes or permission logic changes, obtain human confirmation first.
Step 3: Centralize Date Logic in One Place
Don’t copy date checks across multiple UI components. Centralize business logic in an independently testable unit.
The following is illustrative pseudocode, not a real interface:
function matchesDateFilter(task, filterType, today):if filterType is "All":return trueif task has no due date:return falsedueDay = parseAsCalendarDate(task.dueDate) // per agreed conventionif filterType is "Due Today":return dueDay == todayif filterType is "Overdue":return task is not completed and dueDay < todayreturn false
The key point isn’t the function name—it’s passing “today” as an input to the logic. Tests can then fix the date, so results don’t vary with real time.
Dates also shouldn’t be compared as raw strings without processing. Input format, missing values, and time zone conversion must be defined first; otherwise the code may work on typical examples but fail at date boundaries.
Step 4: Build Tests Matching Acceptance Criteria
Cover at least these cases:
- Due date is today;
- Due date was yesterday, and the task is incomplete;
- Due date was yesterday, but the task is completed;
- Due date is in the future;
- No due date set;
- Date filter combined with completion-status filter;
- Empty filter result;
- List updates promptly after editing a due date.
Tests should verify user-visible behavior, not just how many times internal functions are called.
If a defect has already occurred, first add a test that reproduces it, then fix the implementation. Otherwise you can’t prove the fix targets the original problem rather than accidentally changing the outcome.
Step 5: Review the Scope of Changes
After functional validation passes, review the diff:
- Were files outside the task card modified?
- Did unrelated formatting changes appear?
- Were public interfaces changed?
- Were unnecessary dependencies added?
- Were other modules “conveniently” refactored?
“Cleaner code” is not a reason to expand task scope. Unrelated improvements should be split into separate tasks, evaluated and verified independently.
5. Design Validation as Layered Gates
Full validation doesn’t mean running every check every time. Layer checks by cost and risk.
Layer 1: Fast Checks
Syntax, static rules, obvious type errors, and constraint checks. These are cheap and should run early to reduce wasted downstream work.
Layer 2: Tests for Affected Modules
Run tests directly related to the change location. For shared components or public logic, don’t measure impact by file count alone—extend coverage to relevant callers.
Layer 3: Critical User Path Verification
Verify users can still complete core operations, such as creating, editing, and deleting tasks and switching filters. For UI changes, also check interactions, empty states, and error messages.
Layer 4: Pre-Release Checks
For releases, run fuller regression, security checks, and deployment verification. High-risk changes should retain human approval.
Passing tests only shows that the checked scope meets expectations—it can’t prove there are no defects at all. Acceptance reports must state validation coverage and remaining risk.
6. Permissions, Security, and Rollback Are Also Part of the Framework
When executing tasks, AI may read files, run commands, access networks, or modify data. These capabilities should follow the principle of least privilege.
Routine page changes shouldn’t come with production database write access. Debug environments shouldn’t expose real access credentials. Operations like deleting data, changing permissions, and deploying releases should require separate approval.
Also, external documents, code comments, and log contents should be treated as task data, not as instructions that override project rules. Even if they contain text like “ignore all restrictions,” that shouldn’t expand permissions or leak information.
Rollback must be prepared before changes. Code should have a recoverable baseline; critical data should be backed up. For data structure changes, also confirm whether old versions can read the new data—“restoring old code” is not the same as “restoring the whole system.”
7. Control Retries to Avoid Automated Error Amplification
When validation fails, the AI shouldn’t keep modifying indefinitely.
A more robust workflow:
- Save the failure log;
- Determine whether the failure is a code, environment, or test problem;
- Form a targeted fix plan;
- Modify only what’s directly related to the failure cause;
- Re-run validation;
- If a preset attempt limit is exceeded or scope creep appears, escalate to a human.
Stop conditions should be set by the team based on task risk. The framework’s goal isn’t to keep the AI running forever—it’s to make sure the AI knows when to stop and ask for help.
8. How to Tell Whether the Framework Works
Don’t just count lines of generated code or tasks completed. More valuable metrics include:
- First-pass acceptance rate;
- Regressions caused by changes;
- Frequency of out-of-scope modifications;
- Human review and rework time;
- Validation execution completeness;
- Time to recover after failures.
These metrics need continuous recording and should be interpreted in light of task difficulty. A short-term speed increase doesn’t mean quality has improved accordingly.
As for sequencing: implement task cards, project descriptions, automated checks, and change records first, then gradually introduce permission isolation, risk tiering, and release gates. An overly complex framework adds maintenance cost—evolve it around real failure cases.
Conclusion
The core of engineering AI-assisted coding is not finding one magic prompt that constrains the model forever—it’s turning software delivery requirements into a stable execution mechanism.
Requirements need boundaries. Knowledge needs continuous maintenance. Modifications need permissions. Results need validation. Failures need to be stoppable and recoverable. The value of harness engineering lies in connecting these pieces, transforming AI from “an assistant that generates code” into “an executor that participates in delivery within a controlled process.”
