fix: adapt to AgentState.error → errorMessage rename

pi-coding-agent 0.70 replaced the mutable \`AgentState.error\` field with
a readonly \`AgentState.errorMessage\`. \`session.prompt()\` still does
not throw when retries are exhausted, so we still need to re-raise the
stored error after each prompt.

- checkSessionError (usage-limit-detector): widen parameter to accept
  either key; prefer errorMessage so new sessions work, fall back to
  error so we can deploy without forcing everyone's caches to rebuild.
- agent-reflection: same widening at the call site.
- pi.ts helpers: read both keys, best-effort clear both (the new field
  is readonly, so the write is a no-op on 0.70 sessions but still
  matters for mock sessions in tests).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
gsxdsm
2026-04-23 17:13:45 -07:00
parent 6a8568e77c
commit 4ce0bf57ac
3 changed files with 29 additions and 16 deletions

View File

@@ -47,20 +47,28 @@ export interface PromptableSession extends AgentSession {
}
function getSessionStateError(session: AgentSession): string {
const error = (session as any).state?.error;
const state = (session as any).state;
const error = state?.errorMessage ?? state?.error;
return typeof error === "string" ? error : "";
}
function clearSessionStateError(session: AgentSession): void {
const state = (session as any).state;
if (!state || typeof state !== "object" || !("error" in state)) {
if (!state || typeof state !== "object") {
return;
}
try {
state.error = undefined;
} catch {
// Best effort only. Some session implementations may expose readonly state.
// pi-coding-agent 0.70+ exposes `errorMessage` as readonly — writes are
// silently ignored. Pre-0.70 used mutable `state.error`. Best-effort clear
// both so transcripts carry forward to the next prompt cleanly.
for (const key of ["errorMessage", "error"]) {
if (key in state) {
try {
state[key] = undefined;
} catch {
// readonly — no-op
}
}
}
}