Skip to content

fix: harden reminder lifecycle and cross-process execution#5

Open
kernel-oops wants to merge 5 commits into
zelenkovsky:mainfrom
kernel-oops:integrate/maintained-main
Open

fix: harden reminder lifecycle and cross-process execution#5
kernel-oops wants to merge 5 commits into
zelenkovsky:mainfrom
kernel-oops:integrate/maintained-main

Conversation

@kernel-oops

Copy link
Copy Markdown

Summary

This is a consolidated, integration-tested replacement for #2, #3, and #4.

It combines the independently developed reminder reliability fixes into one coherent implementation:

  • abort in-flight prompts when reminders are cancelled or the plugin generation is replaced
  • fence stale timers, tools, reconciliations, and scheduler generations
  • coordinate executions across local OpenCode processes with atomic occurrence leases and mutation locks
  • persist reminder state with same-directory atomic replacement
  • recover dead-owner leases and reconcile recurring reminders that lose lease contention
  • capture the creating OpenCode agent and reuse it when the reminder fires, while preserving compatibility with legacy reminders that have no stored agent
  • preserve skip-overdue policy through persistence retries and apply bounded exponential retry backoff
  • prevent reconciliation from restoring local state after successful cancellation
  • restore authoritative local state when durable cancellation fails, so removal can be retried without restarting OpenCode

Why a consolidated PR

The three original PRs overlap substantially in the scheduler and tests. Reviewing or merging them independently would require resolving their lifecycle behavior manually. This branch integrates them deliberately and adds fixes for races found only while testing the combined implementation.

The original PRs are left open for history and discussion, but this PR is intended to supersede:

Important behavior

  • Coordination is host-local and assumes a local filesystem with atomic rename, hard-link, and exclusive-create semantics.
  • Prompt delivery is at-least-once. If a prompt is accepted and the subsequent state write fails, a bounded retry may submit it again; exactly-once behavior would require prompt-side idempotency.
  • Persistent failures use exponential backoff from 250 ms to a 30-second cap.
  • Startup missed recurring occurrences are advanced without being executed, even when advancement persistence temporarily fails.

Verification

Final committed suite:

  • bun test — 78 passed, 0 failed, 174 assertions
  • bun x tsc --noEmit
  • git diff --check origin/main..HEAD
  • npm pack --dry-run --json

Additional stress/regression runs included:

  • failed durable cancellation repeated 100 times
  • completed reconciliation-read/cancellation race repeated 100 times
  • scheduler and cross-process lease suites repeated 10 times: 330 passed
  • startup persistence, runtime retry, and stale-remove regressions repeated 5 times
  • independent reproductions for readable-old-JSON persistence failure, stale reconciliation after cancellation, failed durable cancellation rollback, concurrent cancellation ownership, and generation replacement

All passed on the final branch.

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.

2 participants