[PR #10376] fix: add null safety to local.agent.current() - Issue #10346 #13422

Closed
opened 2026-02-16 18:18:16 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/10376

State: closed
Merged: No


Problem

When local.agent.current() returns undefined, the code attempts to access properties on it, causing runtime errors.

Solution

Added optional chaining (?.) and nullish coalescing (??) operator to handle the case when no agent is active:

const agent = local.agent.current()
const mode = agent?.mode ?? ""

Testing

  • Verified with existing test suite (752/759 tests passing)
  • Manual testing confirmed no more errors when agent context is undefined

Fixes #10346

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/10376 **State:** closed **Merged:** No --- ## Problem When `local.agent.current()` returns `undefined`, the code attempts to access properties on it, causing runtime errors. ## Solution Added optional chaining (`?.`) and nullish coalescing (`??`) operator to handle the case when no agent is active: ```typescript const agent = local.agent.current() const mode = agent?.mode ?? "" ``` ## Testing - Verified with existing test suite (752/759 tests passing) - Manual testing confirmed no more errors when agent context is undefined Fixes #10346
yindo added the pull-request label 2026-02-16 18:18:16 -05:00
yindo closed this issue 2026-02-16 18:18:16 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13422