Skip to content

fix(kernel): cron dedupe + next_run + token_length annotation#3109

Merged
houko merged 3 commits into
mainfrom
followup/cron-telegram-tokens-review
Apr 25, 2026
Merged

fix(kernel): cron dedupe + next_run + token_length annotation#3109
houko merged 3 commits into
mainfrom
followup/cron-telegram-tokens-review

Conversation

@houko

@houko houko commented Apr 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Follow-up review concerns from #3090 (already merged).

  • Dedupe cron jobs in saved_crons during restore so concurrent hand-reactivation paths cannot end up activating the same cron twice.
  • Recompute next_run from the cron expression on hand reactivation instead of restoring a stale fire time, preventing an immediate spurious refire just after restart.
  • Annotate text_length token estimation as an upper-bound heuristic (char ≈ 4 tokens) so callers don't treat it as exact.

Cherry-picks: 3dc39d4, b64a24c, 9203a83

Test plan

  • Existing kernel cron/restore tests still pass
  • Manual verification of restart-without-immediate-refire behaviour

houko added 3 commits April 25, 2026 18:51
…rrent activation duplicates

If two registry entries share the same `hand_tag` and `hand_role` (a
race between concurrent `activate_hand` calls or a stale cleanup), the
loop would collect the same CronJob twice from list_jobs and replay
both via add_job — leaving duplicate jobs that fire in lockstep.
Track seen CronJobIds per role bucket so each saved job is added at
most once.
…avoid immediate refire

Previously the restore path set `next_run = None` and relied on the
implicit recompute inside `add_job`. That coupling is fragile: a
future change to `add_job` semantics could let restored jobs fire on
the very next scheduler tick. Compute the next fire time explicitly
from the saved schedule at the call site so the intent — "resume on
the natural next future fire" — is visible and locally enforced.
…tokens)

`MessageContent::text_length` is sometimes used as a proxy for LLM
token count, but it returns UTF-8 byte length — not Unicode chars and
not real tokens. Document the upper-bound semantics, the ~4 bytes ≈
1 token rule of thumb, and that exact counts should swap to a real
tokenizer rather than mutate this function.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions github-actions Bot added area/kernel Core kernel (scheduling, RBAC, workflows) ready-for-review PR is ready for maintainer review size/M 50-249 lines changed labels Apr 25, 2026
@houko
houko merged commit 2551885 into main Apr 25, 2026
22 checks passed
@houko
houko deleted the followup/cron-telegram-tokens-review branch April 25, 2026 12:03
@github-actions github-actions Bot removed the ready-for-review PR is ready for maintainer review label Apr 25, 2026
@houko houko mentioned this pull request Apr 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/kernel Core kernel (scheduling, RBAC, workflows) size/M 50-249 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant