DEV Community

Cover image for My dead link agent leaves dead links on purpose
Carlos José Castro Galante
Carlos José Castro Galante

Posted on

My dead link agent leaves dead links on purpose

This is a submission for the MLH x DEV Writing Challenge

What I Built

The example autopsy linked at the top of Linkmortem's README no longer opens. Anyone who clicks it now reads "That autopsy doesn't exist or has expired," which is an odd thing to find in a project built to fight dead links. MongoDB Atlas deleted that autopsy on schedule, thirty days after I created it, because I told it to.

Linkmortem is an open source agent that finds dead links in websites and GitHub repositories, recovers what each page said from the Wayback Machine and looks for where the content lives now. It proposes a replacement only when it can prove the new page is the same one. I built it alone in five days for the last week of Hacktoberfest 2026, and my Week 4 submission tells how the agent decides. That post gave MongoDB Atlas a single paragraph, even though Atlas is what won Linkmortem the Best Use of MongoDB Atlas prize on November 13.

This post is about that paragraph. Giving the agent a memory looked like adding a cache, and it turned into a series of decisions about what to keep, for how long and what never to trust without checking again, including the decision that broke the link in my own README.

Demo

You can scan a repository at linkmortem.tech, or press "Or try it on the demo repository" for a full scan in one click. The share link at the end of every scan is the first thing Atlas stores, and it lasts thirty days.

GitHub logo carlosjcastro / linkmortem

Every dead link is a ghost. Finds dead links and dead sections in websites and GitHub repos, recovers what each page said from the Internet Archive, finds where it lives now and opens a pull request with the fixes it can prove. Code decides what it can verify, and Gemma 4 reads the rest.

The Linkmortem home page with a ghost made of light

Linkmortem

Every dead link is a ghost. Linkmortem finds the dead links and dead sections in a website or in the Markdown docs of a GitHub repository, works out why each one died, recovers what the page said from the Internet Archive, finds where the content lives now and writes the fix. Code decides everything it can verify. Gemma 4, an open weights model, reads only the pages code can't judge.

Live at linkmortem.tech Demo video on YouTube Example autopsy

GitHub Action demo, pull request opened by the Action GitHub Action demo, issue kept by the Action CI status MIT license

Built for the DEV Hacktoberfest 2026 Open Source AI Challenge, Week 4, Ghost in the Machine

Contents

Why it exists

The web forgets faster than we think. 38% of the web pages that existed in 2013 were gone…

Partner Technologies

Linkmortem's memory runs on a free M0 cluster in MongoDB Atlas, with four collections and one Vector Search index. Gemma 4 through Backboard, SerpApi and Sentry appear below only where they meet that memory, since the Week 4 post covers them in depth.

The Linkmortem database in Atlas with its four collections, showing saved scans that carry an expires_at date and one that also carries preserved_at

Thirty days, seven days and forever

Each collection keeps its contents for as long as they stay useful. A finished autopsy lives in scans for thirty days, long enough to send it to a maintainer and give them time to open it. What the Wayback Machine returned for a page lives in memories for seven days, and so does the answer to where a dead page moved, in afterlives, because the live web keeps changing and a page with no new home today may have one next week. The graveyard keeps every proven move with no expiry.

None of the three expiring collections needs a cleanup job. Each document carries its own expires_at date, and the app creates a TTL index on startup so Atlas removes every document once that date passes.

async def ensure_indexes(self) -> None:
    if self._client is None:
        return
    try:
        for name in EXPIRING:
            await self._client[self._database][name].create_index(EXPIRES_FIELD, expireAfterSeconds=0)
    except PyMongoError:
        return
Enter fullscreen mode Exit fullscreen mode

That thirty day lifetime explains the expired link in my README, and it forced a decision I hadn't planned for. A shared autopsy indexed by search engines would become a dead result the day Atlas deletes it, which means Linkmortem would be creating the same ghosts it hunts. Every /r/<id> page is served with noindex, follow, and the path isn't blocked in robots.txt, because X's card crawler respects that file and the link preview would disappear. When someone opens an autopsy that has expired, the page says that autopsies last thirty days and invites them to scan the address again.

"I don't know" is not "it doesn't exist"

The worst bug in Linkmortem's memory looked harmless. When Gemma failed to answer while comparing candidates for a new home, the agent read the silence as "no match," cached that empty answer for seven days and buried it in the graveyard. A link with a perfectly good new home would show "No new home found" for a week, and every scan during that week would trust it.

The fix was to separate answers about the link from answers about the moment. A search for a new home can end with a page found, with nothing found, with the model unavailable or with the search budget spent, and only the first two say anything about the link.

LASTING = (Rebirth.FOUND, Rebirth.NONE)

if afterlife.status in LASTING:
    await self._cache.put(original_url, afterlife.model_dump(mode="json"))
Enter fullscreen mode Exit fullscreen mode

Memories follow the same rule. A page the archive never captured is remembered as missing, while a request the Wayback Machine failed to answer isn't remembered at all.

Remembering "nothing found" has a cost too, and I paid it during the challenge. I taught the agent to follow moves that archived pages announce themselves, like the old Enzyme docs saying "Enzyme has moved. Redirecting now to enzymejs.github.io," and the fix still didn't show up in production. The previous "no new home" for Enzyme was sitting in afterlives exactly as designed, so I deleted that one document by hand to see the new answer. I kept the rule anyway. SerpApi's free plan gave me 225 searches until November 26, and I had capped them at 20 a day so readers of my post couldn't spend the searches judges would need. Against that budget, remembering an empty result for a week costs far less than paying for the same empty search on every scan.

The graveyard answers before the search

The graveyard is the only memory that grows. Every time the agent proves where a dead page moved, it buries the answer with the original URL as the document's _id, so a link only ever has one grave. Before Linkmortem spends a web search on a new dead page, it asks the graveyard whether a page that reads like this one has already been resolved.

The lookup runs on Atlas Vector Search with Automated Embedding. My backend sends plain text, and Atlas creates the embeddings with voyage-4 both for the stored graves and for each query, so there's no embedding model in my code and no vectors for me to keep in sync.

pipeline = [
    {
        "$vectorSearch": {
            "index": INDEX,
            "path": "text",
            "query": remembered_text(memory, QUERY_CHARS),
            "model": MODEL,
            "numCandidates": CANDIDATES,
            "limit": MATCHES,
        }
    },
    {"$project": {"_id": 0, "new_url": 1, "score": {"$meta": "vectorSearchScore"}}},
]
Enter fullscreen mode Exit fullscreen mode

The query is the first 300 characters of the archived title and text, and each grave keeps up to 1,500. Atlas considers 20 candidates and returns the closest 3, and the code drops any match that scores under 0.75 or points back to the dead address.

A close embedding still isn't proof that two pages are the same, so the graveyard never decides alone. Gemma compares every suggestion with the archived copy, and a page it judges to be the same ends the search without a single call to SerpApi. A newer version of the page is held as a fallback while the web search runs, and that search skips every address the graveyard already offered. If the daily budget is spent or SerpApi is down, the fallback from the graveyard still becomes the answer. Whatever the search path settles on gets buried, so every scan that pays for a search leaves the next one better informed, and the results tell people when a new home came from the graveyard instead of a fresh search.

Sentry traces search_graveyard as its own tool in every scan, next to web_search, so each trace shows whether memory answered before the agent paid.

One preservation per autopsy

Linkmortem can also ask the Internet Archive to save living links that were never archived, up to ten per autopsy, nine seconds apart and with a one minute wait whenever the archive says it's busy. That's slow, and it runs on my own Internet Archive account, so it has to happen once per autopsy even if someone clicks twice or opens the same share link in two tabs. A single conditional update decides who goes first.

result = await self._collection.update_one(
    {"_id": scan_id, "preserved_at": {"$exists": False}},
    {"$set": {"preserved_at": datetime.now(UTC)}},
)
return result.modified_count == 1
Enter fullscreen mode Exit fullscreen mode

