Skip to content

Commit adb9032

Browse files
authored
fix: revert last change staging (#135)
1 parent bee8db5 commit adb9032

32 files changed

+25
-2975
lines changed

go.sum

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEW
5555
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
5656
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
5757
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
58-
github.com/google/subcommands v1.2.0 h1:vWQspBTo2nEqTUFita5/KeEWlUL8kQObDFbub/EN9oE=
59-
github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
6058
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
6159
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
6260
github.com/google/wire v0.7.0 h1:JxUKI6+CVBgCO2WToKy/nQk0sS+amI9z9EjVmdaocj4=
@@ -162,8 +160,6 @@ golang.org/x/crypto v0.41.0/go.mod h1:pO5AFd7FA68rFak7rOAGVuygIISepHftHnr8dr6+sU
162160
golang.org/x/exp v0.0.0-20250819193227-8b4c13bb791b h1:DXr+pvt3nC887026GRP39Ej11UATqWDmWuS99x26cD0=
163161
golang.org/x/exp v0.0.0-20250819193227-8b4c13bb791b/go.mod h1:4QTo5u+SEIbbKW1RacMZq1YEfOBqeXa19JeshGi+zc4=
164162
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
165-
golang.org/x/mod v0.27.0 h1:kb+q2PyFnEADO2IEF935ehFUXlWiNjJWtRNgBLSfbxQ=
166-
golang.org/x/mod v0.27.0/go.mod h1:rWI627Fq0DEoudcK+MBkNkCe0EetEaDSwJJkCcjpazc=
167163
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
168164
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
169165
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
@@ -192,8 +188,6 @@ golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
192188
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
193189
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
194190
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
195-
golang.org/x/tools v0.36.0 h1:kWS0uv/zsvHEle1LbV5LE8QujrxB3wfQyxHfhOk0Qkg=
196-
golang.org/x/tools v0.36.0/go.mod h1:WBDiHKJK8YgLHlcQPYQzNCkUxUypCaa5ZegCVutKm+s=
197191
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
198192
gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
199193
gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E=

internal/api/chat/create_conversation_message_stream_v2.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ func (s *ChatServerV2) CreateConversationMessageStream(
281281
APIKey: settings.OpenAIAPIKey,
282282
}
283283

284-
openaiChatHistory, inappChatHistory, err := s.aiClientV2.ChatCompletionStreamV2(ctx, stream, conversation.UserID, conversation.ID.Hex(), modelSlug, conversation.OpenaiChatHistoryCompletion, llmProvider)
284+
openaiChatHistory, inappChatHistory, err := s.aiClientV2.ChatCompletionStreamV2(ctx, stream, conversation.ID.Hex(), modelSlug, conversation.OpenaiChatHistoryCompletion, llmProvider)
285285
if err != nil {
286286
return s.sendStreamError(stream, err)
287287
}
@@ -307,7 +307,7 @@ func (s *ChatServerV2) CreateConversationMessageStream(
307307
for i, bsonMsg := range conversation.InappChatHistory {
308308
protoMessages[i] = mapper.BSONToChatMessageV2(bsonMsg)
309309
}
310-
title, err := s.aiClientV2.GetConversationTitleV2(ctx, conversation.UserID, protoMessages, llmProvider)
310+
title, err := s.aiClientV2.GetConversationTitleV2(ctx, protoMessages, llmProvider)
311311
if err != nil {
312312
s.logger.Error("Failed to get conversation title", "error", err, "conversationID", conversation.ID.Hex())
313313
return

internal/api/grpc.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
chatv2 "paperdebugger/pkg/gen/api/chat/v2"
1616
commentv1 "paperdebugger/pkg/gen/api/comment/v1"
1717
projectv1 "paperdebugger/pkg/gen/api/project/v1"
18-
usagev1 "paperdebugger/pkg/gen/api/usage/v1"
1918
userv1 "paperdebugger/pkg/gen/api/user/v1"
2019

2120
// "github.com/grpc-ecosystem/go-grpc-middleware"
@@ -107,7 +106,6 @@ func NewGrpcServer(
107106
userServer userv1.UserServiceServer,
108107
projectServer projectv1.ProjectServiceServer,
109108
commentServer commentv1.CommentServiceServer,
110-
usageServer usagev1.UsageServiceServer,
111109
) *GrpcServer {
112110
grpcServer := &GrpcServer{}
113111
grpcServer.userService = userService
@@ -123,6 +121,5 @@ func NewGrpcServer(
123121
userv1.RegisterUserServiceServer(grpcServer.Server, userServer)
124122
projectv1.RegisterProjectServiceServer(grpcServer.Server, projectServer)
125123
commentv1.RegisterCommentServiceServer(grpcServer.Server, commentServer)
126-
usagev1.RegisterUsageServiceServer(grpcServer.Server, usageServer)
127124
return grpcServer
128125
}

internal/api/server.go

Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,17 @@ import (
66
"fmt"
77
"net"
88
"net/http"
9-
"os"
10-
"os/signal"
119
"strings"
12-
"syscall"
1310

1411
"paperdebugger/internal/libs/logger"
1512
"paperdebugger/internal/libs/metadatautil"
1613
"paperdebugger/internal/libs/shared"
17-
"paperdebugger/internal/services"
18-
aiclient "paperdebugger/internal/services/toolkit/client"
1914
authv1 "paperdebugger/pkg/gen/api/auth/v1"
2015
chatv1 "paperdebugger/pkg/gen/api/chat/v1"
2116
chatv2 "paperdebugger/pkg/gen/api/chat/v2"
2217
commentv1 "paperdebugger/pkg/gen/api/comment/v1"
2318
projectv1 "paperdebugger/pkg/gen/api/project/v1"
2419
sharedv1 "paperdebugger/pkg/gen/api/shared/v1"
25-
usagev1 "paperdebugger/pkg/gen/api/usage/v1"
2620
userv1 "paperdebugger/pkg/gen/api/user/v1"
2721

2822
"github.com/gin-gonic/gin"
@@ -36,37 +30,25 @@ import (
3630
)
3731

3832
type Server struct {
39-
grpcServer *GrpcServer
40-
ginServer *GinServer
41-
pricingService *services.PricingService
42-
aiClientV2 *aiclient.AIClientV2
33+
grpcServer *GrpcServer
34+
ginServer *GinServer
4335

4436
logger *logger.Logger
4537
}
4638

4739
func NewServer(
4840
grpcServer *GrpcServer,
4941
ginServer *GinServer,
50-
pricingService *services.PricingService,
51-
aiClientV2 *aiclient.AIClientV2,
5242
logger *logger.Logger,
5343
) *Server {
5444
return &Server{
55-
grpcServer: grpcServer,
56-
ginServer: ginServer,
57-
pricingService: pricingService,
58-
aiClientV2: aiClientV2,
59-
logger: logger,
45+
grpcServer: grpcServer,
46+
ginServer: ginServer,
47+
logger: logger,
6048
}
6149
}
6250

6351
func (s *Server) Run(addr string) {
64-
// Start the pricing updater in the background
65-
ctx, cancel := context.WithCancel(context.Background())
66-
defer cancel()
67-
68-
s.pricingService.StartPriceUpdater(ctx)
69-
7052
listener, err := net.Listen("tcp", ":0")
7153
if err != nil {
7254
s.logger.Fatalf("failed to start grpc server listener: %v", err)
@@ -123,22 +105,6 @@ func (s *Server) Run(addr string) {
123105
s.logger.Fatalf("failed to register comment service grpc gateway: %v", err)
124106
return
125107
}
126-
err = usagev1.RegisterUsageServiceHandler(context.Background(), mux, client)
127-
if err != nil {
128-
s.logger.Fatalf("failed to register usage service grpc gateway: %v", err)
129-
return
130-
}
131-
132-
// Set up signal handling for graceful shutdown
133-
sigChan := make(chan os.Signal, 1)
134-
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
135-
136-
go func() {
137-
<-sigChan
138-
s.logger.Info("[PAPERDEBUGGER] received shutdown signal, shutting down gracefully...")
139-
s.Shutdown()
140-
os.Exit(0)
141-
}()
142108

143109
s.logger.Infof("[PAPERDEBUGGER] http server listening on %s", addr)
144110
s.ginServer.Any("/_pd/api/*path", func(c *gin.Context) { mux.ServeHTTP(c.Writer, c.Request) })
@@ -148,16 +114,6 @@ func (s *Server) Run(addr string) {
148114
}
149115
}
150116

151-
// Shutdown gracefully shuts down all server components.
152-
func (s *Server) Shutdown() {
153-
s.logger.Info("[PAPERDEBUGGER] shutting down AI client (draining usage records)...")
154-
s.aiClientV2.Shutdown()
155-
s.logger.Info("[PAPERDEBUGGER] AI client shutdown complete")
156-
157-
s.grpcServer.GracefulStop()
158-
s.logger.Info("[PAPERDEBUGGER] gRPC server shutdown complete")
159-
}
160-
161117
func (s *Server) metadataAnnotator() func(ctx context.Context, req *http.Request) metadata.MD {
162118
return func(ctx context.Context, req *http.Request) metadata.MD {
163119
md := metadata.New(map[string]string{})

internal/api/usage/get_session_usage.go

Lines changed: 0 additions & 40 deletions
This file was deleted.

internal/api/usage/get_weekly_usage.go

Lines changed: 0 additions & 32 deletions
This file was deleted.

internal/api/usage/server.go

Lines changed: 0 additions & 42 deletions
This file was deleted.

internal/libs/db/db.go

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66

77
"paperdebugger/internal/libs/cfg"
88
"paperdebugger/internal/libs/logger"
9-
"paperdebugger/internal/models"
109

1110
"go.mongodb.org/mongo-driver/v2/bson"
1211
"go.mongodb.org/mongo-driver/v2/mongo"
@@ -44,47 +43,5 @@ func NewDB(cfg *cfg.Cfg, logger *logger.Logger) (*DB, error) {
4443
}
4544

4645
logger.Info("[MONGO] initialized")
47-
48-
db := &DB{Client: client, cfg: cfg, logger: logger}
49-
db.ensureIndexes()
50-
return db, nil
51-
}
52-
53-
// ensureIndexes creates necessary indexes for the database collections.
54-
func (db *DB) ensureIndexes() {
55-
sessions := db.Database("paperdebugger").Collection((models.LLMSession{}).CollectionName())
56-
57-
// TTL index: auto-delete sessions after 30 days past their expiry time
58-
_, err := sessions.Indexes().CreateOne(context.Background(), mongo.IndexModel{
59-
Keys: bson.D{{Key: "session_expiry", Value: 1}},
60-
Options: options.Index().SetExpireAfterSeconds(30 * 24 * 60 * 60),
61-
})
62-
if err != nil {
63-
db.logger.Error("Failed to create TTL index on llm_sessions", "error", err)
64-
}
65-
66-
// Compound index for efficient active session lookups
67-
_, err = sessions.Indexes().CreateOne(context.Background(), mongo.IndexModel{
68-
Keys: bson.D{
69-
{Key: "user_id", Value: 1},
70-
{Key: "session_expiry", Value: -1},
71-
},
72-
})
73-
if err != nil {
74-
db.logger.Error("Failed to create compound index on llm_sessions", "error", err)
75-
}
76-
77-
// Unique compound index for session creation and queries.
78-
// session_start is rounded to the second, so concurrent requests within the same
79-
// second will conflict, triggering duplicate key handling in RecordUsage.
80-
_, err = sessions.Indexes().CreateOne(context.Background(), mongo.IndexModel{
81-
Keys: bson.D{
82-
{Key: "user_id", Value: 1},
83-
{Key: "session_start", Value: -1},
84-
},
85-
Options: options.Index().SetUnique(true),
86-
})
87-
if err != nil {
88-
db.logger.Error("Failed to create session_start index on llm_sessions", "error", err)
89-
}
46+
return &DB{Client: client, cfg: cfg, logger: logger}, nil
9047
}

internal/models/model_pricing.go

Lines changed: 0 additions & 23 deletions
This file was deleted.

internal/models/usage.go

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)