Skip to content

fix(dev): use stable sessionId as AGUI threadId for session persistence#1687

Closed
C0d3N1nja97342 wants to merge 1 commit into
aws:mainfrom
C0d3N1nja97342:fix/agui-stable-thread-id
Closed

fix(dev): use stable sessionId as AGUI threadId for session persistence#1687
C0d3N1nja97342 wants to merge 1 commit into
aws:mainfrom
C0d3N1nja97342:fix/agui-stable-thread-id

Conversation

@C0d3N1nja97342

Copy link
Copy Markdown
Contributor

Description

In browser mode (agentcore dev without -b), handleAguiInvocation built the AGUI RunAgentInput with threadId: randomUUID() on every message, so each message in a chat got a brand-new thread. AGUI agents could not keep multi-turn session state (e.g. AgentCore Memory STM) across a conversation.

The per-chat sessionId was already in scope (assigned in handleInvocations, returned as the x-session-id response header) but was never used as the threadId. This change reuses it, falling back to randomUUID() only when no sessionId is present.

This mirrors the deployed path, which already builds the input via buildAguiRunInput(prompt, sessionId) — so local dev and deployed behaviour now agree. The TUI path (agentcore dev -b) was already correct via aguiThreadIdRef; the bug was specific to the browser-mode HTTP proxy.

Related Issue

Closes #1678

Type of Change

  • Bug fix

Testing

  • I ran npm run typecheck — clean
  • I ran npm run lint — clean (only pre-existing security/detect-unsafe-regex warnings, unrelated to this change)
  • I ran npm run test:unit and npm run test:integ — ran test:unit; the web-ui suite that covers this change passes 78/78 on Linux. The remaining unit failures are pre-existing, environment-dependent tests (python/docker subprocesses, etc.) that also fail on the main baseline and are unrelated to this change. test:integ was not run (requires AWS credentials).
  • If I modified src/assets/, I ran npm run test:update-snapshots and committed the updated snapshots — N/A

Added a regression test (agui-invocation.test.ts) that mocks the proxied AGUI request, sends two messages with the same sessionId, and asserts both bodies carry that sessionId as threadId (verified to fail against the pre-fix code). Also covers the randomUUID() fallback when no sessionId is supplied.

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly — N/A (internal dev-server fix)
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published — N/A

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

handleAguiInvocation regenerated a random threadId on every browser-mode
message, so AGUI agents could not keep multi-turn state (e.g. AgentCore
Memory STM) across a chat. The per-chat sessionId was already in scope,
stable for the session, and returned as the x-session-id response header
— reuse it as the threadId, falling back to a UUID only when no sessionId
is present.

Mirrors the deployed path, which builds RunAgentInput via
buildAguiRunInput(prompt, sessionId).

Adds a regression test that mocks the proxied AGUI request and asserts
the threadId matches the sessionId across two messages (and that the
UUID fallback still yields a valid threadId).
@C0d3N1nja97342 C0d3N1nja97342 requested a review from a team July 6, 2026 08:56
@github-actions github-actions Bot added the size/m PR size: M label Jul 6, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label Jul 7, 2026
@agentcore-devx-automation

Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label Jul 7, 2026
@tejaskash

Copy link
Copy Markdown
Contributor

Hi @C0d3N1nja97342 , closing out this PR in favor of #1686 which addresses the same concern.

@tejaskash tejaskash closed this Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AGUI threadId is regenerated on every message, breaking session persistence

2 participants