feat(dm): durable send stage timers (#336 phase 1) - #352
Merged
Conversation
dirvine
marked this pull request as ready for review
August 19, 2026 07:51
Comment on lines
+501
to
+509
| let timeout_stages = matches!(e, x0x::dm::DmError::Timeout { .. }) | ||
| .then(|| { | ||
| state | ||
| .agent | ||
| .direct_messaging() | ||
| .diagnostics_snapshot() | ||
| .last_durable_send | ||
| }) | ||
| .flatten(); |
There was a problem hiding this comment.
Timeout stages lose request correlation
If two durable /direct/send requests overlap, each send overwrites the same daemon-wide last_durable_send slot before the timeout handler reads it, causing a 504 response to report another request's stage timings and budget_stage.
Knowledge Base Used:
- Direct Messaging: Send, Capability Gate, Inbox, and Forward
- Server API: HTTP/WebSocket/SSE surface and agent signing
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/server/routes/direct.rs
Line: 501-509
Comment:
**Timeout stages lose request correlation**
If two durable `/direct/send` requests overlap, each send overwrites the same daemon-wide `last_durable_send` slot before the timeout handler reads it, causing a 504 response to report another request's stage timings and `budget_stage`.
**Knowledge Base Used:**
- [Direct Messaging: Send, Capability Gate, Inbox, and Forward](https://app.greptile.com/saorsa-labs/-/custom-context/knowledge-base/saorsa-labs/x0x/-/docs/dm-messaging.md)
- [Server API: HTTP/WebSocket/SSE surface and agent signing](https://app.greptile.com/saorsa-labs/-/custom-context/knowledge-base/saorsa-labs/x0x/-/docs/server-api.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
dirvine
force-pushed
the
cursor/durable-dm-stage-timers-2453
branch
2 times, most recently
from
August 20, 2026 16:14
7fedafd to
15cb585
Compare
Record strict_gate_ms, publish_ms, and ack_wait_ms on durable gossip-inbox sends so a slow first DM can name which stage consumed the budget. Export the timers on the existing 504 timeout body and GET /diagnostics/dm. Measurement only: no latency cut, no ACK-semantics or HTTP-status change. Co-authored-by: David Irvine <dirvine@users.noreply.github.com>
dirvine
force-pushed
the
cursor/durable-dm-stage-timers-2453
branch
from
August 20, 2026 16:15
15cb585 to
3f05ea4
Compare
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.
Summary
Phase 1 of #336 only: measure the first durable DM to a new peer. This does not cut latency.
A durable gossip-inbox send now records three named stages that partition daemon-side wall time:
strict_gate_ms— advert / capability store (ADR 0030 §2 refresh)publish_ms— inbox / topic fan-outack_wait_ms— sender waiter vs receiver ACK publish-completebudget_stagenames which of the three consumed the most time, so a slow send can say which stage ate the budget. Until that exists, no "we warmed X" merge.Exported on:
errorstaystimeout,detailstays the existing Display string)GET /diagnostics/dmaslast_durable_send(sender) andlast_ack_publish_ms(receiver ACK publish)Out of scope (deliberately not in this PR)
prefer_raw_quic_if_connectedon for durable sendsapi-referenceas an SLAValidation
cargo fmt --allcargo clippy --locked --all-features --all-targets -- -D warningscargo check --workspace --all-targetscargo test --locked --all-features --test durable_send_stage_timers(two-daemon loopback first send: stages sum to wall)Coverage
main: n/aTest Quality Checklist
just coverage-summary.coverage-skip:comment and a matching register entry.Greptile Summary
The PR adds sender-side durable-DM stage timing and receiver ACK-publish timing to identify where first-send latency is spent.
/diagnostics/dm.Confidence Score: 4/5
The timeout-stage correlation defect should be fixed before merging because concurrent sends can return another request's diagnostics.
Durable sends overwrite one daemon-wide timing slot, while a timed-out handler reads that slot later without request correlation, allowing an overlapping send to replace the measurements attached to the 504 response.
Files Needing Attention: src/server/routes/direct.rs, src/direct.rs, src/lib.rs
Important Files Changed
/diagnostics/dm.Sequence Diagram
Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "feat(dm): add durable send stage timers ..." | Re-trigger Greptile
Context used: