prompt-url-widget: before_agent_start throws "Cannot read properties of undefined (reading 'match')" on every background/extension turn

Open Beginner friendly
#6,969 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript

Research direction

Read packages/coding-agent/src/core/extensions/builtin/prompt-url-widget.ts and the BeforeAgentStartEvent definition in packages/coding-agent/src/core/extensions/types.ts. Check how delivery and extension turns populate the event, then verify the extension handles turns without prompt text and the type reflects that contract. Done means background turns no longer produce the reported error while prompt URL matching still works.

Written by the indexing model from the issue text.

Description

Summary

The builtin prompt-url-widget extension throws on every non-prompt turn:

prompt-url-widget failed during before_agent_start.
Cannot read properties of undefined (reading 'match')

It fires reliably (>10 times per session) whenever a turn starts from background activity — e.g. a delegated subagent finishing, or any trigger: "extension" / "delivery" turn.

Environment

  • @code-yeongyu/senpi 2026.9.27
  • Linux x64, Bun global install
  • Occurs in the TUI with a UI context available (ctx.hasUI === true)

Reproduction

  1. Start a session in the TUI.
  2. Delegate work to a background subagent (or let any background activity complete so it starts a turn).
  3. On the resulting before_agent_start, the extension errors out.

No GitHub PR/issue URL is involved — the failure happens before any pattern matching could meaningfully run.

Root cause

packages/coding-agent/src/core/extensions/builtin/prompt-url-widget.ts:103

const onBeforeAgentStart: ExtensionHandler<BeforeAgentStartEvent, BeforeAgentStartEventResult> = async (
    event,
    ctx,
) => {
    if (event.preview === true || !ctx.hasUI) return;
    const match = extractPromptMatch(event.prompt);   // <- event.prompt is undefined here

and extractPromptMatch (:26) dereferences unconditionally:

function extractPromptMatch(prompt: string): PromptMatch | undefined {
    const prMatch = prompt.match(PR_PROMPT_PATTERN);   // TypeError

BeforeAgentStartEvent.prompt is typed as prompt: string (non-optional) in
packages/coding-agent/src/core/extensions/types.ts:1745, but the same interface documents that
turns can start with trigger: "delivery" or trigger: "extension", where no user prompt exists.
So the declared type does not match the runtime contract.

Suggested fix

Two independent layers (either one stops the crash; both together fix the contract):

1. Defensive guard in the extension (extractPromptMatch):

function extractPromptMatch(prompt: string | undefined): PromptMatch | undefined {
    if (typeof prompt !== "string") return undefined;
    const prMatch = prompt.match(PR_PROMPT_PATTERN);
    // ...

2. Correct the event type so extension authors are not misled:

export interface BeforeAgentStartEvent {
    type: "before_agent_start";
    /** The raw user prompt text (after expansion). Absent for `delivery` / `extension` turns. */
    prompt?: string;
    trigger: "prompt" | "delivery" | "extension";
    // ...

Verified locally: with the guard applied, undefined / null / "" / non-string inputs all return undefined instead of throwing, and legitimate PR/issue prompts still resolve correctly.

Impact

Low (cosmetic) — the throw is caught by the extension host and surfaced as a UI error notice; it does not block the turn or corrupt state. But it produces a spurious red error line on essentially every background-triggered turn, which trains users to ignore extension errors.

Workaround

Apply the guard to the compiled artifact until a release ships:

node_modules/@code-yeongyu/senpi/dist/core/extensions/builtin/prompt-url-widget.js

or delete ~/.config/pi/extensions/prompt-url-widget.js to disable the builtin extension entirely.

Dominant language
TypeScript
Stars
521
Forks
167
Avg merge
23h 39m
Merged PRs (30d)
692

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from code-yeongyu/senpi

All issues in code-yeongyu/senpi

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.