fix(memory): P2 review fixes — API boundaries + identity + experimental flag

This commit is contained in:
matevip 2026-04-21 17:34:15 +08:00
parent 84c8f8f9a0
commit e69aa2be04
2 changed files with 17 additions and 5 deletions

View File

@ -129,6 +129,17 @@ public class DreamController {
@PathVariable Long reportId,
@PathVariable String key,
@RequestBody Map<String, String> body) {
// P2-5: Validate reportId belongs to this agent (0 = direct edit, skip validation)
if (reportId != 0L) {
DreamReportEntity report = dreamReportMapper.selectOne(
new LambdaQueryWrapper<DreamReportEntity>()
.eq(DreamReportEntity::getId, reportId)
.eq(DreamReportEntity::getAgentId, agentId)
.eq(DreamReportEntity::getDeleted, 0));
if (report == null) {
return R.fail("Report not found or does not belong to this agent");
}
}
String newContent = body.get("content");
if (newContent == null || newContent.isBlank()) {
return R.fail("content is required");
@ -144,8 +155,8 @@ public class DreamController {
if (principal instanceof vip.mate.auth.model.UserEntity user) {
return user.getId();
}
// Fallback: use abs(hashCode) to avoid negative IDs, add offset to avoid collision with real IDs
return Math.abs((long) auth.getName().hashCode()) + 1_000_000_000L;
// No stable user ID available refuse rather than fabricate
return null;
} catch (Exception e) {
return null;
}

View File

@ -21,9 +21,10 @@ import java.util.Set;
* Called as a synchronous step at the end of MemoryEmergenceService.consolidate
* (rfc-038 §3.7, decision D11 NOT an event listener).
*
* <p>Phase 3 L1: simple string-overlap detection between promoted entries
* and existing facts with the same subject but different object values.
* Full LLM batch judgment deferred to Phase 3 L4+.
* <p><b>EXPERIMENTAL</b> Phase 3 L1 uses simple string-overlap detection
* (same subject, different object). False positives are expected.
* Gated behind {@code mate.memory.fact.contradiction-check-enabled=false} (default off).
* Full LLM batch judgment (using contradiction-batch.txt prompt) deferred to Phase 3 L4+.
*
* @author MateClaw Team
*/