Skip to content

fix: prevent AttributeError in _apply_settings when context has no agent0#1615

Open
PaoloC68 wants to merge 1 commit into
agent0ai:readyfrom
PaoloC68:fix/apply-settings-agent0-attr-error
Open

fix: prevent AttributeError in _apply_settings when context has no agent0#1615
PaoloC68 wants to merge 1 commit into
agent0ai:readyfrom
PaoloC68:fix/apply-settings-agent0-attr-error

Conversation

@PaoloC68
Copy link
Copy Markdown
Contributor

@PaoloC68 PaoloC68 commented May 8, 2026

Summary

_apply_settings crashes with AttributeError: 'AgentContext' object has no attribute 'agent0' in contexts where agent0 has not been initialized yet (e.g. during early startup or in lightweight contexts created for settings application before the agent loop starts).

Root Cause

# Before
agent = ctx.agent0  # AttributeError if agent0 not set on ctx

AgentContext does not guarantee agent0 is set at the point _apply_settings is called. The attribute access raises AttributeError instead of gracefully handling the missing agent.

Fix

# After
agent = getattr(ctx, 'agent0', None)

One-line change. getattr with a default of None matches the existing null-check pattern already used downstream in the same function.

Impact

  • Prevents a crash during settings application in contexts without an initialized agent
  • No behavior change when agent0 is present
  • Consistent with how other optional context attributes are accessed in the codebase

@PaoloC68 PaoloC68 changed the base branch from main to ready May 8, 2026 21:49
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.

1 participant