Skip to content

fix(resume): add Pi models.json regeneration on URL change#19

Open
rounakbende10 wants to merge 2 commits into
redhat-et:mainfrom
rounakbende10:fix/resume-pi-mount-regen
Open

fix(resume): add Pi models.json regeneration on URL change#19
rounakbende10 wants to merge 2 commits into
redhat-et:mainfrom
rounakbende10:fix/resume-pi-mount-regen

Conversation

@rounakbende10

Copy link
Copy Markdown
Contributor

Problem

Pi agent stores the server URL in a bind-mounted models.json file, not in env vars. The URL replacement in the resume endpoint only walks JSON files in the job dir — it doesn't regenerate Pi's mount file.

Fix

After replacing URLs across all JSON files, check if the agent is Pi and regenerate /app/models.json with the new URL. Added inline in the existing URL replacement script.

Also includes the HOME=/tmp fix from PR #18 for mc permissions.

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: b356578f-5db6-4d3b-9d4e-c27732b9d341

📥 Commits

Reviewing files that changed from the base of the PR and between 277a4c7 and 2073f57.

📒 Files selected for processing (1)
  • src/coding_agent_bench/api.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/coding_agent_bench/api.py

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • When resuming a job with a new server URL, references are now updated across all relevant job configuration files.
    • The pi model configuration is refreshed to use the new server address, and codex settings are updated when present.
    • The update process continues even when no matching hosts are found, reporting zero updated files; only modified content is rewritten.
  • Documentation
    • Clarified that the server URL provided during resume replaces the old model-server URL across all job files.

Walkthrough

The resume endpoint optionally replaces old server URLs across job JSON files and regenerates pi models.json and codex config.toml with the new server configuration.

Changes

Resume URL configuration updates

Layer / File(s) Summary
URL replacement and mount configuration
src/coding_agent_bench/api.py
The server_url description documents replacement across job files. The resume command continues through zero host matches, reports the replacement count, updates changed JSON files, regenerates pi models.json, and updates codex config.toml when present.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main resume URL-change behavior and Pi models.json regeneration.
Description check ✅ Passed The description matches the Pi models.json regeneration fix and the additional HOME=/tmp permissions fix.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@rounakbende10 rounakbende10 reopened this Jul 21, 2026
@rounakbende10
rounakbende10 force-pushed the fix/resume-pi-mount-regen branch from fda7c77 to 6102e45 Compare July 21, 2026 22:41

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
src/coding_agent_bench/api.py (3)

60-60: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Document JSON-only replacement behavior.

The script updates only files ending in .json (Line 528), so “across all job files” overstates the request contract. Clarify this as “all job JSON files” or update the traversal.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/coding_agent_bench/api.py` at line 60, Update the `server_url` field
description to state that the replacement applies to all job JSON files,
matching the script’s `.json`-only traversal behavior; do not change traversal
unless intentionally expanding the request contract.

525-542: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Do not exit before regenerating Pi models.

When no matching old host is found, the exit(0) at Line 524 prevents Lines 537-542 from running. Thus a resume with an already-current URL—or a host outside the derived domain—never updates models.json, despite the new server_url being supplied. Make URL replacement conditional without terminating the script, then always perform Pi model regeneration when applicable.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/coding_agent_bench/api.py` around lines 525 - 542, Update the URL
replacement flow before the Pi regeneration block so the no-matching-host case
does not call exit(0). Make replacement conditional, but allow execution to
continue into the mounts loop and regenerate models.json whenever the selected
agent is Pi and its mount target matches models.json.

506-513: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Reject malformed or scheme-less server URLs here. urlparse(...).netloc is empty for inputs like not-a-url or example.com, so new_domain becomes ""; the host filter then matches every host and can rewrite job JSONs to https:///v1. Validate the scheme and hostname before building the replacement script.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/coding_agent_bench/api.py` around lines 506 - 513, Validate
req.server_url before deriving new_host and new_domain: require a supported URL
scheme and a non-empty parsed hostname, rejecting malformed or scheme-less
values instead of generating replacement lines. Use the validated hostname when
constructing new_domain, while preserving the existing replacement-script flow
for valid URLs.
🧹 Nitpick comments (1)
src/coding_agent_bench/api.py (1)

542-542: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove the unnecessary f-string prefix.

Ruff reports F541 because this string contains no interpolated expressions; removing the f prefix avoids the lint failure.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/coding_agent_bench/api.py` at line 542, Remove the unnecessary f-string
prefix from the string containing the Pi models.json regeneration command in the
surrounding code, since it has no interpolation. Preserve the command contents
and behavior unchanged.

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/coding_agent_bench/api.py`:
- Around line 537-542: Update the generated Pi mount-file logic around
PiAgentConfig.configure to reuse the persisted complete server_url, including
its scheme and path, instead of constructing a new HTTPS URL from new_host.
Populate contextWindow from the configured model_max_len rather than hardcoding
262000, while preserving the existing model and provider fields.

---

Outside diff comments:
In `@src/coding_agent_bench/api.py`:
- Line 60: Update the `server_url` field description to state that the
replacement applies to all job JSON files, matching the script’s `.json`-only
traversal behavior; do not change traversal unless intentionally expanding the
request contract.
- Around line 525-542: Update the URL replacement flow before the Pi
regeneration block so the no-matching-host case does not call exit(0). Make
replacement conditional, but allow execution to continue into the mounts loop
and regenerate models.json whenever the selected agent is Pi and its mount
target matches models.json.
- Around line 506-513: Validate req.server_url before deriving new_host and
new_domain: require a supported URL scheme and a non-empty parsed hostname,
rejecting malformed or scheme-less values instead of generating replacement
lines. Use the validated hostname when constructing new_domain, while preserving
the existing replacement-script flow for valid URLs.

---

Nitpick comments:
In `@src/coding_agent_bench/api.py`:
- Line 542: Remove the unnecessary f-string prefix from the string containing
the Pi models.json regeneration command in the surrounding code, since it has no
interpolation. Preserve the command contents and behavior unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: f761a8f2-c990-440e-a3e8-7e47e7ca33b2

📥 Commits

Reviewing files that changed from the base of the PR and between f8ef06b and 6102e45.

📒 Files selected for processing (1)
  • src/coding_agent_bench/api.py

Comment on lines +537 to +542
"# Regenerate Pi mount file with new URL",
"agent = c.get('agents', [{}])[0]",
"mounts = c.get('environment', {}).get('mounts', [])",
"for m in mounts:",
" src, tgt = m.get('source',''), m.get('target','')",
f" if agent.get('name') == 'pi' and 'models.json' in tgt: json.dump({{'providers': {{'vllm': {{'baseUrl': 'https://' + new_host + '/v1', 'api': 'openai-completions', 'apiKey': 'NONE', 'models': [{{'id': agent.get('model_name',''), 'name': agent.get('model_name',''), 'contextWindow': 262000}}]}}}}}}, open(src, 'w')); print('Regenerated Pi models.json')",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Preserve the canonical Pi configuration values.

PiAgentConfig.configure uses the complete server_url (including scheme/path) and the configured model_max_len. This regeneration instead forces https://, discards any URL path, and hardcodes contextWindow to 262000, which can break deployments using HTTP, a URL prefix, or a custom context window. Reuse the persisted URL/configuration values.

🧰 Tools
🪛 Ruff (0.15.21)

[error] 542-542: f-string without any placeholders

Remove extraneous f prefix

(F541)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/coding_agent_bench/api.py` around lines 537 - 542, Update the generated
Pi mount-file logic around PiAgentConfig.configure to reuse the persisted
complete server_url, including its scheme and path, instead of constructing a
new HTTPS URL from new_host. Populate contextWindow from the configured
model_max_len rather than hardcoding 262000, while preserving the existing model
and provider fields.

Pi agent stores the server URL in a bind-mounted models.json file that
doesn't persist to MinIO. When resuming with a new server_url, the URL
replacement walks all JSON files but misses this mount file.

Added Pi models.json regeneration inline in the URL replacement script.
@rounakbende10
rounakbende10 force-pushed the fix/resume-pi-mount-regen branch from 6102e45 to 277a4c7 Compare July 21, 2026 22:50

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/coding_agent_bench/api.py`:
- Around line 542-543: Remove the unnecessary f-string prefixes from the two
command strings in the agent configuration generation logic, including the lines
handling Pi models.json and Codex config.toml. Keep their contents and behavior
unchanged.
- Around line 537-543: Update the server URL handling before the Pi/Codex
regeneration block so URL replacement is conditional rather than exiting when no
URLs match. When req.server_url is set, always continue into the mounts loop and
regenerate Pi models.json or Codex config.toml using the new host, regardless of
whether any prior URLs were replaced; preserve replacement behavior when matches
exist.
- Line 543: Update the Codex config generation in the agent config handling to
parse the existing config.toml, preserve unrelated settings, and modify only
api.base_url and model.model_id. Serialize the updated TOML using the project’s
proper TOML writer or escaping mechanism so new_host and agent.get('model_name',
'') remain valid even with quotes or newlines, rather than overwriting the file
with a handcrafted string.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: 92a80a33-9bff-4036-943c-c4202edca7ab

