Skip to content

fix(pin): guard null content block in isPinReply - #263

Open
dex0shubham wants to merge 1 commit into
teamchong:mainfrom
dex0shubham:fix/pin-null-block
Open

fix(pin): guard null content block in isPinReply#263
dex0shubham wants to merge 1 commit into
teamchong:mainfrom
dex0shubham:fix/pin-null-block

Conversation

@dex0shubham

@dex0shubham dex0shubham commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Problem

isPinReply (src/core/pin.ts) took the sole content block after a length check and read .type without guarding it:

const blk = blocks[0]!;
return (blk as { type?: string }).type === 'text' && ...

A null content block (e.g. {"role":"assistant","content":[null]} following a @pxpipe pin … command turn — the only path that evaluates isPinReply) passes the length !== 1 check, and blocks[0]!.type throws TypeError: Cannot read properties of null (reading 'type').

The throw is caught at the pin call site, so it doesn't 500 — instead the whole pin feature silently no-ops for that request: the raw @pxpipe pin … command lines stay in the outbound body (forwarded to the model) and the user's pinned rules are not re-emitted at the tail.

Every sibling that walks content blocks in this module guards this first (isCommandOnlyTurn, pinLines, systemPinLines, stripFromMessage all do if (!blk || typeof blk !== 'object')). isPinReply was the exception.

Fix

Add the same !!blk && typeof blk === 'object' guard, so a malformed turn is simply not treated as a pin reply.

Added a regression test (stripPinCommands with a null assistant block after a pin command) — it throws on the old code and passes with the fix.

Full suite green (1207/1207); typecheck clean.

isPinReply took blocks[0] after only a `blocks.length !== 1` check and read
`.type` off it. A null content block (e.g. an assistant turn `content: [null]`
following a `@pxpipe pin ...` command) passes the length check, and `blocks[0]!.type`
throws TypeError. The throw is caught upstream, so the effect is silent: pinning is
disabled for that request - the raw `@pxpipe pin` command lines are forwarded to the
model and the user's pinned rules are not re-emitted.

Every sibling that walks content blocks here guards this first (isCommandOnlyTurn,
pinLines, systemPinLines, stripFromMessage). Add the same `!!blk && typeof blk ===
'object'` guard so a malformed turn is simply not treated as a pin reply.
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