Repository navigation
fix(memory): stop storing permission refusals as errors to avoid - #4058
Conversation
Most auto-stored tool errors were permission refusals (a command not on the allowlist, a path outside allowed_paths). They describe that run's settings, go stale when the settings change, and were replayed into later prompts as "Known errors to avoid", teaching the model to skip calls that are now allowed. - A result the tool marks executed: False (refused before running) is no longer stored. The file tools' path-guard refusals now carry that flag, as the shell tool's already did. - A success retires only errors stored for the same operation (tool plus the command's binary, or the path), so a working `ls` no longer wipes a real lesson about pytest. Rows stored before this keep the old per-tool rule.
|
Verdict: Approve with suggestions This stops the agent from writing "you're not allowed to do that" into its long-term memory and replaying it at itself forever — a good fix, aimed at the biggest single source of junk memories in the benchmark sweep. The new tests are strong: they drive the real shell and file tools through a real SQLite store rather than asserting against mocks, so they'd actually catch a regression. Two things worth a look before merge, neither of them a regression this PR introduces:
Real-world evidenceN/A — no 🔍 Technical details🟡 A declined confirmation retires stored errors (
|
`env TOYBOX_CLOCK=frozen pytest -q` was keyed as `env`, so the call that fixed a pytest failure never retired it. Leading `env` and `VAR=value` tokens are now skipped, and `python -m <module>` is keyed by the module.
Declining a tool's confirmation prompt used to wipe the errors GAIA had
remembered for that operation, so a call the agent knew was broken came
back looking clean the next time it planned around it.
A denied confirmation returns {"status": "denied"}, not "error", so the
retire branch in MemoryMixin._execute_tool read it as proof the operation
works. It now gates on check_was_executed(), which is already how
_auto_store_error tells a refusal apart from a real failure.
Three permission refusals returned bare error dicts and so were persisted
into "Known errors to avoid" despite the tool never running: index_document,
its auto-index guard in query_specific_file, and add_watch_directory. They
now carry NOT_EXECUTED like the file and shell tools already do.
|
Both 🟡 findings are fixed. Declining a confirmation prompt was wiping the errors GAIA had remembered for that operation, so a call the agent knew was broken came back looking clean the next time it planned around it. Separately, three permission refusals in the RAG and file-monitor tools were being written into "Known errors to avoid" even though the tool never ran. I did not touch Both 🟢 findings skipped as scoped. Tests: 22 pass in the refusal suite (3 new), 352 pass across the memory suites. Each new test was confirmed to fail with the fix reverted. 🔍 Technical detailsFinding 1 — declined confirmation retires stored errors. Verified before relying on it: Finding 2 —
The real issue there is the one the review scoped out for 🟢 skipped: dedup stranding, and hashing the fallback operation key — the latter breaks Docs synced. Tests added to |
…amd#4066) **Stacked on amd#4058.** The first four commits are that PR. Review the last two here. The agent rediscovered the same project quirk every session. When a call failed and the agent worked around it (say `pytest` fails with "test clock not configured", it reads the doc, reruns with `env TOYBOX_CLOCK=frozen` and it passes), memory stored the error and then deleted it on the success. Nothing recorded what fixed it, so the next session started from scratch. Now that fail-then-fix sequence in one turn becomes a lesson, built only from the two calls: the failing call and its error, the call that worked, and what changed ("added `env TOYBOX_CLOCK=frozen`"). It belongs to the workspace it happened in, and the next session there sees it in its memory prompt with the date learned. It gains confidence each session the fix works again and is dropped when the fix itself fails. Other folders never see it. <details> <summary>🔍 Technical details</summary> - The pairing key is amd#4058's operation key: the tool plus the program it runs (past `env`, `VAR=value` and `python -m`) or the path. The failing and working calls must have different arguments, so a plain retry that happens to pass teaches nothing. Refusals (`executed: False`) never count, either as the failure or as a failed fix. There's no matching on error wording. - Scope: stored as `category="note"`, `domain="lesson"`, in the memory context `workspace:<most specific allowed path>`. That context keeps lessons out of every other workspace's prompt and retrieval, including amd#4061's per-request recall. So lessons are shown in their own stable-prompt section (top 3 by confidence), not through relevance search, which would also hide them whenever the request is worded differently from the lesson. - Within a session, later turns get the new lessons in the per-turn context, since the stable prompt is frozen. Within a turn there was a real loss path: overflow recovery stubs every tool result except the latest, which drops the failure a fix answered. The recovery now restates this turn's lessons on the last user message. The cache is already lost at that moment, so this costs nothing extra. - A lesson whose text looks like a credential isn't stored. </details> ## Test plan - [x] `pytest tests/unit/test_memory_heal_lessons.py`: 14 tests on a real on-disk store, over several sessions sharing one DB. All 7 positive tests fail on the pre-change source. Covers the exact lesson text and row shape, no lesson for a same-call retry / a refused failure / a different program / a failure and fix in different turns, a path tool's changed argument, the next session's prompt in the same workspace but not another, the rest of the session, confirm once per session (0.5 → 0.6), drop when the fix fails, keep when the fix is refused, and overflow recovery keeping the lesson (idempotent) - [x] `pytest tests/unit -k "memory or overflow or shrink"`: 1155 passed. The 1 failure, `test_tool_loader_token_budget`, also fails on main - [x] black + isort on changed files - [ ] `gaia eval agent` on the memory categories vs the committed baseline (memory prompt content changed) --------- Co-authored-by: Kalin Ovtcharov <[email protected]> Co-authored-by: Ovtcharov <[email protected]> Co-authored-by: Kalin Ovtcharov <[email protected]>
The agent was teaching itself to avoid things it's allowed to do. In a 2,121-task benchmark sweep, 114 of the 161 memories left behind were auto-stored tool errors, and most were permission refusals like "Command 'rm' is not in the allowed list" or "Access denied: … is not in allowed paths". Those describe one run's permission settings. They were replayed into later sessions as "Known errors to avoid" and kept steering the model away after the settings changed. Clean-up was also too blunt: one successful
lsdeleted every stored shell error, including real lessons.Now a call the permission layer refused before running is never stored. The tool reports the refusal fresh each time anyway. The signal is the result's
executed: Falseflag: the shell tool already set it, and the file tools' path-guard refusals now set it too. A success now clears only errors from the same operation (same tool plus the same command binary or path). Errors from tools that actually ran and failed are still stored.🔍 Technical details
metadata.operation. A shell operation is keyed by the program it runs. Leadingenv/VAR=valuetokens are skipped andpython -m Xcounts asX, soenv TOYBOX_CLOCK=frozen pytestworking again clears apytestfailure. Rows stored before this have no operation key, so they are still cleared per tool as before. Legacy refusal rows go away the first time the tool succeeds.executed: Falsealso makes the verification footer report them as "not run" instead of "ran and failed". That's the same meaning the flag already had for shell refusals (fix(agent): verification footer counts rejected test commands as executed #3677).execute_python_filepath check (2 of the 114 rows). It lives in a separately versioned hub package.Test plan
pytest tests/unit/test_memory_error_refusals.py: new tests with a real SQLite store. 16 of 18 fail on main. Covers a real shell refusal, a realwrite_filepath refusal (nothing stored), a real failure (stored, with its operation key), and per-operation clean-uppytest tests/unit -k memory: 1102 passedpytest tests/unit -k "file_io or file_tools or shell or verification or security or write": 1121 passedpython util/lint.py --black --isort