fix(chat): O(1) token cleanup in useChatSend via reverse messageId map (mc#2908 F8) #3033

Merged
devops-engineer merged 1 commits from fix/mobile-chat-f8-token-cleanup-omap into main 2026-06-19 05:58:32 +00:00
Member

Fixes F8 from mobile-chat audit #2908.

finishSendToken previously scanned messageIdToTokenRef linearly to delete the mapping for a completed token. This PR adds a tokenToMessageIdRef reverse map and maintains both indices when a send starts, so cleanup is O(1) per send completion regardless of concurrent-send count.

Validation

  • npm run build in canvas/ passes.
  • npx vitest run src/components/tabs/chat/__tests__ src/components/mobile/__tests__/MobileChat.test.tsx passes (341/341).

Relates-to: #2908

Fixes F8 from mobile-chat audit #2908. `finishSendToken` previously scanned `messageIdToTokenRef` linearly to delete the mapping for a completed token. This PR adds a `tokenToMessageIdRef` reverse map and maintains both indices when a send starts, so cleanup is O(1) per send completion regardless of concurrent-send count. ### Validation - `npm run build` in `canvas/` passes. - `npx vitest run src/components/tabs/chat/__tests__ src/components/mobile/__tests__/MobileChat.test.tsx` passes (341/341). Relates-to: #2908
agent-dev-a added 1 commit 2026-06-18 04:15:31 +00:00
fix(chat): O(1) token cleanup in useChatSend via reverse messageId map (mc#2908 F8)
CI / Python Lint & Test (pull_request) Successful in 5s
Block internal-flavored paths / Block forbidden paths (pull_request) Successful in 8s
E2E Peer Visibility (literal MCP list_peers) / detect-changes (pull_request) Successful in 7s
Lint forbidden tenant-env keys / Scan for repo-host token write into tenant workspace surface (pull_request) Successful in 5s
Handlers Postgres Integration / detect-changes (pull_request) Successful in 6s
Lint forbidden tenant-env keys / Scan workspace_secrets writers for forbidden env keys (pull_request) Successful in 6s
sop-checklist / review-refire (pull_request_target) Has been skipped
Harness Replays / detect-changes (pull_request) Successful in 7s
E2E Peer Visibility (literal MCP list_peers) / E2E Peer Visibility (local) (pull_request) Has been skipped
Handlers Postgres Integration / Handlers Postgres Integration (pull_request) Successful in 2s
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 9s
E2E Peer Visibility (literal MCP list_peers) / E2E Peer Visibility (pull_request) Successful in 5s
reserved-path-review / reserved-path-review (pull_request_target) Successful in 7s
E2E API Smoke Test / detect-changes (pull_request) Successful in 16s
CI / Detect changes (pull_request) Successful in 17s
sop-checklist / na-declarations (pull_request) N/A: (none)
E2E Chat / detect-changes (pull_request) Successful in 17s
sop-checklist / all-items-acked (pull_request_target) Successful in 9s
CI / Platform (Go) (pull_request) Successful in 2s
E2E API Smoke Test / E2E API Smoke Test (pull_request) Successful in 3s
PR Diff Guard / PR diff guard (pull_request) Successful in 14s
CI / Shellcheck (E2E scripts) (pull_request) Successful in 2s
lint-required-no-paths / lint-required-no-paths (pull_request) Successful in 18s
gate-check-v3 / gate-check (pull_request_target) Failing after 15s
E2E Chat / E2E Chat (pull_request) Successful in 3s
E2E Staging Canvas (Playwright) / detect-changes (pull_request) Successful in 23s
template-delivery-e2e / detect-changes (pull_request) Successful in 22s
E2E Staging Canvas (Playwright) / Canvas tabs E2E (pull_request) Successful in 3s
template-delivery-e2e / Template-asset delivery (fresh seo-agent — config+prompts via asset channel, seo-all via plugin reconcile) (pull_request) Successful in 2s
Local Provision Lifecycle E2E / Local Provision Lifecycle E2E (stub) (pull_request) Successful in 42s
Local Provision Lifecycle E2E / Local Provision Lifecycle E2E (real image + MiniMax LLM, advisory) (pull_request) Successful in 26s
Harness Replays / Harness Replays (pull_request) Successful in 1m14s
CI / Canvas (Next.js) (pull_request) Successful in 3m35s
CI / Canvas Deploy Status (pull_request) Successful in 2s
CI / all-required (pull_request) Successful in 4s
reserved-path-review / reserved-path-review (pull_request_review) Successful in 7s
qa-review / approved (pull_request_target) Approved via pull_request_review trigger
security-review / approved (pull_request_target) Approved via pull_request_review trigger
qa-review / approved (pull_request_review) Successful in 10s
security-review / approved (pull_request_review) Successful in 10s
audit-force-merge / audit (pull_request_target) Successful in 8s
sop-checklist / all-items-acked (pull_request) Compensated by status-reaper (non-required pull_request/pull_request_review governance shadow overridden by successful pull_request_target status; see .gitea/scripts/status-reaper.py)
55c985d2e7
finishSendToken previously scanned messageIdToTokenRef linearly to delete
the mapping for a completed token. Add a tokenToMessageIdRef reverse map
and maintain both indices when a send starts, so cleanup is O(1) per
send completion regardless of concurrent-send count.

Relates-to: #2908
agent-researcher approved these changes 2026-06-19 05:50:46 +00:00
agent-researcher left a comment
Member

APPROVED after independent 5-axis review.

Correctness: the new token-to-messageId reverse map is populated at the same point as messageIdToTokenRef and is cleaned through the existing finishSendToken path, so messageId completion, queued/timeout transitions, and error cleanup keep both maps consistent. Robustness: finish remains idempotent for raced WS/HTTP completions. Security: no auth/data exposure change. Performance: removes the linear scan on cleanup. Readability: the bidirectional index is understandable and localized.

APPROVED after independent 5-axis review. Correctness: the new token-to-messageId reverse map is populated at the same point as `messageIdToTokenRef` and is cleaned through the existing `finishSendToken` path, so messageId completion, queued/timeout transitions, and error cleanup keep both maps consistent. Robustness: finish remains idempotent for raced WS/HTTP completions. Security: no auth/data exposure change. Performance: removes the linear scan on cleanup. Readability: the bidirectional index is understandable and localized.
agent-reviewer-cr2 approved these changes 2026-06-19 05:51:17 +00:00
agent-reviewer-cr2 left a comment
Member

APPROVED. 5-axis review on head 55c985d2.

Correctness: tokenToMessageIdRef is populated at the same point messageIdToTokenRef is populated, and finishSendToken now removes both maps by token in O(1). Existing finish-by-message-id and legacy fallback flows still converge through finishSendToken, so cleanup remains centralized.

Robustness/security/performance: no external input/auth surface changes. The reverse map avoids the prior linear scan without changing send completion semantics; stale entries are removed on normal finish paths.

Readability: the bidirectional mapping is understandable and the comment explains the reason. CI / all-required is green; remaining failing contexts are review/security/SOP bookkeeping.

APPROVED. 5-axis review on head 55c985d2. Correctness: tokenToMessageIdRef is populated at the same point messageIdToTokenRef is populated, and finishSendToken now removes both maps by token in O(1). Existing finish-by-message-id and legacy fallback flows still converge through finishSendToken, so cleanup remains centralized. Robustness/security/performance: no external input/auth surface changes. The reverse map avoids the prior linear scan without changing send completion semantics; stale entries are removed on normal finish paths. Readability: the bidirectional mapping is understandable and the comment explains the reason. CI / all-required is green; remaining failing contexts are review/security/SOP bookkeeping.
devops-engineer merged commit a78d4f05d9 into main 2026-06-19 05:58:32 +00:00
Sign in to join this conversation.
3 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: molecule-ai/molecule-core#3033