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

Aperta Adatta ai principianti
#6,969 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript

Direzione di ricerca

Leggi packages/coding-agent/src/core/extensions/builtin/prompt-url-widget.ts e la definizione di BeforeAgentStartEvent in packages/coding-agent/src/core/extensions/types.ts. Verifica come i turni di consegna e di estensione popolano l’evento, quindi verifica che l’estensione gestisca i turni senza testo del prompt e che il tipo rifletta questo contratto. Il lavoro è completato quando i turni in background non producono più l’errore segnalato e la corrispondenza degli URL del prompt continua a funzionare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
TypeScript
Stelle
521
Fork
167
Merge medio
23h 39m
PR unite (30g)
692

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di code-yeongyu/senpi

Tutte le issue di code-yeongyu/senpi

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.