Skip to content

[3832 by Claude Opus 5.5] Pi: agent type and PiAgent implementation for tasks, with full persisted execution events - #3849

Merged
integry merged 3 commits into
3831-epic-pi-coding-jmlfrom
3832/claude-opus-5-5-pi-agent-type-and-piagent-20261127-1622-0nl
Nov 27, 2026
Merged

integry merged 3 commits into
3831-epic-pi-coding-jmlfrom
3832/claude-opus-5-5-pi-agent-type-and-piagent-20261127-1622-0nl

Conversation

@propr-dev

@propr-dev propr-dev Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

AI Implementation Summary

Closes #3832

Branch: 3832/claude-opus-5-5-pi-agent-type-and-piagent-20261127-1622-0nl
Commits: ✅ Changes committed (989cf03)


AI Processing Completed

Execution Details:

Summary:
I've registered pi as a full agent type, and implementation tasks and PR follow-ups now run through Pi in JSON mode with the whole trace saved as execution events. The new tests pass (23 of 23). So do the existing suites I picked that touch agent types, models, reasoning levels, metrics, the watchdog and the CLI, plus the propr-ui Settings/config tests. Typecheck passes for every package and lint passes for core and root src/. I did not run a real containerised Pi task: there's no Docker here, so the full in-image run hasn't happened yet.

Agent type. pi is now in the shared and core type lists, createAgentFromConfig, the default config path (~/.pi/agent, overridable with PI_CONFIG_PATH/HOST_PI_DIR), the in-container path, the health-check models, the PR template's agent name, and the CLI and UI types. Now that pi is a real agent type, I removed the temporary image-only pi entry that #3839 added; AgentCliType is now just an alias for the agent type.

Invocation. Each run is pi -p --mode json --model <provider/id> [--thinking <level>] --session-dir /tmp/propr-pi-home/agent/sessions --no-approve, with the prompt on stdin.

  • Reasoning levels: low through max pass straight through. ultra and ultracode run at max. Unset or auto leaves the model's own default.
  • Docker: the container starts as root only so the existing entrypoint can set up the per-run Pi home, then Pi runs as node.
  • Pi config dir: mounted only if it exists on the host, because Docker would otherwise create it there owned by root. It is mounted read-write so the entrypoint can write refreshed sign-in tokens back.
  • Secrets: the GitHub token and provider API keys go in through the Docker client's environment, so they never appear in the command line.
  • Analysis runs: read-only workspace and no saved session. They get no tools, or only read,grep,find,ls when the caller allows read-only inspection.

Model IDs. These use the form pi-<provider>/<model>, with an optional :<thinking> suffix. The defaults are Opus 5.5, Sonnet 5.5, GPT-6.2 Astra, Gemini 4 Argon and Devstral 2 via OpenRouter. PR titles, aliases (e.g. llm-pi-devstral2) and pricing resolve to the underlying model. The startup config migration no longer drops Pi models that aren't in the catalog, and doesn't re-add default models an operator has removed.

Parser. It reads the session id, summary, success rule, per-response token sums and provider cost exactly as the issue specifies. Each tool call gets exactly one result event: Pi reports a result in both tool_execution_end and a toolResult message, and turn_end repeats it, so duplicates are skipped. The failed cat missing.txt call is recorded with is_error: true.

Things that behave differently from what you might assume:

  • Pi exits 0 even when the provider rejects the request. I checked this against a real Pi 1.6.1 run with a bad OpenRouter key: it ended with stopReason: "error" and exit code 0. The success rule catches this, and there's a test built from that output.
  • Provider cost needed a shared change. To use Pi's reported cost instead of ProPR pricing, I added a providerCostUsd field. It's passed through the result converters into recordLLMMetrics, which uses it before pricing. It is only set when every response says totalFromProvider, so other agents are unaffected.
  • Managed diagnostics skip Pi, because its sessions live in a per-run directory and the host dir holds nothing to inventory.
  • Context scouting stays off for Pi. It isn't added to the agents allowed to do repository scouting.

Watchdog. Pi's toolCall blocks, tool_execution_start/_end, toolResult messages and turn_end results are now tracked as tool calls. A long-running tool is held to the longer tool threshold instead of being treated as a stall.

Tests and docs. The fixture is at test/fixtures/pi/pi-1.6.1-json-tool-task.jsonl and the tests are in test/piAgent.test.ts. I updated two existing tests for the new type: a missing pi entry in agentDefaultConfigPaths and an expected error message in apiOpenCodeRoutes. docs/docs/features/agents-and-models.md now has a Pi row and a short Pi section.

Not done:

  • Launcher and CLI setup plumbing for HOST_PI_DIR (orchestrator, initStack, checkCommands).
  • A Pi parser for the live output view in the API.
  • Pi-specific fields in the agent settings dialog. Pi does now appear in the agent type selector automatically.

No preview was made: the only visible change is that new "Pi" option in the type selector.

Review digest

Risk-tiered paths

  • High risk: none
  • Normal risk (33 files)
    • packages/api/services/agentHealthCheck.ts (+1/−0)
    • packages/cli/src/api/agents.ts (+6/−4)
    • packages/core/src/agents/constants.ts (+6/−11)
    • packages/core/src/agents/createAgentFromConfig.ts (+3/−0)
    • packages/core/src/agents/impl/PiAgent.ts (added, +226/−0)
    • packages/core/src/agents/impl/piModelIds.ts (added, +69/−0)
    • packages/core/src/agents/impl/utils/failedAgentExecution.ts (+1/−0)
    • packages/core/src/agents/impl/utils/piDockerArgsBuilder.ts (added, +121/−0)
    • packages/core/src/agents/impl/utils/piExecutionResult.ts (added, +53/−0)
    • packages/core/src/agents/impl/utils/piOutputParser.ts (added, +318/−0)
    • packages/core/src/agents/types.ts (+4/−1)
    • packages/core/src/claude/claudeService.ts (+2/−0)
    • packages/core/src/claude/docker/agentOutputActivity.ts (+40/−2)
    • packages/core/src/config/agentConfigPaths.ts (+6/−3)
    • packages/core/src/config/configManager.ts (+2/−0)
    • packages/core/src/config/configManagerAgentMigrations.ts (+7/−2)
    • packages/core/src/config/configManagerReasoning.ts (+15/−0)
    • packages/core/src/config/modelAliases.ts (+21/−2)
    • packages/core/src/config/modelDefinitions.ts (+1/−0)
    • packages/core/src/config/modelLabelResolution.ts (+1/−1)
    • packages/core/src/index.ts (+5/−1)
    • packages/core/src/utils/llmMetrics.ts (+3/−3)
    • packages/core/src/utils/llmMetrics.types.ts (+2/−0)
    • packages/shared/src/index.ts (+2/−0)
    • packages/shared/src/modelDefinitions.ts (+27/−4)
    • packages/shared/src/prTemplate.ts (+1/−1)
    • packages/shared/src/reasoningLevels.ts (+10/−0)
    • propr-ui/src/api/proprTypes.ts (+2/−2)
    • src/daemon/managedDiagnostics.ts (+3/−1)
    • src/jobs/errorHandlers.ts (+2/−1)
    • src/jobs/issueJob/agent.ts (+3/−1)
    • src/jobs/prCommentJobUtils.ts (+2/−1)
    • src/jobs/prFileUtils.ts (+1/−0)
  • Low risk (5 files)
    • docs/docs/features/agents-and-models.md (+8/−1)
    • test/agentDefaultConfigPaths.test.ts (+1/−0)
    • test/apiOpenCodeRoutes.test.ts (+1/−1)
    • test/fixtures/pi/pi-1.6.1-json-tool-task.jsonl (added, +16/−0)
    • test/piAgent.test.ts (added, +292/−0)

Diff size: 38 files changed, +1,284/−43 lines

View task for the run's logs and conversation.


This PR was created automatically by ProPR after processing issue #3832.


💡 Need changes?

Comment on this PR to request refinements — the AI agent monitors comments and will update the implementation based on your feedback. Keep iterating until you're satisfied!

