Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ NOTE: all releases may include dependency updates, not specifically mentioned
## 2025-07-14 - Runtime v0.18.6

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

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

Expand Down
7 changes: 3 additions & 4 deletions runtime/actors/agents.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,11 @@ func SendAgentMessage(ctx context.Context, agentId string, msgName string, data

if errors.Is(err, goakt.ErrActorNotFound) {
state, err := db.GetAgentState(ctx, agentId)
if err != nil {
if errors.Is(err, db.ErrAgentNotFound) {
return newAgentMessageErrorResponse(fmt.Sprintf("agent %s not found", agentId)), nil
} else if err != nil {
return nil, fmt.Errorf("error getting agent state for %s: %w", agentId, err)
}
if state == nil {
return newAgentMessageErrorResponse("agent not found"), nil
}

switch AgentStatus(state.Status) {
case AgentStatusStopping, AgentStatusTerminated:
Expand Down
11 changes: 11 additions & 0 deletions runtime/db/agentstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ package db

import (
"context"
"errors"
"fmt"
"time"

"github.com/hypermodeinc/modus/runtime/sentryutils"
"github.com/hypermodeinc/modus/runtime/utils"

"github.com/hypermodeinc/modusgraph"
mg_utils "github.com/hypermodeinc/modusgraph/api/apiutils"
"github.com/jackc/pgx/v5"
)

var ErrAgentNotFound = errors.New("agent not found")

type AgentState struct {
Gid uint64 `json:"gid,omitempty"`
Id string `json:"id" db:"constraint=unique"`
Expand Down Expand Up @@ -93,6 +97,10 @@ func getAgentStateFromModusDB(ctx context.Context, id string) (*AgentState, erro
Key: "id",
Value: id,
})
if errors.Is(err, mg_utils.ErrNoObjFound) {
return nil, ErrAgentNotFound
}

if err != nil {
return nil, fmt.Errorf("failed to query agent state: %w", err)
}
Expand Down Expand Up @@ -174,6 +182,9 @@ func getAgentStateFromPostgresDB(ctx context.Context, id string) (*AgentState, e
err := WithTx(ctx, func(tx pgx.Tx) error {
row := tx.QueryRow(ctx, query, id)
if err := row.Scan(&a.Id, &a.Name, &a.Status, &a.Data, &ts); err != nil {
if errors.Is(err, pgx.ErrNoRows) {
return ErrAgentNotFound
}
return fmt.Errorf("failed to get agent state: %w", err)
}
a.UpdatedAt = ts.UTC().Format(utils.TimeFormat)
Expand Down
Loading