Commit 42b3215
committed
impl(sprint-11/wave-A): resolve codex P1 — v2 forward/set_temporal/pack semantic-routing bugs
Codex review on PR #383 surfaced three semantic-routing bugs all
sharing the root cause of "v1 API path bypasses v2 mantissa /
reclaim-zone semantics". Same anti-pattern as the W3 spec codex P1
from PR #381. All three fixed + paired with regression tests.
P1 #1 — forward() decoded weight.inference_type() (3-bit unsigned)
even under v2, so a v2 edge built with `with_inference_mantissa(-1)`
(Abduction direction) would read bits 46-48 as 0b111 = Reserved7 and
dispatch through the synthesis/default branch instead of Abduction.
Negative mantissas (Abduction, Counterfactual) silently produced
wrong NARS truth propagation.
Fix: under `causal-edge-v2-layout`, decode via
`InferenceType::from_mantissa(weight.inference_mantissa())` for the
match arm. Result re-stamped via `with_inference_mantissa(
resolved_infer.to_mantissa())` so the sign bit (49) survives pack()'s
v2 mantissa write (pack() needs the v1 enum value but to_mantissa()
maps it through correctly — see P2 fix below).
P1 #2 — set_temporal() unconditionally wrote bits 52-63 even under
v2 where those bits are plasticity[2] + W-slot + lens + spare. The
v1 learn() path calls set_temporal(current_time) after every
observation; that call clobbered W-slot routing state and corrupted
the reclaim zone for any edge that had been stamped via with_w_slot/
with_truth/etc. Same root cause as the pack() temporal-write bug
fixed in commit ab39d01 — just a different setter path that wasn't
gated.
Fix: feature-gate set_temporal() the same way as pack(): under v2,
the call is a complete no-op (the `t: u16` arg is silently dropped
with documented migration pointer to chain-position + AriGraph
Triplet.timestamp). learn() transitively becomes safe under v2 since
the only reclaim-zone write was the set_temporal call.
P2 — pack() under v2 wrote the raw `inference as u8` discriminant
into bits 46-48 (3-bit mask). With the v1 enum:
- Deduction=0, Induction=1, Abduction=2, Revision=3, Synthesis=4
- pack(Abduction) → bits 46-48 = 0b010, bit 49 = 0
- inference_mantissa() reads 4 bits as i4 → +2
- from_mantissa(+2) decodes as Induction, NOT Abduction
Silent semantic drift on every v2 pack() call for any non-Deduction
inference type.
Fix: under v2, pack() writes `inference.to_mantissa() as i4` (4 bits
including sign) so the round-trip pack→inference_mantissa→
from_mantissa preserves the semantic. The v1 branch keeps the
original 3-bit discriminant write for back-compat. forward()'s
final re-stamp (P1 #1 fix) covers the case where the resolved
InferenceType needs to be re-encoded after composition.
Three regression tests added to `v2_layout_tests.rs`:
- `test_forward_decodes_negative_mantissa_under_v2` — Abduction via
mantissa=-1 must NOT alias Reserved7
- `test_set_temporal_no_op_under_v2` — set_temporal(1023) on an edge
with w=42/truth=Fuzzy/spare=0b101 must leave the raw u64 unchanged
- `test_pack_uses_mantissa_mapping_under_v2` — pack(Abduction),
pack(Counterfactual), pack(Intervention) all round-trip through
inference_mantissa → from_mantissa with semantic identity preserved
Test status post-fix:
- v2 (default): 33 pass / 1 pre-existing fail (test_build_fast)
- v1 (no features): 16 pass / 1 pre-existing fail
- The 3 new regression tests prevent silent re-introduction
https://claude.ai/code/session_01UwJuKqP828qyX1VkLgGJFS1 parent fd61310 commit 42b3215
2 files changed
Lines changed: 162 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
178 | 179 | | |
179 | 180 | | |
| 181 | + | |
| 182 | + | |
180 | 183 | | |
181 | 184 | | |
182 | 185 | | |
| |||
185 | 188 | | |
186 | 189 | | |
187 | 190 | | |
| 191 | + | |
188 | 192 | | |
189 | 193 | | |
190 | 194 | | |
| |||
480 | 484 | | |
481 | 485 | | |
482 | 486 | | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
483 | 498 | | |
484 | 499 | | |
485 | | - | |
486 | | - | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
487 | 509 | | |
488 | 510 | | |
489 | 511 | | |
| |||
533 | 555 | | |
534 | 556 | | |
535 | 557 | | |
536 | | - | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
537 | 569 | | |
538 | 570 | | |
539 | 571 | | |
| |||
577 | 609 | | |
578 | 610 | | |
579 | 611 | | |
580 | | - | |
| 612 | + | |
| 613 | + | |
581 | 614 | | |
582 | 615 | | |
583 | 616 | | |
584 | 617 | | |
585 | 618 | | |
586 | 619 | | |
587 | 620 | | |
588 | | - | |
| 621 | + | |
589 | 622 | | |
590 | 623 | | |
591 | | - | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
592 | 632 | | |
593 | 633 | | |
594 | 634 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
279 | 279 | | |
280 | 280 | | |
281 | 281 | | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
282 | 394 | | |
0 commit comments