Skip to content

fix(daemon): crash when fully synced and no new events arrive#375

Merged
andreabadesso merged 2 commits intorelease-candidatefrom
fix/check-missed-events-no-context-event
Mar 5, 2026
Merged

fix(daemon): crash when fully synced and no new events arrive#375
andreabadesso merged 2 commits intorelease-candidatefrom
fix/check-missed-events-no-context-event

Conversation

@andreabadesso
Copy link
Copy Markdown
Collaborator

Motivation

The daemon crashes on startup when the fullnode has no new events to send (i.e. the daemon is fully synced).

Here is the sequence of events that leads to the crash:

  1. The daemon starts and calls fetchInitialState, which reads the last synced event ID from the database (e.g. 25717039).
  2. It connects to the fullnode websocket and sends a START_STREAM message with last_ack_event_id: 25717039.
  3. Since the fullnode has no new events after that ID, it sends nothing back. This is expected behavior from the fullnode.
  4. The daemon enters the CONNECTED.idle state and waits. After 20 seconds (the ACK_TIMEOUT), it transitions to CONNECTED.checkingForMissedEvents to verify that no events were lost due to network issues.
  5. checkForMissedEvents tries to read context.event.event.id to know which event ID to check from. However, context.event is null because no fullnode event was ever received in this session.
  6. The service throws Error('No event in context when checking for missed events'), which causes the state machine to transition to ERROR and the daemon stops.

The root cause is that checkForMissedEvents assumes context.event has been populated by a prior storeEvent action, but this is not true when the daemon is fully synced and no events arrive before ACK_TIMEOUT fires.

The startStream action already handles this case correctly by falling back to context.initialEventId:

const lastAckEventId = get(context, 'event.event.id', context.initialEventId);

This fix applies the same pattern to checkForMissedEvents: use context.event.event.id if available, otherwise fall back to context.initialEventId. It only throws if both are missing, which would indicate a real initialization problem.

Acceptance Criteria

  • The daemon should not crash when fully synced and no new events arrive from the fullnode
  • checkForMissedEvents should use context.initialEventId as a fallback when context.event is null
  • The missed events check should still work correctly by querying the fullnode HTTP API with the right event ID

Checklist

  • If you are requesting a merge into master, confirm this code is production-ready and can be included in future releases as soon as it gets merged
  • Make sure either the unit tests and/or the QA tests are capable of testing the new features
  • Make sure you do not include new dependencies in the project unless strictly necessary and do not include dev-dependencies as production ones. More dependencies increase the possibility of one of them being hijacked and affecting us.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 4, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dd420be6-689a-4fb8-852a-cc53ba5c998f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/check-missed-events-no-context-event

Comment @coderabbitai help to get the list of available commands and usage tips.

@andreabadesso andreabadesso self-assigned this Mar 4, 2026
@andreabadesso andreabadesso added the enhancement New feature or request label Mar 4, 2026
@andreabadesso andreabadesso added bug Something isn't working and removed enhancement New feature or request labels Mar 4, 2026
@andreabadesso andreabadesso moved this from Todo to In Progress (Done) in Hathor Network Mar 4, 2026
@andreabadesso andreabadesso merged commit b6ce579 into release-candidate Mar 5, 2026
2 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress (Done) to Waiting to be deployed in Hathor Network Mar 5, 2026
@andreabadesso andreabadesso deleted the fix/check-missed-events-no-context-event branch March 5, 2026 01:28
This was referenced Mar 5, 2026
@andreabadesso andreabadesso moved this from Waiting to be deployed to Done in Hathor Network Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants