Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/ContextMemory.Core/Agentic/AgentContextCompactor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ public AgentContextCompactor(
if (estimated <= maxTokens || messages.Count < 4)
return null;

var historyId = $"history:{sessionId}:{iteration}:{Guid.NewGuid():N}"[..64];
// Keep under common FS/DB id limits without assuming the prefix is already >= 64 chars
// (short session ids like Jira keys produced ArgumentOutOfRange on ..[64]).
var historyId = $"history:{sessionId}:{iteration}:{Guid.NewGuid():N}";
if (historyId.Length > 64)
historyId = historyId[..64];
var transcript = SerializeTranscript(messages);

try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ internal static string TruncateWithPointer(
return string.IsNullOrWhiteSpace(artifactId) ? payload : payload + pointer;
}

var previewLen = Math.Max(64, Math.Min(maxChars - 120, maxChars));
// previewLen must never exceed payload.Length (maxChars can be < 64 + pointer overhead).
var previewLen = Math.Clamp(maxChars - 120, 1, payload.Length);
previewLen = Math.Min(previewLen, Math.Max(1, payload.Length - 1));
var preview = payload[..previewLen];
return preview
+ $"\n\n…[truncated {payload.Length - previewLen} chars; artifactId={id} "
Expand Down
3 changes: 2 additions & 1 deletion src/ContextMemory.Core/Agentic/SessionDiscoveryTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ public static string ShortenDescription(string? description, int maxChars = 120)
if (trimmed.Length <= maxChars)
return trimmed + " (tool_describe for full schema)";

return trimmed[..Math.Max(40, maxChars - 32)].TrimEnd() + "… (tool_describe for full schema)";
var keep = Math.Clamp(maxChars - 32, 1, trimmed.Length);
return trimmed[..keep].TrimEnd() + "… (tool_describe for full schema)";
}
}
3 changes: 2 additions & 1 deletion src/ContextMemory.Core/Session/SessionWikiCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ public static WikiCompileResult Compile(
if (sb.Length > 0)
sb.Append("\n\n");
sb.Append(header);
sb.Append(body[..availableForBody].TrimEnd());
var take = Math.Min(availableForBody, body.Length);
sb.Append(body[..take].TrimEnd());
sb.Append(PageTruncatedSuffix);
remaining = 0;
included++;
Expand Down
Loading