singularity-forge/src
Mikael Hugo 8ee4d83581 fix(agent-runner): retry inbox refresh + throw loud on missing message
Closes sf-mp8g4rcd-w01tkh (FINAL prompt-never-sent root cause) — the
agent-runner.js:182 silent early-return that has been causing 59+
runaway-loop:idle-halt feedback entries and the recurring "Autonomous
loop stuck — no heartbeat" cascade.

Root cause: when swarm-dispatch's bus delivers a message and SF
kernel marks the unit as dispatched, the consumer agent's inbox
sometimes doesn't see the message immediately (different MessageBus
instance, SQLite read-cache lag). Previous code returned
{turnsProcessed:0, response:null} silently — caller (swarm-dispatch
dispatchAndWait) swallowed it as "no work" — LLM never ran — unit
appeared cancelled with no diagnostic.

Fix: bounded retry on missing-message with exponential backoff:
50, 100, 200, 400, 800 ms (1.55s total max). If target message
appears during retry → log recovery event, proceed normally. If still
missing after the last retry → throw a loud error with full inbox
state in the message. The caller wraps in try/catch and surfaces it
as turnResult.error, so the autonomous loop sees a real failure
instead of phantom forward progress.

What this resolves:
- Earlier today: `sf headless triage --apply` timed out at 480000ms
  because triage-decider subagent hit this bug. With retries, the
  triage-decider has 1.55s of latency tolerance to receive its prompt.
- The 59 backlogged runaway-loop:idle-halt entries are symptoms of
  the same root cause. Future occurrences will surface as loud errors,
  not phantom "stuck" units — operator/auto-supervisor can react.

Validated:
- 578 tests pass (49 files) including agent-runner / swarm-dispatch /
  inbox tests.
- runAgentTurn callers (auto/loop.js, agent-swarm.js, swarm-dispatch
  dispatchAndWait) all already handle thrown errors via try/catch
  with explicit error surfacing — the contract change is safe.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-16 20:30:58 +02:00
..
resources fix(agent-runner): retry inbox refresh + throw loud on missing message 2026-05-16 20:30:58 +02:00
tests fix(headless): remove legacy v1 fallback path 2026-05-15 20:12:00 +02:00
web
app-paths.ts
bundled-extension-paths.ts
bundled-resource-path.ts
claude-cli-check.ts
cli-key.ts feat(cli): add sf key subcommand for auth.json management 2026-05-15 16:37:04 +02:00
cli-logs.ts
cli-stats.ts
cli-status.ts
cli-web-branch.ts sf snapshot: uncommitted changes after 33m inactivity 2026-05-16 17:00:13 +02:00
cli.ts feat(cli): sf --maintain drains self-feedback triage queue too 2026-05-16 19:04:03 +02:00
env.ts
errors.ts
extension-discovery.ts
extension-registry.ts
headless-answers.ts
headless-context.ts
headless-events.ts
headless-feedback.ts feat(self-feedback): purpose_anchor on entries (ADR-0000 restoration, v71) 2026-05-15 18:51:52 +02:00
headless-import-backlog.ts
headless-mark-state.ts feat(memory): add debug logging to memory extraction pipeline 2026-05-15 16:09:36 +02:00
headless-query.ts feat(headless): surface memory auth pause 2026-05-15 18:16:08 +02:00
headless-reflect.ts
headless-status.ts fix(headless): bypass rpc for status 2026-05-15 17:32:21 +02:00
headless-triage.ts feat(prompts): add v2 migration regression tests + fix template variable drift 2026-05-15 19:46:13 +02:00
headless-types.ts
headless-ui.ts
headless-uok-status.ts
headless-usage.ts feat(catalog/quota): global model catalog, benchmark coverage audit, provider quota visibility 2026-05-16 17:37:20 +02:00
headless.ts feat(headless): autonomous mode auto-drains self-feedback triage queue first 2026-05-16 19:01:50 +02:00
help-text.ts feat(self-feedback): purpose_anchor on entries (ADR-0000 restoration, v71) 2026-05-15 18:51:52 +02:00
interactive-session-lock.ts
loader.ts
logger.ts
logo.ts
models-resolver.ts
onboarding.ts
pi-migration.ts
project-sessions.ts
provider-migrations.ts
remote-questions-config.ts
resource-loader.ts
rtk.ts
security-overrides.ts
startup-model-validation.ts
startup-timings.ts
tool-bootstrap.ts
traces.ts
update-check.ts
update-cmd.ts
web-mode.ts
welcome-screen.ts
wizard.ts
worktree-cli.ts
worktree-name-gen.ts