I've registered `pi` as a full agent type, and implementation tasks and PR follow-ups now run through Pi in JSON mode with the whole trace saved as execution events. The new tests pass (23 of 23). So do the existing suites I picked that touch agent types, models, reasoning levels, metrics, the watchdog and the CLI, plus the propr-ui Settings/config tests. Typecheck passes for every package and lint passes for core and root `src/`. I did not run a real containerised Pi task: there's no Docker here, so the full in-image run hasn't happened yet.

Agent type. `pi` is now in the shared and core type lists, `createAgentFromConfig`, the default config path (`~/.pi/agent`, overridable with `PI_CONFIG_PATH`/`HOST_PI_DIR`), the in-container path, the health-check models, the PR template's agent name, and the CLI and UI types. Now that `pi` is a real agent type, I removed the temporary image-only `pi` entry that #3839 added; `AgentCliType` is now just an alias for the agent type.

Invocation. Each run is `pi -p --mode json --model <provider/id> [--thinking <level>] --session-dir /tmp/propr-pi-home/agent/sessions --no-approve`, with the prompt on stdin.
- Reasoning levels: `low` through `max` pass straight through. `ultra` and `ultracode` run at `max`. Unset or `auto` leaves the model's own default.
- Docker: the container starts as root only so the existing entrypoint can set up the per-run Pi home, then Pi runs as `node`.
- Pi config dir: mounted only if it exists on the host, because Docker would otherwise create it there owned by root. It is mounted read-write so the entrypoint can write refreshed sign-in tokens back.
- Secrets: the GitHub token and provider API keys go in through the Docker client's environment, so they never appear in the command line.
- Analysis runs: read-only workspace and no saved session. They get no tools, or only `read,grep,find,ls` when the caller allows read-only inspection.

Model IDs. These use the form `pi-<provider>/<model>`, with an optional `:<thinking>` suffix. The defaults are Opus 5.5, Sonnet 5.5, GPT-6.2 Astra, Gemini 4 Argon and Devstral 2 via OpenRouter. PR titles, aliases (e.g. `llm-pi-devstral2`) and pricing resolve to the underlying model. The startup config migration no longer drops Pi models that aren't in the catalog, and doesn't re-add default models an operator has removed.

Parser. It reads the session id, summary, success rule, per-response token sums and provider cost exactly as the issue specifies. Each tool call gets exactly one result event: Pi reports a result in both `tool_execution_end` and a `toolResult` message, and `turn_end` repeats it, so duplicates are skipped. The failed `cat missing.txt` call is recorded with `is_error: true`.

Things that behave differently from what you might assume:
- Pi exits 0 even when the provider rejects the request. I checked this against a real Pi 1.6.1 run with a bad OpenRouter key: it ended with `stopReason: "error"` and exit code 0. The success rule catches this, and there's a test built from that output.
- Provider cost needed a shared change. To use Pi's reported cost instead of ProPR pricing, I added a `providerCostUsd` field. It's passed through the result converters into `recordLLMMetrics`, which uses it before pricing. It is only set when every response says `totalFromProvider`, so other agents are unaffected.
- Managed diagnostics skip Pi, because its sessions live in a per-run directory and the host dir holds nothing to inventory.
- Context scouting stays off for Pi. It isn't added to the agents allowed to do repository scouting.

Watchdog. Pi's `toolCall` blocks, `tool_execution_start`/`_end`, `toolResult` messages and `turn_end` results are now tracked as tool calls. A long-running tool is held to the longer tool threshold instead of being treated as a stall.

Tests and docs. The fixture is at `test/fixtures/pi/pi-1.6.1-json-tool-task.jsonl` and the tests are in `test/piAgent.test.ts`. I updated two existing tests for the new type: a missing `pi` entry in `agentDefaultConfigPaths` and an expected error message in `apiOpenCodeRoutes`. `docs/docs/features/agents-and-models.md` now has a Pi row and a short Pi section.

Not done:
- Launcher and CLI setup plumbing for `HOST_PI_DIR` (orchestrator, `initStack`, `checkCommands`).
- A Pi parser for the live output view in the API.
- Pi-specific fields in the agent settings dialog. Pi does now appear in the agent type selector automatically.

No preview was made: the only visible change is that new "Pi" option in the type selector.

ProPR-Agent: claude/claude-opus-5-5
@propr-dev

propr-dev Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

/ultrafix goal=8 max=8
Triggered automatically by the requested execution settings.

@propr-dev propr-dev Bot added the ultrafix label Nov 27, 2026
@propr-dev

propr-dev Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

🔄 Ultrafix loop started (goal: 8/10, max cycles: 8)

First action: /review

💡 Tip: Remove the ultrafix label from this PR to stop further ultrafix cycles.

@propr-dev

propr-dev Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ AI Code Review Complete requested by @propr-ultrafix

Posted 1 review:

View Task Details

@propr-dev

propr-dev Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

CI failed: Full Test Suite Shard 3/4

Please investigate and fix this CI failure.

  • Check: Full Test Suite Shard 3/4
  • Result: failure
  • Commit: 989cf0375300 (989cf0375300f1105556052e774e35a7533ba352)
  • Run: View CI failure

Failure evidence

.github:11
Process completed with exit code 1.

.github:53157
Process completed with exit code 1.

.github:2
Node.js 20 is deprecated. The following actions target Node.js 20 but are being forced to run on Node.js 24: actions/checkout@11d5960. For more information see: https://github.blog/changelog/2025-09-19-deprecation-of-node-20-on-github-actions-runners/

@propr-dev

propr-dev Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Applied the requested follow-up changes in commit 4301cd9

Summary of Changes

I fixed the one failing test in shard 3. Everything else in the shard passed.

Cause: test/cliAgentOpenCode.test.ts:29 checks the help text for the agent add command against a hard-coded list of agent types. This branch adds pi, so the help now reads Agent type (claude, codex, antigravity, opencode, vibe, pi). The old pattern ended at vibe) and no longer matched.

Fix: I added pi to the expected list in that pattern. The file now passes locally (3 of 3).

I also searched the other tests for the same hard-coded list. packages/cli/src/commands/setupCommand.test.ts has a similar one, but it's for skill targets, not agent types. This branch doesn't add pi to that list, so I left it alone.

No preview, since this only changes a test.

Review digest

Risk-tiered paths

  • High risk: none
  • Normal risk: none
  • Low risk (1 file)
    • test/cliAgentOpenCode.test.ts (+1/−1)

Diff size: 1 file changed, +1/−1 lines


🤖 Implementation Details

  • Model: Claude Opus 5.5 (medium)
  • Requested By: @propr-dev[bot]
  • Time: 3m 30s
  • Tokens: 384,759 (383,529 in / 1,230 out)
  • Cost: $0.32

Undo Changes • View Task Execution


💡 ProPR Slash Commands
Command Description Example
/merge Merge target branch into this PR and resolve conflicts /merge
/review Request an AI code review /review or /review claude-sonnet
/fix Address review blockers, or blockers and suggestions with /fix all /fix, /fix all, or /fix F3 S5
/switch Change the AI model for this PR /switch claude-opus
/use Override the model for a single follow-up run /use claude-sonnet
/ultrafix Loop review→fix cycles until score goal is met /ultrafix or /ultrafix goal=8 max=10

🤖 Generated by ProPR
Processing comment ID: 7224133308✓

I fixed the one failing test in shard 3. Everything else in the shard passed.

**Cause:** `test/cliAgentOpenCode.test.ts:29` checks the help text for the `agent add` command against a hard-coded list of agent types. This branch adds `pi`, so the help now reads `Agent type (claude, codex, antigravity, opencode, vibe, pi)`. The old pattern ended at `vibe)` and no longer matched.

**Fix:** I added `pi` to the expected list in that pattern. The file now passes locally (3 of 3).

I also searched the other tests for the same hard-coded list. `packages/cli/src/commands/setupCommand.test.ts` has a similar one, but it's for skill targets, not agent types. This branch doesn't add `pi` to that list, so I left it alone.

No preview, since this only changes a test.

