Thomas M
0a01386756
fix: canonicalize session keys at write time ( #30654 ) (thanks @thomasxm)
...
* fix: canonicalize session keys at write time to prevent orphaned sessions (#29683 )
resolveSessionKey() uses hardcoded DEFAULT_AGENT_ID="main", but all read
paths canonicalize via cfg. When the configured default agent differs
(e.g. "ops" with mainKey "work"), writes produce "agent:main:main" while
reads look up "agent:ops:work", orphaning transcripts on every restart.
Fix all three write-path call sites by wrapping with
canonicalizeMainSessionAlias:
- initSessionState (auto-reply/reply/session.ts)
- runWebHeartbeatOnce (web/auto-reply/heartbeat-runner.ts)
- resolveCronAgentSessionKey (cron/isolated-agent/session-key.ts)
Add startup migration (migrateOrphanedSessionKeys) to rename existing
orphaned keys to canonical form, merging by most-recent updatedAt.
* fix: address review — track agent IDs in migration map, align snapshot key
P1: migrateOrphanedSessionKeys now tracks agentId alongside each store
path in a Map instead of inferring from the filesystem path. This
correctly handles custom session.store templates outside the default
agents/<id>/ layout.
P2: Pass the already-canonicalized sessionKey to getSessionSnapshot so
the heartbeat snapshot reads/restores use the same key as the write path.
* fix: log migration results at all early return points
migrateOrphanedSessionKeys runs before detectLegacyStateMigrations, so
it can canonicalize legacy keys (e.g. "main" → "agent:main:main") before
the legacy detector sees them. This caused the early return path to skip
logging, breaking doctor-state-migrations tests that assert log.info was
called.
Extract logMigrationResults helper and call it at every return point.
* fix: handle shared stores and ~ expansion in migration
P1: When session.store has no {agentId}, all agents resolve to the same
file. Track all agentIds per store path (Map<path, Set<id>>) and run
canonicalization once per agent. Skip cross-agent "agent:main:*"
remapping when "main" is a legitimate configured agent sharing the store,
to avoid merging its data into another agent's namespace.
P2: Use expandHomePrefix (environment-aware ~ resolution) instead of
os.homedir() in resolveStorePathFromTemplate, matching the runtime
resolveStorePath behavior for OPENCLAW_HOME/HOME overrides.
* fix: narrow cross-agent remap to provable orphan aliases only
Only remap agent:main:* keys where the suffix is a main session alias
("main" or the configured mainKey). Other agent:main:* keys — hooks,
subagents, cron sessions, per-sender keys — may be intentional
cross-agent references and must not be silently moved into another
agent's namespace.
* fix: run orphan-key session migration at gateway startup (#29683 )
* fix: canonicalize cross-agent legacy main aliases in session keys (#29683 )
* fix: guard shared-store migration against cross-agent legacy alias remap (#29683 )
* refactor: split session-key migration out of pr 30654
---------
Co-authored-by: Your Name <your_email@example.com >
Co-authored-by: Ayaan Zaidi <hi@obviy.us >
2026-03-29 18:59:25 +05:30
..
2026-03-27 23:33:08 +00:00
2026-03-27 23:33:08 +00:00
2026-03-29 09:10:38 +01:00
2026-03-27 11:29:32 +00:00
2026-03-27 23:33:08 +00:00
2026-03-13 18:51:21 +00:00
2026-02-26 04:36:25 +01:00
2026-03-21 11:00:21 -04:00
2026-03-24 11:45:27 -07:00
2026-03-27 23:33:08 +00:00
2026-03-27 23:33:08 +00:00
2026-02-18 16:48:35 +00:00
2026-03-13 23:49:07 +00:00
2026-03-10 23:52:31 +00:00
2026-03-20 16:46:34 +00:00
2026-03-22 18:31:52 +00:00
2026-03-14 00:53:47 +00:00
2026-03-27 23:33:08 +00:00
2026-03-10 20:16:35 -04:00
2026-03-27 16:40:27 +00:00
2026-03-13 19:59:11 +00:00
2026-03-22 15:02:43 -07:00
2026-03-22 15:02:43 -07:00
2026-03-23 00:38:31 -07:00
2026-03-14 00:36:31 +00:00
2026-03-14 00:36:31 +00:00
2026-03-28 05:22:26 +00:00
2026-03-28 05:22:26 +00:00
2026-03-23 00:37:05 +00:00
2026-03-23 00:37:05 +00:00
2026-03-13 18:38:12 +00:00
2026-03-07 10:41:05 +00:00
2026-03-13 23:47:22 +00:00
2026-03-26 18:43:57 +00:00
2026-03-22 22:23:25 -07:00
2026-03-27 23:33:08 +00:00
2026-02-16 16:42:28 +00:00
2026-03-14 00:55:32 +00:00
2026-03-23 08:07:44 +00:00
2026-03-15 20:10:43 -07:00
2026-03-13 19:56:04 +00:00
2026-02-18 01:34:35 +00:00
2026-03-29 00:38:03 -05:00
2026-03-29 00:38:03 -05:00
2026-03-28 00:02:09 +00:00
2026-03-24 10:17:17 -04:00
2026-03-13 19:50:27 +00:00
2026-03-27 02:11:26 -05:00
2026-03-23 13:45:04 -05:00
2026-03-13 20:16:57 +00:00
2026-03-22 18:09:45 +00:00
2026-03-24 21:00:36 +00:00
2026-03-27 23:33:08 +00:00
2026-03-14 00:26:03 +00:00
2026-03-13 20:20:27 +00:00
2026-03-27 03:41:40 +00:00
2026-03-23 00:15:55 -07:00
2026-03-23 00:15:55 -07:00
2026-03-13 19:16:38 +00:00
2026-03-13 23:50:15 +00:00
2026-03-13 23:50:15 +00:00
2026-03-27 18:55:33 +00:00
2026-03-27 18:55:33 +00:00
2026-03-13 20:18:50 +00:00
2026-03-23 01:21:19 -07:00
2026-03-13 19:56:04 +00:00
2026-03-27 10:05:35 +00:00
2026-03-25 15:49:26 -06:00
2026-03-25 15:49:26 -06:00
2026-03-17 07:06:25 +00:00
2026-03-27 16:40:27 +00:00
2026-03-27 23:33:08 +00:00
2026-03-02 19:57:33 +00:00
2026-03-28 00:26:55 +00:00
2026-03-13 23:13:33 -05:00
2026-03-12 04:01:49 -04:00
2026-03-27 23:33:08 +00:00
2026-03-22 22:52:14 -07:00
2026-03-28 00:02:09 +00:00
2026-03-27 09:06:40 -07:00
2026-03-28 00:46:53 +00:00
2026-03-13 20:37:21 +00:00
2026-03-28 00:02:09 +00:00
2026-03-13 20:19:39 +00:00
2026-03-29 00:43:58 +00:00
2026-03-15 22:39:00 -07:00
2026-03-27 19:07:47 +00:00
2026-03-27 19:07:47 +00:00
2026-03-28 00:02:09 +00:00
2026-03-23 19:36:44 -07:00
2026-03-28 00:02:09 +00:00
2026-03-28 00:02:09 +00:00
2026-03-28 00:02:09 +00:00
2026-03-28 00:46:53 +00:00
2026-03-17 07:06:25 +00:00
2026-03-23 19:36:44 -07:00
2026-03-23 19:36:44 -07:00
2026-03-11 01:43:06 +00:00
2026-03-28 00:46:53 +00:00
2026-03-23 19:36:44 -07:00
2026-03-13 20:12:04 +00:00
2026-02-15 13:56:50 +00:00
2026-03-28 00:26:55 +00:00
2026-03-22 09:35:25 -07:00
2026-03-12 21:00:00 -04:00
2026-03-13 12:35:39 +11:00
2026-03-22 10:14:46 -07:00
2026-03-22 17:28:04 +00:00
2026-03-27 18:37:31 +00:00
2026-03-22 10:14:46 -07:00
2026-03-13 23:55:07 +00:00
2026-03-22 10:14:46 -07:00
2026-03-27 18:37:31 +00:00
2026-02-24 23:29:44 +00:00
2026-02-24 23:29:44 +00:00
2026-03-27 23:33:08 +00:00
2026-03-28 00:02:09 +00:00
2026-03-22 23:18:54 -07:00
2026-03-22 23:18:54 -07:00
2026-03-28 00:02:09 +00:00
2026-03-23 19:04:04 -07:00
2026-03-13 23:13:33 -05:00
2026-03-13 23:13:33 -05:00
2026-03-15 21:07:05 -07:00
2026-02-16 08:24:55 -05:00
2026-03-13 18:35:55 +00:00
2026-02-25 00:42:04 +00:00
2026-03-24 09:24:29 +00:00
2026-03-13 18:49:41 +00:00
2026-02-19 14:55:06 +01:00
2026-03-11 02:38:00 +00:00
2026-03-19 11:08:33 -07:00
2026-03-22 10:48:21 -07:00
2026-03-11 02:38:00 +00:00
2026-03-23 00:38:31 -07:00
2026-03-22 12:04:11 -07:00
2026-03-27 03:41:40 +00:00
2026-03-15 20:12:37 -07:00
2026-03-15 20:12:37 -07:00
2026-03-13 20:31:20 +00:00
2026-03-13 18:33:59 +00:00
2026-03-24 23:45:33 +00:00
2026-03-24 23:45:33 +00:00
2026-03-27 23:33:08 +00:00
2026-02-16 23:53:21 +01:00
2026-03-24 23:45:33 +00:00
2026-03-08 18:40:14 +00:00
2026-03-27 23:08:57 +00:00
2026-02-18 00:45:43 -05:00
2026-03-27 23:33:08 +00:00
2026-03-24 10:01:22 -07:00
2026-03-27 23:33:08 +00:00
2026-02-26 03:59:17 +01:00
2026-02-19 20:03:57 -05:00
2026-02-19 20:03:57 -05:00
2026-03-13 18:34:13 +00:00
2026-02-25 01:28:47 +00:00
2026-03-21 11:00:21 -04:00
2026-03-22 18:09:45 +00:00
2026-03-13 18:48:12 +00:00
2026-03-10 21:42:15 +01:00
2026-03-24 23:47:21 -05:00
2026-03-22 23:00:18 -07:00
2026-03-22 13:10:55 -07:00
2026-03-28 00:53:34 +00:00
2026-03-14 00:51:12 +00:00
2026-03-22 13:10:55 -07:00
2026-03-29 09:10:38 +01:00
2026-03-29 09:10:38 +01:00
2026-03-22 13:10:55 -07:00
2026-03-26 18:29:33 -07:00
2026-03-15 22:55:26 -07:00
2026-02-19 14:27:36 +00:00
2026-03-13 21:40:54 +00:00
2026-03-10 21:42:15 +01:00
2026-03-27 23:08:57 +00:00
2026-03-22 12:31:36 -07:00
2026-03-27 15:16:19 -05:00
2026-03-07 19:18:05 +00:00
2026-03-27 15:16:19 -05:00
2026-03-20 15:44:15 -05:00
2026-03-27 23:08:57 +00:00
2026-03-22 12:04:11 -07:00
2026-03-22 18:35:37 -07:00
2026-03-13 20:18:50 +00:00
2026-03-22 18:31:52 +00:00
2026-03-22 18:31:52 +00:00
2026-03-13 19:54:16 +00:00
2026-03-02 19:57:33 +00:00
2026-03-13 19:53:40 +00:00
2026-02-22 18:37:25 +00:00
2026-03-25 09:59:33 -06:00
2026-03-25 09:59:33 -06:00
2026-03-13 23:45:36 +00:00
2026-03-15 09:07:10 -07:00
2026-03-27 23:33:08 +00:00
2026-03-02 19:57:33 +00:00
2026-03-13 19:54:16 +00:00
2026-03-15 09:07:10 -07:00
2026-03-19 10:34:29 +05:30
2026-03-19 10:34:29 +05:30
2026-03-27 23:33:08 +00:00
2026-03-27 23:33:08 +00:00
2026-03-24 05:29:05 +00:00
2026-03-27 23:33:08 +00:00
2026-03-02 05:20:19 +00:00
2026-03-13 20:12:04 +00:00
2026-03-22 12:04:11 -07:00
2026-03-23 00:58:23 -07:00
2026-03-27 23:08:57 +00:00
2026-03-13 23:43:06 +00:00
2026-03-27 23:08:57 +00:00
2026-02-16 14:59:30 +00:00
2026-03-27 16:08:57 +00:00
2026-03-27 16:08:57 +00:00
2026-03-27 13:46:16 +00:00
2026-03-19 01:58:29 -04:00
2026-03-27 13:46:16 +00:00
2026-03-26 16:25:23 +00:00
2026-03-27 13:46:16 +00:00
2026-03-28 09:35:42 +00:00
2026-03-19 01:58:29 -04:00
2026-03-26 16:25:23 +00:00
2026-03-19 14:21:42 -07:00
2026-03-26 16:25:23 +00:00
2026-03-27 23:33:08 +00:00
2026-03-22 18:35:37 -07:00
2026-03-27 23:33:08 +00:00
2026-03-22 18:35:37 -07:00
2026-02-26 22:01:06 +01:00
2026-03-27 19:14:16 +00:00
2026-03-27 19:14:16 +00:00
2026-03-14 01:05:46 +00:00
2026-03-28 00:26:55 +00:00
2026-02-19 15:08:14 +00:00
2026-03-13 19:45:37 +00:00
2026-03-06 11:13:30 -05:00
2026-03-27 23:33:08 +00:00
2026-03-06 11:13:30 -05:00
2026-03-27 23:33:08 +00:00
2026-03-09 19:14:08 -04:00
2026-03-28 00:02:09 +00:00
2026-03-13 21:40:54 +00:00
2026-03-27 23:08:57 +00:00
2026-03-27 23:08:57 +00:00
2026-03-13 23:39:44 +00:00
2026-03-28 00:02:09 +00:00
2026-03-14 00:23:57 +00:00
2026-03-22 12:02:52 -07:00
2026-03-14 01:29:04 +00:00
2026-02-19 13:54:35 +00:00
2026-03-13 20:38:24 +00:00
2026-02-22 21:19:09 +00:00
2026-03-17 07:06:25 +00:00
2026-03-14 01:04:18 +00:00
2026-03-27 23:33:08 +00:00
2026-03-08 03:02:25 +00:00
2026-03-27 23:33:08 +00:00
2026-02-26 13:19:59 +01:00
2026-03-27 23:08:57 +00:00
2026-03-27 11:29:32 +00:00
2026-03-27 23:33:08 +00:00
2026-03-13 23:37:37 +00:00
2026-03-27 23:33:08 +00:00
2026-03-02 10:14:38 -06:00
2026-03-13 19:24:22 +00:00
2026-02-22 17:11:54 +00:00
2026-03-27 23:08:57 +00:00
2026-02-19 14:27:36 +00:00
2026-03-27 09:06:40 -07:00
2026-03-27 09:06:40 -07:00
2026-03-29 09:10:38 +01:00
2026-03-29 09:10:38 +01:00
2026-03-28 23:25:02 -07:00
2026-03-28 23:25:02 -07:00
2026-03-04 10:52:33 -08:00
2026-03-13 19:35:27 +00:00
2026-03-27 23:33:08 +00:00
2026-02-22 21:19:09 +00:00
2026-02-23 13:53:10 -05:00
2026-03-17 07:06:25 +00:00
2026-03-28 23:25:02 -07:00
2026-03-13 21:40:54 +00:00
2026-03-12 01:16:49 +01:00
2026-03-14 01:01:27 +00:00
2026-02-24 01:09:31 +00:00
2026-03-27 18:15:40 +00:00
2026-03-27 17:57:23 +00:00
2026-03-27 17:57:23 +00:00
2026-03-13 19:23:25 +00:00
2026-02-22 10:59:34 +01:00
2026-03-13 19:22:21 +00:00
2026-03-02 20:35:45 +00:00
2026-03-13 19:13:01 +00:00
2026-02-19 12:51:30 +00:00
2026-03-13 18:10:40 +00:00
2026-02-19 13:28:18 +00:00
2026-03-15 21:07:05 -07:00
2026-03-07 10:41:05 +00:00
2026-03-15 20:12:37 -07:00
2026-03-13 19:15:25 +00:00
2026-03-13 19:15:25 +00:00
2026-03-27 23:33:08 +00:00
2026-02-19 13:28:18 +00:00
2026-03-18 00:20:15 -07:00
2026-03-18 15:36:32 +00:00
2026-03-18 18:19:40 +00:00
2026-03-27 23:33:08 +00:00
2026-03-28 09:35:42 +00:00
2026-03-18 18:19:40 +00:00
2026-03-18 18:19:40 +00:00
2026-02-23 05:20:14 +01:00
2026-03-14 00:11:03 +00:00
2026-03-17 07:23:44 +00:00
2026-03-12 18:15:35 +02:00
2026-03-14 00:13:07 +00:00
2026-03-14 00:19:04 +00:00
2026-03-12 18:15:35 +02:00
2026-03-26 18:34:51 +00:00
2026-03-27 23:33:08 +00:00
2026-03-27 11:29:32 +00:00
2026-03-13 19:36:49 +00:00
2026-03-03 00:30:34 +00:00
2026-03-17 07:06:25 +00:00
2026-03-07 21:36:24 +00:00
2026-03-15 22:32:36 -07:00
2026-03-27 17:57:23 +00:00
2026-03-15 22:32:36 -07:00
2026-03-27 23:08:57 +00:00
2026-03-19 00:04:50 +00:00
2026-03-27 23:33:08 +00:00
2026-03-29 09:10:38 +01:00
2026-03-25 06:22:18 -07:00
2026-03-25 06:22:18 -07:00
2026-03-14 00:24:59 +00:00
2026-03-14 00:24:59 +00:00
2026-03-27 23:33:08 +00:00
2026-03-01 21:41:47 +00:00
2026-03-27 23:33:08 +00:00
2026-03-14 00:38:14 +01:00
2026-03-22 12:58:08 -07:00
2026-03-27 23:33:08 +00:00
2026-03-16 18:57:33 -07:00
2026-03-27 23:33:08 +00:00
2026-02-22 10:16:02 +01:00
2026-03-24 21:00:36 +00:00
2026-03-22 23:00:18 -07:00
2026-03-23 13:10:26 +08:00
2026-03-02 14:36:41 +00:00
2026-03-24 19:36:08 +00:00
2026-03-24 19:36:08 +00:00
2026-03-13 22:02:18 +00:00
2026-02-24 03:11:33 +00:00
2026-03-27 23:33:08 +00:00
2026-03-13 20:37:38 +00:00
2026-03-22 23:18:54 -07:00
2026-03-27 20:24:15 -05:00
2026-03-27 20:24:15 -05:00
2026-03-13 19:15:25 +00:00
2026-03-13 20:12:04 +00:00
2026-02-19 11:08:23 +01:00
2026-03-13 19:50:27 +00:00
2026-03-13 23:13:33 -05:00
2026-03-13 19:42:47 +00:00
2026-02-18 01:34:35 +00:00
2026-03-29 18:59:25 +05:30
2026-03-22 22:19:35 -07:00
2026-03-26 17:39:58 +00:00
2026-03-27 13:46:16 +00:00
2026-03-13 19:57:49 +00:00
2026-03-09 06:19:30 +00:00
2026-03-28 00:02:09 +00:00
2026-03-24 23:47:21 -05:00
2026-03-27 23:33:08 +00:00
2026-02-26 11:00:09 +01:00
2026-03-13 19:03:01 +00:00
2026-03-22 18:35:37 -07:00
2026-03-24 19:16:19 +00:00
2026-03-28 00:02:09 +00:00
2026-03-11 01:43:06 +00:00
2026-03-28 00:02:09 +00:00
2026-03-11 01:43:06 +00:00
2026-03-28 00:02:09 +00:00
2026-03-28 00:02:09 +00:00
2026-03-28 00:02:09 +00:00
2026-03-13 18:38:11 +00:00
2026-03-27 23:33:08 +00:00
2026-03-18 09:43:46 -07:00
2026-03-22 18:35:37 -07:00
2026-03-22 18:35:37 -07:00
2026-03-13 18:24:02 +00:00
2026-03-27 23:08:57 +00:00
2026-03-18 23:29:14 -05:00
2026-03-17 07:06:25 +00:00
2026-02-18 01:34:35 +00:00
2026-03-29 09:10:38 +01:00
2026-03-06 21:47:32 -06:00
2026-03-12 21:52:17 -07:00
2026-03-12 21:52:17 -07:00
2026-03-14 00:56:42 +00:00
2026-02-24 02:05:37 +00:00
2026-03-25 06:22:18 -07:00
2026-03-25 06:01:20 -07:00
2026-03-29 09:10:38 +01:00
2026-03-27 16:39:42 +00:00
2026-03-29 09:10:38 +01:00
2026-03-23 21:04:08 -07:00
2026-03-03 03:04:13 +00:00
2026-03-02 16:45:12 +00:00
2026-03-13 20:00:43 +00:00
2026-02-15 21:46:08 +00:00
2026-03-28 11:57:27 +00:00
2026-03-22 18:09:45 +00:00
2026-03-29 09:10:38 +01:00
2026-03-27 23:33:08 +00:00
2026-03-27 11:29:32 +00:00
2026-03-27 11:29:32 +00:00
2026-03-17 07:06:25 +00:00
2026-03-07 18:00:38 +05:30
2026-03-13 20:38:24 +00:00
2026-02-18 01:34:35 +00:00
2026-03-17 07:06:25 +00:00
2026-03-07 16:43:19 -08:00