Skip to content

Commit e37f3fc

Browse files
committed
fix: address coderabbitai review feedback on PR #127
- Add UTC indicator to env list timestamp output - Add missing godoc comments to credentials, health, db, and metrics packages https://claude.ai/code/session_01KiE3FJpfF6XE2y3Tyth2r3
1 parent e00dfd4 commit e37f3fc

5 files changed

Lines changed: 35 additions & 5 deletions

File tree

packages/engine/internal/api/health/health.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ type LivenessChecker interface {
1717
Name() string
1818
}
1919

20+
// HealthzHandler returns an HTTP handler that always responds 200 OK, used as
21+
// a liveness probe.
2022
func HealthzHandler() http.HandlerFunc {
2123
return func(w http.ResponseWriter, r *http.Request) {
2224
w.Header().Set("Content-Type", "application/json")
@@ -25,6 +27,9 @@ func HealthzHandler() http.HandlerFunc {
2527
}
2628
}
2729

30+
// ReadyzHandler returns an HTTP handler used as a readiness probe. It pings
31+
// the database and checks each LivenessChecker; it responds 503 if any check
32+
// fails.
2833
func ReadyzHandler(database *sql.DB, checkers ...LivenessChecker) http.HandlerFunc {
2934
return func(w http.ResponseWriter, r *http.Request) {
3035
w.Header().Set("Content-Type", "application/json")

packages/engine/internal/cli/credentials.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const (
1515
CredTypeOIDC = "oidc"
1616
)
1717

18+
// Credentials holds the authentication material persisted to disk.
1819
type Credentials struct {
1920
Type string `json:"type"`
2021
APIKey string `json:"api_key,omitempty"`
@@ -23,11 +24,15 @@ type Credentials struct {
2324
ExpiresAt time.Time `json:"expires_at,omitempty"`
2425
}
2526

27+
// DefaultCredentialsPath returns ~/.mantle/credentials, the default location
28+
// where authentication material is stored.
2629
func DefaultCredentialsPath() string {
2730
home, _ := os.UserHomeDir()
2831
return filepath.Join(home, ".mantle", "credentials")
2932
}
3033

34+
// SaveCredentials marshals cred to JSON and writes it to path with
35+
// 0600 permissions, creating parent directories as needed.
3136
func SaveCredentials(path string, cred *Credentials) error {
3237
if err := os.MkdirAll(filepath.Dir(path), 0700); err != nil {
3338
return fmt.Errorf("creating credentials directory: %w", err)
@@ -42,6 +47,7 @@ func SaveCredentials(path string, cred *Credentials) error {
4247
return nil
4348
}
4449

50+
// LoadCredentials reads and parses the JSON credentials file at path.
4551
func LoadCredentials(path string) (*Credentials, error) {
4652
data, err := os.ReadFile(path)
4753
if err != nil {
@@ -54,6 +60,8 @@ func LoadCredentials(path string) (*Credentials, error) {
5460
return &cred, nil
5561
}
5662

63+
// DeleteCredentials removes the credentials file at path. It is not an error
64+
// if the file does not exist.
5765
func DeleteCredentials(path string) error {
5866
if err := os.Remove(path); err != nil && !os.IsNotExist(err) {
5967
return fmt.Errorf("removing credentials: %w", err)

packages/engine/internal/cli/env.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func newEnvListCommand() *cobra.Command {
9696
w := tabwriter.NewWriter(cmd.OutOrStdout(), 0, 0, 2, ' ', 0)
9797
fmt.Fprintln(w, "NAME\tCREATED")
9898
for _, e := range envs {
99-
fmt.Fprintf(w, "%s\t%s\n", e.Name, e.CreatedAt.Format("2006-01-02 15:04:05"))
99+
fmt.Fprintf(w, "%s\t%s\n", e.Name, e.CreatedAt.UTC().Format("2006-01-02 15:04:05 UTC"))
100100
}
101101
return w.Flush()
102102
},

packages/engine/internal/db/db.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,13 @@ func Open(cfg config.DatabaseConfig) (*sql.DB, error) {
4343
return database, nil
4444
}
4545

46+
// WithContext stores database in ctx so it can be retrieved by FromContext.
4647
func WithContext(ctx context.Context, database *sql.DB) context.Context {
4748
return context.WithValue(ctx, contextKey{}, database)
4849
}
4950

51+
// FromContext retrieves the *sql.DB previously stored by WithContext. It
52+
// returns nil if no database is present in ctx.
5053
func FromContext(ctx context.Context) *sql.DB {
5154
database, _ := ctx.Value(contextKey{}).(*sql.DB)
5255
return database

packages/engine/internal/metrics/metrics.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,17 @@ var (
131131
// Queue helper functions.
132132

133133
func SetQueueDepth(n int) { QueueDepth.Set(float64(n)) }
134+
// RecordClaimDuration records the duration of a queue claim attempt.
134135
func RecordClaimDuration(d time.Duration) { ClaimDurationSeconds.Observe(d.Seconds()) }
135-
func RecordLeaseRenewal() { LeaseRenewalsTotal.Inc() }
136-
func RecordLeaseExpiration() { LeaseExpirationsTotal.Inc() }
137-
func RecordReaperReclaimed(n int) { ReaperReclaimedTotal.Add(float64(n)) }
136+
137+
// RecordLeaseRenewal increments the lease renewal counter.
138+
func RecordLeaseRenewal() { LeaseRenewalsTotal.Inc() }
139+
140+
// RecordLeaseExpiration increments the lease expiration counter.
141+
func RecordLeaseExpiration() { LeaseExpirationsTotal.Inc() }
142+
143+
// RecordReaperReclaimed increments the reaper reclaimed counter by n.
144+
func RecordReaperReclaimed(n int) { ReaperReclaimedTotal.Add(float64(n)) }
138145

139146
// Email trigger metrics.
140147
var (
@@ -202,9 +209,16 @@ var (
202209
func RecordToolCall(step, tool, status string) {
203210
ToolCallsTotal.WithLabelValues(step, tool, status).Inc()
204211
}
212+
// RecordToolRound increments the tool-round counter for the given step.
205213
func RecordToolRound(step string) { ToolRoundsTotal.WithLabelValues(step).Inc() }
214+
215+
// RecordToolRoundDuration records the duration of a tool-use round for the given step.
206216
func RecordToolRoundDuration(step string, d time.Duration) {
207217
ToolRoundDurationSeconds.WithLabelValues(step).Observe(d.Seconds())
208218
}
209-
func RecordLLMCacheHit() { LLMCacheHitsTotal.Inc() }
219+
220+
// RecordLLMCacheHit increments the LLM cache hit counter.
221+
func RecordLLMCacheHit() { LLMCacheHitsTotal.Inc() }
222+
223+
// SetParallelStepsInFlight sets the gauge tracking concurrent step executions.
210224
func SetParallelStepsInFlight(n int) { ParallelStepsInFlight.Set(float64(n)) }

0 commit comments

Comments
 (0)