PR: #3849
Comment by: @propr-dev[bot] (ID: 7224133308)
Model: Claude Opus 5.5

ProPR-Agent: claude/claude-opus-5-5
@propr-dev

propr-dev Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

CI failed: Validate unsigned linux-arm64 package

Please investigate and fix this CI failure.

  • Check: Validate unsigned linux-arm64 package
  • Result: failure
  • Commit: 4301cd91752a (4301cd91752a8de0f68c12bac5842d171fb2de86)
  • Run: View CI failure

Failure evidence

.github:9580
Process completed with exit code 1.

@propr-dev

propr-dev Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

ℹ️ Analyzed the follow-up request by @propr-dev[bot]

Analysis Summary

This failure has nothing to do with the Pi changes in this PR, so I didn't change any code. The CI job just needs a re-run, and I couldn't trigger one from here: gh run rerun --failed returned "Resource not accessible by integration".

What failed: one test in apps/desktop/scripts/signing-key-verification.test.mjs, "stored key pair verification signs and independently verifies the fixed challenge". It failed with RPM signing/verification tool failed: gpg, thrown by the GnuPG signing call at apps/desktop/scripts/linux-package-auth.mjs:25. That code hides the gpg error output on purpose so key material can't leak, so the log doesn't say why gpg failed. The other tests in that file, which run the same gpg steps, passed in the same job.

Why I think it's a one-off:

  • The same job passed on the previous commit of this branch, 989cf0375.
  • The only change between that commit and the failing one, 4301cd917, is one line in test/cliAgentOpenCode.test.ts.
  • This PR doesn't touch apps/desktop, .github or any dependencies.
  • The other package checks in that run show "cancelled" because the run stopped once this job failed. Nothing else failed.

I couldn't run the test myself: this container has no gpg or rpm, so it skips here.

Next step: re-run the failed jobs of run 46040453460, or push again to start a fresh run. If it fails the same way again, the cause would be on the runner side, and it would be worth seeing whether other branches hit it too.

I saved a note about this failure to memory. There's no visual change, so no preview.

No code changes were necessary based on the current state of the branch.


🤖 Analysis Details

  • Model: Claude Opus 5.5 (medium)
  • Time: 4m 12s
  • Tokens: 748,642 (744,924 in / 3,718 out)
  • Cost: $0.50

View Task Execution


💡 ProPR Slash Commands
Command Description Example
/merge Merge target branch into this PR and resolve conflicts /merge
/review Request an AI code review /review or /review claude-sonnet
/fix Address review blockers, or blockers and suggestions with /fix all /fix, /fix all, or /fix F3 S5
/switch Change the AI model for this PR /switch claude-opus
/use Override the model for a single follow-up run /use claude-sonnet
/ultrafix Loop review→fix cycles until score goal is met /ultrafix or /ultrafix goal=8 max=10

🤖 Generated by ProPR
Processing comment ID: 7224329519✓

@propr-dev

propr-dev Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

🔍 AI Code Review — codex:gpt-6-astra

Overall Evaluation

The PR adds Pi across agent registration, invocation, model routing, output parsing, and metrics. The approach is cohesive, but failure handling needs a localized correction before merge.

✅ Provider errors recognized — A zero process exit does not imply success: the parser also checks settlement, abort state, and the final assistant stop reason.

✅ Tool-result deduplication — Results repeated across Pi events are recorded once per tool-call ID, including their error status.

✅ Secret-safe arguments — Provider keys and scoped GitHub credentials are passed through the Docker client environment rather than embedded in arguments.

The supplied current-head status reports 35 passed checks and 12 skipped, with no failures. This review used the supplied code only; no commands were run.

Merge blockers

Every finding below was introduced by this PR and must be resolved before merging.

F1: 🔴 Preserve results after post-execution failures

  • Category: correctness

  • Required behavior: Once an execution has consumed tokens and produced a trace, a subsequent failure must preserve its usage, cost, session identity, and conversation for downstream recording.

  • Evidence: packages/core/src/agents/impl/PiAgent.ts:executeTask, buildFailedExecutionResult

    1. A Pi execution completes, and buildPiExecutionResult constructs a response containing its conversation, token usage, and authoritative provider cost.
    2. A subsequent awaited onSessionId callback rejects, or post-execution processing throws.
    3. The enclosing catch replaces the completed response with buildFailedExecutionResult, which retains none of those execution details.
    4. The job receives a failed response without the consumed tokens, provider cost, session, or conversation. If the callback failed, persistTaskLog was never reached either.

    static trace: The completed response is scoped inside the try block and is unavailable to the catch. The supplied shared failedExecutionResult helper explicitly supports retaining completed execution data, but Pi bypasses it. The new outcome tests exercise result construction, not failures after construction. A rejecting session callback is the concrete failure input here; no production callback failure or regression test was executed.

  • Minimum fix: Retain the completed response outside the try block and preserve its execution details when returning a failure. Reuse the shared failure helper where practical, ensuring it also retains providerCostUsd.

Suggestions

These are optional follow-ups and are not sent to /fix.

S1: 🟢 Exercise the actual container invocation

Add a container smoke test covering task execution and analysis, including credential import and execution as node. The current tests verify argument construction and recorded JSON, while the implementation summary explicitly notes that an actual container run was not performed. This would improve integration confidence; the missing smoke test alone is not a merge blocker.

S2: 🟢 Record suffix-derived reasoning

When a model ID supplies :high and no separate reasoning level is configured, buildPiCliArgs executes with high thinking, but result construction receives null and omits the reasoning field. Resolving the effective level once for both invocation and reporting would improve metadata consistency. The model ID still retains the suffix, so this is an observability follow-up.

Score

The integration has useful focused coverage and passing current checks. Preserving completed execution data across later failures is necessary before merge.

Score: 6/10


🤖 Review Details

  • Model: GPT-6 Astra
  • Time: 56s
  • Tokens: 77,578 (76,386 in / 1,192 out)
  • Cost: $0.71

View Task


💡 Next step: Comment /fix to address every F# merge blocker, /fix all for every pending blocker and suggestion, or name records explicitly, as in /fix F3 S5.
F# and S# IDs increment across review comments and remain permanent, so selectors such as /fix F3 F5 stay unambiguous across cycles. S# suggestions stay optional: they are implemented only when you name them or request /fix all, and they never relax a merge blocker.

Copy and edit to choose records from this review:

/fix F1 S1 S2

🤖 Review by ProPR

@propr-dev

propr-dev Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Applied the requested follow-up changes in commit e7c9e7e

Addressed 1 AI review comment (IDs: 7224957094)

Addressed finding F1

Summary of Changes

I fixed F1. When a Pi run has finished and something after it fails, the failed result now keeps what the run produced instead of discarding it. The new regression tests pass, and they fail against the previous PiAgent.ts.

Problem. Pi built the finished response inside the try, so the catch couldn't see it. A rejecting onSessionId callback, or a failing log write, produced a failed result with no tokens, cost, session or conversation. In the callback case the run's log row was never written either.

Changes:

  • packages/core/src/agents/impl/PiAgent.ts:
    • What a failure keeps: executeTask now holds the finished response outside the try. On any later failure it builds the result with the shared failedExecutionResult helper. That keeps the session id, conversation, token usage, cost, provider cost, provider model, reasoning level and execution id, and Pi also keeps the run's usage metrics.
    • Failures before Pi produced output: these keep the prompt and carry no run data, as before.
    • Log row: if the run finished but its log row was never written, it is now written once, marked failed, with Pi's provider cost. If that write fails too, a warning is logged and the failed result is still returned.
  • packages/core/src/agents/impl/utils/failedAgentExecution.ts: failedExecutionResult now also keeps providerCostUsd. Claude and Codex already route through this helper; they don't set that field today, so nothing changes for them.

Sibling check. Claude and Codex already keep the finished response this way and write the missing log row. Pi's analyze path doesn't have the bug: it has no awaited step between building the result and returning it.

