Skip to content

fix: read account id from jwt sub in scheduled task tool#1152

Open
saschabuehrle wants to merge 1 commit intoblinkospace:mainfrom
saschabuehrle:fix/issue-1052
Open

fix: read account id from jwt sub in scheduled task tool#1152
saschabuehrle wants to merge 1 commit intoblinkospace:mainfrom
saschabuehrle:fix/issue-1052

Conversation

@saschabuehrle
Copy link
Copy Markdown

Fixes #1052

The scheduled task tool was reading user.id from verifyToken, but the JWT payload provides the user id in sub. This now falls back to sub and rejects invalid numeric ids before creating the task.

Greetings, saschabuehrle

@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. bug Something isn't working labels Apr 2, 2026
Copy link
Copy Markdown
Collaborator

@blinko-space blinko-space left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: Needs one more pass 🔄

Thanks for digging into #1052 — the diagnosis is spot-on. verifyToken in server/lib/helper.ts:173 returns the raw JWT payload which only has sub; getTokenFromRequest at lines 191/198 even backfills id from sub explicitly, which confirms your reading.

However — the same bug is untouched in two sibling tools in this exact file

  • scheduledTask.ts:95deleteScheduledTaskTool still does Number(user.id)
  • scheduledTask.ts:157listScheduledTasksTool still does Number(user.id)

So after this PR the AI can create scheduled tasks via JWT, but delete and list will still silently fail (they'll get NaNInvalid user id or wrong account). Please extend the same fix to both call sites in this PR — it's 4 lines and it's the same bug.

Minor: match the sibling-tool pattern

Every other AI tool in server/aiServer/tools/ already handles this cleanly without as any:

// createBlinko.ts:16, updateBlinko.ts:22, searchBlinko.ts:28,
// deleteBlinko.ts:15, createComment.ts:17
const accountId = runtimeContext?.get('accountId') || (await verifyToken(context.token))?.sub;

Consider refactoring scheduledTask.ts to match — it's more consistent and drops the two as any casts. Your Number.isFinite guard is still a good addition on top.

Tests

Per our contributor guide, backend fixes should include an integration test covering the full JWT → tool call path. Not a hard blocker for this scope, but would be nice.

Once the two extra call sites are fixed, I'll re-review and ship it. 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

createScheduledTaskTool: accountId becomes NaN leading to 'Argument account missing' error

2 participants