Skip to content

Bug: dist/export-html/template.js content.filter crash — missing Array.isArray guard in dist bundle #88255

Closed

Description

@survivor998

Summary

The content.filter is not a function TypeError has been partially fixed upstream in pi-agent-core/dist/agent-loop.js and pi-coding-agent/dist/core/export-html/template.js (both now have Array.isArray() guards). However, the dist bundle dist/export-html/template.js still lacks this guard, leaving the crash vector open.

Reproduction

In dist/export-html/template.js at the msg.content.filter() call site (line ~1477 in v2026.5.28), if msg.content is undefined, null, or a non-array value, the following crash occurs:

TypeError: msg.content.filter is not a function

Root Cause

The source files in pi-agent-core and pi-coding-agent packages were patched with Array.isArray() guards, but the bundled dist artifact dist/export-html/template.js was not regenerated with the same fix, or the bundle copies from an older unpatched source.

Suggested Fix

Apply the same Array.isArray() guard pattern used in pi-coding-agent/dist/core/export-html/template.js:

// Before (vulnerable):
msg.content.filter((c) => c.type === "toolCall")

// After (safe):
(Array.isArray(msg.content) ? msg.content : []).filter((c) => c.type === "toolCall")

Environment

Workaround

Users can manually patch the dist bundle file or use the community safe-upgrade script that applies this guard automatically.

Activity

  1. clawsweeper commented on May 30, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed May 30, 2026, 2:22 AM ET / 06:22 UTC.

    Summary
    Keep open. Current main and v2026.5.27 still call msg.content.filter in the export HTML template after accepting message rows without validating message.content, so the reported export viewer crash remains a real source bug.

    Reproducibility: yes. at source level: a transcript message row with an assistant role but non-array or missing content passes export parsing and reaches msg.content.filter in the template stats path. I did not run the browser template in this read-only review.

    Next step
    This is a safe focused repair candidate, but not an automatic strict-bug lane because the review established source-level reproduction rather than a live current-main browser run.

    Review details

    Best possible solution:

    Normalize message and tool-result content before every template filter/iteration path, add a regression render test for malformed assistant content, and let the build copy step regenerate the dist bundle from source.

    Do we have a high-confidence way to reproduce the issue?

    Yes at source level: a transcript message row with an assistant role but non-array or missing content passes export parsing and reaches msg.content.filter in the template stats path. I did not run the browser template in this read-only review.

    Is this the best way to solve the issue?

    Yes, the maintainable fix is to update the source export template and regression tests, not only patch a generated dist artifact. The repair should audit sibling content access sites so the malformed-message class is fixed consistently.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • A one-line stats-only guard could leave adjacent unguarded msg.content iteration and filtering paths in the same template vulnerable to the same malformed transcript shape.

    Codex review notes: model gpt-5.5, reasoning high; reviewed against 5aa2bd792124.

    Label changes

    Label changes:

    • add P2: This is a normal-priority export viewer crash with a clear source path and limited blast radius.
    • add impact:other: The concrete impact is a broken exported-session HTML viewer, which is maintainer-visible but outside the specific owned impact categories.
    • add issue-rating: 🦞 diamond lobster: Current issue advisory state selects this label.
    • add clawsweeper:source-repro: Current issue advisory state selects this label.
    • add clawsweeper:queueable-fix: Current issue advisory state selects this label.
    • add clawsweeper:fix-shape-clear: Current issue advisory state selects this label.

    Label justifications:

    • P2: This is a normal-priority export viewer crash with a clear source path and limited blast radius.
    • impact:other: The concrete impact is a broken exported-session HTML viewer, which is maintainer-visible but outside the specific owned impact categories.
    Evidence reviewed

    Acceptance criteria:

    • node scripts/run-vitest.mjs src/auto-reply/reply/export-html/template.security.test.ts
    • node scripts/run-vitest.mjs src/auto-reply/reply/commands-export-session.test.ts
    • node --experimental-strip-types scripts/copy-export-html-templates.ts

    What I checked:

    • Current source still has the unguarded filter: computeStats() still does msg.content.filter((c) => c.type === "toolCall") for assistant messages, which will throw when a parsed transcript has missing, null, string, or otherwise non-array content. (src/auto-reply/reply/export-html/template.js:1477, 5aa2bd792124)
    • Malformed content can reach the template: The export parser accepts message entries when message.role is a string and does not validate message.content, then passes those entries into HTML generation after migration. (src/auto-reply/reply/commands-export-session.ts:168, 5aa2bd792124)
    • Latest release still has the same shipped line: The latest release tag v2026.5.27 contains the same unguarded msg.content.filter call, so the issue is not already fixed in the shipped release. (src/auto-reply/reply/export-html/template.js:1477, 27ae826f6525)
    • Generated dist comes from the source template: The build-all profile copies src/auto-reply/reply/export-html into dist/auto-reply/reply/export-html, so the durable fix belongs in the source template and its tests rather than only a hand-edited dist artifact. (scripts/build-all.mjs:84, 5aa2bd792124)
    • History points to the export template feature path: The bundled export HTML template and copy script were introduced in f70b3a2, and git log -S shows the unguarded stats filter carried through v2026.5.27 and current main. (src/auto-reply/reply/export-html/template.js:1477, f70b3a2e6878)

    Likely related people:

    • boris: Introduced the bundled export HTML template and copy script where computeStats() included the unguarded tool-call filter. (role: introduced behavior; confidence: high; commits: f70b3a2e6878, add3afb7439e; files: src/auto-reply/reply/export-html/template.js, scripts/copy-export-html-templates.ts, src/auto-reply/reply/commands-export-session.ts)
    • Peter Steinberger: Recent export-template hardening and release work touched or carried the same template path, and shortlog shows the most commits on the export session/template surface. (role: recent area contributor; confidence: medium; commits: f8524ec77a39, e578521ef493, 82c4f8ca2265; files: src/auto-reply/reply/export-html/template.js, scripts/copy-export-html-templates.ts)
    • Ayaan Zaidi: Current main carries recent edits on the export template path, including the HEAD commit that updated the same file after v2026.5.27. (role: recent current-main contributor; confidence: medium; commits: 1659b2615185, d25b493c7f79, 4bf902de5851; files: src/auto-reply/reply/export-html/template.js)
    How this review workflow works
    • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
    • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
    • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
    • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
    • Maintainers can also comment @clawsweeper review to request a fresh review only.
    • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
    • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
  2. added
    P2Normal backlog priority with limited blast radius.
    impact:otherThis issue has meaningful maintainer-visible impact outside the owned taxonomy.
    issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.
    clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.
    clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.
    clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.
    on May 30, 2026
  3. added a commit that references this issue on May 30, 2026
    2a4aaef
  4. added a commit that references this issue on May 30, 2026
    5811693
  5. steipete commented on May 30, 2026

    @steipete
    Contributor

    Fixed by PR #88271, landed as 5811693c7fce16f9780b904eb9159378f48734ec.

    Proof: targeted export-html security tests passed 13/13 with node scripts/run-vitest.mjs src/auto-reply/reply/export-html/template.security.test.ts; autoreview was clean; changed-path scan, security scans, lint/types/build, and auto-reply CI shards passed on the PR head. The remaining broad CI failures were unrelated Vitest no-output watchdog timeouts in doctor/infra shards.

  6. added a commit that references this issue on May 31, 2026
    4d01c63
  7. locked as resolved and limited conversation to collaborators on Jun 2, 2026
  8. added a commit that references this issue on Jun 10, 2026
    28979ca
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:otherThis issue has meaningful maintainer-visible impact outside the owned taxonomy.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions