@W-22167805@ add sf agent trace delete command#410
@W-22167805@ add sf agent trace delete command#410WillieRuemmele merged 19 commits intowr/listTracesfrom
Conversation
…written to the project dir Without cwd, preview start/send/end wrote the session cache relative to the runner's working directory, causing trace read/delete NUTs to throw SessionNotFound when they ran with cwd: session.project.dir.
QA NotesTested by merging BuildThe One fix was required in Unit Tests3 unit tests in const RECENT_MTIME = new Date('2026-04-07T17:00:00.000Z'); // now ~31 days oldThe test comments say "~23 days ago from 2026-04-30", but as of today (2026-05-08) NUTsRan ✅ Root Cause of NUT FailuresThe 2 failing NUTs expose a design bug in the command itself. The
The trace files are written to disk (confirmed by checking Suggested fix: Either:
|
listCachedPreviewSessions only returns sessions still in the index, but agent preview end removes the entry when it cleans up the active-session marker. Both trace read and trace delete now fall back to a filesystem scan of .sfdx/agents/<agentId>/sessions/ so they work on ended sessions.
When sessions are run with --simulate-actions, the turn index exists but planId entries are null. --turn N now falls back to positional trace file order rather than throwing TurnIndexNotFound. Also relaxes the grounding NUT assertion since simulated sessions may not produce LLMExecutionStep rows with React prompt names.
@W-22167805@ add sf agent trace read command
Move the ended-session filesystem scan into src/agentSessionScanner.ts so all three trace commands (list, read, delete) share the same logic and no longer miss sessions that were ended via agent preview end. Also add missing cwd to the z4.agent.trace.list NUT before() hook.
npiccolo
left a comment
There was a problem hiding this comment.
QA Notes
Tested wr/deleteTraces merged with wr/listTraces (needed for @salesforce/agents@1.6.0 which ships listSessionTraces) against a scratch org on int-hub.
Flags
-
--session-id
✅ Correctly filters to traces for the specified session only.
✅ Returns empty array when no session matches. -
--agent
✅ Case-insensitive substring match works correctly.
✅ Returns empty when no agents match. -
--older-than
✅ Acceptsd,h,m,wunits and all long-form variants.
✅ Correctly filters by file mtime — only deletes traces older than the cutoff.
✅ Returns empty when all traces are newer than the duration.
✅ Rejects invalid formats (no unit, non-numeric) with a helpful error message. -
--no-prompt
✅ Skips confirmation table and prompt, deletes directly.
✅ Without--no-prompt, shows a preview table and prompts for confirmation before deleting.
✅ Cancellation (no/cancel) leaves files untouched.
Unit Tests (after fixes)
✅ 189/189 passing
NUTs — run 4 times against int-hub scratch org
✅ 5/5 passing (after e9c21f9 + 1e32f60 fixes)
Bugs found during testing (now fixed)
- Ended sessions were invisible —
listCachedPreviewSessionsgates onsession-meta.jsonwhichpreview enddeletes. Fixed ine9c21f9by scanning.sfdx/agentson disk directly. - NUT
cwdmismatch —preview start/send/endwere writing the session cache to the wrong directory. Fixed in1e32f60by passingcwd: session.project.dirto all preview calls. - Stale hard-coded dates in unit tests —
RECENT_MTIMEhad gone past the30d/4wthresholds. Fixed by switching to relative dates.
Work Item
@W-22167805@
Summary
Adds the
sf agent trace deletecommand for deleting local trace files recorded during agent preview sessions. No org connection required.Changes
sf agent trace delete--agent(substring match),--session-id,--older-than(e.g.7d,2w,24h),--no-prompt--no-promptis passedmessages/agent.trace.delete.mdFiles Changed
src/commands/agent/trace/delete.tsmessages/agent.trace.delete.mdschemas/agent-trace-delete.jsoncommand-snapshot.jsontest/commands/agent/trace/delete.test.tsTest Plan
npm run buildandnpm testpass cleanlyDependencies