Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: discard consumed agent completion sentinels

[._.]/ Adam Eivy88bb2c7c8750
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 8ec9403950..f5c891535f 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -2,6 +2,8 @@
## Changed
+- **Completed CoS agents no longer strand a worktree because of their own completion marker.** The `.agent-done` sentinel is consumed before worktree cleanup, but Git still reported the untracked file as ordinary authored work and the safety gate preserved the otherwise-clean checkout with a high-priority warning. Cleanup now ignores only that runtime marker: sentinel-only trees are removed normally, while any real source change still preserves the worktree and is named in the warning.
+
- **A failed CoS task now diagnoses itself and comes back on its own.** A failing task used to pile up a queue of approval-gated tasks — the crash filed one, the provider failure filed another, repeated orphaning filed a third — and then, even after the cause was fixed, the original task sat `blocked` until someone un-blocked it by hand (or the 14-day reaper quietly retired it as stale). Both halves of that are now automatic. Every failure-driven investigation is filed through one producer, so they share a single approval policy, a single storm counter, and a single dedup fingerprint: unattended by default, held for you in exactly the two cases where another unattended agent would just repeat itself — the same cause was already investigated in the last 24 hours, or failures are cascading rather than isolated — and the task says which of the two it is. Completing an investigation, whether an agent finished it or you fixed the cause and ticked it off, then automatically retries every task that failure was blocking. Bounded at two automatic retries per task, after which the task stays blocked and says the retry loop gave up rather than still showing the original failure. A task you terminated or paused, one parked awaiting your arbitration, and one waiting on a repository path you have to fix are never revived behind your back.
- **The bundled local-LLM install catalog has been refreshed to the current model landscape.** Every suggested model was re-verified against the Ollama registry and the Hugging Face API, and the list is now built from what's current: Qwen3.5 / Qwen3.6, Gemma 4 (12B alongside the existing 26B/31B), Muse Glimmer, GLM-4.7 Flash, Granite 4.1, Ministral 3, Nemotron 3 Nano (including a 1M-context 30B), Olmo 3.1, LFM2.5, Qwen3-VL, MiniCPM-V 4.6, EmbeddingGemma, and the Ornith / North Mini Code / Devstral Small 2 coding tier. Models superseded by two generations were retired (Llama 3.1/3.2/3.3, Qwen2.5 + Qwen2.5-VL, Mistral 7B, Gemma 2, Phi-3, DeepSeek-R1 Distill, LLaVA 1.5, Code Llama, SmolLM2, Moondream) — but they still map exactly across backends, so migrating an older Ollama library to LM Studio doesn't degrade to a guessed name. Two entries were broken outright: the LM Studio repos for LLaVA 1.5 and Code Llama now 404. Ollama ids are checked for real local weights, because several headline 2026 models (Mistral Large 3, GLM-5.2, DeepSeek-V4, MiniMax-M3, Kimi K3) are published only as `:cloud` passthrough tags that would have installed nothing.
diff --git a/server/services/worktreeManager.js b/server/services/worktreeManager.js
index d3cecfe8aa..79e13671c4 100644
--- a/server/services/worktreeManager.js
+++ b/server/services/worktreeManager.js
@@ -188,6 +188,10 @@ export async function forceRemoveWorktreeDir(repo, worktreePath, { label, log =
* lockfile churn. Pure (testable) — callers decide what to do with the result.
*
* @param {string} porcelain - raw `git status --porcelain` stdout
+ * @param {object} [options]
+ * @param {string[]} [options.ignoredPaths] - runtime-only paths that must not
+ * preserve a completed worktree. They are still removed only when the rest of
+ * the tree is safe to remove.
* @returns {{ clean: boolean, lockfileOnly: boolean, lockfilePaths: string[], realChangePaths: string[], hasRealChanges: boolean }}
* - clean: no changes at all
* - lockfileOnly: every change is an auto-generated lockfile (safe to discard)
@@ -198,15 +202,19 @@ export async function forceRemoveWorktreeDir(repo, worktreePath, { label, log =
* superseded while it sat uncommitted.
* - hasRealChanges: at least one non-lockfile change (worktree must be preserved)
*/
-export function classifyWorktreeDirt(porcelain) {
- const lines = (porcelain || '').split('\n').map(l => l.trim()).filter(Boolean);
+export function classifyWorktreeDirt(porcelain, { ignoredPaths = [] } = {}) {
+ const ignored = new Set(ignoredPaths);
+ const toPath = (line) => line.replace(/^\s*\S+\s+/, '').split(' -> ').pop();
+ const lines = (porcelain || '').split('\n')
+ .map(l => l.trim())
+ .filter(Boolean)
+ .filter(line => !ignored.has(toPath(line)));
if (lines.length === 0) {
return { clean: true, lockfileOnly: false, lockfilePaths: [], realChangePaths: [], hasRealChanges: false };
}
const isLockfile = (line) => AUTO_GENERATED_LOCKFILES.some(f => line.endsWith(f));
// `R old -> new` (rename) names two paths; the post-rename path is the one
// that exists on disk and the one a diff against the default branch reports.
- const toPath = (line) => line.replace(/^\s*\S+\s+/, '').split(' -> ').pop();
const lockfileLines = lines.filter(isLockfile);
const lockfileOnly = lockfileLines.length === lines.length;
return {
@@ -534,17 +542,21 @@ export async function removeWorktree(agentId, sourceWorkspace, branchName, optio
warnings.push(`Worktree preserved — git status failed: ${err.message}`);
return { merged: false, removed: false, uncommittedSaved: false, warnings };
}
- if (dirtyFiles && options.discardDirt) {
+ // `.agent-done` is a completion sentinel, not authored work. It has already
+ // been consumed by finalizeAgent before this cleanup runs. Ignore it for the
+ // preservation decision, while still preserving the tree if any real change
+ // remains; the eventual forced worktree removal discards the sentinel with the
+ // rest of the completed checkout.
+ const dirt = classifyWorktreeDirt(dirtyFiles, { ignoredPaths: ['.agent-done'] });
+ if (!dirt.clean && options.discardDirt) {
// Throwaway posture: the caller has already established that nothing in this
// tree is wanted. Log what is being dropped so a surprising loss is at least
// traceable, then fall through to removal.
- const dirt = classifyWorktreeDirt(dirtyFiles);
const shown = dirt.realChangePaths.slice(0, DIRT_PATHS_IN_WARNING);
if (shown.length) console.log(`🌳 Discarding uncommitted changes in throwaway worktree ${agentId}: ${shown.join(', ')}`);
- } else if (dirtyFiles) {
+ } else if (!dirt.clean) {
// Discard auto-generated lockfile changes that agents don't intend to commit
// (e.g., npm install resolving ^version to exact version in package-lock.json)
- const dirt = classifyWorktreeDirt(dirtyFiles);
if (dirt.lockfileOnly) {
console.log(`🧹 Discarding ${dirt.lockfilePaths.length} auto-generated lockfile change(s) in worktree ${agentId}`);
await execGit(['checkout', '--', ...dirt.lockfilePaths], worktreePath);
diff --git a/server/services/worktreeManager.test.js b/server/services/worktreeManager.test.js
index 2eeec148f4..80b6262482 100644
--- a/server/services/worktreeManager.test.js
+++ b/server/services/worktreeManager.test.js
@@ -325,6 +325,14 @@ describe('classifyWorktreeDirt (real exported helper)', () => {
expect(r.lockfileOnly).toBe(true);
expect(r.lockfilePaths).toEqual(['yarn.lock']);
});
+
+ it('can ignore a consumed completion sentinel without hiding real work', () => {
+ expect(classifyWorktreeDirt('?? .agent-done', { ignoredPaths: ['.agent-done'] }).clean).toBe(true);
+
+ const r = classifyWorktreeDirt('?? .agent-done\n M src/index.js', { ignoredPaths: ['.agent-done'] });
+ expect(r.hasRealChanges).toBe(true);
+ expect(r.realChangePaths).toEqual(['src/index.js']);
+ });
});
describe('Broken Worktree Detection', () => {
@@ -683,6 +691,25 @@ describe('removeWorktree branch preservation for resume (#3167)', () => {
expect(result.warnings.join(' ')).toContain('notes.md');
});
+ it('removes a completed worktree whose only dirt is the consumed sentinel', async () => {
+ scriptGit({ porcelain: '?? .agent-done' });
+
+ const result = await removeWorktree('agent-x', '/repo', 'cos/task-1/agent-x', { merge: false });
+
+ expect(result.removed).toBe(true);
+ expect(result.warnings).toEqual([]);
+ });
+
+ it('preserves real work while excluding the completion sentinel from the warning', async () => {
+ scriptGit({ porcelain: '?? .agent-done\n M src/index.js' });
+
+ const result = await removeWorktree('agent-x', '/repo', 'cos/task-1/agent-x', { merge: false });
+
+ expect(result.removed).toBe(false);
+ expect(result.warnings.join(' ')).toContain('src/index.js');
+ expect(result.warnings.join(' ')).not.toContain('.agent-done');
+ });
+
it('caps the named paths so a broad sweep cannot flood the notification', async () => {
scriptGit({ porcelain: Array.from({ length: 9 }, (_, i) => ` M src/f${i}.js`).join('\n') });