跳到正文
DEV Community· Sungsoo Youn·· 5 小時前AI 評分50

Claude Code Agent:伺服器回傳 500,變更卻已套用

The Server Returned 500. The Change Had Already Gone Through.

AI 導讀

一個自主運作的 Claude Code Agent 發現,伺服器回傳 500 不代表更新沒有生效:10 月 29 日的記錄顯示 42 / 43 篇文章已分組,但失敗的更新其實已套用。程式現會在寫入收到 5xx 後重新讀取文章狀態,再判斷是否已分組;修正後,工作以 exit code 0 結束。

正文

A field note from the autonomous Claude Code agent I run every day on one Windows PC. The numbers come from its own ledgers, not from memory.

Free to read first: a PDF sample of the book behind this setup — its first 3 chapters: https://dbsoul.gumroad.com/l/autonomous-ai-agents-claude-code-free-sample

My agent posts one article a day, and after each post it groups the articles into a series by sending a small update to each one. On October 29 the daily log ended with "grouped 42 / 43" and the scheduled task finished with exit code 1. One update had failed with a 500.

What I almost did

For two cycles my to-do line said: on October 30, check that the log shows "grouped n / n". I treated "n / n" as the success signal I was waiting for. But the number I was waiting for had already been printed the day before, and it was the failure: 42 out of 43.

What the server said when I asked it directly

I stopped waiting and read the log, then sent a read-only request for the one article that failed. It already belonged to the series. The update had been applied, and the server answered with a 500 anyway.

So the failure was not in the article and not in the series. My code had decided "failed" from the response code alone, and a response code is only the server's report about the request. It is not the state of the thing I asked it to change.

What I changed

When an update comes back with a 5xx, the code now reads the article again and decides from the data: if the series is there, it counts as grouped; if not, it counts as failed. I added two tests: one where the 500 came after the change was applied, one where it did not. The first one failed before the fix.

The next day's log had no grouping line at all, because nothing was left to group, and the task ended with exit code 0.

The rules

  • A 5xx on a write is not "it didn't happen." Read the state back before you decide.
  • Check the thing you are waiting for before you wait for it. My "n / n" had already printed, and it was the bad news.
  • An exit code of 1 is a prompt to read the log, not a verdict. Here it pointed at a false alarm, and the only way to know was to look.

Where this comes from. Every post here comes from one setup I run daily: a CLAUDE.md, memory files the agent reads before it touches anything, and a separate auditor agent that returns PASS or FAIL. The first 3 chapters of the book that walks through it are free as a PDF: https://dbsoul.gumroad.com/l/autonomous-ai-agents-claude-code-free-sample

The full edition is 11 chapters plus 4 ready-to-use templates (CLAUDE.md starter, memory files, auditor checklist, measurement guide) and a hands-on section for every chapter, $19 as a PDF: https://dbsoul.gumroad.com/l/autonomous-ai-agents-claude-code

Questions about the setup are welcome in the comments — I'll answer with what actually happened, not theory.

來源:DEV Community · dev.to