Skip to content

fix(tool): require task_id to descend from the calling session - #203

Merged
filipeforattini merged 1 commit into
mainfrom
task-descendant-check
Sep 11, 2026
Merged

fix(tool): require task_id to descend from the calling session#203
filipeforattini merged 1 commit into
mainfrom
task-descendant-check

Conversation

@filipeforattini

@filipeforattini filipeforattini commented Sep 11, 2026

Copy link
Copy Markdown

Problem

packages/redcode/src/tool/task.ts accepted any task_id and prompted into sessions.get(task_id) with no check that the session was a child (or descendant) of the calling session. The subagent depth cap was computed on the caller rather than on the resumed chain, so a model could pass a sibling or a top-level session id from another project and drive it under the subagent ruleset. Separately, the background cap counted every running task job for the session, so a foreground task waiting on its turn blocked background launches.

Fix

  • Load the resumed session first and walk its parentID chain; fail with task_id <id> must reference a subagent session started from this session unless ctx.sessionID appears in it. Passing the caller's own id is refused for the same reason.
  • Measure subagent_depth on the chain that is actually prompted (the resumed session's ancestors, or the caller's ancestors plus the new child). The fresh-child path is unchanged in effect.
  • Count only jobs with metadata.background === true toward background_subagents_max. Promoted foreground jobs already carry that flag, so they are still counted.

Test

packages/redcode/test/tool/task.test.ts adds three tests:

  • execute refuses a task_id that did not descend from the calling session (foreign top-level, foreign child, and own session id)
  • execute caps depth on the resumed chain, not on the caller
  • a running foreground task does not count against the background cap

With the source change stashed, exactly those three fail and the remaining 22 pass (the existing execute resumes an existing task session from task_id stays green). With the fix, 25/25 pass. bun run typecheck in packages/redcode is clean.

https://claude.ai/code/session_01KAcoL6wpgVEs2ebUrUGpHS


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

When the model passed a task_id, the task tool loaded that session and
prompted into it without checking that it belonged to the caller. The
subagent depth was computed on the caller rather than on the resumed
chain and the child ruleset was never re-derived, so a sibling or a
top-level session from another project could be driven under the
subagent rules by guessing its id.

The tool now walks the resumed session's parentID chain and fails with
a clear error unless the calling session appears in it. The depth cap
is measured on the chain that is actually prompted. The background cap
also counts only jobs flagged background instead of every running task
job, so a foreground task waiting on its turn no longer blocks a
background launch.

Claude-Session: https://claude.ai/code/session_01KAcoL6wpgVEs2ebUrUGpHS
@filipeforattini
filipeforattini merged commit 3c3ee73 into main Sep 11, 2026
12 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant