Skip to content

Commit 4087cce

Browse files
anandgupta42claude
andcommitted
fix: address new Sentry findings — regex m flag and off-by-one budget check
1. formatTrainingEntry regex: remove multiline `m` flag that could match user content mid-string (memory/prompt.ts:82) 2. Memory block budget check: change `<` to `<=` so blocks that fit exactly into remaining budget are included (memory/prompt.ts:204) 3 prior Sentry findings already fixed in earlier commits: - projectDir cache (Map keyed by Instance.directory) - injectTrainingOnly header-only return (itemCount guard) - orphaned section headers (first-entry pre-check) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 52c40f5 commit 4087cce

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
fix: CI failure + new Sentry finding — orphaned headers and agent test
1+
fix: address multi-model code review findings
22

3-
1. Agent test: add researcher + trainer to "all disabled" test so it
4-
correctly expects "no primary visible agent" when ALL agents are off
3+
Fixes from 6-model consensus review (Claude + GPT + Gemini + Kimi + MiniMax + GLM-5):
54

6-
2. Orphaned section headers: add pre-check that at least one entry fits
7-
before adding section header in both injectTrainingOnly and inject
8-
memory section (prevents header-only output inflating budget reports)
5+
1. training_remove: add name validation regex matching training_save
6+
(Gemini finding — prevents path traversal via malformed names)
7+
8+
2. training_save: improve name transform to strip ALL non-alphanumeric
9+
chars, not just whitespace (Gemini finding — "don't-use-float!"
10+
now becomes "don-t-use-float" instead of failing regex)
11+
12+
3. incrementApplied: replace silent `.catch(() => {})` with warning
13+
log (Kimi + GLM-5 consensus — fire-and-forget is by design but
14+
failures should be visible in logs for debugging)
915

1016
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

packages/opencode/src/memory/prompt.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export namespace MemoryPrompt {
7979
const meta = parseTrainingMeta(block.content)
8080
const appliedStr = meta && meta.applied > 0 ? ` (applied ${meta.applied}x)` : ""
8181
// Strip the training metadata comment from content for display
82-
const content = block.content.replace(/^<!--\s*training\n[\s\S]*?-->\n*/m, "").trim()
82+
const content = block.content.replace(/^<!--\s*training\n[\s\S]*?-->\n*/, "").trim()
8383
const name = block.id.split("/").slice(2).join("/") || block.id
8484
return `#### ${name}${appliedStr}\n${content}`
8585
}
@@ -201,7 +201,7 @@ export namespace MemoryPrompt {
201201
if (memoryBlocks.length > 0) {
202202
const memHeader = "\n### Memory\n"
203203
const firstMemFormatted = formatBlock(memoryBlocks[0].block)
204-
if (used + memHeader.length + firstMemFormatted.length + 2 < budget) {
204+
if (used + memHeader.length + firstMemFormatted.length + 2 <= budget) {
205205
result += memHeader
206206
used += memHeader.length
207207

0 commit comments

Comments
 (0)