fix(tool): require task_id to descend from the calling session - #203
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
packages/redcode/src/tool/task.tsaccepted anytask_idand prompted intosessions.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 runningtaskjob for the session, so a foreground task waiting on its turn blocked background launches.Fix
parentIDchain; fail withtask_id <id> must reference a subagent session started from this sessionunlessctx.sessionIDappears in it. Passing the caller's own id is refused for the same reason.subagent_depthon 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.metadata.background === truetowardbackground_subagents_max. Promoted foreground jobs already carry that flag, so they are still counted.Test
packages/redcode/test/tool/task.test.tsadds 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 callera running foreground task does not count against the background capWith the source change stashed, exactly those three fail and the remaining 22 pass (the existing
execute resumes an existing task session from task_idstays green). With the fix, 25/25 pass.bun run typecheckinpackages/redcodeis clean.https://claude.ai/code/session_01KAcoL6wpgVEs2ebUrUGpHS
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.