AI Coding in Production Projects: Closing the Specification and Execution Loops
Reliable AI-assisted development requires more than working code. Using a “remember me” feature in an established system as an example, this article explains how connected specification and execution loops turn requirements into verifiable system behavior. It covers requirements clarification, task design, testing, review, release, rollback, and durable engineering records.
1. Real Projects Need More Than Faster Code Generation
Adding a “remember me” option to a backend system that has been running for years looks like a small change: add a checkbox to the login page, extend login persistence on the server, and write a few tests.
But authentication in a mature system is rarely an isolated module. It interacts with tenant policies, account status, device management, authorization checks, audit records, and password changes. A single option on the page can affect multiple stages of the authentication flow.
Given only the instruction “support remember me at login,” an AI coding agent may quickly produce a complete implementation. The interface works, the server issues long-lived credentials, and the tests pass. None of those results, however, proves that the requirement has been implemented correctly:
- Who determines how long persistent login remains valid, and can tenants override that setting?
- How are credentials on existing devices invalidated after a password change?
- Can previous login states remain usable after an administrator disables an account?
- Are third-party identity providers and mobile login included in the scope?
- Do high-risk operations still require reauthentication?
These are definitions of system behavior, not implementation details. When implementation comes before definition, the agent makes product and security decisions on the team’s behalf without explicit approval.
The key to introducing AI coding into real projects is therefore to place implementation generation inside a constrained, evidence-based, traceable engineering process—not to let code generation replace requirements judgment.
2. Why Working Code Does Not Prove System Correctness
Incomplete requirements also cause problems in conventional development. AI coding amplifies that risk by dramatically shortening the path from an ambiguous description to a working implementation.
A developer might previously have consulted a product manager, reviewed historical documentation, or searched for similar implementations before coding. An agent can instead fill gaps from local context and quickly turn those assumptions into code.
This creates three common failure modes.
Treating Default Assumptions as Business Rules
An agent might choose a fixed lifetime for long-lived credentials to finish the task. That value may be reasonable in some contexts but incompatible with the current system’s tenant policies.
The issue is not whether the value seems reasonable. It is whether it has been confirmed, has an identifiable source, and agrees with existing policy. An unsupported default is effectively an unapproved business decision.
Using Implementation Logic to Validate Itself
An agent may generate tests based on the code it has just written. If the implementation treats an unexpired credential as sufficient to restore login, the tests may simply verify that unexpired credentials succeed.
Such tests check internal consistency but can miss external constraints such as disabled accounts, revoked credentials, and tenant restrictions. Passing tests do not establish that the business rules are complete.
Losing the Long-Term Context of a Change
When requirements exist only in chat history, future maintainers struggle to understand why particular logic exists. During a later change, an agent may mistake a historically necessary restriction for redundant code and remove it.
A reliable process must preserve durable system knowledge, not just produce code for a single task.
3. Connect the Specification and Execution Loops
For mature projects, AI-assisted development can be organized into two connected loops: a specification loop and an execution loop.
The specification loop answers:
- Why is this change needed?
- How should the system behave?
- What criteria determine whether the change is complete?
The execution loop answers:
- How can the goal be divided into verifiable tasks?
- How will each task be implemented and checked?
- How will the change be reviewed, released, and verified in production?
These are not unrelated documents. They are two views of the same change. Specifications provide constraints; execution provides evidence. If implementation exposes a gap in the specification, the team should return to the specification layer for a decision rather than silently introduce a new business rule in code.
The full workflow is:
Requirements input → Scope clarification → Specification confirmation → Technical design → Task breakdown → Implementation and verification → Review and release → Archiving and updates
Confirmation does not mean every change needs heavyweight approval. Review intensity should reflect risk. A copy change can follow a lightweight process, while changes involving authentication, authorization, money, or data isolation require stronger checks.
4. The Specification Loop: Define Behavior Before Coding
Establish the Existing System Baseline
In a legacy project, the first step should not be asking an agent to change code. It should be understanding current behavior.
That investigation should cover:
- Login entry points and their call chains.
- Session creation, renewal, and invalidation.
- Account disabling and password-change workflows.
- Storage and retrieval of tenant security policies.
- Existing tests, audit events, and error handling.
Code, documentation, and actual behavior may disagree. The team must distinguish formally agreed behavior from historical implementation details and issues that still require an owner’s decision. Existing code should not automatically be treated as the correct specification.
For legacy behavior without tests, characterization tests can establish a baseline before changes begin. Those tests should be clearly labeled as records of current behavior, not approval of that behavior.
Expand a Short Request into a Behavior Checklist
A “remember me” requirement needs to define at least the following.
Scope. Which login entry points are supported? Which clients or authentication methods are excluded?
Policy source. Is persistent login permitted? Where do credential lifetimes and other restrictions come from? Can tenants impose stricter requirements?
Invalidation conditions. How do password changes, account disabling, explicit logout, device revocation, and security-policy changes affect previously issued credentials?
Session restoration. Does the long-lived credential restore an ordinary session, or does it directly authenticate business requests? These designs have different permission boundaries and risks and should not be treated as equivalent.
Security restrictions. After login is restored, do high-risk operations require reauthentication? How is the impact of a leaked credential limited?
Not every issue must be implemented in the same iteration. However, the specification must identify what is resolved, what is unsupported for now, and what blocks release.
Write Acceptance Criteria as Observable Behavior
“Support secure persistent login” is too vague to verify. These statements provide clearer acceptance criteria:
When a tenant prohibits persistent login, the server must not issue a long-lived login credential, even if the client requests it.
Once an account is disabled, attempts to restore a session using a previously issued long-lived credential must be rejected.
When the user does not select “remember me,” the existing session policy must remain unchanged.
Give each rule a unique identifier where practical. Tasks, tests, and review findings can then reference those identifiers, establishing a traceable relationship between rules, implementation, and evidence.
Record Unresolved Decisions Explicitly
Specification documents should distinguish confirmed rules, design recommendations, and open decisions.
If the time required for credential revocation to take effect has not been decided, it should not be presented as a completed security capability. If that uncertainty affects the correctness of the design, pause the relevant implementation until the decision is made.
An explicit unresolved issue is more reliable than an agent silently choosing a plausible answer.
5. The Execution Loop: Give Every Step Boundaries and Evidence
Design the Core Mechanisms Before Breaking Down Tasks
For “remember me,” first determine the relationship between long-lived credentials and ordinary sessions. Page and API changes come afterward.
One common approach is to use a long-lived credential to obtain a new short-lived session rather than simply extend every session’s lifetime. This separates the management of ordinary sessions from persistent credentials and allows account status, tenant policy, and revocation information to be checked again during session restoration.
This is not the only valid design. Existing architecture, operational cost, client environments, and security requirements all affect the choice. The technical design should explain its rationale and limitations rather than present one pattern as a universal answer.
If the design uses random, opaque long-lived credentials, it should generally consider sufficient randomness, protected transport, avoiding server-side plaintext storage of directly usable credentials, and appropriate revocation mechanisms. Other credential formats require separate analysis of signature verification, state lookups, and invalidation propagation.
Break Work into Independently Verifiable Behaviors
Tasks should not be limited to “finish the frontend” and “finish the backend.” That division can leave cross-module rules without a clear owner.
More useful tasks include:
- Integrate tenant policy and verify prohibited scenarios.
- Implement credential issuance and session restoration.
- Invalidate credentials after password changes.
- Integrate account-disabled checks.
- Complete the interface and verify compatibility when the option is not selected.
- Add auditing, monitoring, and release controls.
Each task should specify its modification scope, dependencies, related rules, verification method, and completion criteria. The agent can then perform bounded work without repeatedly guessing the overall intent.
Use Tests to Constrain Implementation
For tasks with confirmed rules, prepare tests that express expected behavior before completing the implementation.
Test-first development is not merely about creating a test file before a source file. The essential point is that tests derive from specifications and risks rather than from code that already exists.
Persistent-login tests should cover at least:
- Successful issuance and session restoration.
- Rejection of expired credentials.
- Rejection of revoked credentials.
- Restoration attempts after an account is disabled.
- Previously issued credentials after a password change.
- Tenants that prohibit persistent login.
- Clients that bypass interface restrictions and submit requests directly.
- Compatibility with the existing workflow when the new feature is not enabled.
If credential rotation is used, also analyze credential reuse, concurrent requests, and retries. Otherwise, a normal network retry could be mistaken for an attack, or concurrent requests could create multiple credentials that remain valid.
Verify at Multiple Layers
Different forms of verification serve different purposes.
Unit tests check policy calculations, expiration decisions, and state transitions.
Integration tests check persistence, session creation, revocation lookups, and transaction boundaries.
End-to-end tests check user interactions, browser state, and the actual login flow.
Security review checks whether credentials appear in logs, whether clients gain control they should not have, and whether failure responses disclose sensitive information.
No layer fully replaces the others. A large test suite cannot compensate for missing coverage of a critical path.
6. Review Rules and Evidence, Not Just Code Diffs
After an agent generates code, human review should focus less on obvious syntax problems and more on whether system behavior matches the agreed requirements.
A reviewable change should include:
- Related requirements and rule identifiers.
- Design choices and major trade-offs.
- Affected modules and areas intentionally left unchanged.
- Tests and their actual execution results.
- Known limitations and remaining risks.
- Release, rollback, and data-compatibility notes.
It is especially important to distinguish tests written from tests executed. If the agent lacks a runnable environment, its report must state which checks were not performed. Expected outcomes must not be presented as observed evidence.
Automated checks and other agents can provide additional review perspectives for authentication and authorization changes. They cannot replace human approval with clearly assigned accountability.
7. Release and Rollback Are Part of Completion
Risks in a login mechanism do not disappear when the code is merged.
Define observable metrics before release, such as session-restoration success rates, distributions of failure reasons, credential revocation activity, and unusual request patterns. Metrics should correspond to specific behaviors. Logs must avoid passwords, complete tokens, and other reusable credentials.
Configuration controls or staged rollout can reduce release risk, but the team must define what happens when the feature is turned off:
- Does the system stop issuing new long-lived credentials?
- Do previously issued credentials remain valid?
- Is broad revocation necessary?
- Can older service versions handle the new data?
- Could rollback restore a security state that was already invalidated?
Rollback is therefore not simply reverting to a previous code version. It requires consistent handling of code, data, credentials, and policy state.
8. Preserve Each Change as Context for Future Development
After a change is complete, update the system specification to describe current official behavior, retain design decisions to explain the chosen approach, and archive execution records containing verification evidence.
These records serve different purposes:
- System specifications: How should the system work now?
- Design records: Why was it designed this way?
- Execution records: What changed, and how was it verified?
For the next change, the agent can read these materials before investigating the current code. This reduces repeated guesswork and makes it easier to recognize restrictions that exist for historical reasons.
Teams can also periodically check for divergence between specifications and code. For critical paths such as authentication and authorization, these consistency checks are more valuable than accumulating additional chat history.
9. Start with a Small, High-Risk Requirement
The two-loop process does not need to cover an entire project immediately. A practical starting point is a requirement with manageable scope and clear risk.
In the first stage, standardize requirements-clarification and acceptance templates. Require the agent to list assumptions and unresolved questions before implementation.
In the second stage, connect tasks to rule identifiers and verification evidence so that “done” is more than an unsupported statement.
In the third stage, include security review, release controls, and specification updates in the completion criteria.
Success should not be measured only by code-generation speed. More useful measures include requirements gaps found during review, rework, verification coverage of critical rules, behavioral deviations after release, and how quickly historical decisions can be traced.
The ultimate value of AI coding is not producing more code faster. It is turning confirmed requirements into system behavior that can be verified, maintained, and rolled back.
The specification loop constrains the direction. The execution loop demonstrates the result. Connecting them allows AI coding agents to move beyond code generation and become reliable participants in a mature engineering process.
