Skip to content

[staging-livepeer-api] 'api_token id=undefined not found' — lastSeen update fails hourly for token 2f25c979 (18 occurrences) #761

@livepeer-tessa

Description

@livepeer-tessa

Summary

staging-livepeer-api is logging an error every hour when trying to update the lastSeen timestamp for a specific API token. The error indicates that the token ID is being passed as undefined to the DB update query, causing the api_token record lookup to fail.

Error Details

Service: staging-livepeer-api
Time window: 2026-03-29 18:09 UTC – 2026-03-30 06:09 UTC
Total occurrences: 18 (roughly every 30-60 mins, clustered around the :31 minute mark of each hour)
Token ID: 2f25c979-904f-4fce-b329-4174b54fdcbf

Error message

error saving last seen: table=api_token id=2f25c979-904f-4fce-b329-4174b54fdcbf err= Ge [Error]: api_token id=undefined not found

Surrounding context (from Loki)

The same token 2f25c979-904f-4fce-b329-4174b54fdcbf is being successfully used for DB SELECTs and UPDATEs in other queries (e.g. UPDATE api_token SET data = data || ... WHERE id = '2f25c979...' rows=1), but some code path is calling saveLastSeen() with id=undefined instead of the resolved ID. The error message format id=<real-uuid> err=...: api_token id=undefined not found suggests the UUID is logged correctly at the call site, but the DB query receives undefined.

Occurrence timestamps (UTC)

2026-03-29 19:31:42 UTC
2026-03-29 20:31:39 UTC
2026-03-29 21:31:37 UTC
2026-03-29 21:31:48 UTC
2026-03-29 22:31:37 UTC
2026-03-29 22:31:42 UTC
2026-03-29 22:31:48 UTC
2026-03-29 22:31:52 UTC
2026-03-29 23:00:00 UTC (approx)
2026-03-30 00:31:37 UTC
2026-03-30 00:31:45 UTC
2026-03-30 00:31:52 UTC
2026-03-30 01:31:45 UTC
2026-03-30 02:31:48 UTC
2026-03-30 03:31:48 UTC
2026-03-30 04:31:45 UTC
2026-03-30 04:31:51 UTC
2026-03-30 05:31:39 UTC
2026-03-30 05:31:48 UTC

Likely Cause

The saveLastSeen function (or caller) in staging-livepeer-api is receiving the API token object but dereferencing the ID field incorrectly — e.g. token.id returns undefined when the field is named differently (e.g. token.userId, token.tokenId), or a race condition causes the token object to be undefined when the async callback fires.

The real UUID is logged in the error context (id=2f25c979-904f-4fce-b329-4174b54fdcbf), suggesting it's available at the log-writing level but not passed correctly into the DB query.

Impact

  • Staging only (no indication in prod Loki)
  • lastSeen timestamps for this API token are not being updated
  • Token remains functional for auth (SELECT queries succeed)
  • ~18 spurious error log entries per 12h window

Suggested Fix

Search for the saveLastSeen function in staging-livepeer-api and check:

  1. The field name used to extract the token ID (might be id vs. tokenId vs. another field)
  2. Whether the token object could be undefined or re-shaped before being passed to saveLastSeen

Loki Query

{app="staging-livepeer-api"} |~ "api_token id=undefined"

Detected automatically by scope-monitor cron at 2026-03-30 06:09 UTC

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions