Skip to content

refactor(dashboard): route a cron's send_message through session_deliver.deliver - #23052

Merged
KiroCrewCaptain merged 1 commit into
mainfrom
refactor/22747-deliver-cron-send
Oct 22, 2026
Merged

KiroCrewCaptain merged 1 commit into
mainfrom
refactor/22747-deliver-cron-send

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A cron's send_message to its origin session reaches that session through the same session-side deliver() the script-cron result already uses, with its evict-oldest queue behavior unchanged.

api_send_message in handlers/messaging.py still branched on slot.running itself and wrote its own inject row, queued card and turn. The script-cron result path (_deliver_script_result) moved onto session_deliver.deliver in #22937, so the two cron senders had two copies of the same choice. This is slice D of #22747.

Why it matters

Two cron senders with two copies of the idle-or-running branch drift apart: one gets a fix the other misses, and the same cron text lands as different rows depending on which route sent it.

Not a goal

  • Moving the idle autonudge fire onto deliver (slice C).
  • Changing the cron row, queued card, turn actor or the queue-full behavior.
  • Changing api_send_message's redaction, authorization, origin-session resolution or bell fallback.

What changed (motivation → approach → change)

Approach: the cron sender names its cron origin and keeps its own queue-full policy as a flag.

  • dashboard/session_deliver.py: deliver(..., evict_oldest=False). For a cron notification on a running slot whose live queue is full, evict_oldest=True pops the oldest entry and removes its card, then queues the new one, with the same warning log. Without the flag nothing changes for the existing callers.
  • dashboard/handlers/messaging.py (api_send_message): the idle inject row + spawn_guarded_turn branch and the running eviction + queue_cron_notification branch become one deliver(state, slot, wrapped, cron(label), evict_oldest=True) call.
  • Spec: monitor-architecture.md.

Known limit: the two cron senders still differ on a full live queue. api_send_message drops the oldest entry (evict_oldest=True); the script-cron result path does not check the cap. Keeping each sender's current behavior was the scope of this slice; aligning them is a behavior change for a separate decision.

Size: about 25 production lines in 2 files (net −40 in messaging.py).

Backwards compatibility

Compatible: the cron send writes the same inject row (injectKind: cron, cronLabel), the same queued card, the same _turn_actor="cron" turn, and still drops the oldest live entry when the queue is full.

Removes nothing: no key, route or guard goes away; the branch moved into deliver.

Tests

  • test/test_cron_origin_injection.py: api_send_message for a cron's origin session calls deliver with the cron origin, its label, the resolved slot and evict_oldest=True.
  • test/test_session_deliver.py: on a full live queue a cron notification drops the oldest entry and its card only with evict_oldest=True; without it both stay.
  • Inventory guards updated for the moved dispatch: test_chat_turn_timeout_consistency.py (6 sites), test_handlers_messaging_composition_contract.py, test_slot_running_readers.py.

Proof: on origin/main with only session_deliver.py and the new tests added, the api_send_message routing test fails. Related set: 2702 passed (-n 4), including the facade and flake ratchets. No clock, sleep or network in the new tests.

Manual verification

N/A — unit coverage sufficient: the cron rows, queue entries and turns are unchanged and pinned by the existing cron-injection suites.

Related Issues

Part of #22747

Remaining on #22747: slice C, the idle autonudge fire (_fire_dashboard_nudge) onto deliver, so the idle automation path stops returning NOT_DELIVERED.

Pattern harvest

Not generalizable: one more sender onto the entry point slice A added; the pattern was harvested there.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@iamwhatever
iamwhatever requested review from a team and KiroCrewCaptain as code owners October 22, 2026 08:12
@github-actions

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 2452caee505646eaf1b7d22746a493dcaf32ea57 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 2452caee505646eaf1b7d22746a493dcaf32ea57 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the cron sender's idle-or-running branch moves into deliver with the same row, queued card, turn actor and eviction behavior, and nothing is taken away.

Notes

  • evict_oldest is a flag that only cron reads (app returns QUEUE_FULL, and the flag means nothing for automation or peer). If no other cron caller ever wants the non-evicting behavior, making eviction the cron origin's default would remove the flag entirely.

[DESIGN-REVIEWED] 2452cae

Description read

[DESCRIPTION-READ] c42874ebed890ffd0bacd46e00bdb76f48f93e1e5bac46bee22cfbc6772b7497

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 2452caee505646eaf1b7d22746a493dcaf32ea57 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

The refactor keeps every row, card, turn and eviction the same. One note: the new flag keeps the two cron senders behaving differently, which is the drift the PR says it removes.

Notes

  • Item 3 — one consumer, generalized: evict_oldest: bool = False is set to True by exactly 1 of the 7 session_deliver.deliver( callers, handlers/messaging.py:795. The script-cron caller at cron_exec.py:462 takes the default, so a full live queue drops the oldest entry for one cron sender and not the other. That contradicts "Two cron senders with two copies of the idle-or-running branch drift apart." The Goal does freeze the current eviction behaviour, so this is a note, not a block. Subtraction: once a decision says both senders behave the same way, delete the parameter.

What this change ships

Inventory (5 items) — 4 justified

Intent: a cron's message to its origin session goes through the same session-side delivery the script-cron result already uses. This is a refactor (FIX of duplicated logic), not an addition.

  1. A cron's send_message to an idle session writes the same inject row and starts the same cron turn, now through deliver — justified
  2. A cron's send_message to a running session queues the same card through deliver — justified
  3. New evict_oldest option on deliver: a full live queue drops its oldest entry — one consumer, generalized
  4. The queue-full warning now comes from the session_deliver logger with slightly different wording — undeclared
  5. Guard and inventory tests now point at the moved dispatch, and the _run_chat site count goes from 7 to 6 — justified

[FIRST-PRINCIPLES-REVIEWED] 2452cae

Description read

[DESCRIPTION-READ] b0cd50ea3d573ebeacf738fcf0f73827fe682ceb3bf3c2898a75106bdbc300a7

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 2452caee505646eaf1b7d22746a493dcaf32ea57 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 2452cae

Verdict parsed from the review's SHA-scoped output markers for commit 2452caee505646eaf1b7d22746a493dcaf32ea57.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 2452caee505646eaf1b7d22746a493dcaf32ea57: <one-sentence reason>

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 2452caee505646eaf1b7d22746a493dcaf32ea57 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 2452cae

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 2452caee505646eaf1b7d22746a493dcaf32ea57: <one-sentence reason>

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed head 2452cae. This looks good to me.

What I checked:

  • The idle branch in deliver() writes the same inject row as the removed code: role inject, cls with cronLabel, and meta with injectKind cron and cronLabel. It starts the turn with the same arguments: _directive_user_origin=False and _turn_actor set to cron. The synthetic payload flag stays False for a cron.
  • The running branch keeps the eviction order: pop the oldest entry, remove its queued card, then queue the new cron card. Only this caller passes evict_oldest=True, so the script cron result and the app paths do not change.
  • deliver() writes the row before its first await, so the move adds no new interleaving point in the handler.
  • I ran the five changed test files at this head: 141 passed. The new parametrized test in test_session_deliver.py goes red if the eviction branch is removed, and the handler test pins evict_oldest=True.
  • The linked issue is tier T1. No file is on a sensitive path.

Remaining before approval: the PR Readiness check is still pending on this head. I will approve after it passes on the same head.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 22, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Review-ready on head 2452cae: pr_status.py exits 0 (116 checks, 0 failing, readiness: passed), GPT and Opus clean on this head, Design / First Principles / UX PASS. Part of #22747 (slice D): a cron's send_message to its origin session now goes through session_deliver.deliver with the evict-oldest behavior unchanged. Remaining: slice C (idle autonudge fire). Waiting for a maintainer review.

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving head 2452cae.

Gates checked on this head: readiness label is passed, PR Readiness is green, no required check is failing or pending, every review lane reports PASS, there is no merge conflict, the base is main, and no file is on a sensitive path. The linked issue is tier T1.

The change routes a cron's send_message through the shared session delivery path. The five changed test files pass at this head (141 tests), and the new parametrized test fails if the eviction branch is removed.

Setting squash auto merge.

@KiroCrewCaptain
KiroCrewCaptain merged commit 961b568 into main Oct 22, 2026
116 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the refactor/22747-deliver-cron-send branch October 22, 2026 10:07

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Tier 1 auto-approve: refactor (8 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: code move that replaces the cron send_message idle and running branches in the messaging handler with session_deliver.deliver, which writes the same cron row and turn actor when idle and queues the same card when running, with the oldest-entry eviction moved behind an evict_oldest flag; tests pin both paths. Spec files changed as a ride-along (a minority of the diff on both file count and changed lines), not reviewed as a design decision: docs/system-specs/modules/monitor-architecture.md.

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.

3 participants