fix(continuous-learning-v2): run shape patterns before the keyword matcher

_SECRET_RE stops after 256 value chars. With it first, a longer
keyword-labeled key such as OPENAI_API_KEY=sk-proj-... lost its prefix
and the shape pattern could no longer see the rest, so the tail was
persisted. Running _SECRET_VALUE_RE first fixes both the observation
path and the parse-error fallback; "[REDACTED]" is outside the keyword
value class, so the second pass leaves it alone.
This commit is contained in:
Karim Masmoudi committed 2026-11-04 11:43:29 +01:00
1 parent ac89d627b4
commit 16a23737f2
3 files changed
+20 -3

No files matched your search

@@ -10,7 +10,7 @@
"id": "hand-seeded",
"source": "manual-curation-pending-regeneration"
},
"registryDigest": "f24282bd1d290f922b4ffe2f996ae7b249f84ef2a18804ff97633012818f3093",
"registryDigest": "e93e6248f74627968ef65d9bf0e64a6c0d22abce6efc6342c856613bf3262015",
"schemaVersion": 1,
"triggers": {
"skill:agent-runtime-gateway-smoke-test": [
@@ -313,8 +313,10 @@ except Exception:
raw_full = sys.stdin.read()
raw = raw_full[:2000]
raw = _SECRET_RE.sub(lambda m: m.group(1) + m.group(2) + (m.group(3) or "") + "[REDACTED]", raw)
# Shape patterns first: _SECRET_RE stops after 256 value chars, which would
# strip the sk-/eyJ prefix from a longer keyword-labeled key and leave its tail.
raw = _SECRET_VALUE_RE.sub(lambda m: (m.group(2) or "") + "[REDACTED]", raw)
raw = _SECRET_RE.sub(lambda m: m.group(1) + m.group(2) + (m.group(3) or "") + "[REDACTED]", raw)
if len(raw_full) > 2000:
raw = _CUT_TAIL_RE.sub("[REDACTED]", raw)
print(json.dumps({"timestamp": os.environ["TIMESTAMP"], "event": "parse_error", "raw": raw}))
@@ -405,8 +407,10 @@ def scrub(val):
val = str(val)
# Tool I/O is cut to 5000 chars before it reaches this process.
cut = len(val) >= 5000
val = _SECRET_RE.sub(lambda m: m.group(1) + m.group(2) + (m.group(3) or "") + "[REDACTED]", val)
# Shape patterns first: _SECRET_RE stops after 256 value chars, which would
# strip the sk-/eyJ prefix from a longer keyword-labeled key and leave its tail.
val = _SECRET_VALUE_RE.sub(lambda m: (m.group(2) or "") + "[REDACTED]", val)
val = _SECRET_RE.sub(lambda m: m.group(1) + m.group(2) + (m.group(3) or "") + "[REDACTED]", val)
return _CUT_TAIL_RE.sub("[REDACTED]", val) if cut else val
if parsed["input"]:
@@ -190,6 +190,19 @@ if (process.platform === 'win32') {
assert.equal(capturedField(records, 'content'), 'value [REDACTED] end');
});
}
// The keyword matcher stops after 256 value chars, so a long keyword-labeled
// key must be caught by its shape first or its tail is persisted.
for (const [phase, input, expectedEvent] of [
['post', { tool_name: 'Read', tool_input: { file_path: '/tmp/x' },
tool_response: { content: `OPENAI_API_KEY=${openaiProjectKey}${'B'.repeat(300)}${longTail}` } }],
['post', JSON.stringify([`OPENAI_API_KEY=${openaiProjectKey}${'B'.repeat(300)}${longTail}`]), 'parse_error']
]) {
test(`redacts a long keyword-labeled sk-proj key completely (${expectedEvent || 'tool_complete'})`, () => {
const records = capture(phase, input, expectedEvent);
assert.ok(!records.includes(longTail), 'key tail persisted');
assert.ok(records.includes('OPENAI_API_KEY=[REDACTED]'));
});
}
// The end-of-capture match only applies to text that was actually cut.
for (const output of ['git checkout sk-learn', 'payload eyJhIjoxLCJiIjoyfQ']) {