Skip to content

fix(autonudge): name the stop reason at every remaining loop removal - #14493

Merged
chenmingwei23 merged 1 commit into
mainfrom
fix/14409-autonudge-stop-reasons
Sep 28, 2026
Merged

chenmingwei23 merged 1 commit into
mainfrom
fix/14409-autonudge-stop-reasons

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: every auto-nudge loop stop names its real reason in the gateway log.

Since #14131, each loop stop writes one WARNING line to gateway.log. Some callers still stop a loop without saying why. Their line reads reason='removed' or reason='unspecified', which tells a reader nothing.

Why it matters

When a conductor loop stops early, the log line is the only clue. A line that just says removed sends the reader back into the code to guess which of ten paths fired.

Not a goal

What changed (motivation → approach → change)

Stop Where Reason now logged
/goal clear dashboard/chat_runner.py goal_cleared
Slack thread has no channel slack/gateway.py slack_unroutable
DM key has the wrong shape slack/gateway.py unsupported_key
DM user no longer allowed slack/gateway.py user_not_authorized
DM session rotated slack/gateway.py session_rotated
Dashboard session gone slack/gateway.py session_unreachable
Unknown channel prefix slack/gateway.py unsupported_channel
Campaign Stop / Delete apps/builtins/auto_research campaign_stopped / campaign_deleted
Watchdog ends a campaign apps/builtins/auto_research campaign_<status>
Orphaned worker cleanup apps/builtins/spec_builder orphaned_worker
Spec Stop / Delete apps/builtins/spec_builder spec_stopped / spec_deleted
Spec hand-off aborted apps/builtins/spec_builder spec_arm_aborted

The log line takes its reason from the write that turns the loop off. A plain remove() with no reason becomes removed. So each caller that removes a live loop passes stop_reason. Spec Builder's stop, delete and hand-off paths share one removal helper, _remove_nudge_loop_for_slot, so the reason is threaded through that helper.

Two callers turn the loop off first and remove it later. The Auto Research watchdog and Spec Builder orphan cleanup do this. For them the line is written at the turn-off step, so they pass stopped_reason there. deactivate_and_wait in autonudge.py, on the service and its maintenance view, gains an optional stopped_reason for this. The watchdog only sets it on a loop that is still active, so a worker's own autonudge_stop mark is never overwritten.

The Auto Research relaunch cleanup is left as is. It only removes a loop that is already stopped, so it writes no line.

Backwards compatibility

Compatible: stop_reason and stopped_reason are new optional keyword arguments with the old defaults. No stop happens at a different time.

Tests

  • Existing tests for each stop path assert the exact reason, including Spec Builder Stop and Delete: test/test_goal_command.py, test/test_slack_gateway_coverage.py, test/test_autonudge_dashboard_fire.py, test/test_auto_research.py, test/test_auto_research_handlers_coverage.py, Spec Builder's test_routes.py, and test/test_spec_builder_routes_coverage.py.
  • test/test_autonudge_stop_log.py adds a real-service test: a maintenance-view turn-off with stopped_reason="orphaned_worker" logs that reason.

Manual verification

N/A — unit coverage sufficient: the change is the reason string on existing calls, and each call is pinned by a test.

Related Issues

Fixes #14409

Pattern harvest

Not generalizable: the default removed reason is a deliberate fallback; the fix is naming each caller, not a rule.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@iamwhatever
iamwhatever requested a review from a team as a code owner September 27, 2026 17:47
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Intent: every auto-nudge loop stop names its real reason in the gateway WARNING line, instead of removed or unspecified.
Not a goal: changing when or whether a loop stops, or adding a new log type, file or setting.

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Sep 27, 2026
@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 23bd805be79376532c66481834b29b12313ca991 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 23bd805

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 23bd805be79376532c66481834b29b12313ca991: <one-sentence reason>

@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

Design-level review of 23bd805be79376532c66481834b29b12313ca991 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Nothing to check.

[DESIGN-REVIEWED] 23bd805

@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — ✅ PASS

Premise-level review of 23bd805be79376532c66481834b29b12313ca991 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: PASS

One residual to confirm: issue_radar's watchdog-initiated crew stop (crew_runtime.py:616) still logs the pause default manual — verify it is deliberately outside #14409's scope.

What this change ships

Inventory (8 items) — 8 justified

Intent: make every auto-nudge stop line in gateway.log name its real reason instead of removed/unspecified (fixes #14409) — a FIX.

  1. /goal clear stop line now reads goal_cleared — justified
  2. Slack/Discord/Webex/Zulip DM retirements name their cause (unroutable, bad key, deauthorized, rotated, unreachable) — justified
  3. Unknown-channel-prefix retirement logs unsupported_channel — justified
  4. Campaign Stop / Delete log campaign_stopped / campaign_deleted — justified
  5. Auto Research watchdog turn-off logs campaign_<status> — justified
  6. Spec Stop / Delete log spec_stopped / spec_deleted — justified
  7. Spec hand-off abort logs spec_arm_aborted — justified
  8. Spec orphan cleanup logs orphaned_worker via new optional stopped_reason on the maintenance view — justified

Checks run: remove(stop_reason=) and update(stopped_reason=) pre-exist on base (autonudge.py:3620, :3030) — no new mechanism, only threading. Grepped \.remove\( across src/: 13 production sites; 10 now pass a reason, 3 remaining bare calls each act on an already-inactive loop (verified guards at auto_research/handlers.py:1455, :1783, spec_builder/runtime.py:850), which per stop_records writes no line. remove_by_slot already carries session_closed. Bare update(active=False) sites store the documented deliberate default manual, outside the stated defect. New kwarg has 1 consumer in singular form. No deleted pins; test assertions strengthened only.

[FIRST-PRINCIPLES-REVIEWED] 23bd805

@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5 Review — ✅ no blocking findings

Reviewed 23bd805be79376532c66481834b29b12313ca991 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 23bd805

Verdict parsed from the review's SHA-scoped output markers for commit 23bd805be79376532c66481834b29b12313ca991.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 23bd805be79376532c66481834b29b12313ca991: <one-sentence reason>

@iamwhatever
iamwhatever force-pushed the fix/14409-autonudge-stop-reasons branch from 0978a18 to 83d910d Compare September 27, 2026 18:13
@iamwhatever

Copy link
Copy Markdown
Contributor Author

mechanism: stop_reason kwarg on Spec Builder's shared removal helper

  • Spec Builder removal funnel passes no reason span=5bc6711246bc

fixed in 83d910d: _remove_nudge_loop and _remove_nudge_loop_for_slot take stop_reason and pass it to svc.remove.
Callers name the stop: _halt_execution and Stop's claimed-slot sweep pass spec_stopped; Delete and its sweep pass spec_deleted; the hand-off abort unwind passes spec_arm_aborted.
test_teardown_targets_an_idle_published_autonudge_after_identity_rewrite asserts the reason for both Stop and Delete; prove.py shows it fails with the fix reverted.

@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • Make stop_reason a required keyword on the app helpers span=c2b2e8aa1e1e

rebutted as out of goal for this PR: every current caller of _stop_loop(remove=True) and _remove_nudge_loop_for_slot passes a named reason, and tests pin each one.
_stop_loop(remove=False) is the pause path and never removes, so a required stop_reason there would be a meaningless argument.
The "" default matches AutoNudgeService.remove, whose fallback removed is the deliberate signal for an unnamed caller; a new caller that forgets shows up in the log line, not silently.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 27, 2026
@iamwhatever
iamwhatever force-pushed the fix/14409-autonudge-stop-reasons branch from 83d910d to 440e502 Compare September 27, 2026 18:28
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 27, 2026
Pass a specific stop_reason (or stopped_reason on the deactivating write)
at the goal-clear, Slack/Discord/Webex retirement, Auto Research and
Spec Builder orphan-cleanup stops, so the WARNING stop line no longer
reads reason='removed' or 'unspecified' for them.

Fixes #14409
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Rebased onto f57c1de to pick up the main CI fix (#14518); CI re-running.

@iamwhatever
iamwhatever force-pushed the fix/14409-autonudge-stop-reasons branch from 440e502 to 23bd805 Compare September 27, 2026 21:33
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 27, 2026
@chenmingwei23
chenmingwei23 merged commit 6cfb684 into main Sep 28, 2026
142 of 143 checks passed
@chenmingwei23
chenmingwei23 deleted the fix/14409-autonudge-stop-reasons branch September 28, 2026 00:06
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 28, 2026
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.

autonudge: pass a stop_reason at the remaining remove() callers

2 participants