Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.

Commit edf87db

Browse files
fix: handle agent not found (#951)
Co-authored-by: Copilot <[email protected]>
1 parent e6204a9 commit edf87db

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ NOTE: all releases may include dependency updates, not specifically mentioned
1111
## 2025-07-14 - Runtime v0.18.6
1212

1313
- feat: restore agents on demand [#949](https://github.com/hypermodeinc/modus/pull/949)
14+
- fix: handle agent not found [#951](https://github.com/hypermodeinc/modus/pull/951)
1415

1516
## 2025-07-12 - Runtime v0.18.5
1617

runtime/actors/agents.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,11 @@ func SendAgentMessage(ctx context.Context, agentId string, msgName string, data
224224

225225
if errors.Is(err, goakt.ErrActorNotFound) {
226226
state, err := db.GetAgentState(ctx, agentId)
227-
if err != nil {
227+
if errors.Is(err, db.ErrAgentNotFound) {
228+
return newAgentMessageErrorResponse(fmt.Sprintf("agent %s not found", agentId)), nil
229+
} else if err != nil {
228230
return nil, fmt.Errorf("error getting agent state for %s: %w", agentId, err)
229231
}
230-
if state == nil {
231-
return newAgentMessageErrorResponse("agent not found"), nil
232-
}
233232

234233
switch AgentStatus(state.Status) {
235234
case AgentStatusStopping, AgentStatusTerminated:

runtime/db/agentstate.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,20 @@ package db
77

88
import (
99
"context"
10+
"errors"
1011
"fmt"
1112
"time"
1213

1314
"github.com/hypermodeinc/modus/runtime/sentryutils"
1415
"github.com/hypermodeinc/modus/runtime/utils"
1516

1617
"github.com/hypermodeinc/modusgraph"
18+
mg_utils "github.com/hypermodeinc/modusgraph/api/apiutils"
1719
"github.com/jackc/pgx/v5"
1820
)
1921

22+
var ErrAgentNotFound = errors.New("agent not found")
23+
2024
type AgentState struct {
2125
Gid uint64 `json:"gid,omitempty"`
2226
Id string `json:"id" db:"constraint=unique"`
@@ -93,6 +97,10 @@ func getAgentStateFromModusDB(ctx context.Context, id string) (*AgentState, erro
9397
Key: "id",
9498
Value: id,
9599
})
100+
if errors.Is(err, mg_utils.ErrNoObjFound) {
101+
return nil, ErrAgentNotFound
102+
}
103+
96104
if err != nil {
97105
return nil, fmt.Errorf("failed to query agent state: %w", err)
98106
}
@@ -174,6 +182,9 @@ func getAgentStateFromPostgresDB(ctx context.Context, id string) (*AgentState, e
174182
err := WithTx(ctx, func(tx pgx.Tx) error {
175183
row := tx.QueryRow(ctx, query, id)
176184
if err := row.Scan(&a.Id, &a.Name, &a.Status, &a.Data, &ts); err != nil {
185+
if errors.Is(err, pgx.ErrNoRows) {
186+
return ErrAgentNotFound
187+
}
177188
return fmt.Errorf("failed to get agent state: %w", err)
178189
}
179190
a.UpdatedAt = ts.UTC().Format(utils.TimeFormat)

0 commit comments

Comments
 (0)