Skip to content

Commit 39a6d8c

Browse files
committed
fix: enhance Graphiti client methods to handle nil pointer dereference
1 parent 57f1f0e commit 39a6d8c

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

backend/pkg/graphiti/client.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,20 @@ func NewClient(url string, timeout time.Duration, enabled bool) (*Client, error)
6666

6767
// IsEnabled returns whether Graphiti integration is active
6868
func (c *Client) IsEnabled() bool {
69-
return c.enabled
69+
return c != nil && c.enabled
7070
}
7171

7272
// GetTimeout returns the configured timeout duration
7373
func (c *Client) GetTimeout() time.Duration {
74+
if c == nil {
75+
return 0
76+
}
7477
return c.timeout
7578
}
7679

7780
// AddMessages adds messages to Graphiti (no-op if disabled)
7881
func (c *Client) AddMessages(ctx context.Context, req graphiti.AddMessagesRequest) error {
79-
if !c.enabled {
82+
if !c.IsEnabled() {
8083
return nil
8184
}
8285

@@ -86,55 +89,55 @@ func (c *Client) AddMessages(ctx context.Context, req graphiti.AddMessagesReques
8689

8790
// TemporalWindowSearch searches within a time window
8891
func (c *Client) TemporalWindowSearch(ctx context.Context, req TemporalSearchRequest) (*TemporalSearchResponse, error) {
89-
if !c.enabled {
92+
if !c.IsEnabled() {
9093
return nil, fmt.Errorf("graphiti is not enabled")
9194
}
9295
return c.client.TemporalWindowSearch(req)
9396
}
9497

9598
// EntityRelationshipsSearch finds relationships from a center node
9699
func (c *Client) EntityRelationshipsSearch(ctx context.Context, req EntityRelationshipSearchRequest) (*EntityRelationshipSearchResponse, error) {
97-
if !c.enabled {
100+
if !c.IsEnabled() {
98101
return nil, fmt.Errorf("graphiti is not enabled")
99102
}
100103
return c.client.EntityRelationshipsSearch(req)
101104
}
102105

103106
// DiverseResultsSearch gets diverse, non-redundant results
104107
func (c *Client) DiverseResultsSearch(ctx context.Context, req DiverseSearchRequest) (*DiverseSearchResponse, error) {
105-
if !c.enabled {
108+
if !c.IsEnabled() {
106109
return nil, fmt.Errorf("graphiti is not enabled")
107110
}
108111
return c.client.DiverseResultsSearch(req)
109112
}
110113

111114
// EpisodeContextSearch searches through agent responses and tool execution records
112115
func (c *Client) EpisodeContextSearch(ctx context.Context, req EpisodeContextSearchRequest) (*EpisodeContextSearchResponse, error) {
113-
if !c.enabled {
116+
if !c.IsEnabled() {
114117
return nil, fmt.Errorf("graphiti is not enabled")
115118
}
116119
return c.client.EpisodeContextSearch(req)
117120
}
118121

119122
// SuccessfulToolsSearch finds successful tool executions and attack patterns
120123
func (c *Client) SuccessfulToolsSearch(ctx context.Context, req SuccessfulToolsSearchRequest) (*SuccessfulToolsSearchResponse, error) {
121-
if !c.enabled {
124+
if !c.IsEnabled() {
122125
return nil, fmt.Errorf("graphiti is not enabled")
123126
}
124127
return c.client.SuccessfulToolsSearch(req)
125128
}
126129

127130
// RecentContextSearch retrieves recent relevant context
128131
func (c *Client) RecentContextSearch(ctx context.Context, req RecentContextSearchRequest) (*RecentContextSearchResponse, error) {
129-
if !c.enabled {
132+
if !c.IsEnabled() {
130133
return nil, fmt.Errorf("graphiti is not enabled")
131134
}
132135
return c.client.RecentContextSearch(req)
133136
}
134137

135138
// EntityByLabelSearch searches for entities by label/type
136139
func (c *Client) EntityByLabelSearch(ctx context.Context, req EntityByLabelSearchRequest) (*EntityByLabelSearchResponse, error) {
137-
if !c.enabled {
140+
if !c.IsEnabled() {
138141
return nil, fmt.Errorf("graphiti is not enabled")
139142
}
140143
return c.client.EntityByLabelSearch(req)

0 commit comments

Comments
 (0)