fix(agents): reject a blank taskKey on reset-session instead of resetting all task state (#19282)

## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Operators can reset an agent's runtime session with `POST
/agents/:id/runtime-state/reset-session`
> - A `taskKey` scopes the reset to one task. No key resets all task
state.
> - The schema accepted a whitespace-only `taskKey`, and the route
changed it to `null`
> - So a blank key took the full-reset path, and the activity entry
recorded `taskKey: null`
> - This pull request makes the schema trim the key and reject a blank
key with a 400
> - The benefit is that a scoped reset request can never become a full
reset by accident

## Linked Issues or Issue Description

Fixes #19080

Refs #19005 (the parent issue that #19080 was split out of)

I searched open and closed PRs for `19080`, `reset-session` and
`resetAgentSessionSchema`. I found no related PR.

## What Changed

- `resetAgentSessionSchema.taskKey` is now
`z.string().trim().min(1).optional().nullable()`. A blank or
whitespace-only key fails validation with a 400. An omitted key or
`null` still requests the full reset.
- The route uses the parsed `taskKey` directly. The schema already trims
it, so the route no longer has its own trim-and-null step.
- Added tests in `packages/shared/src/validators/agent.test.ts` for
omitted, `null`, trimmed and blank keys.

## Verification

- `pnpm exec vitest run packages/shared/src/validators/agent.test.ts`:
16 tests pass.
- `pnpm exec vitest run cli/src/__tests__/agent-lifecycle.test.ts`: 4
tests pass. The CLI parses its payload with the same schema.
- `pnpm --filter @paperclipai/shared typecheck` passes.
- I ran the server `tsc` locally. It reported no errors in
`server/src/routes/agents.ts`. My local Windows setup cannot build
`@paperclipai/paperclip-runner`, so the full server typecheck depends on
CI.

## Risks

- Low risk. A client that sends `taskKey: ""` or a whitespace-only key
now gets a 400 instead of a full reset. The board UI sends `null` or an
issue id, and the CLI omits the key when `--task-key` is not set.
Neither caller sends a blank key.

## Model Used

- Claude Opus 5.5 (Anthropic, model ID `claude-opus-5-5`), used through
Claude Code with tool use (shell, file editing). It assisted with code
reading, the change, tests and this description. I reviewed the change.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge
This commit is contained in:
Oke Iyanuoluwa Enoch authored and GitHub committed 2026-11-24 15:36:17 -06:00
1 parent dc8cf1e5d0
commit ecef06d246
3 files changed
+19 -6

No files matched your search

+17 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { updateAgentSchema } from "./agent.js";
import { resetAgentSessionSchema, updateAgentSchema } from "./agent.js";
describe("agent update schema", () => {
it.each(["paused", "idle", "terminated"])("accepts lifecycle status request %s", status => {
@@ -23,3 +23,19 @@ describe("agent update schema", () => {
expect(updateAgentSchema.parse({ name: "Renamed", budgetMonthlyCents: 100 })).toEqual({ name: "Renamed", budgetMonthlyCents: 100 });
});
});
describe("reset agent session schema", () => {
it.each([{}, { taskKey: null }])("accepts a full reset request: %j", payload => {
expect(resetAgentSessionSchema.parse(payload)).toEqual(payload);
});
it("trims a task key", () => {
expect(resetAgentSessionSchema.parse({ taskKey: " task-1 " })).toEqual({ taskKey: "task-1" });
});
it.each(["", " ", "\t\n"])("rejects a blank task key %j", taskKey => {
const result = resetAgentSessionSchema.safeParse({ taskKey });
expect(result.success).toBe(false);
if (!result.success) expect(result.error.issues).toEqual(expect.arrayContaining([
expect.objectContaining({ path: ["taskKey"] }),
]));
});
});
+1 -1
View File
@@ -279,7 +279,7 @@ export const wakeAgentSchema = z.object({
export type WakeAgent = z.infer<typeof wakeAgentSchema>;
export const resetAgentSessionSchema = z.object({
taskKey: z.string().min(1).optional().nullable(),
taskKey: z.string().trim().min(1).optional().nullable(),
});
export type ResetAgentSession = z.infer<typeof resetAgentSessionSchema>;