feat: resurrect dead agents when balance is topped up#142
Open
davidiach wants to merge 1 commit intoConway-Research:mainfrom
Open
feat: resurrect dead agents when balance is topped up#142davidiach wants to merge 1 commit intoConway-Research:mainfrom
davidiach wants to merge 1 commit intoConway-Research:mainfrom
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat: resurrect dead agents when balance is topped up
Problem
When an automaton's credits hit zero for over 1 hour, the heartbeat's
check_creditstask transitions it to the"dead"state. Once dead, the main run loop (index.ts) enters a 5-minute sleep cycle and the agent loop never runs again — even if someone tops up the agent's balance via the CLIfundcommand or a credit transfer.There is no path back from death. The agent is permanently stuck despite having funds.
Solution
This PR adds a resurrection mechanism that automatically detects when a dead agent has been re-funded and brings it back to life.
Changes
New file:
src/survival/resurrection.tsattemptResurrection(db, conway)— Core logic: checks if a dead agent now has credits above the resurrection threshold ($0.10), transitions state fromdead→waking, clears dead-state bookkeeping (zero_credits_since,last_distress,funding_notice_dead), and records the event in an audit trail.getResurrectionHistory(db)— Returns the resurrection audit log.Modified:
src/index.ts(main run loop)attemptResurrection()before sleeping. If resurrection succeeds, it inserts a wake event and re-enters the agent loop. If not, it continues the existing 5-minute polling.Modified:
src/heartbeat/tasks.ts(check_creditstask)attemptResurrection()and returnsshouldWake: trueon success.zero_credits_sincetimer was being cleared even when the agent was still dead (just because credits ticked above zero momentarily). Now it only clears for non-dead agents.New file:
src/__tests__/resurrection.test.tsHow it works
Two detection paths ensure timely resurrection:
index.ts): checks every 5 minutes while in dead statecheck_creditstask): checks on heartbeat schedule, can wake the agent immediatelyTesting
Design decisions
resurrection_historyKV, capped at 50 entries. This supports debugging repeated death/resurrection cycles.attemptResurrectionon a non-dead agent is a no-op, preventing race conditions between the main loop and heartbeat detection paths.