Skip to content

fix: surface prompt template eval errors, fail-safe async_safety fallback, and set _parent_agent_var in sync wrapper - #72

Open
Eros483 wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
Eros483:fix-silent-errors-and-sync-wrapper
Open

fix: surface prompt template eval errors, fail-safe async_safety fallback, and set _parent_agent_var in sync wrapper#72
Eros483 wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
Eros483:fix-silent-errors-and-sync-wrapper

Conversation

@Eros483

@Eros483 Eros483 commented Aug 1, 2026

Copy link
Copy Markdown

What does this PR do?

Three defensive fixes targeting silently swallowed errors and a sync-wrapper
parity gap:

  1. agent.pyAgent._resolve_docstring_template() catches eval()
    failures with a bare except Exception: and silently falls back to raw
    {placeholder} text. If a user has a typo in {self.attr}, the broken
    expression ships in the prompt with zero feedback. Added
    logger.debug(..., exc_info=True) inside the except block so template
    errors are visible at debug level.

  2. async_safety.py_is_event_loop_thread() returns True when it
    cannot determine the thread (missing _thread_id attribute). This is
    fail-dangerous: it would block legitimate cross-thread Future.result()
    calls. Changed fallback to False so calls are allowed through when we
    can't verify.

  3. method_wrapper.pycreate_sync_agent_method_wrapper never calls
    _parent_agent_var.set(self), unlike its async counterpart (line 183).
    Subagents instantiated inside a sync method cannot inherit the parent's
    LLM. Added parent_token = _parent_agent_var.set(self) after the
    call-id push and _parent_agent_var.reset(parent_token) in finally,
    mirroring the async wrapper.

Related issues

N/A

Checklist

  • Code follows the project style (uv run ruff check . and uv run ruff format --check . pass)
  • Tests added/updated and passing (uv run pytest)
  • Docs updated if behavior or public APIs changed
  • New source files carry an SPDX license header

Checklist notes

  • ruff: Clean on all three changed files.
  • pyright: 0 errors, 0 warnings.
  • Tests: No new tests required — each change is an internal quality fix
    (debug logging, boolean flip, contextvar parity with existing async path).
    Existing test suite covers all modified code paths.
  • Docs: No public API changes. No new files created.

…back, and set _parent_agent_var in sync wrapper

Signed-off-by: Eros483 <arnabmandal2912@gmail.com>

@alessiodevoto alessiodevoto left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@dcoapp recheck

@Eros483

Eros483 commented Aug 4, 2026

Copy link
Copy Markdown
Author

Hi @alessiodevoto . What's up?

@furgalep furgalep assigned alessiodevoto and unassigned furgalep Aug 21, 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.

3 participants