Skip to content

Fix stub/real-file collision in per-agent Docker builds#19

Merged
iidsample merged 2 commits into
mainfrom
bug_fixes/stub_naming
Jul 22, 2026
Merged

Fix stub/real-file collision in per-agent Docker builds#19
iidsample merged 2 commits into
mainfrom
bug_fixes/stub_naming

Conversation

@Saaketh0

@Saaketh0 Saaketh0 commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Copies each agent's real implementation last when assembling its own Docker build context, so it always overwrites a same-named stub file. Previously the stub could silently replace the real file, causing agents to load their own proxy stub instead of real logic — a silent failure with no working replica to fall back to.

Summary by CodeRabbit

  • Bug Fixes
    • Improved build reliability by aligning generated agent stub naming so Docker packaging references the correct files.
    • Prevented database errors by automatically creating the runtime information table during initialization.
    • Fixed Docker build contexts to reliably include the intended agent configuration files.
  • Performance / Behavior
    • Improved instance provisioning parallelism by scaling concurrency based on workload size and host capacity.

@Saaketh0 Saaketh0 added the bug Something isn't working label Jul 22, 2026
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Generated agent stubs now use .py filenames, Docker context assembly explicitly adds the agent file, SQLAlchemy creates runtime_information when initializing the engine, and instance provisioning derives concurrency from workload and CPU capacity.

Changes

Stub build artifacts

Layer / File(s) Summary
Stub naming and Docker context
ventis/cli.py, ventis/stub_generator.py
Generated stubs omit the _stub suffix, while Docker context generation adds the agent file to the copy list before writing files.

Runtime persistence initialization

Layer / File(s) Summary
Runtime table initialization
ventis/controller/utils/sqlalchemy.py
Defines runtime_information with the upsert payload columns and creates it during first-time engine initialization.

Instance provisioning concurrency

Layer / File(s) Summary
Dynamic provisioning concurrency
ventis/controller/instance_manager.py
Instance provisioning limits worker count using the number of jobs and host CPU capacity instead of the environment variable setting.

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

Possibly related PRs

Suggested reviewers: iidsample

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: resolving stub-versus-real-file collisions in per-agent Docker builds.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bug_fixes/stub_naming

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

@coderabbitai
coderabbitai Bot requested a review from iidsample July 22, 2026 17:56

@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: 2

🤖 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 `@ventis/controller/utils/sqlalchemy.py`:
- Around line 52-59: Update _get_engine to build the SQLAlchemy engine in a
local variable, complete the _CREATE_TABLE initialization, and only then publish
it to _engine while holding an initialization lock. Ensure concurrent callers
cannot observe a partially initialized engine, and leave _engine unset when
initialization fails so later calls can retry.
- Around line 35-49: Update the CREATE TABLE schema in _CREATE_TABLE so the
created_at and updated_at columns use REAL instead of TEXT, matching the
epoch-float values written by send_data. Leave the remaining column definitions
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: Pro Plus

Run ID: 481c1629-f34f-4ff4-b30f-cdbbc7cc1cb9

📥 Commits

Reviewing files that changed from the base of the PR and between c591869 and 52d3bcb.

📒 Files selected for processing (3)
  • ventis/cli.py
  • ventis/controller/utils/sqlalchemy.py
  • ventis/stub_generator.py

Comment on lines +35 to +49
_CREATE_TABLE = text(
f"""
CREATE TABLE IF NOT EXISTS {TABLE_NAME} (
future_id TEXT PRIMARY KEY,
session_id TEXT,
workflow TEXT,
agent TEXT,
execution_time REAL,
cpu_resource REAL,
gpu_resource REAL,
created_at TEXT,
updated_at TEXT
)
"""
)

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 | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Map the target file and nearby symbols first.
ast-grep outline ventis/controller/utils/sqlalchemy.py --view expanded || true

# Show the file with line numbers.
cat -n ventis/controller/utils/sqlalchemy.py

# Find where runtime_information is written/read.
rg -n "created_at|updated_at|send_data|runtime_information|_engine|CREATE TABLE" ventis/controller -S

Repository: CanyonCodeCoreAI/canyoncodecore

Length of output: 6625


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Read only the relevant sections if the file is long.
sed -n '1,220p' ventis/controller/utils/sqlalchemy.py

Repository: CanyonCodeCoreAI/canyoncodecore

Length of output: 3658


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# If tests or examples reference persistence, inspect them too.
rg -n "runtime_information|created_at|updated_at|session_id|future_id" -S .

Repository: CanyonCodeCoreAI/canyoncodecore

Length of output: 7769


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Check for line counts before reading more if needed.
wc -l ventis/controller/utils/sqlalchemy.py

Repository: CanyonCodeCoreAI/canyoncodecore

Length of output: 211


🏁 Script executed:

#!/bin/bash
set -euo pipefail

cat -n tests/test_runtime_sqlalchemy.py

Repository: CanyonCodeCoreAI/canyoncodecore

Length of output: 5069


🏁 Script executed:

#!/bin/bash
set -euo pipefail

python3 - <<'PY'
import sqlite3

for decl in ["TEXT", "REAL", "NUMERIC", "INTEGER"]:
    conn = sqlite3.connect(":memory:")
    conn.execute(f"CREATE TABLE t (v {decl})")
    conn.execute("INSERT INTO t(v) VALUES (?)", (1.5,))
    value, typ = conn.execute("SELECT v, typeof(v) FROM t").fetchone()
    print(decl, repr(value), typ)
PY

Repository: CanyonCodeCoreAI/canyoncodecore

Length of output: 233


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '1,220p' tests/test_runtime_sqlalchemy.py

Repository: CanyonCodeCoreAI/canyoncodecore

Length of output: 4166


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '1,180p' tests/test_runtime_sqlalchemy.py

Repository: CanyonCodeCoreAI/canyoncodecore

Length of output: 4166


Keep the timestamp columns numeric. send_data writes epoch floats into created_at and updated_at, so declaring them as TEXT stores string values in SQLite and leaves the schema contract inconsistent. Use REAL here, or serialize timestamps to text everywhere.

Proposed schema fix
-        created_at TEXT,
-        updated_at TEXT
+        created_at REAL,
+        updated_at REAL
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
_CREATE_TABLE = text(
f"""
CREATE TABLE IF NOT EXISTS {TABLE_NAME} (
future_id TEXT PRIMARY KEY,
session_id TEXT,
workflow TEXT,
agent TEXT,
execution_time REAL,
cpu_resource REAL,
gpu_resource REAL,
created_at TEXT,
updated_at TEXT
)
"""
)
_CREATE_TABLE = text(
f"""
CREATE TABLE IF NOT EXISTS {TABLE_NAME} (
future_id TEXT PRIMARY KEY,
session_id TEXT,
workflow TEXT,
agent TEXT,
execution_time REAL,
cpu_resource REAL,
gpu_resource REAL,
created_at REAL,
updated_at REAL
)
"""
)
🤖 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 `@ventis/controller/utils/sqlalchemy.py` around lines 35 - 49, Update the
CREATE TABLE schema in _CREATE_TABLE so the created_at and updated_at columns
use REAL instead of TEXT, matching the epoch-float values written by send_data.
Leave the remaining column definitions unchanged.

Comment on lines 52 to +59
def _get_engine(database_url):
global _engine
if _engine is None:
_engine = create_engine(
os.environ.get("VENTIS_DATABASE_URL", str(database_url))
)
with _engine.begin() as conn:
conn.execute(_CREATE_TABLE)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Publish the engine only after table initialization succeeds.

_engine is assigned before CREATE TABLE completes. A concurrent caller can observe the non-None engine and execute an upsert before the table exists; if creation fails, the failed engine remains cached and initialization is never retried. Build the engine locally, initialize it, then assign it under a lock.

Proposed initialization fix
 def _get_engine(database_url):
     global _engine
     if _engine is None:
-        _engine = create_engine(
-            os.environ.get("VENTIS_DATABASE_URL", str(database_url))
-        )
-        with _engine.begin() as conn:
-            conn.execute(_CREATE_TABLE)
+        with _engine_lock:
+            if _engine is None:
+                engine = create_engine(
+                    os.environ.get("VENTIS_DATABASE_URL", str(database_url))
+                )
+                with engine.begin() as conn:
+                    conn.execute(_CREATE_TABLE)
+                _engine = engine
     return _engine
🤖 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 `@ventis/controller/utils/sqlalchemy.py` around lines 52 - 59, Update
_get_engine to build the SQLAlchemy engine in a local variable, complete the
_CREATE_TABLE initialization, and only then publish it to _engine while holding
an initialization lock. Ensure concurrent callers cannot observe a partially
initialized engine, and leave _engine unset when initialization fails so later
calls can retry.

@iidsample
iidsample merged commit c38750f into main Jul 22, 2026
3 of 5 checks passed

@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: 2

🤖 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 `@ventis/controller/instance_manager.py`:
- Line 74: Update ensure_instances() to normalize os.cpu_count() with a fallback
of 1 before multiplying by 100, preserving the existing max_workers calculation.
Add a regression test that mocks os.cpu_count() to return None and verifies
provisioning proceeds without a TypeError.
- Line 74: Update the worker-count calculation around max_workers to apply a
separately configurable hard cap for provisioning concurrency, while retaining
the CPU-based limit as the lower bound. Handle os.cpu_count() returning None
safely by using an appropriate fallback before calculating the limit.
🪄 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: Pro Plus

Run ID: 1f897a35-ae7e-4a4e-ad63-3fb9f390b2c8

📥 Commits

Reviewing files that changed from the base of the PR and between 52d3bcb and 8bada23.

📒 Files selected for processing (1)
  • ventis/controller/instance_manager.py

)

max_workers = int(os.environ.get("VENTIS_MAX_AGENT_INSTANCES", 8))
max_workers = min(len(jobs),os.cpu_count()*100)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== file map =="
git ls-files 'ventis/controller/instance_manager.py' 'ventis/**' | sed -n '1,120p'

echo
echo "== outline =="
ast-grep outline ventis/controller/instance_manager.py --view expanded || true

echo
echo "== relevant excerpt =="
nl -ba ventis/controller/instance_manager.py | sed -n '1,140p'

echo
echo "== search for cpu_count / max_workers / provisioning caps =="
rg -n "cpu_count|max_workers|VENTIS_MAX_AGENT_INSTANCES|ThreadPoolExecutor|ProcessPoolExecutor|executor" ventis -S || true

echo
echo "== runtime probe: None * 100 behavior =="
python3 - <<'PY'
import os
try:
    print(min(3, os.cpu_count()*100))
except Exception as e:
    print(type(e).__name__, e)
PY

Repository: CanyonCodeCoreAI/canyoncodecore

Length of output: 2516


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== relevant excerpt =="
sed -n '31,115p' ventis/controller/instance_manager.py | cat -n

echo
echo "== runtime probe: cpu_count None behavior =="
python3 - <<'PY'
import os
vals = [None, 0, 1, 8]
for v in vals:
    try:
        result = min(3, v * 100)
        print(f"{v!r}: {result}")
    except Exception as e:
        print(f"{v!r}: {type(e).__name__}: {e}")
PY

echo
echo "== search for max_workers and executor usage =="
rg -n "max_workers|ThreadPoolExecutor|ProcessPoolExecutor|cpu_count|ensure_instances|_provision_one" ventis/controller/instance_manager.py -n -S || true

Repository: CanyonCodeCoreAI/canyoncodecore

Length of output: 4685


Handle os.cpu_count() returning None. os.cpu_count() * 100 raises TypeError on hosts where the CPU count is unavailable, so ensure_instances() crashes before provisioning starts. Use a fallback like os.cpu_count() or 1 and add a regression test for the None case.

🤖 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 `@ventis/controller/instance_manager.py` at line 74, Update ensure_instances()
to normalize os.cpu_count() with a fallback of 1 before multiplying by 100,
preserving the existing max_workers calculation. Add a regression test that
mocks os.cpu_count() to return None and verifies provisioning proceeds without a
TypeError.

🚀 Performance & Scalability | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Map candidate file structure
ast-grep outline ventis/controller/instance_manager.py --view expanded || true

# Show relevant section with line numbers
sed -n '1,220p' ventis/controller/instance_manager.py

# Search for max_workers / executor usage in repo
rg -n "max_workers|ThreadPoolExecutor|ProcessPoolExecutor|concurrent\.futures|executor" ventis -S

Repository: CanyonCodeCoreAI/canyoncodecore

Length of output: 10485


🏁 Script executed:

#!/bin/bash
set -euo pipefail

ast-grep outline ventis/controller/instance_manager.py --view expanded || true
sed -n '1,220p' ventis/controller/instance_manager.py
rg -n "max_workers|ThreadPoolExecutor|ProcessPoolExecutor|concurrent\.futures|executor" ventis -S

Repository: CanyonCodeCoreAI/canyoncodecore

Length of output: 10485


🏁 Script executed:

#!/bin/bash
set -euo pipefail

pwd
git ls-files | rg '^ventis/controller/instance_manager\.py$|^ventis/controller/'
sed -n '1,220p' ventis/controller/instance_manager.py
rg -n "max_workers|ThreadPoolExecutor|ProcessPoolExecutor|concurrent\.futures|executor" ventis -S

Repository: CanyonCodeCoreAI/canyoncodecore

Length of output: 9948


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate the file and print a small window around the target line.
file=$(git ls-files | rg '^ventis/controller/instance_manager\.py$' || true)
printf 'FILE=%s\n' "$file"
if [ -n "$file" ]; then
  nl -ba "$file" | sed -n '1,180p'
fi

Repository: CanyonCodeCoreAI/canyoncodecore

Length of output: 252


🏁 Script executed:

#!/bin/bash
set -euo pipefail

python3 - <<'PY'
import os
print("cwd:", os.getcwd())
print("has ventis/controller/instance_manager.py:", os.path.exists("ventis/controller/instance_manager.py"))
PY

Repository: CanyonCodeCoreAI/canyoncodecore

Length of output: 241


🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n "def provision_instance|def bootstrap_instance|terminate_instance|validate_config" ventis/controller/cloud_provider_logic -S
sed -n '1,220p' ventis/controller/cloud_provider_logic/Local/_runtime.py
sed -n '1,260p' ventis/controller/cloud_provider_logic/EC2/_runtime.py

Repository: CanyonCodeCoreAI/canyoncodecore

Length of output: 13069


Add a hard cap for provisioning concurrency. This pool can still grow to 100 * CPU count, which means thousands of simultaneous Docker/AWS calls on large hosts. Keep the limit separately configurable and fall back safely when CPU count is unavailable.

🤖 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 `@ventis/controller/instance_manager.py` at line 74, Update the worker-count
calculation around max_workers to apply a separately configurable hard cap for
provisioning concurrency, while retaining the CPU-based limit as the lower
bound. Handle os.cpu_count() returning None safely by using an appropriate
fallback before calculating the limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants