Skip to content

[3831 by Claude Opus 5.5] Pi: install the CLI in the agent image with a disposable runtime and safe credential handling - #3839

Merged
integry merged 3 commits into
3831-epic-pi-coding-jmlfrom
3831/claude-opus-5-5-pi-install-the-cli-in-the-20261127-1443-62s
Nov 27, 2026
Merged

integry merged 3 commits into
3831-epic-pi-coding-jmlfrom
3831/claude-opus-5-5-pi-install-the-cli-in-the-20261127-1443-62s

Conversation

@propr-dev

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

Copy link
Copy Markdown
Contributor

AI Implementation Summary

Closes #3831

Branch: 3831/claude-opus-5-5-pi-install-the-cli-in-the-20261127-1443-62s
Commits: ✅ Changes committed (0f5b94c)


AI Processing Completed

Execution Details:

Summary:
Pi 1.6.1 is now in the agent image, with its own entrypoint and the credential write-back helper. I couldn't build the image here because there's no Docker in this container, so the image build and the new smoke checks haven't run. Their first real run will be CI.

Tested:

  • I installed Pi 1.6.1 from npm and ran the Dockerfile's pi --version / pi --help flag check against it; it passes and catches a missing flag.
  • Through a local logging proxy, Pi sent its provider traffic via HTTPS_PROXY and contacted only the provider host (api.anthropic.com, openrouter.ai). It made no pi.dev calls in -p mode.
  • The new test file test/piCredentials.test.ts (23 cases) passes. It covers the credential helper and runs the entrypoint as a non-root user with a stand-in pi.
  • The related suites pass, and typecheck (core, API, root) and core lint are clean.
  • One test fails, and it was already failing: thirdPartyNotices "committed notice carries the date…". The Generated: date in THIRD_PARTY_LICENSES.md doesn't match the last package-lock.json commit; I didn't change either.

Decision for you: the issue asks for pi: '1.6.1' in AGENT_DEFAULT_VERSIONS, but pi only becomes an agent type in #3832. Adding it to AgentType now would ripple through the UI and about 40 typed lookup tables. Instead I added an AgentCliType (the agent types plus pi) and used it only for the image version tables, labels, build args, egress lists and the entrypoint map. When #3832 adds pi as an agent type the extra entry deduplicates itself and nothing else needs undoing. The catch: if you'd rather pi became a full agent type in this change, that pulls a chunk of #3832 forward.

What's in place:

  • Image: a pi-cli stage installs @earendil-works/pi-coding-agent@${PI_CLI_VERSION} (default 1.6.1), checks pi --version and that pi --help lists the eight required flags, and puts pi on PATH. The final image gets a dev.propr.agent.pi.version label. scripts/build-images.sh has the matching PI_CLI_VERSION. Both content-hash lists and the app image's build context include the new files. Npm version lookup works for the scoped package.
  • Entrypoint (scripts/pi-entrypoint.sh), dispatched from agent-entrypoint.sh:
    • Each run starts with a fresh /tmp/propr-pi-home/agent as PI_CODING_AGENT_DIR, with sessions under it.
    • It copies only auth.json, settings.json, models.json, AGENTS.md, SYSTEM.md and APPEND_SYSTEM.md from PROPR_PI_SOURCE_DIR. Host sessions/, extensions/ and mcp.json are never copied; ProPR can supply its own mcp.json through PROPR_PI_MCP_CONFIG.
    • It sets PI_SKIP_VERSION_CHECK=1 and PI_TELEMETRY=0. It also sets PI_OFFLINE=1, which the issue didn't ask for. It stops Pi's startup model-catalog fetch from pi.dev, and the value can be overridden.
    • Every Pi or helper call (seed, version probe, the task, sync) goes through su-exec node. The task's exit status is passed through.
    • Provider API-key env vars pass through unchanged.
  • Credentials (scripts/pi-credentials.py): seed saves an owner-only snapshot of the imported auth.json before Pi touches it. sync writes refreshed OAuth entries back one provider at a time, only if the host entry still equals the snapshot. It never rewrites API-key entries, never adds or removes providers, and writes nothing if no OAuth entry changed. The write is atomic: temp file opened with O_CREAT|O_EXCL, 0o600, original mode kept. It also takes Pi's own auth.json.lock (same format as Pi's locking library), so it can't interleave with a host Pi refresh; stale locks are taken over.
  • Egress: Pi's allowlist covers Anthropic, OpenAI and ChatGPT sign-in, OpenRouter, Gemini and GitHub Copilot, including their token-refresh hosts. pi.dev and radius.pi.dev are excluded, and Pi is marked as proxy-compatible.
  • Smoke tests: scripts/smoke-test-images.sh runs pi --version through the entrypoint and compares it with the image label. It also starts the entrypoint as --user 0:0 with a mounted source dir and fails if anything under /tmp/propr-pi-home isn't owned by node. The preview-image smoke test covers Pi the same way.
  • Other: third-party notices list the new package as MIT, and agent-runtime.md has a short Pi section. I updated the existing test fixtures that list image labels, and added a Pi case to the provider-egress test.

There's nothing visible to capture, so I made no preview.

Review digest

Risk-tiered paths

  • High risk (1 file)
    • scripts/pi-credentials.py (added, +166/−0): auth-looking path
  • Normal risk (19 files)
    • Dockerfile.agent (+26/−0)
    • docker/Dockerfile.app.prod (+2/−0)
    • packages/core/src/agents/constants.ts (+11/−0)
    • packages/core/src/agents/managedAgentImage.ts (+2/−2)
    • packages/core/src/agents/managedAgentPin.ts (+4/−4)
    • packages/core/src/agents/version/types.ts (+13/−9)
    • packages/core/src/agents/version/versionService.ts (+11/−10)
    • packages/core/src/claude/docker/dockerImageBuilder.ts (+2/−1)
    • packages/core/src/claude/docker/repoSetupWrapper.ts (+8/−6)
    • packages/core/src/index.ts (+2/−2)
    • packages/core/src/network/egressAllowlist.ts (+20/−5)
    • packages/core/src/network/egressExecution.ts (+4/−4)
    • scripts/agent-entrypoint.sh (+4/−3)
    • scripts/build-images.sh (+6/−1)
    • scripts/generate-notices.sh (+9/−2)
    • scripts/pi-entrypoint.sh (added, +141/−0)
    • scripts/preview-runtime-images.mjs (+1/−0)
    • scripts/smoke-test-images.sh (+47/−2)
    • scripts/smoke-test-preview-agent-image.sh (+4/−2)
  • Low risk (12 files)
    • THIRD_PARTY_LICENSES.md (+6/−0)
    • docs/docs/architecture/agent-runtime.md (+6/−0)
    • packages/core/test/egressProxy.test.ts (+11/−1)
    • test/agentBundleContentFiles.test.ts (+2/−1)
    • test/agentDockerfileSupplyChain.test.ts (+1/−1)
    • test/agentProviderEgress.test.ts (+7/−2)
    • test/agentRegistryManagedAgentPin.test.ts (+1/−0)
    • test/agentVersionManagement.test.ts (+56/−0)
    • test/piCredentials.test.ts (added, +464/−0)
    • test/previewAgentImage.test.mjs (+2/−1)
    • test/previewCliPackage.test.mjs (+1/−1)
    • test/releaseRolloutWorkflow.test.mjs (+1/−1)

Diff size: 32 files changed, +1,041/−61 lines

View task for the run's logs and conversation.


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


💡 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!

Pi 1.6.1 is now in the agent image, with its own entrypoint and the credential write-back helper. I couldn't build the image here because there's no Docker in this container, so the image build and the new smoke checks haven't run. Their first real run will be CI.

Tested:
- I installed Pi 1.6.1 from npm and ran the Dockerfile's `pi --version` / `pi --help` flag check against it; it passes and catches a missing flag.
- Through a local logging proxy, Pi sent its provider traffic via `HTTPS_PROXY` and contacted only the provider host (`api.anthropic.com`, `openrouter.ai`). It made no `pi.dev` calls in `-p` mode.
- The new test file `test/piCredentials.test.ts` (23 cases) passes. It covers the credential helper and runs the entrypoint as a non-root user with a stand-in `pi`.
- The related suites pass, and typecheck (core, API, root) and core lint are clean.
- One test fails, and it was already failing: `thirdPartyNotices` "committed notice carries the date…". The `Generated:` date in `THIRD_PARTY_LICENSES.md` doesn't match the last `package-lock.json` commit; I didn't change either.

Decision for you: the issue asks for `pi: '1.6.1'` in `AGENT_DEFAULT_VERSIONS`, but `pi` only becomes an agent type in #3832. Adding it to `AgentType` now would ripple through the UI and about 40 typed lookup tables. Instead I added an `AgentCliType` (the agent types plus `pi`) and used it only for the image version tables, labels, build args, egress lists and the entrypoint map. When #3832 adds `pi` as an agent type the extra entry deduplicates itself and nothing else needs undoing. The catch: if you'd rather `pi` became a full agent type in this change, that pulls a chunk of #3832 forward.

What's in place:
- Image: a `pi-cli` stage installs `@earendil-works/pi-coding-agent@${PI_CLI_VERSION}` (default 1.6.1), checks `pi --version` and that `pi --help` lists the eight required flags, and puts `pi` on PATH. The final image gets a `dev.propr.agent.pi.version` label. `scripts/build-images.sh` has the matching `PI_CLI_VERSION`. Both content-hash lists and the app image's build context include the new files. Npm version lookup works for the scoped package.
- Entrypoint (`scripts/pi-entrypoint.sh`), dispatched from `agent-entrypoint.sh`:
  - Each run starts with a fresh `/tmp/propr-pi-home/agent` as `PI_CODING_AGENT_DIR`, with sessions under it.
  - It copies only `auth.json`, `settings.json`, `models.json`, `AGENTS.md`, `SYSTEM.md` and `APPEND_SYSTEM.md` from `PROPR_PI_SOURCE_DIR`. Host `sessions/`, `extensions/` and `mcp.json` are never copied; ProPR can supply its own `mcp.json` through `PROPR_PI_MCP_CONFIG`.
  - It sets `PI_SKIP_VERSION_CHECK=1` and `PI_TELEMETRY=0`. It also sets `PI_OFFLINE=1`, which the issue didn't ask for. It stops Pi's startup model-catalog fetch from `pi.dev`, and the value can be overridden.
  - Every Pi or helper call (seed, version probe, the task, sync) goes through `su-exec node`. The task's exit status is passed through.
  - Provider API-key env vars pass through unchanged.
- Credentials (`scripts/pi-credentials.py`): `seed` saves an owner-only snapshot of the imported `auth.json` before Pi touches it. `sync` writes refreshed OAuth entries back one provider at a time, only if the host entry still equals the snapshot. It never rewrites API-key entries, never adds or removes providers, and writes nothing if no OAuth entry changed. The write is atomic: temp file opened with `O_CREAT|O_EXCL, 0o600`, original mode kept. It also takes Pi's own `auth.json.lock` (same format as Pi's locking library), so it can't interleave with a host Pi refresh; stale locks are taken over.
- Egress: Pi's allowlist covers Anthropic, OpenAI and ChatGPT sign-in, OpenRouter, Gemini and GitHub Copilot, including their token-refresh hosts. `pi.dev` and `radius.pi.dev` are excluded, and Pi is marked as proxy-compatible.
- Smoke tests: `scripts/smoke-test-images.sh` runs `pi --version` through the entrypoint and compares it with the image label. It also starts the entrypoint as `--user 0:0` with a mounted source dir and fails if anything under `/tmp/propr-pi-home` isn't owned by `node`. The preview-image smoke test covers Pi the same way.
- Other: third-party notices list the new package as MIT, and `agent-runtime.md` has a short Pi section. I updated the existing test fixtures that list image labels, and added a Pi case to the provider-egress test.

There's nothing visible to capture, so I made no preview.

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 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

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

Overall Evaluation

The PR adds Pi to the unified image, version metadata, entrypoint dispatch, and restricted networking without prematurely exposing it as a selectable agent. It needs changes before merge because two filesystem cases can damage or misdirect host credential state.

✅ Consistent image integration — Pi participates in build arguments, image labels, version hashes, managed-image verification, and build-context file lists.

✅ Selective credential updates — The helper compares OAuth entries against their seeded values and preserves concurrent host changes and API-key entries.

This review used static analysis of the supplied code only; no commands were run. Current checks show 19 passed, five pending, and no failures.

Merge blockers

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

