Skip to content

Commit c6e5c94

Browse files
committed
mason: m1 renders host memory ids on host-backed harnesses, as m0 does
compose_m1_from_store decided its memory id space from meta.last_serializer_profile, which is only written for Claude Code. On OpenCode (and every other host-backed profile) it was empty, so m1 <new-memories> and <memory-updates> rendered MODULE ids while m0 rendered host mirror ids, and the m0 baseline in meta.rendered_memory_ids (host ids) was read as module ids. New test host_backed_m1_new_memories_render_host_ids_and_ride_the_next_bust was red (rendered #1 instead of #901) before this change. The caller now passes host_backed_memory_ids, computed exactly as m0 does: serializer_profile != Some(ClaudeCodeAnthropic). Claude Code keeps module ids (claude_code_m1_new_memories_keep_module_ids). The m1 revision is unchanged and m1 is composed only on bust passes, so the byte change rides the next natural bust; the new test asserts the defer after the memory insert serves byte-identical output. facade_merge_renders_a_budget_trimmed_target_then_defer_replays_bytes runs on the owned-llmrunner profile (host-backed) and relied on m1 rendering the merge's new row by its module id before any host acknowledgement. It now acknowledges that row (host id = module id, like the insert_memory helper) before the next pass; its assertions are unchanged. Also carries a rustfmt reflow of the status-report pending-delta check from the previous commit.
1 parent 77ea2da commit c6e5c94

3 files changed

Lines changed: 115 additions & 10 deletions

File tree

‎crates/mc-module/src/lib.rs‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7505,11 +7505,9 @@ impl McHandler {
75057505
}
75067506
};
75077507
let pending_m1_delta = loaded.meta.initialized
7508-
&& m1_signal
7509-
.as_ref()
7510-
.is_some_and(|signal| {
7511-
signal.revision != signal.equivalent_applied_revision(loaded.meta.m1_revision)
7512-
});
7508+
&& m1_signal.as_ref().is_some_and(|signal| {
7509+
signal.revision != signal.equivalent_applied_revision(loaded.meta.m1_revision)
7510+
});
75137511
let pending_m1_age_ms = pending_m1_delta
75147512
.then(|| now_ms().saturating_sub(loaded.meta.m1_pending_since_ms.unwrap_or(now_ms())));
75157513
let tail_hygiene = loaded.meta.tail_hygiene_baseline.as_ref().map(|baseline| {
@@ -30821,6 +30819,18 @@ mod tests {
3082130819
.superseded_by_memory_id
3082230820
.expect("merge created a canonical replacement");
3082330821
assert_ne!(canonical, target);
30822+
// This request uses a host-backed profile, so m1 renders host mirror ids. The host
30823+
// mirror acknowledges the merge's new row before the next pass, as it does for the
30824+
// rows `insert_memory` created.
30825+
store
30826+
.acknowledge_host_memory_ids(
30827+
project,
30828+
&[HostMemoryIdentityAck {
30829+
module_row_id: canonical,
30830+
host_row_id: canonical,
30831+
}],
30832+
)
30833+
.unwrap();
3082430834
let revision_after = crate::m1_compose::m1_revision_signal(&store, project, "ses").unwrap();
3082530835
assert_ne!(revision_before, revision_after);
3082630836
assert_eq!(
@@ -30906,6 +30916,7 @@ mod tests {
3090630916
&before_transition.meta,
3090730917
before_transition.meta.expiry_cutoff_ms,
3090830918
true,
30919+
true,
3090930920
8_000.0,
3091030921
4_000.0,
3091130922
true,

‎crates/mc-module/src/m1_compose.rs‎

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,10 @@ pub struct M1Composition {
311311
/// the last HARD froze in `meta`. `now_ms` is the frozen expiry cutoff (same as the m0
312312
/// compose). Reads compartments + memories; never call on a defer. `_note_project_path`
313313
/// is accepted for call-site stability only: ready smart notes are not rendered into m1.
314+
///
315+
/// `host_backed_memory_ids` must be the same choice the m0 render made for this request's
316+
/// serializer profile: true for every harness except Claude Code. It selects which id space
317+
/// m1 renders, and which id space `meta.rendered_memory_ids` (written by m0) is in.
314318
#[allow(clippy::too_many_arguments)]
315319
pub fn compose_m1_from_store(
316320
store: &McStore,
@@ -320,6 +324,7 @@ pub fn compose_m1_from_store(
320324
meta: &ModuleMeta,
321325
now_ms: i64,
322326
memory_enabled: bool,
327+
host_backed_memory_ids: bool,
323328
memory_budget_tokens: f64,
324329
user_profile_budget_tokens: f64,
325330
temporal_awareness: bool,
@@ -373,8 +378,6 @@ pub fn compose_m1_from_store(
373378
.map(|workspace| workspace.union_identities.clone())
374379
.unwrap_or_else(|| vec![project_path.to_string()]);
375380

376-
let host_backed_memory_ids = !meta.last_serializer_profile.is_empty()
377-
&& meta.last_serializer_profile != "claude-code-anthropic";
378381
let baseline_module_ids = if host_backed_memory_ids {
379382
let mapped = store.module_memory_ids_for_host_ids(&paths, &meta.rendered_memory_ids)?;
380383
meta.rendered_memory_ids
@@ -791,6 +794,7 @@ mod tests {
791794
&profile_delta_meta(),
792795
0,
793796
true,
797+
false,
794798
8_000.0,
795799
100.0,
796800
true,
@@ -811,6 +815,7 @@ mod tests {
811815
&profile_delta_meta(),
812816
0,
813817
true,
818+
false,
814819
8_000.0,
815820
100.0,
816821
true,
@@ -831,6 +836,7 @@ mod tests {
831836
&profile_delta_meta(),
832837
0,
833838
true,
839+
false,
834840
8_000.0,
835841
1.0,
836842
true,
@@ -936,6 +942,7 @@ mod tests {
936942
&meta,
937943
0,
938944
false,
945+
false,
939946
8_000.0,
940947
4_000.0,
941948
true,
@@ -965,6 +972,7 @@ mod tests {
965972
&meta,
966973
0,
967974
true,
975+
false,
968976
8_000.0,
969977
4_000.0,
970978
true,
@@ -992,6 +1000,7 @@ mod tests {
9921000
&meta,
9931001
0,
9941002
true,
1003+
false,
9951004
8_000.0,
9961005
4_000.0,
9971006
true,
@@ -1027,6 +1036,7 @@ mod tests {
10271036
&meta,
10281037
0,
10291038
true,
1039+
false,
10301040
8_000.0,
10311041
4_000.0,
10321042
true,
@@ -1122,6 +1132,7 @@ mod tests {
11221132
&meta,
11231133
1,
11241134
true,
1135+
false,
11251136
8_000.0,
11261137
4_000.0,
11271138
true,
@@ -1155,6 +1166,7 @@ mod tests {
11551166
&meta,
11561167
1,
11571168
true,
1169+
false,
11581170
8_000.0,
11591171
4_000.0,
11601172
true,
@@ -1196,6 +1208,7 @@ mod tests {
11961208
&reconciled_meta,
11971209
30,
11981210
true,
1211+
false,
11991212
8_000.0,
12001213
4_000.0,
12011214
true,
@@ -1289,6 +1302,7 @@ mod tests {
12891302
&meta,
12901303
0,
12911304
true,
1305+
false,
12921306
8_000.0,
12931307
4_000.0,
12941308
true,
@@ -1343,6 +1357,7 @@ mod tests {
13431357
&meta,
13441358
0,
13451359
true,
1360+
false,
13461361
8_000.0,
13471362
4_000.0,
13481363
true,
@@ -1357,6 +1372,7 @@ mod tests {
13571372
&meta,
13581373
0,
13591374
true,
1375+
false,
13601376
8_000.0,
13611377
4_000.0,
13621378
true,
@@ -1410,6 +1426,7 @@ mod tests {
14101426
&meta,
14111427
0,
14121428
true,
1429+
false,
14131430
8_000.0,
14141431
4_000.0,
14151432
true,
@@ -1468,6 +1485,7 @@ mod tests {
14681485
&meta,
14691486
0,
14701487
true,
1488+
false,
14711489
8_000.0,
14721490
4_000.0,
14731491
true,
@@ -1543,6 +1561,7 @@ mod tests {
15431561
&meta_after_hard(0, None, terminal, cursor, vec![source]),
15441562
0,
15451563
true,
1564+
false,
15461565
8_000.0,
15471566
4_000.0,
15481567
true,
@@ -1590,6 +1609,7 @@ mod tests {
15901609
&meta_after_hard(0, None, terminal, folded_cursor, vec![source]),
15911610
0,
15921611
true,
1612+
false,
15931613
8_000.0,
15941614
4_000.0,
15951615
true,
@@ -1628,6 +1648,7 @@ mod tests {
16281648
&meta_after_hard(0, None, cycle_target, 0, vec![cycle_source]),
16291649
0,
16301650
true,
1651+
false,
16311652
8_000.0,
16321653
4_000.0,
16331654
true,
@@ -1670,6 +1691,7 @@ mod tests {
16701691
&meta_after_hard(0, None, target, cursor, vec![source]),
16711692
0,
16721693
true,
1694+
false,
16731695
8_000.0,
16741696
4_000.0,
16751697
true,
@@ -1749,6 +1771,7 @@ mod tests {
17491771
&meta_after_hard(0, None, own_id, 0, vec![own_id]),
17501772
100,
17511773
true,
1774+
false,
17521775
8_000.0,
17531776
4_000.0,
17541777
true,
@@ -1781,6 +1804,7 @@ mod tests {
17811804
&meta_after_hard(0, None, own_id, grant_cursor, vec![foreign_id, own_id]),
17821805
100,
17831806
true,
1807+
false,
17841808
8_000.0,
17851809
4_000.0,
17861810
true,
@@ -1835,6 +1859,7 @@ mod tests {
18351859
&meta,
18361860
0,
18371861
true,
1862+
false,
18381863
8_000.0,
18391864
4_000.0,
18401865
true,
@@ -1880,6 +1905,7 @@ mod tests {
18801905
&meta,
18811906
0,
18821907
true,
1908+
false,
18831909
8_000.0,
18841910
4_000.0,
18851911
true,

‎crates/mc-module/src/transform.rs‎

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3091,6 +3091,7 @@ fn apply_additive_only(
30913091
&additive_meta,
30923092
meta.expiry_cutoff_ms,
30933093
ctx.memory_enabled,
3094+
serializer_profile != Some(SerializerProfile::ClaudeCodeAnthropic),
30943095
ctx.memory_budget_tokens,
30953096
ctx.user_profile_budget_tokens,
30963097
ctx.temporal_awareness,
@@ -5197,6 +5198,7 @@ fn apply_once(
51975198
&meta,
51985199
meta.expiry_cutoff_ms,
51995200
ctx.memory_enabled,
5201+
serializer_profile != Some(SerializerProfile::ClaudeCodeAnthropic),
52005202
ctx.memory_budget_tokens,
52015203
ctx.user_profile_budget_tokens,
52025204
ctx.temporal_awareness,
@@ -5489,9 +5491,7 @@ fn apply_once(
54895491
boundary_present: boundary_token,
54905492
..Default::default()
54915493
});
5492-
if compartment_seq_changed_since_meta
5493-
&& current_m1_digest == applied_m1_revision
5494-
{
5494+
if compartment_seq_changed_since_meta && current_m1_digest == applied_m1_revision {
54955495
meta.coverage_compartment_seq = Some(m1_signal.max_compartment_seq);
54965496
}
54975497
}
@@ -27856,6 +27856,74 @@ pub(crate) mod tests {
2785627856
);
2785727857
}
2785827858

27859+
/// Boot a session on `profile`, then insert a memory whose host mirror id differs from its
27860+
/// module id. Returns the boot response, the defer that follows the insert, and the SOFT
27861+
/// that an explicit refresh opens afterwards.
27862+
fn new_memory_passes_with_distinct_host_id(
27863+
profile: SerializerProfile,
27864+
) -> (TransformResponse, TransformResponse, TransformResponse) {
27865+
let dir = tempfile::tempdir().unwrap();
27866+
let s = store(dir.path());
27867+
s.replace_compartments("ses", &[comp(1, 1, 1, "m1msg", "SUMMARY")])
27868+
.unwrap();
27869+
let request = profile_req(profile, "ses", "cfg0", vec![item("m1msg", 1, "raw")]);
27870+
let boot = run(&s, &request, &spine());
27871+
assert_eq!(boot.action, "HARD");
27872+
27873+
let module_id = s
27874+
.insert_memory(memory_input(
27875+
"git:proj",
27876+
"ARCHITECTURE",
27877+
"a durable rule",
27878+
1,
27879+
))
27880+
.unwrap();
27881+
assert_eq!(module_id, 1);
27882+
s.acknowledge_host_memory_ids(
27883+
"git:proj",
27884+
&[mc_store::HostMemoryIdentityAck {
27885+
module_row_id: module_id,
27886+
host_row_id: 901,
27887+
}],
27888+
)
27889+
.unwrap();
27890+
27891+
let deferred = run(&s, &request, &spine());
27892+
s.arm_soft_refresh("ses").unwrap();
27893+
let soft = run(&s, &request, &spine());
27894+
(boot, deferred, soft)
27895+
}
27896+
27897+
#[test]
27898+
fn host_backed_m1_new_memories_render_host_ids_and_ride_the_next_bust() {
27899+
let (boot, deferred, soft) =
27900+
new_memory_passes_with_distinct_host_id(SerializerProfile::OpencodeAiSdk);
27901+
// A pending memory changes nothing on its own: the defer replays the frozen bytes.
27902+
assert_eq!(deferred.action, "SOFT+");
27903+
assert_eq!(
27904+
serde_json::to_string(deferred.messages()).unwrap(),
27905+
serde_json::to_string(boot.messages()).unwrap()
27906+
);
27907+
assert_eq!(soft.action, "SOFT");
27908+
let m1 = m1_bytes(&soft);
27909+
assert!(m1.contains("<new-memories>"), "{m1}");
27910+
assert!(
27911+
m1.contains("#901: a durable rule"),
27912+
"OpenCode m1 must render the host id, as m0 does: {m1}"
27913+
);
27914+
assert!(!m1.contains("#1: a durable rule"), "{m1}");
27915+
}
27916+
27917+
#[test]
27918+
fn claude_code_m1_new_memories_keep_module_ids() {
27919+
let (_, _, soft) =
27920+
new_memory_passes_with_distinct_host_id(SerializerProfile::ClaudeCodeAnthropic);
27921+
assert_eq!(soft.action, "SOFT");
27922+
let m1 = m1_bytes(&soft);
27923+
assert!(m1.contains("#1: a durable rule"), "{m1}");
27924+
assert!(!m1.contains("#901"), "{m1}");
27925+
}
27926+
2785927927
#[test]
2786027928
fn memory_off_absorbs_legacy_digest_without_leaking_and_reenable_hard_restores_memory() {
2786127929
let dir = tempfile::tempdir().unwrap();

0 commit comments

Comments
 (0)