Repository navigation
Deliver a courier_later message within about a second of its time - #660
Merged
Merged
Conversation
A message due within two ticks gets a timer, set as it is scheduled and by each tick's scan of the pending ones, cleared when it is cancelled or delivered. The timer delivers nothing itself: it asks the hub for a tick at once, behind one under way, so the owner key and the claim set decide as at any tick. The 15-second tick stays as the safety net. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_0138xCuDYXnVSZNjmzjuLbFw
One message near as it is scheduled and one more than two ticks away, which a tick finds near, each no earlier than its time and at most two seconds after. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_0138xCuDYXnVSZNjmzjuLbFw
…re notes Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_0138xCuDYXnVSZNjmzjuLbFw
Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_0138xCuDYXnVSZNjmzjuLbFw
Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_0138xCuDYXnVSZNjmzjuLbFw
|
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.



Issue
Closes #657
Type of change
What does this PR do?
A
courier_latermessage was delivered at the scheduler's next 15-second tick after its time. It now gets a timer set for its time, and the tick stays as the safety net.src/scheduling/timer.tskeeps onesetTimeoutper message due within two ticks (NEAR_MS, 30 s).schedulesets it for a message that is near; each tick's scan oflater/, which the tick does anyway, sets it for the ones that have come near, another server's and the ones from before a restart included.cancel(socancelScheduledtoo) and the delivery clear it.tickNowinsrc/platform/hub.ts: wait for a tick under way, then tick), so everything that guards a tick guards it too: the owner key, the claim set, the copy loaded last running through the instance loaded first.Decisions:
setTimeout's 2^31-1 ms limit needs no cap, nothing has to be cleared on unload (the timers are unref'd, and a leftover one only asks for a tick, which is harmless), and a non-owner never arms for a far message because only the owner's tick scans. Two ticks, not one, so a single tick that does not come leaves no gap.Date.nowcan disagree by a millisecond) is set again by the tick it asked for.HUB_VERSIONstays 2:tickNowis a module function over the existingscheduler.runningandscheduler.tick. With an older copy of hub version 2 in the process it degrades to the tick.deliverDueuses no new port of a member:LaterPorts.timeris optional, absent on every real member, and stands in for the copy's own timer in unit tests.courier_later's description still says "may arrive up to ~15 seconds late", which stays true as the worst case (another server, a restart). So no real-model run is owed.docs/reference.mdgrows by 25 words, within its budget.How #656 would replace this: all of it sits in
src/scheduling/behindschedule,cancel,cancelScheduled,isScheduledanddueJob. Delegating to the host's automations removestimer.ts,deliverDueanddueJobwith their tests, andtickNowif nothing else uses it;scheduleandcanceldrop theirarmanddisarmcalls as they move to the host. Nothing outside the module knows the timer exists, and there is no stored state to migrate beyond thelater/keys #656 already lists.How did you verify it?
test/later.test.ts(the timer is set for a near message and not for a far one, a tick sets it once the message is near or was scheduled elsewhere, cancel, stop and delivery clear it, an early firing is set again, a failed request for a tick is logged) andtest/hub.test.ts(tickNowbetween two ticks, behind one under way, with no instance, on a server that does not hold the owner key, and one message through the real timer and the hub).latergroup ofe2e/run.shgains two scenarios that measure a message's arrival against its time, one due in 3 s and one due in 33 s that a tick has to find near; each must arrive no earlier than its time and at most 2 s after. CI runs them.e2e/two-servers.sh(not in CI), run locally against OpenCode 2.3.2: each of the 20courier_latermessages was delivered once, none twice and none never, with the schedulers in step and out of step, and every other result is as seen at the pin.Screenshots / recordings
None: no change to the terminal part.
Checklist
bun run typecheck, the touched test files; CI runs the rest)e2e/run.shscenario (ore2e/tui.shfor the terminal part)docs/reference.mdare updated where behaviour changeddocs/reference.mdis rendering detail, internals or restated model-facing textsrc/**/text.ts,src/kernel/protocol.ts,src/skill.ts, a tool description) updatestest/__snapshots__/(none changed)🤖 Generated with Claude Code
https://claude.ai/code/session_0138xCuDYXnVSZNjmzjuLbFw