Skip to content

The agent that grows with you

fix(tui): banner shows main's 8-character label for a resumed stored session

Tekniumb63a7fc31a02
diff --git a/ui-tui/src/lib/sessionLabel.test.ts b/ui-tui/src/lib/sessionLabel.test.ts
index 256bc435b21..6bd3139d5e0 100644
--- a/ui-tui/src/lib/sessionLabel.test.ts
+++ b/ui-tui/src/lib/sessionLabel.test.ts
@@ -7,9 +7,17 @@ describe('sessionLabel', () => {
expect(sessionLabel(`local-${'ab12cd34'}${'0'.repeat(56)}`)).toBe('ab12cd34')
})
- it('leaves every other id as it is', () => {
+ it('leaves an 8-character label as it is', () => {
expect(sessionLabel('a707d4c3')).toBe('a707d4c3')
- expect(sessionLabel('20261012_134501_abcdef')).toBe('20261012_134501_abcdef')
expect(sessionLabel(null)).toBeNull()
})
+
+ // PR #106742 row 33: main's banner named a resumed session by its 8-hex runtime label, never by the
+ // stored `YYYYMMDD_HHMMSS_xxxxxx` id the canonical owner keys it on.
+ it('shows a resumed stored id as a stable 8-character label', () => {
+ const label = sessionLabel('20261012_134501_abcdef')
+ expect(label).toMatch(/^[0-9a-f]{8}$/)
+ expect(sessionLabel('20261012_134501_abcdef')).toBe(label)
+ expect(sessionLabel('20261012_134501_abcdeg')).not.toBe(label)
+ })
})
diff --git a/ui-tui/src/lib/sessionLabel.ts b/ui-tui/src/lib/sessionLabel.ts
index 6865d43dfc1..db65557cb1a 100644
--- a/ui-tui/src/lib/sessionLabel.ts
+++ b/ui-tui/src/lib/sessionLabel.ts
@@ -1,6 +1,21 @@
-// The canonical owner names a session by its durable id (`local-` + 64 hex). The banner shows
-// main's short 8-character label; the full id stays in state for every RPC.
+import { createHash } from 'node:crypto'
+
+// The canonical owner names a session by its durable id: `local-` + 64 hex for sessions it created,
+// the stored `YYYYMMDD_HHMMSS_xxxxxx` id for history adopted from main. Main's banner always showed an
+// 8-hex runtime label; the full id stays in state for every RPC.
const CANONICAL_LOCAL_ID = /^local-([0-9a-f]{8})[0-9a-f]{56}$/
+const STORED_ID = /^\d{8}_\d{6}_[0-9a-z]+$/i
+
+export const sessionLabel = (sid: null | string | undefined): null | string | undefined => {
+ if (!sid) {
+ return sid
+ }
+
+ const local = CANONICAL_LOCAL_ID.exec(sid)?.[1]
+
+ if (local) {
+ return local
+ }
-export const sessionLabel = (sid: null | string | undefined): null | string | undefined =>
- sid ? (CANONICAL_LOCAL_ID.exec(sid)?.[1] ?? sid) : sid
+ return STORED_ID.test(sid) ? createHash('sha256').update(sid).digest('hex').slice(0, 8) : sid
+}