Skip to content

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

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

Steven Enamakelb29fe974db75
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 67519b8f73..ea28d0b445 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,13 +1,13 @@
-//! Phase-out migration: removes legacy `### PROFILE.md` blocks from
-//! persisted session transcripts.
+//! 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
-//! this migration, an upgrade leaves the leaked content replaying
-//! inside every resumed thread forever — the runtime loader reuses the
-//! persisted system message verbatim for KV-cache stability.
+//! 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.
//!
//! ## What it does
//!
@@ -16,32 +16,15 @@
//! 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. **Walks every JSONL transcript** under `{workspace}/session_raw/`
-//! (both the current flat layout and the legacy `DDMMYYYY/`
-//! date-grouped subdirs), reads each file, and — if the first
-//! message is a system message containing a `### PROFILE.md`
-//! heading — removes the heading and everything beneath it up to
-//! the next `### ` heading (or end-of-prompt). The walk and the
-//! rewrite are TinyAgents' legacy maintenance
-//! (`tinyagents_session::legacy::rewrite_legacy_transcripts`), which
-//! owns the format, so the on-disk shape stays byte-compatible and this
-//! module names no transcript file. It runs before the workspace's
-//! one-time import into the session store.
-//! 3. **Sweeps `.md` companions** under `{workspace}/sessions/**/*.md`,
-//! rewriting in place any file whose body still contains a
-//! `### PROFILE.md` heading. The rest of the transcript
-//! (conversation messages, metadata header) is preserved — only
-//! the PROFILE.md block is removed. Supports both the new
-//! JSONL-companion format (`## [role]` headers, `---` separators)
-//! and the legacy HTML-comment format (`<!--MSG …-->` markers) via
-//! the boundary set in [`strip_profile_md_block`].
+//! 2. Leaves JSONL transcripts and Markdown companions byte-for-byte intact.
+//! `storage::import::sessions` removes the block only from imported bytes.
//!
//! ## Idempotency
//!
//! Gated externally by [`Config::schema_version`] — once the migration
//! succeeds and the bump is persisted, future launches skip it.
-//! Internally self-idempotent too: a transcript without any
-//! `### PROFILE.md` block is detected and left unchanged.
+//! The file deletion is idempotent; the import-time byte transform is also
+//! idempotent.
//!
//! ## Fresh installs
//!
@@ -67,18 +50,14 @@ pub struct PhaseOutStats {
/// True when the legacy `PROFILE.md` file at the workspace root was
/// deleted by this run. `false` when no file was present.
pub profile_md_removed: bool,
- /// Number of stale `.md` companions / legacy-format transcripts
- /// under `sessions/**/*.md` that contained a `### PROFILE.md` block
- /// and were rewritten in place with the block stripped (proofs
- /// preserved).
+ /// Retained for migration report compatibility. Source companions are
+ /// never rewritten, so this is always zero.
pub md_companions_altered: usize,
}
/// Run the migration over `workspace_dir`. Returns aggregate stats.
///
-/// Per-file failures are logged and counted in `stats.errors` but do
-/// not abort the walk — a single unreadable transcript shouldn't keep
-/// the rest of the fleet stuck on the old data.
+/// Legacy transcript files are handled by the read-only session importer.
pub fn run(workspace_dir: &Path) -> Result<PhaseOutStats> {
let mut stats = PhaseOutStats::default();
diff --git a/crates/openhuman-core/src/storage/import/sessions_tests.rs b/crates/openhuman-core/src/storage/import/sessions_tests.rs
index 6193fe184c..3ecce0d33c 100644
--- a/crates/openhuman-core/src/storage/import/sessions_tests.rs
+++ b/crates/openhuman-core/src/storage/import/sessions_tests.rs
@@ -53,6 +53,53 @@ fn host_jsonl_reader_preserves_meta_usage_typed_rows_and_tool_state() {
assert_eq!(row.message.tool_call_id.as_deref(), Some("call-1"));
}
+#[test]
+fn profile_phase_out_rewrites_imported_bytes_without_mutating_legacy_source() {
+ use tinyagents_session::transcript::DisplayRecord;
+
+ let dir = TempDir::new().unwrap();
+ let path = dir.path().join("thread.orchestrator.jsonl");
+ let prompt = "## Identity\n\nhello\n\n### PROFILE.md\n\nprivate\n\n### Tools\n\nshell\n";
+ write_classic(
+ &path,
+ &[
+ TranscriptMessage::system(prompt),
+ TranscriptMessage::user("question"),
+ ],
+ &TranscriptMeta {
+ agent_name: "Orchestrator".into(),
+ agent_id: Some("orchestrator".into()),
+ agent_type: None,
+ dispatcher: "native".into(),
+ provider: None,
+ model: None,
+ created: "2026-01-01T00:00:00Z".into(),
+ updated: "2026-01-01T00:00:00Z".into(),
+ turn_count: 1,
+ prefix_message_count: None,
+ input_tokens: 0,
+ output_tokens: 0,
+ cached_input_tokens: 0,
+ charged_amount_usd: 0.0,
+ thread_id: Some("thread".into()),
+ task_id: None,
+ session_id: None,
+ parent_session_id: None,
+ },
+ );
+ let source_before = std::fs::read(&path).unwrap();
+
+ let (_, _, records) = decode_transcript(&path).unwrap();
+
+ let DisplayRecord::Message(system) = &records[0] else {
+ panic!("expected imported system message");
+ };
+ assert!(!system.message.content.contains("PROFILE.md"));
+ assert!(!system.message.content.contains("private"));
+ assert!(system.message.content.contains("### Tools"));
+ assert_eq!(std::fs::read(&path).unwrap(), source_before);
+}
+
#[cfg(unix)]
#[test]
fn session_file_discovery_never_follows_symlinks_outside_legacy_roots() {