F1: 🔴 Reject runtime paths that contain host credentials

  • Category: correctness

  • Required behavior: Preparing disposable Pi state must not delete the mounted host credential source.

  • Evidence: scripts/pi-entrypoint.sh:24–30, prepare_runtime_home

    1. Set the supported PROPR_PI_RUNTIME_HOME override to /home/node/.pi, leaving the source at its default /home/node/.pi/agent.
    2. The guard checks whether the runtime home is inside the source. The runtime home is its parent, so validation passes.
    3. pi_agent_dir becomes /home/node/.pi/agent, and rm -rf -- "$pi_agent_dir" runs before importing any files.
    4. With a writable host .pi directory mounted at /home/node/.pi, this deletes the host credentials, sessions, and extensions. With the agent directory itself mounted, deletion can remove its contents before failing to remove the mount point.

    The existing containment check protects only the opposite direction. static trace: the configurable path assignments, guard, and deletion order directly establish this sequence; it was not executed.

  • Minimum fix: Before any deletion or ownership changes, canonicalize both paths and reject overlap in either direction between the host source and disposable runtime home.

F2: 🔴 Preserve symlinked credential destinations

  • Category: correctness

  • Required behavior: Credential write-back must update the host credential file without replacing its symlink or leaving its backing credential store stale.

  • Evidence: scripts/pi-credentials.py:sync, AuthLock.__init__, and write_private

    1. The mounted source contains auth.json as a symlink to another accessible credential file. The entrypoint explicitly follows that link with cp -L, so importing and seeding succeed.
    2. Pi refreshes an OAuth entry in the disposable copy.
    3. AuthLock resolves the host symlink and locks the backing file; read_json and stat also follow the symlink.
    4. write_private nevertheless calls os.replace against the original symlink pathname. This replaces the link with a regular file instead of updating the backing file.
    5. The helper reports successful write-back, but consumers of the backing file retain the old credentials, and the host's credential-link arrangement is permanently broken.

    The lock and compare-and-swap protect the read contents, but do not align the replacement destination with the resolved file. static trace: Python path operations in the supplied helper establish this behavior; the tests cover regular files only.

  • Minimum fix: Resolve the host credential destination once and consistently use that destination for locking, reading, mode preservation, and atomic replacement. Preserve the original symlink.

Suggestions

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

S1: 🟢 Exercise termination cleanup

Add an entrypoint regression test that refreshes credentials during a long-running task and then terminates the container. The current tests cover normal and nonzero command exits, while synchronization occurs only after the foreground command returns. This optional test would establish signal-forwarding and credential-cleanup behavior.

Score

The image integration and ordinary credential-update paths are well covered, but host-state deletion and symlink replacement require localized corrections. Pending checks are not themselves blockers.

Score: 6/10


🤖 Review Details

  • Model: GPT-6 Astra
  • Time: 50s
  • Tokens: 75,594 (74,353 in / 1,241 out)
  • Cost: $0.67

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 F2 S1

🤖 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 dc9ba04

Addressed 1 AI review comment (IDs: 7221798476)

Addressed findings F1, F2

Summary of Changes

I fixed both findings, F1 and F2. test/piCredentials.test.ts now passes in full (26 of 26). I also ran the new tests against the old scripts: the two regressions below fail there, so they do catch the original bugs.

F1: a runtime home could delete the host Pi dir (scripts/pi-entrypoint.sh)

  • Before anything is deleted or chowned, the entrypoint now resolves both PROPR_PI_RUNTIME_HOME and PROPR_PI_SOURCE_DIR to real paths, following symlinks and ...
  • It then refuses with exit 64 if either path is inside the other. Before, it only caught a runtime home inside the source dir, not one that contains it.
  • It also refuses a runtime home that resolves to /. The old check only caught the literal value /, so something like /tmp/.. would have got through.
  • New tests: a runtime home that contains the source dir, given as the parent dir (the /home/node/.pi case), as agent/.., and as a symlink to the parent. Each one exits 64 and leaves the host auth.json and sessions/ untouched. A runtime home equal to the source dir is also refused.

F2: write-back replaced a symlinked auth.json (scripts/pi-credentials.py)

  • sync now resolves the host auth.json path once. It uses that real file for the lock, the read, the file mode and the atomic replace. The temp file is created next to the real file, the target gets the new credentials, and the symlink stays in place.
  • This matches Pi's own lock, which is also taken on the real file.
  • New test: with auth.json as a symlink to a mode-0640 file elsewhere, after a refresh the link still exists and points to the same file. That file holds the refreshed entry, keeps mode 0640, and has no temp or lock files left next to it.

The other place this could matter is seed, which writes the snapshot. It deletes the snapshot path first, so it never writes through a link and needed no change.

Review digest

Risk-tiered paths

  • High risk (1 file)
    • scripts/pi-credentials.py (+5/−1): auth-looking path
  • Normal risk (1 file)
    • scripts/pi-entrypoint.sh (+18/−2)
  • Low risk (1 file)
    • test/piCredentials.test.ts (+45/−0)

Diff size: 3 files changed, +68/−3 lines


🤖 Implementation Details

  • Model: Claude Opus 5.5 (medium)
  • Requested By: @propr-ultrafix
  • Time: 5m 16s
  • Tokens: 674,663 (669,542 in / 5,121 out)
  • Cost: $0.49

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 both findings, F1 and F2. `test/piCredentials.test.ts` now passes in full (26 of 26). I also ran the new tests against the old scripts: the two regressions below fail there, so they do catch the original bugs.

**F1: a runtime home could delete the host Pi dir** (`scripts/pi-entrypoint.sh`)
- Before anything is deleted or chowned, the entrypoint now resolves both `PROPR_PI_RUNTIME_HOME` and `PROPR_PI_SOURCE_DIR` to real paths, following symlinks and `..`.
- It then refuses with exit 64 if either path is inside the other. Before, it only caught a runtime home inside the source dir, not one that contains it.
- It also refuses a runtime home that resolves to `/`. The old check only caught the literal value `/`, so something like `/tmp/..` would have got through.
- New tests: a runtime home that contains the source dir, given as the parent dir (the `/home/node/.pi` case), as `agent/..`, and as a symlink to the parent. Each one exits 64 and leaves the host `auth.json` and `sessions/` untouched. A runtime home equal to the source dir is also refused.

**F2: write-back replaced a symlinked `auth.json`** (`scripts/pi-credentials.py`)
- `sync` now resolves the host `auth.json` path once. It uses that real file for the lock, the read, the file mode and the atomic replace. The temp file is created next to the real file, the target gets the new credentials, and the symlink stays in place.
- This matches Pi's own lock, which is also taken on the real file.
- New test: with `auth.json` as a symlink to a mode-0640 file elsewhere, after a refresh the link still exists and points to the same file. That file holds the refreshed entry, keeps mode 0640, and has no temp or lock files left next to it.

The other place this could matter is `seed`, which writes the snapshot. It deletes the snapshot path first, so it never writes through a link and needed no change.

PR: #3839
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 to the unified image, version management, entrypoint dispatch, and restricted networking while keeping selectable agent types unchanged. It needs a localized lifecycle fix before merge.

✅ Consistent image integration — Pi participates in build arguments, image labels, content hashes, managed-image verification, and the application’s bundled build context.

✅ Selective credential updates — Write-back preserves unrelated providers and skips entries changed on the host since import. Tests cover these cases and symlinked credential files.

The supplied current-head status shows 22 passed checks, two pending, and no failures. This review used static analysis only, as requested.

Merge blockers

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

F3: 🔴 Forward termination and preserve credential cleanup

  • Category: correctness

  • Required behavior: The new entrypoint must preserve container termination behavior and perform credential write-back after an interrupted task when graceful shutdown permits it.

  • Evidence: scripts/pi-entrypoint.sh:148-155, run_as_node and post-command synchronization; Dockerfile.agent, final ENTRYPOINT.

    1. Start a Pi task through the supplied entrypoint. The shell remains running while run_as_node "$@" executes Pi as a child.
    2. Pi refreshes an OAuth entry in the disposable auth.json, then continues working.
    3. Stop the container during that command. The configured tini invocation forwards termination to its immediate child—the entrypoint shell—and does not specify process-group forwarding.
    4. The entrypoint has no termination handler to forward the signal to Pi, wait for it, and execute synchronization. Termination therefore bypasses the subsequent sync block; the refreshed credentials disappear with the disposable container. Pi also lacks a reliable graceful termination path.

    The ordinary exit-status handling only runs when execution returns to the shell. The credential lock and compare-and-swap cannot help because synchronization is never reached. Existing tests exercise a nonzero command exit, not termination during execution. static trace: supplied entrypoint control flow and Docker entrypoint configuration; no commands were executed.

  • Minimum fix: Add signal-aware child supervision: forward termination to the running task, wait for its exit, and perform credential synchronization once before exiting with the appropriate status. Cover termination after a simulated credential refresh with a regression test.

Suggestions

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

S2: 🟢 Exercise actual lock interoperability

The credential tests simulate Pi’s lock using Python-created directories. A follow-up test against the pinned Pi implementation would help detect differences in lock acquisition, stale-lock handling, and release behavior during future upgrades. This is additional interoperability coverage, not a separately demonstrated blocker.

Score

The image integration and credential merge logic are well covered, but interrupted execution can bypass credential persistence and graceful shutdown. The correction is localized; current checks report no failures.

Score: 6/10


🤖 Review Details

  • Model: GPT-6 Astra
  • Time: 52s
  • Tokens: 76,756 (75,699 in / 1,057 out)
  • Cost: $0.68

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 F3 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 b5bcc09

Addressed 1 AI review comment (IDs: 7222346921)

Addressed finding F3

Summary of Changes

I fixed F3: stopping a Pi container mid-task now passes the signal on to Pi, waits for Pi to exit, and still writes refreshed OAuth credentials back to the host. All 28 tests in test/piCredentials.test.ts pass, including the two new ones. Against the old entrypoint, both new tests fail. I couldn't run the root code path (starting as root and dropping to node via su-exec) here, because there's no root or Docker in this container; CI's image smoke test is its first real run.

What changed in scripts/pi-entrypoint.sh:

  • Signal forwarding: Pi now runs as a background child instead of in the foreground. Handlers for SIGTERM, SIGINT and SIGHUP pass the signal to Pi. The shell keeps waiting until Pi has actually exited, then runs the credential sync once.
  • Exit status: the container exits with Pi's status, which is 143 after docker stop if Pi doesn't handle the signal. If Pi exits cleanly after being told to stop, the entrypoint reports 128 + signal rather than 0. A signal that arrives during the sync waits until the sync finishes.
  • Three problems I hit and fixed while testing:
    • The background job was a bash subshell running a helper function, so signals reached the subshell and left Pi orphaned. A new exec_as_node helper makes the task's PID Pi itself.
    • Bash without job control makes background commands ignore SIGINT and SIGQUIT. The task now starts with env --default-signal=INT,QUIT to undo that; Debian bookworm's coreutils 9.1 supports the flag.
    • Bash also points a background command's stdin at /dev/null, so the prompt on stdin is now passed through explicitly.

Tests and docs:

  • New tests for SIGTERM and SIGINT. A stand-in Pi refreshes the Anthropic token and keeps running; the test then signals the entrypoint the way tini would. They check:
    • the exit status is 143 or 130.
    • Pi was stopped, not left running.
    • the host auth.json holds the refreshed entry and nothing else changed.
  • The existing run test now also checks that the prompt on stdin reaches Pi.
  • I updated the existing check that every Pi call drops to node so it covers exec_as_node.
  • The Pi section of agent-runtime.md now has one sentence on the shutdown behaviour.

Separate finding (not changed): in an interactive docker run -it, Ctrl-C reaches Pi from the terminal and again from the entrypoint, so Pi gets SIGINT twice. ProPR runs Pi with -p and no terminal, so this only matters for manual interactive use.

I didn't change tini to signal the whole process group (tini -g). That would affect every agent image, which is beyond this finding.

Review digest

Risk-tiered paths

  • High risk: none
  • Normal risk (1 file)
    • scripts/pi-entrypoint.sh (+52/−2)
  • Low risk (2 files)
    • docs/docs/architecture/agent-runtime.md (+1/−1)
    • test/piCredentials.test.ts (+65/−9)

Diff size: 3 files changed, +118/−12 lines


🤖 Implementation Details

  • Model: Claude Opus 5.5 (medium)
  • Requested By: @propr-ultrafix
  • Time: 11m 5s
  • Tokens: 1,092,892 (1,078,400 in / 14,492 out)
  • Cost: $0.82

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 F3: stopping a Pi container mid-task now passes the signal on to Pi, waits for Pi to exit, and still writes refreshed OAuth credentials back to the host. All 28 tests in `test/piCredentials.test.ts` pass, including the two new ones. Against the old entrypoint, both new tests fail. I couldn't run the root code path (starting as root and dropping to `node` via `su-exec`) here, because there's no root or Docker in this container; CI's image smoke test is its first real run.

**What changed in `scripts/pi-entrypoint.sh`:**
- **Signal forwarding:** Pi now runs as a background child instead of in the foreground. Handlers for `SIGTERM`, `SIGINT` and `SIGHUP` pass the signal to Pi. The shell keeps waiting until Pi has actually exited, then runs the credential sync once.
- **Exit status:** the container exits with Pi's status, which is 143 after `docker stop` if Pi doesn't handle the signal. If Pi exits cleanly after being told to stop, the entrypoint reports `128 + signal` rather than 0. A signal that arrives during the sync waits until the sync finishes.
- **Three problems I hit and fixed while testing:**
  - The background job was a bash subshell running a helper function, so signals reached the subshell and left Pi orphaned. A new `exec_as_node` helper makes the task's PID Pi itself.
  - Bash without job control makes background commands ignore `SIGINT` and `SIGQUIT`. The task now starts with `env --default-signal=INT,QUIT` to undo that; Debian bookworm's coreutils 9.1 supports the flag.
  - Bash also points a background command's stdin at `/dev/null`, so the prompt on stdin is now passed through explicitly.

**Tests and docs:**
- New tests for `SIGTERM` and `SIGINT`. A stand-in Pi refreshes the Anthropic token and keeps running; the test then signals the entrypoint the way tini would. They check:
  - the exit status is 143 or 130.
  - Pi was stopped, not left running.
  - the host `auth.json` holds the refreshed entry and nothing else changed.
- The existing run test now also checks that the prompt on stdin reaches Pi.
- I updated the existing check that every Pi call drops to `node` so it covers `exec_as_node`.
- The Pi section of `agent-runtime.md` now has one sentence on the shutdown behaviour.

**Separate finding (not changed):** in an interactive `docker run -it`, Ctrl-C reaches Pi from the terminal and again from the entrypoint, so Pi gets `SIGINT` twice. ProPR runs Pi with `-p` and no terminal, so this only matters for manual interactive use.

I didn't change tini to signal the whole process group (`tini -g`). That would affect every agent image, which is beyond this finding.

PR: #3839
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 to the unified agent image, version matrix, entrypoint dispatch, and restricted-network configuration while keeping selectable agent integration separate. The implementation appears merge-ready within scope, conditional on the remaining check completing successfully.

✅ Consistent image integration — Pi participates in build arguments, image labels, version hashes, managed-image verification, and both build-context file lists.

✅ Careful credential write-back — Sync compares individual OAuth entries against the imported snapshot, preserves concurrent host changes, and uses an atomic replacement under the credential lock.

✅ Execution lifecycle coverage — Tests cover stdin forwarding, exit-status preservation, signal forwarding, credential sync, and rejection of overlapping runtime/source directories.

This assessment is based on static review of the supplied code; no commands were run. The authoritative checks report 24 passed, none failed, and one pending.

Merge blockers

No merge blockers.

Suggestions

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

S3: 🟢 Test real lock interoperability

The credential tests exercise simulated lock holders, but do not directly exercise Pi’s locking library against AuthLock. A follow-up integration test using the pinned Pi implementation would help detect changes in lock naming, stale-lock handling, or refresh timing during future upgrades. This is additional compatibility assurance, not a demonstrated defect.

S4: 🟢 Exercise root task execution

The new root smoke test checks ownership through pi --version, while the unit test for privilege dropping primarily checks script text. Consider extending the container smoke test with a task that records its UID and updates disposable credentials, then verifies write-back. This would strengthen coverage of the complete root-to-node execution path; the supplied implementation already routes those calls through the privilege-dropping helpers.

Score

The implementation is coherent and well covered, with no verified merge blockers in the supplied diff. Final readiness remains conditional on the pending validation check.

Score: 9/10


🤖 Review Details

  • Model: GPT-6 Astra
  • Time: 52s
  • Tokens: 77,848 (76,975 in / 873 out)
  • Cost: $0.68

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
@integry
integry merged commit 8523920 into 3831-epic-pi-coding-jml Nov 27, 2026
45 checks passed
@propr-dev propr-dev Bot changed the title 🔨 [3831 by Claude Opus 5.5] Pi: install the CLI in the agent image with a disposable runtime and safe credential handling [3831 by Claude Opus 5.5] Pi: install the CLI in the agent image with a disposable runtime and safe credential handling Nov 27, 2026
propr-dev Bot pushed a commit that referenced this pull request Nov 27, 2026
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
integry pushed a commit that referenced this pull request Nov 27, 2026
…or tasks, with full persisted execution events (#3849)

* feat: add Pi agent type with JSON-mode runs and persisted events

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

* test: add pi to expected agent types in OpenCode CLI help test

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

* fix: keep Pi run results when post-run steps fail

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

---------

Co-authored-by: propr-dev[bot] <1316198+propr-dev[bot]@users.noreply.github.com>
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