Skip to content

feat(run): Propagates model_name from the gateway request through the runtime and persistence stack to the SQLite database.#2775

Open
yitang wants to merge 4 commits intobytedance:mainfrom
yitang:feat/model-name-propagation
Open

feat(run): Propagates model_name from the gateway request through the runtime and persistence stack to the SQLite database.#2775
yitang wants to merge 4 commits intobytedance:mainfrom
yitang:feat/model-name-propagation

Conversation

@yitang
Copy link
Copy Markdown

@yitang yitang commented May 7, 2026

Changes:

  • services.py: Extract model_name from RunCreateRequest.context
  • manager.py: RunRecord dataclass and create_or_reject() accept model_name
  • base.py: RunStore.put() interface includes model_name parameter
  • memory.py: MemoryRunStore implementation updated
  • sql.py: RunRepository.put() writes model_name to database

Verified: model_name correctly persisted in deerflow.db (tested manually with gpt-4o)

Enables users to track which model was used for each run by persisting model_name to the database. This supports auditability, cost tracking, and debugging by making model usage visible in stored run records.

…stence layer

Pass model_name through the full run creation pipeline — from
RunCreateRequest.context in the gateway, through RunManager, to the
RunStore interface and SQL persistence. This enables client-specified
model selection to be recorded per-run in the database.
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 7, 2026

CLA assistant check
All committers have signed the CLA.

@ggnnggez
Copy link
Copy Markdown
Contributor

ggnnggez commented May 7, 2026

@yitang
Thanks for the contribution. I think we should avoid persisting context.model_name directly from the request body, even it already process by FastAPI. At least we should do:

  • DB compatibility check (normalize and enforce the column length limit)
  • model allowlist check

And there is also an edge case around effective model resolution. This PR currently records the requested model name, not the model that was actually used. If the requested model is invalid and fallback to the default model, the persisted model_name would be inaccurate.

@yitang
Copy link
Copy Markdown
Author

yitang commented May 7, 2026

@ggnnggez, thanks for looking at it and providing feedback. I think I understand the 1st and 3rd point, I can try to incorporate them into the next PR.

Would you be able to elaborate a bit more on the 2nd point? I can see allowlist about skills, not about models.

Thanks

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

This PR threads a model_name value from the gateway run request (body.context) through the run lifecycle so it can be persisted on run records (in-memory store and SQL-backed repository), enabling auditing/cost/debug workflows based on the model used.

Changes:

  • Extract model_name from the gateway request context and pass it into RunManager.create_or_reject().
  • Extend the RunRecord / RunStore.put() API surface to carry model_name.
  • Persist model_name in both the in-memory RunStore and the SQL-backed runs table via RunRepository.put().

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
backend/app/gateway/services.py Extracts model_name from request context and forwards it into run creation.
backend/packages/harness/deerflow/runtime/runs/manager.py Adds model_name to RunRecord and persists it via the RunStore.
backend/packages/harness/deerflow/runtime/runs/store/base.py Extends the RunStore put() interface to include model_name.
backend/packages/harness/deerflow/runtime/runs/store/memory.py Stores model_name in the in-memory run record dict.
backend/packages/harness/deerflow/persistence/run/sql.py Writes model_name into RunRow when persisting runs to SQL.

Comment on lines +252 to +254
body_context = getattr(body, "context", None) or {}
model_name = body_context.get("model_name")

Comment on lines 84 to 90
row = RunRow(
run_id=run_id,
thread_id=thread_id,
assistant_id=assistant_id,
user_id=resolved_user_id,
model_name=model_name,
status=status,
Comment on lines 171 to 177
*,
on_disconnect: DisconnectMode = DisconnectMode.cancel,
metadata: dict | None = None,
kwargs: dict | None = None,
multitask_strategy: str = "reject",
model_name: str | None = None,
) -> RunRecord:
@WillemJiang WillemJiang added question Further information is requested reviewing The PR is in reviewing status labels May 8, 2026
yitang added 3 commits May 8, 2026 06:29
…pture

- Validate model_name against allowlist in gateway services.py using
  get_app_config().get_model_config()
- Truncate model_name to 128 chars to match DB column constraint
- In worker.py, capture effective model name from agent.metadata after
  agent creation and persist if resolved differently than requested
…ip persistence tests

- Add _normalize_model_name() to RunRepository for whitespace stripping
  and 128-char truncation before DB writes.
- Add round-trip unit tests for model_name creation and default None
  in test_run_manager.py.
@yitang
Copy link
Copy Markdown
Author

yitang commented May 8, 2026

@ggnnggez @WillemJiang updated the PR to address your comments and Copilot's comments. please have a look when you have time.

@WillemJiang WillemJiang changed the title Propagates model_name from the gateway request through the runtime and persistence stack to the SQLite database. feat(run): Propagates model_name from the gateway request through the runtime and persistence stack to the SQLite database. May 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

question Further information is requested reviewing The PR is in reviewing status

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants