Skip to content

fix: guard against undefined session.title and part.tool in message-part - #337

Merged
jeonghun-jj-lee merged 1 commit into
local/amicodefrom
fix/task-session-undefined-title
Sep 11, 2026
Merged

fix: guard against undefined session.title and part.tool in message-part#337
jeonghun-jj-lee merged 1 commit into
local/amicodefrom
fix/task-session-undefined-title

Conversation

@jeonghun-jj-lee

Copy link
Copy Markdown
Contributor

Problem

Some Amicode users see a crash on app load:

TypeError: Cannot read properties of undefined (reading 'startsWith')
    at Object.fn (index-DkV_211M.js:1978:944)

The app fails to render when the most recent session contains Task tool calls whose child sessions have no title yet (spawned but not titled, or errored before the LLM generated one).

Root cause

taskSession() in message-part.tsx calls session.title.startsWith() and session.title.includes() without guarding for undefined. The Session type declares title: string (required), but at runtime titles can be absent for newly-spawned or errored sessions.

A secondary site, amicodeReceiptCandidateKey(), calls part.tool.startsWith() without a typeof check — same class of bug, though less likely to trigger in practice.

Fix

  • Lines 658–659: Add optional chaining — session.title?.startsWith() / session.title?.includes()
  • Line 716: Add typeof part.tool !== "string" guard before .startsWith() (matching the safe pattern in rail-gate.ts:31)
  • Extract findTaskSession and isAmicodeToolCall into message-part-task.ts with 14 unit tests covering the undefined-title and undefined-tool cases (same extraction pattern as message-part-text.ts)

Tests

TDD — failing tests written first, then fixed:

  • findTaskSession: 8 tests (normal matching, parentID filtering, archived skip, sort order, undefined title cases)
  • isAmicodeToolCall: 6 tests (normal matching, non-tool parts, undefined/null tool property)

All 394 session-ui tests pass. Typecheck clean across all 30 packages.

taskSession() crashes with 'Cannot read properties of undefined (reading
startsWith)' when a child session has no title (spawned but not yet titled,
or errored before the LLM generated one). The Session type declares title
as required string, but at runtime it can be undefined.

Similarly, amicodeReceiptCandidateKey() calls part.tool.startsWith()
without checking typeof — a tool-typed part with a missing tool name
would crash.

Fixes:
- Add optional chaining on session.title in taskSession() filters
- Add typeof guard on part.tool in amicodeReceiptCandidateKey()
- Extract findTaskSession/isAmicodeToolCall into message-part-task.ts
  with 14 unit tests covering the undefined-title and undefined-tool
  cases (same extraction pattern as message-part-text.ts)
@coderabbitai

coderabbitai Bot commented Sep 11, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: b8bcddb4-e9f5-4cf4-a744-4d93eca33cba


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@jeonghun-jj-lee
jeonghun-jj-lee merged commit 6fa55b6 into local/amicode Sep 11, 2026
4 checks passed
@jeonghun-jj-lee
jeonghun-jj-lee deleted the fix/task-session-undefined-title branch September 11, 2026 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant