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

Commit ba9a685

Browse files
fix: write inference history directly (#938)
1 parent 480e68d commit ba9a685

File tree

6 files changed

+107
-192
lines changed

6 files changed

+107
-192
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ NOTE: all releases may include dependency updates, not specifically mentioned
77
## UNRELEASED
88

99
- feat: integrate try-as library [#912](https://github.com/hypermodeinc/modus/pull/912)
10-
- feat: improve sentry usage [#931](https://github.com/hypermodeinc/modus/pull/931)
10+
- feat: improve sentry usage [#931](https://github.com/hypermodeinc/modus/pull/931) [#937](https://github.com/hypermodeinc/modus/pull/937)
11+
- fix: write inference history directly [#938](https://github.com/hypermodeinc/modus/pull/938)
1112

1213
## 2025-07-03 - Runtime v0.18.3
1314

runtime/db/agentstate.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func writeAgentStateToModusDB(ctx context.Context, state AgentState) error {
6666
span, ctx := sentryutils.NewSpanForCurrentFunc(ctx)
6767
defer span.Finish()
6868

69-
gid, _, _, err := modusgraph.Upsert(ctx, GlobalModusDbEngine, state)
69+
gid, _, _, err := modusgraph.Upsert(ctx, globalModusDbEngine, state)
7070
state.Gid = gid
7171

7272
return err
@@ -93,7 +93,7 @@ func getAgentStateFromModusDB(ctx context.Context, id string) (*AgentState, erro
9393
span, ctx := sentryutils.NewSpanForCurrentFunc(ctx)
9494
defer span.Finish()
9595

96-
_, result, err := modusgraph.Get[AgentState](ctx, GlobalModusDbEngine, modusgraph.ConstrainedField{
96+
_, result, err := modusgraph.Get[AgentState](ctx, globalModusDbEngine, modusgraph.ConstrainedField{
9797
Key: "id",
9898
Value: id,
9999
})
@@ -108,7 +108,7 @@ func queryActiveAgentsFromModusDB(ctx context.Context) ([]AgentState, error) {
108108
span, ctx := sentryutils.NewSpanForCurrentFunc(ctx)
109109
defer span.Finish()
110110

111-
_, results, err := modusgraph.Query[AgentState](ctx, GlobalModusDbEngine, modusgraph.QueryParams{
111+
_, results, err := modusgraph.Query[AgentState](ctx, globalModusDbEngine, modusgraph.QueryParams{
112112
Filter: &modusgraph.Filter{
113113
Not: &modusgraph.Filter{
114114
Field: "status",

runtime/db/db.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"os"
1616
"strconv"
1717
"sync"
18-
"time"
1918

2019
"github.com/hypermodeinc/modus/runtime/app"
2120
"github.com/hypermodeinc/modus/runtime/logger"
@@ -28,24 +27,16 @@ import (
2827

2928
var errDbNotConfigured = errors.New("database not configured")
3029

31-
const inferenceRefresherInterval = 5 * time.Second
32-
3330
type runtimePostgresWriter struct {
3431
dbpool *pgxpool.Pool
35-
buffer chan inferenceHistory
36-
quit chan struct{}
37-
done chan struct{}
3832
once sync.Once
3933
}
4034

4135
func Stop(ctx context.Context) {
42-
pool, _ := globalRuntimePostgresWriter.GetPool(ctx)
36+
pool, _ := globalRuntimePostgresWriter.getPool(ctx)
4337
if pool == nil {
4438
return
4539
}
46-
47-
close(globalRuntimePostgresWriter.quit)
48-
<-globalRuntimePostgresWriter.done
4940
pool.Close()
5041
}
5142

@@ -67,16 +58,14 @@ func Initialize(ctx context.Context) {
6758
return
6859
}
6960

70-
// this will initialize the pool and start the worker
71-
_, err := globalRuntimePostgresWriter.GetPool(ctx)
61+
_, err := globalRuntimePostgresWriter.getPool(ctx)
7262
if err != nil {
7363
logger.Warn(ctx, err).Msg("Metadata database is not available.")
7464
}
75-
go globalRuntimePostgresWriter.worker(ctx)
7665
}
7766

7867
func GetTx(ctx context.Context) (pgx.Tx, error) {
79-
pool, err := globalRuntimePostgresWriter.GetPool(ctx)
68+
pool, err := globalRuntimePostgresWriter.getPool(ctx)
8069
if err != nil {
8170
return nil, err
8271
}

0 commit comments

Comments
 (0)