Tests. The new file test/piAgentPostExecutionFailure.test.ts runs the real executeTask against the recorded Pi 1.6.1 trace, with only the Docker call replaced. It covers:

  • A rejecting session callback: the result keeps the run, and the log row is written exactly once.
  • A failing log write: the result still keeps the run.
  • Docker throwing before any output: the prompt is kept, there is no run data, and no row is written.
  • The shared helper keeping providerCostUsd.

All 4 pass, and 2 of them fail against the old PiAgent.ts. test/piAgent.test.ts and test/llmMetricsFailedExecutions.test.ts still pass (30 of 30). The core typecheck passes, and zero-warning lint passes on the two changed source files. Lint has no config that covers the new test file, so it wasn't linted.

One thing to know: when the log write itself is what fails, the failure path tries it once more. The Codex agent does the same.

No preview was made, because nothing visible changed.

Review digest

Risk-tiered paths

  • High risk: none
  • Normal risk (2 files)
    • packages/core/src/agents/impl/PiAgent.ts (+25/−5)
    • packages/core/src/agents/impl/utils/failedAgentExecution.ts (+1/−0)
  • Low risk (1 file)
    • test/piAgentPostExecutionFailure.test.ts (added, +118/−0)

Diff size: 3 files changed, +144/−5 lines


🤖 Implementation Details

  • Model: Claude Opus 5.5 (medium)
  • Requested By: @propr-ultrafix
  • Time: 5m 57s
  • Tokens: 1,437,277 (1,424,567 in / 12,710 out)
  • Cost: $0.91

View Task Execution


💡 ProPR Slash Commands
Command Description Example
/merge Merge target branch into this PR and resolve conflicts /merge
/review Request an AI code review /review or /review claude-sonnet
/fix Address review blockers, or blockers and suggestions with /fix all /fix, /fix all, or /fix F3 S5
/switch Change the AI model for this PR /switch claude-opus
/use Override the model for a single follow-up run /use claude-sonnet
/ultrafix Loop review→fix cycles until score goal is met /ultrafix or /ultrafix goal=8 max=10

🤖 Generated by ProPR

I fixed F1. When a Pi run has finished and something after it fails, the failed result now keeps what the run produced instead of discarding it. The new regression tests pass, and they fail against the previous `PiAgent.ts`.

**Problem.** Pi built the finished response inside the `try`, so the `catch` couldn't see it. A rejecting `onSessionId` callback, or a failing log write, produced a failed result with no tokens, cost, session or conversation. In the callback case the run's log row was never written either.

**Changes:**
- **`packages/core/src/agents/impl/PiAgent.ts`:**
  - **What a failure keeps:** `executeTask` now holds the finished response outside the `try`. On any later failure it builds the result with the shared `failedExecutionResult` helper. That keeps the session id, conversation, token usage, cost, provider cost, provider model, reasoning level and execution id, and Pi also keeps the run's usage metrics.
  - **Failures before Pi produced output:** these keep the prompt and carry no run data, as before.
  - **Log row:** if the run finished but its log row was never written, it is now written once, marked failed, with Pi's provider cost. If that write fails too, a warning is logged and the failed result is still returned.
- **`packages/core/src/agents/impl/utils/failedAgentExecution.ts`:** `failedExecutionResult` now also keeps `providerCostUsd`. Claude and Codex already route through this helper; they don't set that field today, so nothing changes for them.

**Sibling check.** Claude and Codex already keep the finished response this way and write the missing log row. Pi's `analyze` path doesn't have the bug: it has no awaited step between building the result and returning it.

**Tests.** The new file `test/piAgentPostExecutionFailure.test.ts` runs the real `executeTask` against the recorded Pi 1.6.1 trace, with only the Docker call replaced. It covers:
- A rejecting session callback: the result keeps the run, and the log row is written exactly once.
- A failing log write: the result still keeps the run.
- Docker throwing before any output: the prompt is kept, there is no run data, and no row is written.
- The shared helper keeping `providerCostUsd`.

All 4 pass, and 2 of them fail against the old `PiAgent.ts`. `test/piAgent.test.ts` and `test/llmMetricsFailedExecutions.test.ts` still pass (30 of 30). The core typecheck passes, and zero-warning lint passes on the two changed source files. Lint has no config that covers the new test file, so it wasn't linted.

One thing to know: when the log write itself is what fails, the failure path tries it once more. The Codex agent does the same.

No preview was made, because nothing visible changed.

PR: #3849
Comment by: @propr-ultrafix (ID: 0)
Model: Claude Opus 5.5

ProPR-Agent: claude/claude-opus-5-5
@propr-dev

propr-dev Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ AI Code Review Complete requested by @propr-ultrafix

Posted 1 review:

View Task Details

@propr-dev

propr-dev Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

🔍 AI Code Review — codex:gpt-6-astra

Overall Evaluation

The PR adds Pi across agent registration, execution, model routing, output parsing, and cost accounting. No merge-blocking defect is established by the supplied code. It is merge-ready within the reviewed scope, conditional on the remaining checks passing.

✅ Provider costs survive conversion — The authoritative cost field reaches metrics through task, PR-follow-up, and failed-result conversions, including zero-cost responses.

✅ Provider failures are recognized — Success requires a settled, unaborted run and rejects an assistant error even when Pi exits with code zero.

✅ Secret transport avoids argv — Provider keys and scoped GitHub credentials use Docker environment forwarding; configured GitHub credentials and reserved Pi variables are filtered.

This was a static review of the supplied diff and surrounding excerpts. No commands were run. Current checks report 30 passed, four pending, and ten neutral/skipped; container execution remains unverified here.

Merge blockers

No merge blockers.

Suggestions

These are optional follow-ups and are not sent to /fix.

S3: 🟢 Report model-suffix reasoning consistently

buildPiCliArgs applies a model’s thinking suffix when no explicit reasoning level exists, but PiAgent passes only the separately resolved level into task and analysis result construction. Consequently, a model such as pi-anthropic/claude-opus-5-5:high can run with high thinking while omitting reasoning metadata. Reusing the effective CLI level for reporting would improve observability. This is optional because the requested execution level is still applied.

S4: 🟢 Exercise host-path mounting in Docker

Add a smoke test covering both implementation and analysis using existing host credentials in a containerized deployment. In piDockerArgsBuilder.ts, mount inclusion depends on fs.existsSync(configPath) in the worker, whereas Docker resolves the mount source on its host. The supplied excerpts do not establish whether every supported deployment exposes that resolved path to the worker. Testing this would resolve an integration uncertainty; it is not a verified failure or a requirement to complete the deferred launcher plumbing.

Score

The implementation is cohesive and has targeted parser, invocation, watchdog, and post-execution failure coverage. No verified blocker remains, although the assessment is static and four current-head checks are still pending.

Score: 8/10


🤖 Review Details

  • Model: GPT-6 Astra
  • Time: 51s
  • Tokens: 80,059 (79,078 in / 981 out)
  • Cost: $0.71

View Task


💡 Next step: Comment /fix to address every F# merge blocker, /fix all for every pending blocker and suggestion, or name records explicitly, as in /fix F3 S5.
F# and S# IDs increment across review comments and remain permanent, so selectors such as /fix F3 F5 stay unambiguous across cycles. S# suggestions stay optional: they are implemented only when you name them or request /fix all, and they never relax a merge blocker.

Copy and edit to choose records from this review:

/fix S3 S4

🤖 Review by ProPR

@propr-dev propr-dev Bot removed the ultrafix label Nov 27, 2026
@propr-dev propr-dev Bot changed the title 🔨 [3832 by Claude Opus 5.5] Pi: agent type and PiAgent implementation for tasks, with full persisted execution events ✅❽ [3832 by Claude Opus 5.5] Pi: agent type and PiAgent implementation for tasks, with full persisted execution events Nov 27, 2026
@integry
integry merged commit a6f4c6f into 3831-epic-pi-coding-jml Nov 27, 2026
50 checks passed
@propr-dev propr-dev Bot changed the title ✅❽ [3832 by Claude Opus 5.5] Pi: agent type and PiAgent implementation for tasks, with full persisted execution events [3832 by Claude Opus 5.5] Pi: agent type and PiAgent implementation for tasks, with full persisted execution events Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant