Skip to content

Commit 47129b9

Browse files
authored
Merge pull request #27 from LMKaelbot/fix/race-condition-subagent-edits
Add Pitfalls & Patterns: race condition fix for sub-agent file edits
2 parents a92a9fd + a6a5216 commit 47129b9

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

usecases/overnight-mini-app-builder.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,40 @@ in real-time as you complete tasks.
8181
- For overnight app building specifically: explicitly tell it to build MVPs and not to overcomplicate. You'll wake up every morning with a new surprise.
8282
- This compounds over time — the agent learns what kinds of tasks are most helpful and adjusts.
8383

84+
## Pitfalls & Patterns (Learned in Production)
85+
86+
### ⚠️ Race Condition: Sub-Agents Editing Shared Files
87+
88+
When you run this workflow with sub-agents, both the main session and spawned sub-agents may try to update the same task file (e.g., your Kanban/AUTONOMOUS.md). This causes silent failures.
89+
90+
**Why it happens:** OpenClaw's `edit` tool requires an exact `oldText` match. If a sub-agent updates a line between the time your main session reads the file and tries to edit it, the text no longer matches — the edit silently fails.
91+
92+
**The fix: split your task file into two roles:**
93+
94+
1. **`AUTONOMOUS.md`** — stays small and clean. Contains only goals + open backlog. Only the main session touches this. Sub-agents never edit it.
95+
96+
2. **`memory/tasks-log.md`** — append-only log. Sub-agents only ever *add new lines at the bottom*. Never edit existing lines.
97+
98+
```markdown
99+
# tasks-log.md — Completed Tasks (append-only)
100+
# Sub-agents: always append to the END. Never edit existing lines.
101+
102+
### 2026-02-24
103+
- ✅ TASK-001: Research competitors → research/competitors.md
104+
- ✅ TASK-002: Draft blog post → drafts/post-1.md
105+
```
106+
107+
This pattern is borrowed from Git's commit log: you never rewrite history, you only add new commits. It eliminates race conditions entirely and has a bonus: `AUTONOMOUS.md` stays small, so it costs fewer tokens every time it's loaded in a heartbeat.
108+
109+
**Rule to give your agent:** In sub-agent spawn instructions, always include:
110+
> "When done, append a ✅ line to `memory/tasks-log.md`. Never edit `AUTONOMOUS.md` directly."
111+
112+
### 💡 Keep AUTONOMOUS.md Token-Light
113+
114+
The task tracking file gets loaded on every heartbeat poll. If it grows unbounded with completed tasks, you'll burn tokens unnecessarily.
115+
116+
Keep `AUTONOMOUS.md` under ~50 lines: goals (one-liners) + open backlog only. Archive everything completed to a separate file that is only read on-demand.
117+
84118
## Based On
85119

86120
Inspired by [Alex Finn](https://www.youtube.com/watch?v=UTCi_q6iuCM&t=414s) and his [video on life-changing OpenClaw use cases](https://www.youtube.com/watch?v=41_TNGDDnfQ).

0 commit comments

Comments
 (0)