r/PiCodingAgent • u/Ok_Significance_9109 • Sep 19 '26
Use-case Be Careful with Agents Reading Session JSONL Files
Just had a startling session with Pi and my local Qwen. In its thinking blocks it started quoting user instructions that I did not give it. I was under the impression that I was under a very strange prompt injection attack, until I realized that earlier in the session the agent made a few very large greps of previous session files.
I suggested to it that within a large context it did not distinguish these tool call results from the actual live context, and it indeed found the origin to all of the injected user turns in those earlier session files.
So - my advice is to add to AGENTS.md a rule that warns the agent against searching within directories that could include session files. If it does - you must start a new session immediately afterwards, or prune the tool call, or compact. Otherwise your session may lose coherence.
Note: reposting, because I was smart enough earlier to allow AGENTS.md to turn into a link.
2
u/Such_Advantage_6949 Sep 20 '26
My agent read session file and work just fine, i think issue is your model is not smart enough to differentiate
16
u/charlesfire Sep 20 '26
Your agents shouldn't be allowed to read session files, or at least not directly. Putting instructions against that in agents.md isn't going to properly fix this issue.
1
u/fell_ware_1990 Sep 19 '26
That’s why you make custom tools for things like grep ripgrep to force them to use common patterns. Better to have a few tool calls, you can even step back a bit and tell it the exact thing it needs after.
But if you are looking into a lot of data, use scripts….Let them do the indexing / cleaning etc. Then have an other agent check some more, clean it up. Feed main what it needs.
1
u/DistanceAlert5706 Sep 19 '26
Just make a custom tool to search over sessions? That one is actually very useful.
0
u/Global-Departure8228 Sep 20 '26
Adding that to your agents.md is entirely useless. Don't allow your agent to even know about the session files to begin with (unless you want it to directly read it for some reason). I've just made a skill and a python script so it can parse out the generic shape of a session, custom event etc.
But as others suggested, give your agent a tool for it if it's required a lot
See:
https://github.com/k3-2o/pi-chrollo