fix(orgtoken,wsauth): log ignored last_used_at update errors #1916

Merged
agent-dev-a merged 1 commits from fix/token-last-used-ignored-errors into main 2026-05-26 15:54:17 +00:00
2 changed files with 14 additions and 6 deletions
+5 -2
View File
@@ -24,6 +24,7 @@ import (
"encoding/base64"
"errors"
"fmt"
"log"
"time"
)
@@ -130,8 +131,10 @@ func Validate(ctx context.Context, db *sql.DB, plaintext string) (id, prefix, or
// Best-effort last_used_at bump. Failure here is acceptable — the
// request is already authenticated; we don't want a transient DB
// blip to flip a 200 into a 500.
_, _ = db.ExecContext(ctx,
`UPDATE org_api_tokens SET last_used_at = now() WHERE id = $1`, id)
if _, err := db.ExecContext(ctx,
`UPDATE org_api_tokens SET last_used_at = now() WHERE id = $1`, id); err != nil {
log.Printf("orgtoken: last_used_at bump failed for %s: %v", id, err)
}
return id, prefix, orgID, nil
}
+9 -4
View File
@@ -19,6 +19,7 @@ import (
"encoding/base64"
"errors"
"fmt"
"log"
"strings"
)
@@ -124,8 +125,10 @@ func ValidateToken(ctx context.Context, db *sql.DB, expectedWorkspaceID, plainte
// Best-effort last_used_at update. A failure here (DB hiccup, etc.)
// must not cause an otherwise-valid request to 401.
_, _ = db.ExecContext(ctx,
`UPDATE workspace_auth_tokens SET last_used_at = now() WHERE id = $1`, tokenID)
if _, err := db.ExecContext(ctx,
`UPDATE workspace_auth_tokens SET last_used_at = now() WHERE id = $1`, tokenID); err != nil {
log.Printf("wsauth: last_used_at bump failed for %s: %v", tokenID, err)
}
return nil
}
@@ -250,7 +253,9 @@ func ValidateAnyToken(ctx context.Context, db *sql.DB, plaintext string) error {
}
// Best-effort last_used_at update.
_, _ = db.ExecContext(ctx,
`UPDATE workspace_auth_tokens SET last_used_at = now() WHERE id = $1`, tokenID)
if _, err := db.ExecContext(ctx,
`UPDATE workspace_auth_tokens SET last_used_at = now() WHERE id = $1`, tokenID); err != nil {
log.Printf("wsauth: last_used_at bump failed for %s: %v", tokenID, err)
}
return nil
}