fix(state): recognize every persisted session-id shape in salvage

The cherry-picked recognizers cover cron_, the CLI/gateway /bg shape and
room_, but a census of every site that hands an id to SessionDB on base
finds more shapes that salvage still drops (and that, as a
parent_session_id, still veto layout inference for the whole table):

  tui_gateway/methods_prompt.py:1289   f"bg_{uuid4().hex[:6]}" (TUI/Desktop /bg)
  gateway/platforms/api_server.py:3156/3341  f"api_{epoch}_{hex8}" (create/fork)
  gateway/platforms/api_server.py:1084 f"api-{sha256[:16]}" (chat completions)
  gateway/platforms/api_server_runs.py:689/703  run_{uuid4().hex} fallback
  acp_adapter/session.py:179/203, api_server_openai_routes.py:1127  str(uuid4())

Each pattern stays anchored on exactly what its mint site fixes.
This commit is contained in:
kshitijk4poor
2026-10-04 10:58:48 +05:30
committed by kshitij
parent 0788e759dd
commit d7732ca75e
2 changed files with 20 additions and 3 deletions

View File

@@ -32,10 +32,19 @@ SESSION_ID_RECOGNIZERS = (
# cron/scheduler.py: f"cron_{job_id}_{now:%Y%m%d_%H%M%S}". job_id is uuid4().hex[:12] for jobs
# minted by cron/jobs.py, but user/legacy job ids ("job-1") are real and still in live stores.
re.compile(r"^cron_[A-Za-z0-9][A-Za-z0-9._-]*_\d{8}_\d{6}$"),
# hermes_cli/cli_commands_mixin.py (/bg): f"bg_{now:%H%M%S}_{uuid4().hex[:6]}" -- time only, no date.
re.compile(r"^bg_\d{6}_[0-9a-f]{6}$"),
# /bg: CLI + gateway mint f"bg_{now:%H%M%S}_{hex6}" (time only, no date); the TUI/Desktop
# (tui_gateway/methods_prompt.py _side_agent_args) mints f"bg_{uuid4().hex[:6]}".
re.compile(r"^bg_(?:\d{6}_)?[0-9a-f]{6}$"),
# gateway/platforms/api_server_room_dispatch.py: f"room_{sha256(seed)[:32]}".
re.compile(r"^room_[0-9a-f]{32}$"),
# gateway/platforms/api_server.py: POST /api/sessions + fork f"api_{int(time())}_{hex8}",
# chat-completions _derive_chat_session_id f"api-{sha256[:16]}".
re.compile(r"^api_\d{9,}_[0-9a-f]{8}$"),
re.compile(r"^api-[0-9a-f]{16}$"),
# gateway/platforms/api_server_runs.py: /v1/runs falls back to its f"run_{uuid4().hex}".
re.compile(r"^run_[0-9a-f]{32}$"),
# acp_adapter/session.py and /v1/responses: str(uuid4()).
re.compile(r"^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"),
)

View File

@@ -59,7 +59,13 @@ CRON_SLUG_ID = "cron_job-1_20260707_195958" # legacy/user job id, real in l
BG_ID = "bg_124526_be5bed"
ROOM_ID = "room_" + "0123456789abcdef" * 2
DERIVED_IDS = [CRON_ID, CRON_SLUG_ID, BG_ID, ROOM_ID]
TUI_BG_ID = "bg_be5bed"
API_ID = "api_1790000000_0123abcd"
API_CHAT_ID = "api-0123456789abcdef"
RUN_ID = "run_" + "0123456789abcdef" * 2
UUID_ID = "0b36145a-e5c7-4d2a-9f00-0123456789ab"
DERIVED_IDS = [CRON_ID, CRON_SLUG_ID, BG_ID, ROOM_ID, TUI_BG_ID, API_ID, API_CHAT_ID, RUN_ID, UUID_ID]
# Near-misses and arbitrary cell values. These sit at the id position of a candidate
# layout, so accepting any of them costs real wrong-column-mapping safety.
@@ -74,6 +80,8 @@ NOT_SESSION_IDS = [
"/Users/adam/some/path", "https://example.com", "hello world",
'{"json": true}', "claude-opus-5", "assistant",
"20260101_100500",
"bg_abcde", "api_123_0123abcd", "api-0123", "run_" + "a" * 31,
"0b36145a-e5c7-1d2a-9f00-0123456789ab",
]