Stop your AI agent from redoing finished work

●1 ●8 ●19
calendar_today • schedule5 min read

I maintain Selvedge. This article was prepared with AI assistance and checked against the released v0.3.17 documentation.

A recent question in the OpenAI Codex discussions describes a familiar failure. After months of AI-assisted development on an internal business app, the author asks: "How do experienced developers prevent AI coding agents from producing disconnected code and repeatedly rebuilding or breaking previously completed functionality?" (openai/codex #52835). I'm citing it as a clear public statement of the problem, not as a Selvedge user story.

A new session sees the code but not its history. It doesn't know which feature was signed off last week, or which "obvious" improvement was already tried and dropped. From the agent's point of view, rewriting a working module is as reasonable as extending it.

Most of the fix is process, not tooling. These tactics work with any agent.

1. Write "done" down where the agent will read it

An agent can't respect a boundary it never sees. Keep a short, maintained list of completed areas in the instruction file your agent loads at startup (for example AGENTS.md, CLAUDE.md, GEMINI.md or a Cursor rules file, depending on the client). For each entry, name the files or modules, the behavior that is finished, and the test that proves it:

DONE: approval flow (src/approvals.py). Covered by tests/test_approvals.py.
Extend it; do not restructure it without asking.

Prune it regularly; a stale list gets skimmed.

2. Make finished behavior executable

A sentence saying "the approval flow works" is weaker than a test that fails when it stops working. Before you call a feature done, make sure at least one test exercises it from the user's side, and ask the agent to run the full suite before declaring any later task complete. A rebuild that breaks finished work then shows up as a red test rather than a surprise.

3. Record what you rejected, not just what you chose

Code shows the approach you picked. It doesn't show the alternative you ruled out, and that is exactly what a fresh session is most likely to propose again. When you decline an approach, write down three things: what you rejected, why, and what would make it worth reconsidering. An architecture decision record (ADR) or a section of your project docs works. The revisit condition matters because it stops a reasonable rejection from becoming a permanent rule.

4. Scope every task, including what not to touch

"Add CSV export to the dashboard" invites the agent to reorganize the dashboard. "Add CSV export in src/export.py; do not modify src/approvals.py or the database schema" does not. Name the files in scope and the finished areas out of scope, and keep each diff small enough to review in full.

5. Look before editing, and review against the record

Start each task by asking the agent to read the relevant notes and say what it will leave unchanged. Then review the diff against that statement. A change to a "done" file isn't automatically wrong, but it should come with a reason you can check.

Where Selvedge fits

These steps work with plain files. Their weak point is lookup: as notes grow, the right one must surface just as the agent edits a specific function or column. Selvedge is one way to handle step 3 and the lookup in step 5.

Selvedge is an open-source local decision log for coding agents. It runs as a local stdio MCP server or a CLI, stores records in SQLite under .selvedge/, needs no hosted account, and makes no LLM calls in core storage and retrieval. You or your agent save a decision, its reason and any rejected approach against an entity such as src/approvals.py::submit_for_review, users.email or deps/stripe. A later session queries that entity before editing it.

Here is a synthetic example I ran with Selvedge 0.3.17 in a temporary project. The rejection is invented for illustration:

selvedge init
selvedge log src/approvals.py::submit_for_review reject \
  --reasoning "Rejected rebuilding approvals on browser localStorage; went with the server-side approvals table instead, which passes tests/test_approvals.py. A manager on another device would not see a pending submission." \
  --constraint "Approval state must be visible to every reviewer on any device." \
  --stale-when "approval state moves to a different shared store"

Before the next edit, an agent with shell access can run selvedge prior-attempts src/approvals.py::submit_for_review, or call the prior_attempts MCP tool. In the synthetic run, the CLI returned the record labeled rejected (exact) along with the saved reasoning. The summary line still reads current status … reverted; in 0.3.17 that status covers both reverted and rejected records, and the row label shows which one it was. "Exact" means an explicit rejection was recorded. It doesn't mean the rejection was correct or still applies. selvedge blame showed the constraint and revisit condition, and selvedge search localStorage found the record. For an entity with no qualifying records, the CLI reported "No prior attempts found". That means nothing was recorded, not that nothing was ever tried.

For reviewers, selvedge export --format markdown -o DECISIONS.md writes a digest that lists explicit rejections under "Considered and rejected". Since 0.3.17, adding --check exits 0 silently when the file is current and 1 with a diff when it is stale or missing. In the synthetic run, logging a second rejection made the check exit 1 and print the missing entry. A hook or CI job can use this to catch a stale copy.

Tip: name the chosen approach inside the rejection itself. If you log a finished change and then a rejection on the same entity, prior-attempts shows the finished change as tried, then reverted.

If a rejection stops applying, selvedge supersede reopens it and keeps the original record in the history.

Limits

  • Only explicitly saved decisions can be retrieved. Connecting the MCP server doesn't capture every decision automatically.
  • Selvedge stores the reasoning a person or agent supplies. It doesn't verify that the reasoning is true or complete.
  • Nothing guarantees an agent will consult the record. The built-in selvedge demo runs on a temporary database; it doesn't verify your agent's configuration, activation or hooks. Check those separately in your own client.
  • It doesn't replace tests, scoped tasks, code review or a single maintained codebase.

If you try it, the useful test is one real rejection: save it, close the session, and check whether a new session retrieves it before proposing the same idea. Setup is in the quickstart, and the source is at masondelan/selvedge.

Want more #ai & #programming deep dives?

Join 6,163+ developers sharing real benchmarks, code breakdowns, and projects. Free forever.

More Posts

I’m a Senior Dev and I’ve Forgotten How to Think Without a Prompt

Karol Modelski - Mar 19

TypeScript Complexity Has Finally Reached the Point of Total Absurdity

Karol Modelski - Apr 23

The Sovereign Vault — A Comprehensive Guide to Protocol-Driven AI

Ken W. Algerverified - Jun 4

Stop trusting verdicts your policy no longer supports

VEACESLAV - Dec 1

Frameworks Are Institutional Memory

Ken W. Algerverified - Sep 17
chevron_left
1.1k Points • 28 Badges
Southern California, USA • linkedin.com/in/masondelan
9Posts
2Comments
4Connections
Applied Data Science M.S. | Statistics & Data Science B.S.

Commenters (This Week)

13 comments
2 comments
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!