WeKnora/internal/database
Ochan Kwon 8af7938aed
fix(mcp): keep OAuth token expiry independent of the process time zone (#4207)
* fix(mcp): keep OAuth token expiry independent of the process time zone

mcp_oauth_tokens.expires_at is a naive TIMESTAMP column. The token store
computes the expiry from the process clock, the column drops its offset,
and the driver reads the stored wall clock back as UTC. When the
application runs outside UTC, every stored expiry is therefore shifted
by the process offset: with TZ=Asia/Shanghai, the docker compose default,
a token is reported as expiring eight hours after it really does.

WeKnora trusts that value. The OAuth status endpoint reports a token as
authorized for those extra hours, and the runtime neither refreshes it
ahead of time nor asks for authorization again. It sends the expired
access token to the MCP server and only recovers after the server
rejects it.

Promote the token and client timestamps to TIMESTAMP WITH TIME ZONE, as
migration 000072 did for API keys and resource grants, and normalize the
values the repository writes to UTC, so new rows are right even before
the migration is applied. The status endpoint keeps reporting the expiry
in UTC as before: the driver returns timestamptz values in the process
time zone, and the response would otherwise vary by deployment.

The migration cannot repair existing rows, because the time zone of the
process that wrote them is unknown. Like 000072, it reads them as UTC,
so they keep their shifted value until the token is authorized or
refreshed again.

* fix(migrations): renumber MCP OAuth timestamptz migration to 000118

000117 is now taken on main by messages_attachment_lookup.

---------

Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-10-13 16:56:51 +08:00
..
im_transport_migration_test.go fix: align client sessions and integration request handling (#3305) 2026-09-16 16:20:57 +08:00
migration.go feat(system-info): surface DB migration errors with troubleshooting links 2026-05-14 16:34:50 +08:00
migration_postgres_agent_allowed_tools_test.go fix(agent): make agent tool selection match the tools the runtime registers (#4211) 2026-10-13 11:29:24 +08:00
migration_postgres_mcp_oauth_test.go fix(mcp): keep OAuth token expiry independent of the process time zone (#4207) 2026-10-13 16:56:51 +08:00
migration_postgres_test.go fix(deploy): bump paradedb image to v0.25.11-pg17 (#4120) 2026-10-12 11:50:11 +08:00
migration_sqlite_agent_allowed_tools_test.go fix(agent): make agent tool selection match the tools the runtime registers (#4211) 2026-10-13 11:29:24 +08:00
migration_sqlite_mcp_metadata_test.go fix(sqlite): add MCP metadata migration 2026-10-10 20:47:20 +08:00
migration_sqlite_message_artifacts_test.go feat(artifacts): artifacts library page backed by a message_artifacts table (#3384) 2026-09-18 12:10:19 +08:00
migration_sqlite_test.go fix(knowledge): address auto-tag review findings 2026-08-07 15:01:01 +08:00
migration_sqlite_versioned_schema_test.go feat(agent): read chat attachments on demand (#4203) 2026-10-13 14:37:17 +08:00
migration_versions_test.go fix(migrations): renumber the context checkpoint migration to 000105 2026-09-18 21:26:26 +08:00