📥 Commits

Reviewing files that changed from the base of the PR and between 6102e45 and 277a4c7.

📒 Files selected for processing (1)
  • src/coding_agent_bench/api.py

Comment thread src/coding_agent_bench/api.py
Comment on lines +542 to +543
f" if agent.get('name') == 'pi' and 'models.json' in tgt: json.dump({{'providers': {{'vllm': {{'baseUrl': 'https://' + new_host + '/v1', 'api': 'openai-completions', 'apiKey': 'NONE', 'models': [{{'id': agent.get('model_name',''), 'name': agent.get('model_name',''), 'contextWindow': 262000}}]}}}}}}, open(src, 'w')); print('Regenerated Pi models.json')",
f" if agent.get('name') == 'codex' and 'config.toml' in tgt: open(src, 'w').write('[api]\\nbase_url = \"https://' + new_host + '\"\\napi_key = \"sk-no-key\"\\n[model]\\nmodel_id = \"' + agent.get('model_name','') + '\"\\n'); print('Regenerated Codex config.toml')",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Remove the unnecessary f-string prefixes.

Ruff F541 reports that these strings contain no interpolation; removing the f prefixes will clear the lint errors.

🧰 Tools
🪛 Ruff (0.15.21)

[error] 542-542: f-string without any placeholders

Remove extraneous f prefix

(F541)


[error] 543-543: f-string without any placeholders

Remove extraneous f prefix

(F541)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/coding_agent_bench/api.py` around lines 542 - 543, Remove the unnecessary
f-string prefixes from the two command strings in the agent configuration
generation logic, including the lines handling Pi models.json and Codex
config.toml. Keep their contents and behavior unchanged.

Source: Linters/SAST tools

"for m in mounts:",
" src, tgt = m.get('source',''), m.get('target','')",
f" if agent.get('name') == 'pi' and 'models.json' in tgt: json.dump({{'providers': {{'vllm': {{'baseUrl': 'https://' + new_host + '/v1', 'api': 'openai-completions', 'apiKey': 'NONE', 'models': [{{'id': agent.get('model_name',''), 'name': agent.get('model_name',''), 'contextWindow': 262000}}]}}}}}}, open(src, 'w')); print('Regenerated Pi models.json')",
f" if agent.get('name') == 'codex' and 'config.toml' in tgt: open(src, 'w').write('[api]\\nbase_url = \"https://' + new_host + '\"\\napi_key = \"sk-no-key\"\\n[model]\\nmodel_id = \"' + agent.get('model_name','') + '\"\\n'); print('Regenerated Codex config.toml')",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Preserve and safely serialize the existing Codex configuration.

open(src, 'w').write(...) discards unrelated Codex settings, while unescaped model_name and new_host can corrupt the generated TOML when they contain quotes or newlines. Parse and update only base_url/model_id, then serialize with proper TOML escaping.

🧰 Tools
🪛 Ruff (0.15.21)

[error] 543-543: f-string without any placeholders

Remove extraneous f prefix

(F541)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/coding_agent_bench/api.py` at line 543, Update the Codex config
generation in the agent config handling to parse the existing config.toml,
preserve unrelated settings, and modify only api.base_url and model.model_id.
Serialize the updated TOML using the project’s proper TOML writer or escaping
mechanism so new_host and agent.get('model_name', '') remain valid even with
quotes or newlines, rather than overwriting the file with a handcrafted string.

The URL replacement script had 'if not hosts: exit(0)' which killed
the entire script before reaching Pi models.json / Codex config.toml
mount file regeneration when the harness stores URLs in mount files
instead of env vars.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant