8000 Fix #300: Count worktree file activity toward the idle timeout and keep a killed agent's work by vicgupta · Pull Request #303 · vicgupta/auto-mini-factory · GitHub
[go: up one dir, main page]

Skip to content

Fix #300: Count worktree file activity toward the idle timeout and keep a killed agent's work - #303

Merged
vicgupta merged 3 commits into
mainfrom
amf/issue-300
Nov 11, 2026
Merged

vicgupta merged 3 commits into
mainfrom
amf/issue-300

Conversation

@vicgupta
@vicgupta vicgupta commented Nov 11, 2026 •
Copy link
Copy Markdown
Owner

Summary

Fixes #300. On vicgupta/tinyagent the opencode idle timeout killed an agent that was still editing files, and its work was thrown away with the worktree.

  • File activity counts. While an agent runs, amf also scans its worktree, skipping .git/, for files that were created, changed (mtime or size) or removed. Any change resets the idle timer, just like output does. The scan runs every quarter of the limit, between 10ms and 30s, so every 30s at the default. It stops when the agent exits and only runs when the idle timeout is on.
  • Default raised from 15m to 30m for AMF_AGENT_IDLE_TIMEOUT. The overall agent timeout stays 1h. amf init's template, .env.example and help are updated.
  • Partial work is kept. When amf kills an agent at the idle or agent timeout, it commits the agent's changes before the worktree is removed or reset for a fallback. The commit uses the normal commit's exclusions plus .amf/, and goes to a local-only branch amf/wip/issue-N-<UTC time> (with -2, -3… on a clash). amf prints the branch and git log -p <default>..<branch> in the log, emits an issue.wip event, and names it in the failure comment. Nothing is pushed from it and no PR is opened or updated. An agent that changed nothing leaves no WIP branch. If saving fails, amf logs a warning and still reports the timeout.
  • Hand fixes on top of amf's commit:
    • saveWIPBranch now moves the worktree's amf/issue-N back to where it was (with reset --soft), so only the WIP branch holds the partial commit.
    • The scan interval cap went from 5s to 30s, so large worktrees aren't walked every few seconds.
    • New tests for both, and for the fallback path.

Testing

  • New:
    • TestAgentIdleTimeoutCountsFileActivity: an agent that is silent but keeps writing outlives a 600ms limit, and a PR is opened.
    • TestKilledAgentSavesWIP, with idle-timeout and agent-timeout subtests: edits land on the local WIP branch, which isn't on origin. No PR is opened, and the comment and log name the branch.
    • TestKilledPrimaryKeepsWIPThroughFallback: the killed primary's edits survive the fallback's fresh worktree and stay out of the pushed branch and the PR.
    • TestSaveWIPBranchLeavesIssueBranch and TestFileActivityInterval.
  • Extended: TestAgentIdleTimeout, where an agent that neither prints nor writes is still stopped and leaves no WIP branch, and the default test now expects 30m.
  • Gate: gofmt -l clean; go build ./..., go vet ./..., go vet -tags live ./..., go test -count=1 ./... and go test -race -count=1 ./cmd/amf all pass. TestHelpFitsEightyColumns passes.

Docs

docs/SPECS.md (the agent Timeout step, failure handling, dry-run note, files table, issue.wip event), docs/CONFIGURATION.md, docs/TROUBLESHOOTING.md, docs/COMMANDS.md, README.md, .env.example, and the amf run help plus the AMF_AGENT_IDLE_TIMEOUT entry.

Decisions

  • Polling scan instead of fsnotify, so no new dependency. It compares mtime and size per file, which is cheap and catches edits to untracked files that git status hashing would cost more to see.
  • Both fixes: file activity and a 30m default. File activity covers an agent that edits quietly, and the longer default covers long silent reasoning between edits.
  • WIP is a local branch, not a kept worktree and not pushed. It survives worktree remove and the fallback's worktree add -B, can be inspected with plain git, and can't reach a PR or CI. A Ctrl-C interrupt isn't a kill by amf, so it saves no WIP. The worktree is kept as before.
  • Read-only stages (plan and eval) that time out also save whatever is in the worktree, including earlier code-round commits, before the stage's reset throws it away.

Closes #300

…and keep a killed agent's partial work

Closes #300
@vicgupta vicgupta changed the title Fix #300: Count worktree file activity toward the agent idle timeout and keep a killed agent's partial work Fix #300: Count worktree file activity toward the idle timeout and keep a killed agent's work Nov 11, 2026
@vicgupta
vicgupta merged commit 72f82fb into main Nov 11, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Count worktree file activity toward the agent idle timeout and keep a killed agent's partial work

1 participant

0