Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(config): update profile md phase-out migration logic

Steven Enamakelaf8ba84bc94f
diff --git a/crates/openhuman-core/src/config/migrations/README.md b/crates/openhuman-core/src/config/migrations/README.md
index 145db95055..82da75bde4 100644
--- a/crates/openhuman-core/src/config/migrations/README.md
+++ b/crates/openhuman-core/src/config/migrations/README.md
@@ -19,7 +19,7 @@ Startup data-migration runner gated by `Config::schema_version`. Each migration
| File | Role |
| ---------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`crates/openhuman-core/src/config/migrations/mod.rs`](./mod.rs) | Module docstring + the `run_pending` runner, `seed_new_workspace`, and the `CURRENT_SCHEMA_VERSION` constant; declares each migration as a private `mod`. The 10→11 step (`reseed_cloud_providers`) is written inline here rather than as its own module. |
-| [`crates/openhuman-core/src/config/migrations/phase_out_profile_md.rs`](./phase_out_profile_md.rs) | **0→1.** Deletes `{workspace}/PROFILE.md` and strips `### PROFILE.md` blocks from persisted JSONL session transcripts (`session_raw/**`) and `.md` companions (`sessions/**`). Blocking fs I/O. |
+| [`crates/openhuman-core/src/config/migrations/phase_out_profile_md.rs`](./phase_out_profile_md.rs) | **0→1.** Retains source `PROFILE.md`, JSONL transcripts, and `.md` companions. Session import strips the retired prompt section in memory before writing destination rows. |
| [`crates/openhuman-core/src/config/migrations/unify_ai_provider_settings.rs`](./unify_ai_provider_settings.rs) | **1→2.** Consolidates scattered AI-provider settings into per-workload provider strings; seeds `cloud_providers` (always an `Openhuman` entry) and migrates a non-backend `inference_url` into a `Custom` cloud entry. Pure in-memory. |
| [`crates/openhuman-core/src/config/migrations/retire_chat_v1_model.rs`](./retire_chat_v1_model.rs) | **2→3.** Legacy `chat-v1` migration hook retained for schema-version progression; a no-op (the slug itself is retired by 12→13). Pure in-memory. |
| [`crates/openhuman-core/src/config/migrations/expand_autonomy_defaults.rs`](./expand_autonomy_defaults.rs) | **3→4.** Additively merges expanded `autonomy.allowed_commands` / `auto_approve` defaults (PR #2500) and bumps `max_actions_per_hour` from the old `20` to `u32::MAX` only when still exactly `20`. Pure in-memory. |
@@ -62,12 +62,12 @@ None. No event-bus publishers or subscribers.
Does not own a `store.rs`. Its effects are written through other layers:
- `Config` mutations (incl. `schema_version`) persisted via `Config::save()` to `config.toml`, driven by the runner in `mod.rs`.
-- `phase_out_profile_md` rewrites session transcript files in place under `{workspace}/session_raw/**` and `{workspace}/sessions/**`, and deletes `{workspace}/PROFILE.md`.
+- `phase_out_profile_md` preserves workspace source files; `storage::import::sessions` transforms only the in-memory transcript bytes imported into the new session store.
## Dependencies
- `crate::config` (`Config`, `HttpRequestConfig`, `schema::cloud_providers::{CloudProviderCreds, AuthStyle, builtin_cloud_provider, generate_provider_id}`, `schema::LlmBackend`, `MODEL_CHAT_V1`, `MODEL_REASONING_V1`, `MODEL_REASONING_QUICK_V1`): the migrations read and mutate the config struct; `schema_version` is the gating field.
-- `tinyagents_session::transcript` (`transcript`, `SessionTranscript`, `write_transcript`): `phase_out_profile_md` parses and rewrites persisted session transcripts byte-compatibly.
+- `tinyagents_session::transcript`: the sessions importer applies its pure JSONL transformer to a byte copy before decoding; source transcripts remain unchanged.
- `crate::inference::provider::factory`: `reconcile_orphaned_providers` mirrors the factory's exact, case-sensitive provider-string grammar so "resolvable here" matches "resolvable at inference time"; `unify_ai_provider_settings` references the factory's provider-string format.
- `crate::inference::host_runtime::ollama_base_url_from_config`: the runner's Ollama reachability probe for the 6→7 step. That step and the 9→10 step mirror, by hand, the provider-string grammar of `embeddings::factory::create_embedding_provider` and `voice::factory::create_stt_provider` respectively (doc-linked, not imported), so keep them in sync when those factories change.
- `tinyagents_session::transcript::TranscriptMessage`, `schema::{LocalAiConfig, LocalAiUsage, ModelRouteConfig, SttEngine}` and `voice::factory::effective_stt_provider` are imported only by tests.
diff --git a/crates/openhuman-core/src/config/migrations/phase_out_profile_md.rs b/crates/openhuman-core/src/config/migrations/phase_out_profile_md.rs
index ea28d0b445..26414f1973 100644
--- a/crates/openhuman-core/src/config/migrations/phase_out_profile_md.rs
+++ b/crates/openhuman-core/src/config/migrations/phase_out_profile_md.rs
@@ -1,30 +1,22 @@
//! Phase-out migration: retires workspace `PROFILE.md` without modifying
//! legacy transcript source files.
//!
-//! `PROFILE.md` is being retired as a system-prompt injection. Earlier
-//! builds wrote the file into the system prompt of every session and
-//! froze those bytes inside `session_raw/{stem}.jsonl` (see
-//! [`tinyagents_session::transcript`]). Without
-//! Transcript source bytes are preserved. The session importer strips that
-//! block from a temporary in-memory copy before importing it into the new
-//! session store.
+//! `PROFILE.md` is no longer injected into new prompts. Older transcripts may
+//! still contain its section; the session importer removes that section from
+//! imported bytes in memory while preserving all source files.
//!
//! ## What it does
//!
-//! 1. **Deletes `{workspace}/PROFILE.md`** if it exists. With the file
-//! gone, the renderer's `inject_workspace_file_capped` short-circuits
-//! silently — agents that still have `omit_profile = false`
-//! (orchestrator, welcome, trigger_*, help) produce a clean prompt
-//! on every new session without any source-code change.
-//! 2. Leaves JSONL transcripts and Markdown companions byte-for-byte intact.
-//! `storage::import::sessions` removes the block only from imported bytes.
+//! 1. Leaves `PROFILE.md`, JSONL transcripts, and Markdown companions
+//! byte-for-byte intact.
+//! 2. `storage::import::sessions` strips the old prompt section from imported
+//! JSONL bytes through TinyAgents' format-aware pure transformer.
//!
//! ## Idempotency
//!
//! Gated externally by [`Config::schema_version`] — once the migration
//! succeeds and the bump is persisted, future launches skip it.
-//! The file deletion is idempotent; the import-time byte transform is also
-//! idempotent.
+//! The import-time byte transform is idempotent.
//!
//! ## Fresh installs
//!
@@ -33,7 +25,6 @@
//! `schema_version` so future launches don't re-check.
use anyhow::Result;
-use std::fs;
use std::path::Path;
/// Line that opens a `PROFILE.md` block in a system prompt. Matches the
@@ -47,8 +38,8 @@ pub struct PhaseOutStats {
pub cleaned: usize,
pub skipped: usize,
pub errors: usize,
- /// True when the legacy `PROFILE.md` file at the workspace root was
- /// deleted by this run. `false` when no file was present.
+ /// Retained for report compatibility. Source profile files are preserved,
+ /// so this is always false.
pub profile_md_removed: bool,
/// Retained for migration report compatibility. Source companions are
/// never rewritten, so this is always zero.
@@ -58,16 +49,8 @@ pub struct PhaseOutStats {
/// Run the migration over `workspace_dir`. Returns aggregate stats.
///
/// Legacy transcript files are handled by the read-only session importer.
-pub fn run(workspace_dir: &Path) -> Result<PhaseOutStats> {
- let mut stats = PhaseOutStats::default();
-
- // Final piece of the consumer-side phase-out: delete the legacy
- // `PROFILE.md` file at the workspace root. With the file gone the
- // renderer's `inject_workspace_file_capped` short-circuits silently,
- // so even the agents whose `omit_profile = false` still want it will
- // produce a clean prompt. This is intentionally done *before* the
- // transcript walk so that a partial run still removes the file.
- stats.profile_md_removed = remove_workspace_profile_md(workspace_dir, &mut stats);
+pub fn run(_workspace_dir: &Path) -> Result<PhaseOutStats> {
+ let stats = PhaseOutStats::default();
// Transcript JSONL and Markdown companions are immutable source
// evidence. The session importer applies the pure TinyAgents rewrite to
@@ -87,32 +70,6 @@ pub fn run(workspace_dir: &Path) -> Result<PhaseOutStats> {
Ok(stats)
}
-/// Delete `{workspace_dir}/PROFILE.md` if it exists. Errors are folded
-/// into `stats.errors`. Returns `true` when a file was removed.
-fn remove_workspace_profile_md(workspace_dir: &Path, stats: &mut PhaseOutStats) -> bool {
- let path = workspace_dir.join("PROFILE.md");
- if !path.exists() {
- return false;
- }
- match fs::remove_file(&path) {
- Ok(()) => {
- log::info!(
- "[migration:phase-out-profile-md] removed legacy file path={}",
- path.display()
- );
- true
- }
- Err(err) => {
- stats.errors += 1;
- log::warn!(
- "[migration:phase-out-profile-md] failed to remove {}: {err:#}",
- path.display()
- );
- false
- }
- }
-}
-
/// Strip a `### PROFILE.md` block from a string.
///
/// The block is anchored on a line equal to [`PROFILE_HEADING`] and
diff --git a/crates/openhuman-core/src/config/migrations/phase_out_profile_md_tests.rs b/crates/openhuman-core/src/config/migrations/phase_out_profile_md_tests.rs
index f9489dd8d6..7472e01f78 100644
--- a/crates/openhuman-core/src/config/migrations/phase_out_profile_md_tests.rs
+++ b/crates/openhuman-core/src/config/migrations/phase_out_profile_md_tests.rs
@@ -37,14 +37,14 @@ fn leaves_legacy_transcript_and_markdown_source_bytes_unchanged() {
}
#[test]
-fn removes_only_the_retired_workspace_profile_file() {
+fn preserves_workspace_profile_source_file() {
let workspace = TempDir::new().unwrap();
let profile = workspace.path().join("PROFILE.md");
fs::write(&profile, "profile content").unwrap();
let stats = run(workspace.path()).unwrap();
- assert!(stats.profile_md_removed);
- assert!(!profile.exists());
+ assert!(!stats.profile_md_removed);
+ assert_eq!(fs::read_to_string(profile).unwrap(), "profile content");
assert_eq!(stats.errors, 0);
}