Skip to content

fix(sdk): mark corrective nudge as environment event - #3954

Merged
neubig merged 12 commits into
OpenHands:mainfrom
Sehlani042:codex/corrective-nudge-source
Jul 28, 2026
Merged

neubig merged 12 commits into
OpenHands:mainfrom
Sehlani042:codex/corrective-nudge-source

Conversation

@Sehlani042

@Sehlani042 Sehlani042 commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

HUMAN:

This makes framework-generated corrective nudges appear as environment-origin events while preserving the user-role message sent to the model. I reviewed the follow-up scope, including visualizer/event attribution, so the PR should no longer treat synthetic recovery nudges as human input.


AGENT:
This PR was created by an AI agent (OpenHands) on behalf of Sehlani042.

Why

The corrective nudge emitted after an empty or reasoning-only model response is synthetic framework feedback. It should remain a user-role LLM message so the model receives the same instruction, but the event source should not be user; otherwise UI/event consumers and stuck detection can treat it as human input.

Summary

  • Emit corrective nudge MessageEvent with source="environment" while keeping llm_message.role == "user".
  • Update regression coverage for empty and reasoning-only responses to lock the event-source / LLM-role split.
  • Update the docstring to match the new origin semantics.

Issue Number

Closes #3883

How to Test

Baseline before the fix:

  • OPENHANDS_SUPPRESS_BANNER=1 uv run pytest tests/sdk/agent/test_response_dispatch.py::test_empty_response_sends_nudge tests/sdk/agent/test_response_dispatch.py::test_reasoning_only_sends_nudge -q failed with assert "user" == "environment" on both regression cases.

After the fix:

  • OPENHANDS_SUPPRESS_BANNER=1 uv run pytest tests/sdk/agent/test_response_dispatch.py::test_empty_response_sends_nudge tests/sdk/agent/test_response_dispatch.py::test_reasoning_only_sends_nudge -q passed: 2 passed.
  • OPENHANDS_SUPPRESS_BANNER=1 uv run pytest tests/sdk/agent/test_response_dispatch.py tests/cross/test_stuck_detector.py -q passed: 29 passed.
  • OPENHANDS_SUPPRESS_BANNER=1 uv run pre-commit run --files openhands-sdk/openhands/sdk/agent/response_dispatch.py tests/sdk/agent/test_response_dispatch.py passed Ruff format, Ruff lint, pycodestyle, pyright, import dependency rules, and tool registration checks.

Note: local uv run still prints the existing settings-discovery warning about exclude-newer = "7 days", but the commands exit successfully.

Video/Screenshots

N/A - SDK behavior change covered by regression tests.

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

This keeps the LLM-visible message role unchanged and only changes event attribution, matching the existing stop-hook feedback pattern of source="environment" plus role="user".

@VascoSch92

Copy link
Copy Markdown
Member

Hey @Sehlani042

thanks for the PR.

Can you complete the HUMAN part? Moreover, the change is not complete

Co-authored-by: openhands <openhands@all-hands.dev>
@Sehlani042
Sehlani042 force-pushed the codex/corrective-nudge-source branch from d039f05 to 0d1d789 Compare July 2, 2026 08:23
@all-hands-bot

Copy link
Copy Markdown
Collaborator

[Automatic Post]: It has been a while since there was any activity on this PR. @Sehlani042, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up.

This comment was created by an AI agent (OpenHands) on behalf of the user.

@Sehlani042
Sehlani042 marked this pull request as ready for review July 18, 2026 09:42
@all-hands-bot
all-hands-bot requested a review from neubig July 18, 2026 12:39
@all-hands-bot

Copy link
Copy Markdown
Collaborator

[Automatic Post]: I have assigned @neubig as a reviewer based on the repository MAINTAINERS file. Thanks in advance for the help!

This comment was created by an AI agent (OpenHands) on behalf of the user.

@neubig neubig left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@neubig neubig left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually tests, are failing. Could you please fix them and re-request my review?

@Sehlani042
Sehlani042 requested a review from neubig July 21, 2026 05:45
@VascoSch92

Copy link
Copy Markdown
Member

@Sehlani042 tests are failing

@VascoSch92

VascoSch92 commented Jul 24, 2026 •

Copy link
Copy Markdown
Member

Thanks for the contribution

The code looks good, but there is still one related case to address before this is complete.

DelegationVisualizer overrides the default message-rendering path and still classifies messages using event.llm_message.role. Because the corrective nudge now has source="environment" while intentionally retaining role="user", delegated conversations still render it as human input (for example, User Message to Worker Agent). This preserves the original false-attribution problem in delegation views.

Could you update openhands-tools/openhands/tools/delegate/visualizer.py to identify human messages using event.source == "user", give environment/hook messages an appropriate framework title/color, and add a regression test under tests/tools/delegate/test_visualizer.py for an environment-source, user-role message?

@neubig
neubig enabled auto-merge (squash) July 27, 2026 18:50
@neubig

neubig commented Jul 27, 2026

Copy link
Copy Markdown
Member

Thank you!

@neubig
neubig merged commit 8e7e785 into OpenHands:main Jul 28, 2026
28 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.

Synthetic corrective nudge is emitted as user-authored MessageEvent

4 participants