feat(run): Propagates model_name from the gateway request through the runtime and persistence stack to the SQLite database.#2775
Conversation
…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.
|
@yitang
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 |
|
@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 |
There was a problem hiding this comment.
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_namefrom the gateway request context and pass it intoRunManager.create_or_reject(). - Extend the
RunRecord/RunStore.put()API surface to carrymodel_name. - Persist
model_namein both the in-memory RunStore and the SQL-backedrunstable viaRunRepository.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. |
| body_context = getattr(body, "context", None) or {} | ||
| model_name = body_context.get("model_name") | ||
|
|
| 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, |
| *, | ||
| on_disconnect: DisconnectMode = DisconnectMode.cancel, | ||
| metadata: dict | None = None, | ||
| kwargs: dict | None = None, | ||
| multitask_strategy: str = "reject", | ||
| model_name: str | None = None, | ||
| ) -> RunRecord: |
…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.
…n _normalize_model_name
|
@ggnnggez @WillemJiang updated the PR to address your comments and Copilot's comments. please have a look when you have time. |
model_name from the gateway request through the runtime and persistence stack to the SQLite database.model_name from the gateway request through the runtime and persistence stack to the SQLite database.
Changes:
services.py: Extract model_name from RunCreateRequest.contextmanager.py: RunRecord dataclass and create_or_reject() accept model_namebase.py: RunStore.put() interface includes model_name parametermemory.py: MemoryRunStore implementation updatedsql.py: RunRepository.put() writes model_name to databaseVerified: 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_nameto the database. This supports auditability, cost tracking, and debugging by making model usage visible in stored run records.