Skip to content

fix(runtime): persist resolved model name to DB even when not explicitly provided#3110

Open
yitang wants to merge 1 commit into
bytedance:mainfrom
yitang:fix/empty-model-name-in-database
Open

fix(runtime): persist resolved model name to DB even when not explicitly provided#3110
yitang wants to merge 1 commit into
bytedance:mainfrom
yitang:fix/empty-model-name-in-database

Conversation

@yitang
Copy link
Copy Markdown
Contributor

@yitang yitang commented May 20, 2026

Summary

Fixes the model_name column in the runs database table being permanently empty. When a user starts a run without specifying a model_name in the request context, the agent resolves an effective model at runtime, but this was never persisted to the database due to a guard condition that skipped the update entirely when record.model_name was None.

Changes

File: backend/packages/harness/deerflow/runtime/runs/worker.py (lines 237–242)

  • Removed the "record.model_name is not None" early-exit guard
  • The code now always resolves the effective model name from agent metadata and persists it to the DB when available
  • When model_name was already set at creation time, behavior is unchanged (same or different effective model gets written)
  • When model_name was never set (the bug case), the resolved default model is now correctly persisted

Test Plan

  • All 64 tests in tests/test_run_manager.py pass (including test_model_name_create_or_reject, test_model_name_default_is_none)
  • Python syntax check via ruff: clean
  • Manual verification: start a run without explicit model_name, query the DB to confirm it's populated

Related Issues

Closes #3109

…tly provided

Remove the 'record.model_name is not None' guard in worker.py so that
runs created without an explicit model_name (which leaves it as None)
still get their resolved effective model persisted from agent metadata.

Previously, when no model_name was passed in the request context, the
update_model_name call was skipped entirely because of an early-exit
condition, leaving the DB column permanently NULL.

Closes bytedance#3109
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes run metadata persistence so the runs.model_name column is populated even when the user doesn’t explicitly provide a model name, by persisting the agent-resolved effective model name during runtime.

Changes:

  • Update run_agent() to always read agent.metadata["model_name"] (when available) and persist it via run_manager.update_model_name(...).
  • Add .agents/plans/ to .gitignore.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.

File Description
backend/packages/harness/deerflow/runtime/runs/worker.py Removes the record.model_name is not None guard and persists the resolved effective model name from agent metadata.
.gitignore Ignores .agents/plans/ directory.
Comments suppressed due to low confidence (1)

backend/packages/harness/deerflow/runtime/runs/worker.py:244

  • The new logic updates the run’s model_name whenever effective is truthy, even if it’s identical to the already-persisted value. Because the SQL store’s update_model_name always writes updated_at (and doesn’t short-circuit on same value), this introduces an extra DB write and changes semantics by bumping updated_at for runs that already had the correct model_name. Consider restoring a value-change guard, e.g. only call update_model_name when effective is set and effective != record.model_name (this still fixes the None case since None != effective).
        resolved = getattr(agent, "metadata", {}) or {}
        if isinstance(resolved, dict):
            effective = resolved.get("model_name")
            if effective:
                await run_manager.update_model_name(record.run_id, effective)

Comment on lines +237 to +244
# NOTE: Removed the "record.model_name is not None" guard so that runs
# created without an explicit model_name (which leaves it as None) still
# get their resolved effective model persisted to the database.
resolved = getattr(agent, "metadata", {}) or {}
if isinstance(resolved, dict):
effective = resolved.get("model_name")
if effective:
await run_manager.update_model_name(record.run_id, effective)
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.

fix: model_name column in runs table stays empty when not explicitly passed

3 participants