Only the request that sets preserved_at starts the captures. Any other request gets a 409 that says "The living links of this autopsy were already sent to the archive," and the scan with preserved_at in the screenshot above is one of those claims.

A memory the agent can live without

I wanted Atlas to make scans cheaper without ever being the reason one fails. Every read and write is wrapped, so a failed graveyard search returns no suggestions, a failed cache read counts as a miss and a failed write is skipped. The client stops looking for a server after three seconds, and the health check reports whether the database answered instead of crashing when it doesn't.

Without a connection string, Linkmortem still runs and only loses shared autopsies and memory. That's how the GitHub Action works today, since it has no database input at all and scans a repository with nothing more than a Backboard key and a SerpApi key, both optional. Anyone can self-host the agent without creating a cluster, and memory becomes something you add for speed and cost rather than something the agent needs to tell a living link from a dead one.

Hackathon Experience

I took part in Hacktoberfest 2026, run by MLH and DEV, alone and online from San Juan, Argentina. The Open Source AI Challenge brought a new prompt every week, and by the last one I had already built two tools that ran Gemma on my own computer. Linkmortem was my first project meant to live online for people I'd never meet, and that changed what I had to think about. A tool on my laptop can repeat work for free, while an agent on the internet pays for every repeated search out of a shared quota, so memory stopped being an optimization and became part of keeping the demo working while judges and readers tried it.

I made the first commit on October 26 at 9:19 p.m. in Argentina, and the deadline landed at 3:59 a.m. on November 1, like most deadlines that month. Between weeks I read other entries to learn how people explained their projects, which is also how I learned that a good post tells why a decision was made and not only what the code does. I finished the month as a Hacktoberfest Completionist, and two weeks after the last deadline Linkmortem won Best Use of MongoDB Atlas.

What changed most is the first question I ask when an agent needs to store something. I used to ask what to save, and now I ask how long it stays true and what the agent should do once it doesn't.

If you've built an agent that remembers between runs, what did you decide it should forget, and what did that decision cost you?

Top comments (9)

Collapse
 
nullandvoid_ profile image
Jyanthi •

A rather ingenious undertaking! I find the distinction between what is truly irretrievable and what merely eludes discovery particularly commendable. There is considerable wisdom in an agent that knows the limits of its own certainty, rather than presuming every answer to be within its grasp. After all, discernment lies not merely in knowing what to remember, but in recognising when a memory has outlived its usefulness. A most thoughtful piece of work!

Collapse
 
carlosjcastrog profile image
Carlos José Castro Galante •

Thank you! That line between "I don't know" and "it doesn't exist" was the hardest lesson of the whole build because the bug that taught it looked completely harmless until a link with a perfectly good new home showed "No new home found" for a week.

Collapse
 
matas_edgardotulasarqu profile image
Matías Edgardo Tula Sarquis •

Beautiful work, I'm really impressed by your work. Keep it up! ☺️

Collapse
 
carlosjcastrog profile image
Carlos José Castro Galante •

Thank you so much, I really appreciate it! Memory was the part of Linkmortem I enjoyed building the most, so I'm glad it came through in the post! 🙌

Collapse
 
robertpaschal profile image
Odinaka Robert Nnamani •

your dead-link hunter created a dead link in its own readme, on schedule. thirty days and the autopsy deletes itself.

Collapse
 
carlosjcastrog profile image
Carlos José Castro Galante •

Thanks for reading! That irony was the part that surprised me most. Once I saw that the autopsies would disappear on schedule, I had to make sure they never reached search results, so every shared page carries noindex. Otherwise Linkmortem would have been creating ghosts for everyone else, not just in my own README.

Collapse
 
robertpaschal profile image
Odinaka Robert Nnamani •

noindex on every shared page is the fix that keeps it from haunting anyone else. the hunter policing its own ghosts.

Thread Thread
 
carlosjcastrog profile image
Carlos José Castro Galante •

Exactly, a ghost hunter that leaves ghosts behind would lose all credibility. Thanks for the comments!

Thread Thread
 
robertpaschal profile image
Odinaka Robert Nnamani •

a ghost hunter that leaves ghosts behind is just a tour guide.