fix: guard against undefined session.title and part.tool in message-part - #337
Merged
Merged
Conversation
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)
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 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. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Some Amicode users see a crash on app load:
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()inmessage-part.tsxcallssession.title.startsWith()andsession.title.includes()without guarding forundefined. TheSessiontype declarestitle: string(required), but at runtime titles can be absent for newly-spawned or errored sessions.A secondary site,
amicodeReceiptCandidateKey(), callspart.tool.startsWith()without atypeofcheck — same class of bug, though less likely to trigger in practice.Fix
session.title?.startsWith()/session.title?.includes()typeof part.tool !== "string"guard before.startsWith()(matching the safe pattern inrail-gate.ts:31)findTaskSessionandisAmicodeToolCallintomessage-part-task.tswith 14 unit tests covering the undefined-title and undefined-tool cases (same extraction pattern asmessage-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.