Skip to content

Perf: Optimize get_parent_session_id() to read only first line #4

@samkeen

Description

@samkeen

Current behavior

get_parent_session_id() in api/src/utils.py reads the entire JSONL file to extract the parent session ID:

content = agent_path.read_text()
lines = parse_jsonl_file(content)
if lines:
    return lines[0].get("sessionId")

Problem

For large sub-agent sessions with many messages, this reads unnecessary data. Only the first line is needed.

Proposed fix

with open(agent_path) as f:
    first_line = f.readline()
    if first_line:
        return json.loads(first_line).get("sessionId")

This would be more efficient for projects with many or large sub-agent files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions