Skip to content

Track container image metadata in sqlite records - #122

Open
nezhar wants to merge 3 commits into
mainfrom
issue77
Open

Track container image metadata in sqlite records#122
nezhar wants to merge 3 commits into
mainfrom
issue77

Conversation

@nezhar

@nezhar nezhar commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Adds best-effort collection and persistence of container image metadata (tag, hash, and agent version) for both session and task records, improving traceability and auditing for VibePod runs. The metadata is now stored in the respective SQLite databases, and the schema is automatically migrated to support these new columns. Comprehensive tests have also been added to ensure robust metadata extraction, even in edge cases or failures.

Image metadata collection and persistence:

  • Introduced a new ImageMetadata dataclass and a collect_image_metadata function in src/vibepod/core/image_metadata.py to extract image_tag, image_hash, and agent_version from container images in a best-effort, failure-tolerant manner.
  • Updated the session logging (src/vibepod/core/session_logger.py) and task recording (src/vibepod/core/tasks.py) logic to store the collected image metadata in the database. This includes schema migrations for backward compatibility and updates to the relevant data models and insert logic.

Integration into agent commands:

  • Modified vp run and vp task create commands to collect image metadata at launch and pass it through to logging and task persistence layers.

Documentation and testing:

  • Updated documentation (docs/configuration.md) to describe the new session and task record columns and their purpose for traceability.
  • Added a comprehensive test suite for image metadata extraction, covering various edge cases and failure scenarios.

Summary by CodeRabbit

  • New Features
    • Session and background task records now store available image tag, image hash, and agent version metadata.
    • Metadata capture is best-effort, with unavailable or unparseable details recorded as NULL.
  • Bug Fixes
    • Improved resilience when image metadata is missing, partially labeled, or unavailable.
    • Existing databases now migrate automatically to support the new metadata.
  • Documentation
    • Clarified metadata availability, nullable fields, and automatic database migration behavior.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Image tags, hashes, and agent versions are collected from Docker images during logged runs and task creation, stored in session and task SQLite records, migrated into older databases, tested, and documented.

Changes

Image provenance persistence

Layer / File(s) Summary
Image metadata extraction
src/vibepod/core/image_metadata.py, tests/test_image_metadata.py
Adds optional metadata extraction with tag parsing, hash fallbacks, label precedence, and exception-safe reads.
Shared SQLite schema migration
src/vibepod/core/sqlite_migrations.py, src/vibepod/core/session_logger.py, src/vibepod/core/tasks.py, tests/test_sqlite_migrations.py
Centralizes missing-column migration behavior and applies it to session and task schemas.
Session metadata persistence
src/vibepod/core/session_logger.py, src/vibepod/commands/run.py, tests/test_session_logger.py, tests/test_run.py
Stores session metadata and collects it only when logging is enabled.
Task metadata persistence
src/vibepod/core/tasks.py, src/vibepod/commands/task.py, tests/test_tasks.py, tests/test_task_cmd.py
Extends task records and persists metadata collected during task creation.
Record documentation
docs/configuration.md
Documents provenance fields, nullable values, and automatic migrations.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related issues

Possibly related PRs

Sequence Diagram(s)

sequenceDiagram
  participant RunOrTask
  participant DockerContainer
  participant collect_image_metadata
  participant SQLiteStore
  RunOrTask->>DockerContainer: access image and container attributes
  DockerContainer-->>collect_image_metadata: image id, labels, attrs
  collect_image_metadata-->>RunOrTask: ImageMetadata
  RunOrTask->>SQLiteStore: persist image_tag, image_hash, agent_version
  SQLiteStore-->>RunOrTask: created session or task record
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.43% 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 and concisely describes the main change: tracking container image metadata in SQLite records.
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 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue77

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/vibepod/core/image_metadata.py (1)

8-8: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Reaching across a module boundary for a private helper.

_parse_image_name is private to vibepod.core.docker; consider exposing a public alias (e.g. parse_image_name) so this dependency is part of the intended surface and refactors in docker.py don't silently break provenance collection.

🤖 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/vibepod/core/image_metadata.py` at line 8, Expose a public
`parse_image_name` alias in `vibepod.core.docker` and update `image_metadata.py`
to import and use it instead of the private `_parse_image_name` helper, keeping
the existing parsing behavior unchanged.
src/vibepod/core/session_logger.py (1)

40-52: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Duplicate migration helper across the two stores.

This mirrors TaskStore._migrate_schema in src/vibepod/core/tasks.py (Lines 142-153) almost verbatim, only differing in table name and row[1] vs row["name"]. A shared _add_missing_columns(conn, table, columns) helper would keep both schemas migrating identically.

Note: the OpenGrep f-string/SQL-injection hint here is a false positive — column names come from the module-level _MIGRATION_COLUMNS constant, and SQLite has no placeholder for identifiers in DDL.

🤖 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/vibepod/core/session_logger.py` around lines 40 - 52, Extract the
duplicated schema migration logic from session logger’s _migrate_schema and
TaskStore._migrate_schema into a shared _add_missing_columns(conn, table,
columns) helper. Have both stores call it with their table names and migration
column definitions, while preserving each store’s existing schema behavior and
safe constant-derived column identifiers.

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 `@docs/configuration.md`:
- Around line 247-249: Update the documentation around the nullable image_tag
and agent_version fields to state that missing metadata is stored as NULL,
rather than describing it as empty. Preserve the existing examples and automatic
migration statement.

---

Nitpick comments:
In `@src/vibepod/core/image_metadata.py`:
- Line 8: Expose a public `parse_image_name` alias in `vibepod.core.docker` and
update `image_metadata.py` to import and use it instead of the private
`_parse_image_name` helper, keeping the existing parsing behavior unchanged.

In `@src/vibepod/core/session_logger.py`:
- Around line 40-52: Extract the duplicated schema migration logic from session
logger’s _migrate_schema and TaskStore._migrate_schema into a shared
_add_missing_columns(conn, table, columns) helper. Have both stores call it with
their table names and migration column definitions, while preserving each
store’s existing schema behavior and safe constant-derived column identifiers.
🪄 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 228766a4-35d4-46db-82b9-26f909118e34

📥 Commits

Reviewing files that changed from the base of the PR and between aa51fe1 and 56783a0.

📒 Files selected for processing (11)
  • docs/configuration.md
  • src/vibepod/commands/run.py
  • src/vibepod/commands/task.py
  • src/vibepod/core/image_metadata.py
  • src/vibepod/core/session_logger.py
  • src/vibepod/core/tasks.py
  • tests/test_image_metadata.py
  • tests/test_run.py
  • tests/test_session_logger.py
  • tests/test_task_cmd.py
  • tests/test_tasks.py

