Skip to content

AI-3878: a message waits one second at most for the node directory - #2471

Merged
thesyncim merged 12 commits into
mainfrom
fix/ai-3878-directory-read-limit
Nov 26, 2026
Merged

thesyncim merged 12 commits into
mainfrom
fix/ai-3878-directory-read-limit

Conversation

@thesyncim

@thesyncim thesyncim commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Problem
writesElsewhere asks the node directory whether another customer's session writes as the agent, before the session running here answers a message that names no customer. The read had no limit of its own, and rueidis retries a read until its context ends. With a Redis that takes the command and never answers, the message was not answered in the test's 10 s. The fallback, answering here when the directory cannot be read, was not reached.

Fix

  • writesElsewhere waits one second for the directory, then answers here as for any other failed read. A directory that takes longer than a second to answer now counts as one that cannot be read.
  • The read runs in a goroutine. A context alone does not end it: while another caller dials the connection again, rueidis waits for that dial past the context, and a message took 5.0 s in the test. The goroutine ends with that dial, which rueidis gives 5 s to connect and 5 s to greet Redis, so each message may leave one that long.
  • The limit is at this read, not in node.Directory. answeringNode's caller hands the message to a worker on an error, and handDeliveryToPeer reopens the session, so with these two a short limit could start a second session while a slow Redis still knew of the first. They are unchanged.
  • Follow-up: nodeFor and forwardedToWorkers still read without a limit.

Tests

  • TestAMessageNamingNoCustomerIsAnsweredHereInTimeWhenTheDirectoryHangs: a Redis that drops every answer, the hook answered in under 1.5 s and the session asked. Without the limit it fails: context deadline exceeded (Client.Timeout exceeded while awaiting headers). It also fails with a 1.9 s limit, and with return true on the read error.
  • TestAMessageNamingNoCustomerIsAnsweredHereInTimeWhileAnotherReadDialsTheHungDirectory: the same while a read without a limit dials the connection again, and the goroutine ends once that dial does. With the read outside a goroutine it fails: "5.00055825s" is not less than "2s". With an unbuffered channel, or the read on context.WithoutCancel, it fails: what asked the directory is still running.
  • TestAMessageNamingNoCustomerIsAnsweredByNeitherThoughTheDirectoryIsSlow: answers 700 ms late are still waited for. Fails with a 400 ms limit.
  • The limit is held to a range: 900 ms and 1.1 s pass these tests, 400 ms and 1.9 s do not.
  • TestARenewedClaimOnAnAgentIsInItsSessionsApp: a renewal keeps the app of a claim. It is here because the ticket asks for it: storing app 0 in d.held, which the renewal reads, passed every suite. Fails when Hold keeps app 0 in d.held.

Fixes AI-3878

@thesyncim thesyncim added the data-layer-review: ready Data layer review fix: passed automated review, merges cleanly, ready for a human review label Nov 25, 2026

@kanat kanat 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.

VERDICT: GO

Reviewed 65c70b4 merged onto main 05cafd6 (clean). CI on the head: every integration job passes; go fails TestRefusedAttemptsSuite in keypool, a known base failure (#2500), not this PR.

Checked and sound: the 1 s limit is a WithTimeout of the caller's ctx, so it never outlasts it, and cancel is deferred. The read runs in a goroutine with a buffered channel and ends with the derived ctx. A bound hit answers here and logs a Warn with the agent and the error, so no message is lost silently. The three new tests and CannotBeRead passed 5 of 5 with -count=5 at machine load ~28. The mutants I tried were killed: no limit, 2 s, 650 ms, 400 ms, true on the read error, an unbuffered channel, no ctx.Done() case, the read outside the goroutine, WithoutCancel. One survived (R1.1). #2402 is not on main, so there is no InTime to compare with.

Outside the diff:

[Question] R1.3 A message with no session on this node still waits without a limit. answeringNode (forward.go:387/389, reached by forwardedMessage at messagehooks.go:414) and Waiting in forwardedToWorkers (forward.go:432, messagehooks.go:456) read the directory with the hook's ctx. The title says a message waits one second at most, which holds only for the writesElsewhere read. The body lists nodeFor and forwardedToWorkers as follow-ups but not answeringNode. Ticket all three, and consider rewording the title to the one read.

Details: reviewer-1.md in the ledger.

@kanat kanat 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.

Approving on the reviewer's GO.

@kanat kanat 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.

Re-approving: the new commits merge main and change only tests (checked).

@thesyncim
thesyncim merged commit ee2e94f into main Nov 26, 2026
23 of 26 checks passed
@thesyncim
thesyncim deleted the fix/ai-3878-directory-read-limit branch November 26, 2026 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data-layer-review: ready Data layer review fix: passed automated review, merges cleanly, ready for a human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants