Repository navigation
learn: right tool per result, misuse notes count, nightly SCARS refresh - #628
Conversation
…ightly Three changes to failure mining, the record behind SCARS.md. Attribution. A tool result went to the first call in the session with its id. Some servers number calls per turn (c1, c2 ...: the relay provider, several local OpenAI-compatible servers), so a later turn's result was blamed on turn one's tool. On the live security run, a shell_exec refusal was reported as grep_files'. The latest call with the id wins now. Misuse. When a tool's result says it was used wrongly (grep_files given a regex, a definition hunted by guessing its keyword), nothing failed, so nothing was counted. Those lines are patterns now, of kind "misuse". They cluster by what was done wrong rather than by their text, because the definition note names the symbol searched for and every name would otherwise be a one-off. A test runs grep_files itself, so a reworded note fails there instead of going quietly uncounted. Nightly. The mining moves from the learn command into PasClaw.Learn, and pasclaw maintain (and so the @Maintain cron entry) runs it over the last 30 days: a Recurring section in the report, and an anchor in SCARS.md for each recurring pattern the file lacks (not on --dry-run). Existing anchors and the operator's text under them are left alone. Each session is still read once for all three windows. The anchor mark is a SectionSign constant: a literal glyph was transcoded to the Latin-1 byte in a test binary, and the UTF-8 byte escapes are two characters under Delphi. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4ce9e951dd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if not WriteScars(Path, Patterns, MinSessions, Fresh, Skipped) then | ||
| begin | ||
| PrintLn(Ansi.Red + 'could not write ' + Path + Ansi.Reset); | ||
| Exit; |
There was a problem hiding this comment.
Propagate SCARS write failures to the command exit status
When learn --write-scars cannot read or write SCARS.md (for example, because the memory directory is read-only or the disk is full), WriteScars now catches the exception and returns false, but this branch only prints a message and exits the procedure. Cmd_Learn_Run consequently returns its initialized status of 0, so scripts treat a failed persistence operation as successful. Previously, the I/O exception propagated instead. Return the failure to Cmd_Learn_Run and set a nonzero exit status.
Useful? React with 👍 / 👎.
The nightly pass writes SCARS.md unattended, so what it mines and what it keeps had to tighten. - Quoted text is not mined. A tool that fetches or stores text (read_file, grep_files, memory_search, web_fetch ...) counts only by its first line, and only as its own ERROR: or misuse note; lines of SCARS.md and of a maintenance report are skipped wherever they turn up. Before, SCARS.md read back in two sessions came back as new patterns, and the next night wrote anchors for its own Symptom lines. - Misuse notes are one table in the new PasClaw.Tools.Notes, which grep_files builds its notes from (output byte-identical) and Learn reads; a line counts only when it starts with a note, so a file or a memory note that quotes one is not a misuse. - Credentials are masked before a line is kept, in sample and signature: URL userinfo, prefixed tokens, password= / token: / Bearer values, long mixed-case runs. SCARS.md goes into committed rule files via export. - WriteScars hands back counts only after the write, follows a renamed anchor through its signature, gives a colliding anchor a -2 suffix instead of dropping the pattern as "already there", claims a hand-written block once, and has a dry-run mode. It returns each pattern's anchor as the file has it, which the report now cites. - Maintain loads each session for the widest of its three windows and checks each on its own, so --since past unused_skill_days counts every session in it. Its session stats use Learn's classifier, so the failure count and the Recurring list agree, and misuses are counted. Its own failure heuristic is gone. - One window rule (InWindow) for both callers: a session with no timestamp is inside it, for maintain as for learn. ScanSession lost its own window check. - A miner keeps one signature index for the whole pass; lines are split in one pass; the sort is a stable merge sort. Pattern kind is an enum. Samples are clipped by character, not byte. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
- Tools that quote stored text are a table beside the tools
(QuotingTools in PasClaw.Tools.Notes), and it now covers the board and
subagents: task and rule carry checks' output, agent and spawn_wait a
subagent's answer. Before, one failing check read by every agent on a
team recurred across their sessions and got a SCARS anchor. A test
registers the tools and fails on a read-only one in neither the table
nor its own-outcome list.
- A line that says a result failed but not how -- a nonzero exit=N, a
traceback's header, "build FAILED" -- is Bare: it counts the result as
failed and is never a pattern. "exit=1" had been a content-free
pattern shared by every failing command, and the traceback header one
shared by every Python error. Every nonzero exit counts now, not only
1 and 2; maintain's sample is the line that says how it failed.
- A session without timestamps ages by its CreatedAt, else its file's
mtime, and one of unknown age is outside a window: undated sessions
no longer recur in "the last 30 days" forever.
- Lines lose their colour codes, are redacted over their first 4000
columns and then cut to 400, so a minified bundle on one line is not
a megabyte in SCARS.md and no secret is cut before it is seen whole.
- Redaction also takes a flag's value after a space (--password x) and
whole base64 keys ('+' or '=' padding).
- MEMORY.md's Patterns bullets and recurring lines without an anchor are
recorded lines too.
- SCARS.md signatures compare by case, as the miner keeps them; the
file is read once per write; maintain walks each session's messages
once and classifies each tool result once.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
Three fixes to
pasclaw learn, the failure mining that fillsSCARS.md. They came out of reading what it made of the live security run. Two more commits fix what two rounds of code review found; see Review fixes and Second review below.1. Each result goes to the call that made it
A tool result was matched to the first call in the session with its id. Some servers number calls per turn (
c1,c2, ...): the relay provider, and several local OpenAI-compatible servers. So every laterc1went to turn one's tool.On the live security run, the
evalrefusal fromshell_execwas reported as agrep_filesfailure.The fix: the latest call with the id wins. A result always follows its own call.
2. Misuse notes count
Some tool results say the call was the wrong one and what to do instead:
grep_filesgiven a regex:(no matches) -- note: grep_files matches a LITERAL substring ...-- to find where a name is defined ... code_outline symbol="X"Nothing failed, so nothing counted them. They are patterns now, of kind misuse, shown in the report and in SCARS.md (
**Kind:** misuse).§GREP-FILES-DEFINITION-HUNT-KEYWORD), not two one-offs.grep_filesitself, so a reworded note fails that test instead of going quietly uncounted.3. The nightly pass runs it
The mining moves out of the command into
src/pkg/memory/PasClaw.Learn.pas.pasclaw maintain, and so the@maintaincron entry, runs it over the last 30 days:§ANCHORit has in SCARS.md. The optional review model sees this section too.learn --write-scarsdoes by hand.--dry-runlists the patterns and how many anchors a real run would add, and leaves the file untouched.N recurring (M new in SCARS.md).Review fixes
The nightly pass writes SCARS.md with nobody looking, so what it mines and what it keeps had to tighten.
Quoted text is no longer mined.
ERROR:or misuse note.catin a shell.**Symptom:**lines.Misuse notes are one table in the new
PasClaw.Tools.Notes.grep_filesbuilds its notes from it, and its output is byte-identical (make bench-codenavis unchanged).Credentials are masked as
<redacted>before a line is kept, in both the sample and the signature. This covers:ghp_,sk-,xoxb-,AKIA, ...);password=/token:/Bearer;The reason:
pasclaw exportcopies SCARS.md into committed rule files. Hashes and plain lowercase words stay as they are.Anchors.
-2,-3, .... Before, the second was dropped as "already there".A failed SCARS write reports nothing added.
One failure definition. Maintain's session stats use Learn's classifier, so the Sessions count and the Recurring list agree, and misuses are counted (
..., 1 tool failure, 1 misuse).The stats window is checked on its own, so a
--sincelonger thanunused_skill_dayscounts every session in it.Efficiency. One signature index for the whole pass, line splitting in a single pass, a stable merge sort, samples clipped by character, and the pattern kind as an enum.
Second review
taskandrulecarry the checks' output, andagent,spawn_waitandspawn_statuscarry another agent's answer.ruleresult carries a check thatfailed (exit 1), with its output; that failure is the point of the proof.QuotingToolsinPasClaw.Tools.Notes, beside the tools.plan_write). It also fails on a listed name that is not a real tool.exit=N, a traceback's header,build FAILED (...).exit=1, the first line of every failingshell_exec, had been a content-free pattern shared by every failing command; the traceback header was one shared by every Python error.CreatedAt, else by its file's modification time. One of unknown age is outside a window, so undated sessions no longer recur in "the last 30 days" forever.--password x) and whole base64 keys (+, or=padding). Paths, andKEY=valuewith its key, stay readable.--writeputs in MEMORY.md, and recurring lines without an anchor, are recorded lines too.On the live run's sessions
pasclaw learn --min 1grep_filesshell_exec; the regex misuse, toolgrep_filespasclaw maintainThe second row is correct: each problem happened once, in one session.
To exercise the recurring path through the real binary, I added a copy of the security session under a second id, as if it had happened twice. This is a simulation, not real data:
maintainlisted both patterns and wrote two anchors.0 new anchors added, 2 already there.--dry-runsaid0 new anchors would be added.ruleresult's check output was not mined.The § mark
The anchor mark is a
SectionSignconstant.§came out as the Latin-1 byte in a test binary, because FPC transcodes literals through the runtime codepage.#$C2#$A7byte escapes used before are two characters under Delphi.#$00A7under Delphi.Tests
=;grep_filesrun for real, both for its notes and for a file that quotes a note;SessionStamp;exit=1results sampled by the line that says how, as valid UTF-8.Verification
make testpasses on FPC 3.2.2.make bench-codenav: the definition-hunt bytes (8,499) are unchanged.PasClaw.Learn.pasandPasClaw.Tools.Notes.pasare added toPasClaw.dproj.Notes
memory_search, as before. Whether to inject it is a separate decision.🤖 Generated with Claude Code
https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U