Comment thread docs/configuration.md Outdated

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 56783a0683

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/vibepod/core/session_logger.py Outdated
Comment on lines +48 to +51
existing = {row[1] for row in conn.execute("PRAGMA table_info(sessions)").fetchall()}
for column, definition in _MIGRATION_COLUMNS.items():
if column not in existing:
conn.execute(f"ALTER TABLE sessions ADD COLUMN {column} {definition}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Make metadata migrations safe for concurrent launches

When two vp run processes first open the same pre-upgrade logging database concurrently, both can read the old column list before either finishes migrating it, causing the second ALTER TABLE to raise sqlite3.OperationalError: duplicate column name. Because run.py calls open_session after starting the container but before entering its attach/cleanup block, this aborts the command and leaves that container running; serialize the migration or tolerate a column added concurrently. The equivalent migration loop in TaskStore has the same race.

Useful? React with 👍 / 👎.

Comment thread src/vibepod/core/image_metadata.py Outdated
containers in tests, or a daemon that dropped away mid-inspect must never
break the launch — missing pieces simply become ``None``.
"""
_, image_tag = _parse_image_name(image)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Recognize bare image IDs before parsing tags

When an agent image override uses a valid bare image ID such as sha256:<hex>, _parse_image_name interprets the colon as a repository/tag separator, so the persisted image_tag becomes only <hex>. This records a nonexistent tag and drops the digest algorithm from the provenance data; detect bare image IDs before applying the repository/tag parser and leave the tag null or preserve the complete digest.

Useful? React with 👍 / 👎.

nezhar added a commit that referenced this pull request Jul 29, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (1)
src/vibepod/core/image_metadata.py (1)

69-74: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Guard the attrs fallback as well.

getattr(container, "attrs", None) can execute a property that raises. Unlike the preceding Docker property reads, this access is unguarded, so a daemon/API failure can break launch despite the function’s best-effort contract.

Suggested fix
 if image_hash is None:
-    attrs = getattr(container, "attrs", None)
-    if isinstance(attrs, dict):
-        attr_image = attrs.get("Image")
-        if isinstance(attr_image, str) and attr_image:
-            image_hash = attr_image
+    try:
+        attrs = getattr(container, "attrs", None)
+        if isinstance(attrs, dict):
+            attr_image = attrs.get("Image")
+            if isinstance(attr_image, str) and attr_image:
+                image_hash = attr_image
+    except Exception:
+        pass
🤖 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/vibepod/core/image_metadata.py` around lines 69 - 74, Guard the
`getattr(container, "attrs", None)` access in the image-hash fallback so
property or daemon/API errors are caught and do not escape the function.
Preserve the existing dictionary and non-empty `"Image"` extraction behavior
when the access succeeds, consistent with the best-effort handling of the
surrounding Docker property reads.
🤖 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/vibepod/core/sqlite_migrations.py`:
- Around line 19-25: Update the migration helper around the PRAGMA and ALTER
TABLE statements to validate or allow-list the interpolated table, column, and
definition inputs, rejecting malformed or unsupported values. Since identifiers
cannot use parameter placeholders, quote validated table and column identifiers
safely before constructing SQL, and only permit approved schema type
definitions.

---

Outside diff comments:
In `@src/vibepod/core/image_metadata.py`:
- Around line 69-74: Guard the `getattr(container, "attrs", None)` access in the
image-hash fallback so property or daemon/API errors are caught and do not
escape the function. Preserve the existing dictionary and non-empty `"Image"`
extraction behavior when the access succeeds, consistent with the best-effort
handling of the surrounding Docker property reads.
🪄 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c56f4b36-c55b-4e45-809c-0bb2eef023ab

📥 Commits

Reviewing files that changed from the base of the PR and between 56783a0 and 094f915.

📒 Files selected for processing (7)
  • docs/configuration.md
  • src/vibepod/core/image_metadata.py
  • src/vibepod/core/session_logger.py
  • src/vibepod/core/sqlite_migrations.py
  • src/vibepod/core/tasks.py
  • tests/test_image_metadata.py
  • tests/test_sqlite_migrations.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/configuration.md

Comment on lines +19 to +25
existing = {row[1] for row in conn.execute(f"PRAGMA table_info({table})").fetchall()}
changed = False
for column, definition in columns.items():
if column in existing:
continue
try:
conn.execute(f"ALTER TABLE {table} ADD COLUMN {column} {definition}")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Validate all interpolated schema inputs.

table, column, and definition are inserted directly into SQL. Current callers pass constants, but this public helper accepts arbitrary strings; a future caller could introduce SQL injection or break migrations with malformed identifiers. Parameter placeholders cannot bind identifiers, so validate/allow-list names and type definitions, then quote identifiers before constructing these statements.

🧰 Tools
🪛 OpenGrep (1.26.0)

[ERROR] 19-19: SQL query built via f-string passed to execute()/executemany(). Use parameterized queries with placeholders instead.

(coderabbit.sql-injection.python-fstring-execute)


[ERROR] 25-25: SQL query built via f-string passed to execute()/executemany(). Use parameterized queries with placeholders instead.

(coderabbit.sql-injection.python-fstring-execute)

🤖 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/vibepod/core/sqlite_migrations.py` around lines 19 - 25, Update the
migration helper around the PRAGMA and ALTER TABLE statements to validate or
allow-list the interpolated table, column, and definition inputs, rejecting
malformed or unsupported values. Since identifiers cannot use parameter
placeholders, quote validated table and column identifiers safely before
constructing SQL, and only permit approved schema type definitions.

Source: Linters/SAST tools

nezhar added a commit that referenced this pull request Jul 29, 2026
nezhar added 3 commits August 1, 2026 09:17
add-trailing-comma and ruff-format landed on main (#126) after this
branch was cut; align the branch files so the pre-commit CI check
passes.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

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

⚠️ Outside diff range comments (1)
tests/test_task_cmd.py (1)

112-112: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Keep the headless-agent error message synchronized.

AGENT_SPECS["jcode"] and AGENT_SPECS["tau"] have non-empty headless_prefix values. However, src/vibepod/commands/task.py still lists only claude, codex, and auggie in its validation message. Build the message from agents with a headless_prefix, or update the list.

🤖 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 `@tests/test_task_cmd.py` at line 112, Update the validation error message in
the task command to include every agent whose AGENT_SPECS entry has a non-empty
headless_prefix, including jcode and tau; preferably derive the listed names
dynamically from AGENT_SPECS instead of maintaining a separate hard-coded list.
🤖 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.

Outside diff comments:
In `@tests/test_task_cmd.py`:
- Line 112: Update the validation error message in the task command to include
every agent whose AGENT_SPECS entry has a non-empty headless_prefix, including
jcode and tau; preferably derive the listed names dynamically from AGENT_SPECS
instead of maintaining a separate hard-coded list.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 85cee174-fa74-4239-814f-061dea8cee13

📥 Commits

Reviewing files that changed from the base of the PR and between 094f915 and 49a4af9.

📒 Files selected for processing (13)
  • docs/configuration.md
  • src/vibepod/commands/run.py
  • src/vibepod/commands/task.py
  • src/vibepod/core/image_metadata.py
  • src/vibepod/core/session_logger.py
  • src/vibepod/core/sqlite_migrations.py
  • src/vibepod/core/tasks.py
  • tests/test_image_metadata.py
  • tests/test_run.py
  • tests/test_session_logger.py
  • tests/test_sqlite_migrations.py
  • tests/test_task_cmd.py
  • tests/test_tasks.py
🚧 Files skipped from review as they are similar to previous changes (9)
  • docs/configuration.md
  • tests/test_session_logger.py
  • tests/test_image_metadata.py
  • src/vibepod/commands/task.py
  • tests/test_sqlite_migrations.py
  • src/vibepod/core/tasks.py
  • src/vibepod/core/session_logger.py
  • src/vibepod/commands/run.py
  • src/vibepod/core/image_metadata.py

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