fix(cron): stamp + replay creator sender/role across cron fires#1129
Open
mozaa-solana wants to merge 1 commit intonextlevelbuilder:devfrom
Open
fix(cron): stamp + replay creator sender/role across cron fires#1129mozaa-solana wants to merge 1 commit intonextlevelbuilder:devfrom
mozaa-solana wants to merge 1 commit intonextlevelbuilder:devfrom
Conversation
Cron jobs created in a group context (group-scope UserID like
"group:telegram:-100…") consistently fail group-scope permission
checks once they fire — the scheduled agent's turn ends up with an
empty SenderID, and any write_file / cron mutation inside that turn
trips:
permission denied: system context cannot ... in group chats.
If this is a legitimate user action, ensure the acting sender is
preserved through the tool chain.
Root cause: gateway_cron.go built RunRequest with UserID=job.UserID
but no SenderID, so loop_context.injectContext skipped WithSenderID
and the agent ran with no human attribution. UserID alone is the
group scope, not a real user.
Fix: capture the human's sender + role at cron-create time, replay
them at every fire.
- store.CronPayload: new CreatorSenderID + CreatorRole fields
(JSON-serialized into existing payload column — no migration).
- CronStore.AddJob: signature gains creatorSenderID + creatorRole;
PG + sqlite impls thread them into the new payload fields.
- tools/cron.go handleAdd: read SenderIDFromContext +
RoleFromContext, drop synthetic prefixes (subagent:, teammate:,
ticker:, system:, notification:, session_send_tool) so we never
attribute future fires to a system component, then call AddJob
with the captured creator.
- cmd/gateway_cron.go: pass job.Payload.CreatorSenderID +
CreatorRole into RunRequest.SenderID + Role each fire. Empty
values preserve prior behaviour (DM crons, system-installed
crons, pre-fix crons all keep the deny-on-empty guard at fire
time — no security relaxation).
- gateway/methods/cron.go (WS RPC): explicitly passes empty
creator strings — there is no separate "Telegram numeric sender"
upstream of the WS handler, so WS-installed crons that need to
fire in group chats should be created via a Telegram-rooted
flow (ctx-aware) instead.
Tests:
- internal/tools/cron_creator_propagation_test.go: real-sender
propagation + synthetic-sender drop coverage (table-driven).
- internal/gateway/methods/cron_test.go: stub updated to match
new AddJob signature, captures creator strings into Payload.
This is the cron-firing counterpart to the team-task announce
attribution fix — together they close the "system context cannot
write" denial across both re-ingress paths a Lead-style agent uses.
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.
Summary
Cron jobs created in a group context (UserID like `group:telegram:-100…`) consistently fail group-scope permission checks the moment they fire — the scheduled agent ends up with an empty SenderID, and any `write_file` or `cron` mutation inside that turn trips:
Root cause: `gateway_cron.go` built the RunRequest with `UserID = job.UserID` but no `SenderID`. `loop_context.injectContext` skips `WithSenderID` when `req.SenderID` is empty, so the agent's resumed ctx had no human attribution. `UserID` alone is the group scope, not a real user.
Fix
Capture the human's sender + role at cron-create time; replay them at every fire.
Failure repro
After this fix the same flow:
1-3. As above; job now stores `Payload.CreatorSenderID = ""`
4. Cron fires with `req.SenderID = ""` → `write_file` succeeds with attributed audit trail.
Test plan
Related
Companion fix to #1128 (team-task announce sender propagation). Together they close the "system context cannot write" denial across both re-ingress paths a Lead-style agent uses inside a daily-cycle workflow.