Repository navigation
fleet-queue: needs-drew alerts into the PM throat on escalated blocks (code#8568) - #8598
Conversation
…blocks (code#8568) Phase 1 of PM-stack notifications: the queue block path learns to speak to the aggregator alert throat (POST /api/alerts, source fleet-queue, key needs-drew:<ledgerId>, deduped by the throat so both halves may post safely). - New needs_drew module: pure throat-body builder pinned by unit tests, a minimal std-TcpStream HTTP/1.1 POST helper, and the snake_case needs_drew block-request parser both halves share. - CLI (cmd_block): --ledger-id/--question/--context/--options-json/--links-json on an escalated-to-user block add needs_drew to the /block body and merge needs_drew.ledger_id into progress (so the current broker stamps the ledger id onto the task row with no broker change); after the block lands, the intake token resolves by name via fleet-secrets Resolver::default_chain (the fleet secrets machinery) and the alert posts. Emission failure warns on stderr and still exits 0; stdout shape unchanged. Escalated blocks without the flags behave exactly as before. - Broker (/block route): after a successful block with reason_class escalated-to-user and a needs_drew payload, the same post fires fire-and-forget on a spawned thread, token resolved via the in-process DirectSecrets secrets source; failures log to stderr only. Hooked on both the Postgres simple_rpc arm and the Turso dispatch branch.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 51 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Merging over merely-QUEUED checks, per established practice: every check is still pending/queued (none red, none failed) and this change is verified locally on the laptop — cargo test -p fleet-queue --all-features: 257 lib tests passed (including the 7 new needs_drew tests) + 2 broker_bin_args, 0 failures; cargo test -p fleet-queue (default features): 30 passed; cargo build --release -p fleet clean. The change is additive and feature-contained in fleet-queue; no binary is deployed and queue-broker is not restarted by this merge — the staged binary at ~/tools/staging/fleet-8568/fleet awaits the coordinated switch. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 995161fca4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "severity": "warning", | ||
| "title": block.question, | ||
| "body": body, | ||
| "needsDrew": needs_drew, |
There was a problem hiding this comment.
Coordinate the needs-drew receiver before enabling emission
Against the aggregator included in this commit, these POSTs succeed without notifying Drew or preserving the actionable question. The /api/alerts handler in pm-stack/aggregator/src/server.ts:2348–2357 passes the body through validateNewIncident, whose projection in alerts.ts:319–327 discards needsDrew, including its ledger ID, options, and links. Furthermore, pendingDeliveries in alerts.ts:570–577 selects only critical incidents, so this warning never generates a push. Land the matching receiver support before enabling this producer; otherwise both CLI and broker report successful raises while escalated tasks remain without the intended notification.
Useful? React with 👍 / 👎.
| if resp.get("ok").and_then(|v| v.as_bool()) != Some(true) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
Require a transitioned task row before raising an alert
On the Postgres path, simple_rpc wraps any successful RPC response as ok: true, including a null row. The client explicitly treats that null row as an unsuccessful block in require_row (for example, when the task is no longer claimed by the requesting worker), but this hook checks only the envelope and still emits the question. Consequently a stale or repeated block request can raise an alert even though no task was blocked. Require a non-null response row before spawning the notification thread, matching the client's success criterion.
Useful? React with 👍 / 👎.
Fleet (Rust) half of PM-stack notifications Phase 1 for #8568: the queue block path now raises a needs-drew event into the PM alert throat.
Wire contract (as fixed by the aggregator lane, unchanged):
POST http://127.0.0.1:4870/api/alerts(env overrideFLEET_ALERTS_URL),Authorization: Bearer <token>where the token is the Bitwarden secret namedpm-aggregator.alerts-intake-tokenresolved by name, body{"source": "fleet-queue", "key": "needs-drew:<ledgerId>", "severity": "warning", "title": <question>, "body": <context or blocker>, "needsDrew": {...}}. The throat dedupes by (source, key); the raise is idempotent.What changed (
pkgs/fleet/crates/fleet-queue):src/needs_drew.rs(new): pure payload builderbuild_throat_body(&BlockNeedsDrew) -> serde_json::Valuepinned by unit tests (exact key/title/needsDrew shape, optionals omitted when absent, blocker as body fallback); a minimal HTTP/1.1 JSON POST helper over stdTcpStream(client.rs transport style);post_needs_drew(token, nd)returning the response'sanswerUrlwhen present; plus the snake_caseneeds_drewblock-request parser both halves share.src/client.rs(cmd_block): new optional flags--ledger-id,--question,--context,--options-json,--links-json. Forescalated-to-userblocks with--ledger-id+--question: the/blockbody gains"needs_drew": {ledger_id, question, context?, options, links}, and"needs_drew": {"ledger_id": …}is merged into the progress object (preserving caller--progresscontent) so the current broker stamps the ledger id onto the task row with no broker change. After the block succeeds, the intake token is resolved by name in-process viafleet_secrets::Resolver::default_chain— the exact machinery behind thefleet secrets getverb (direct secrets-broker source on the laptop, session-proxy source in the sandbox,bwsfallback; the queue CLI has no other named-secret resolver of its own) — and the alert posts. Emission failure printsrepo-queue: WARNING: needs-drew throat post failed: <err>to stderr and still exits 0; success printsrepo-queue: needs-drew raised for ledger item <id>to stderr; stdout keeps its current JSON shape exactly. Escalated blocks without the flags behave exactly as before.src/queue_broker.rs(/block): after a successful block withreason_class == "escalated-to-user"and aneeds_drewpayload, the same POST fires from inside the broker process, fire-and-forget on a spawned thread, token resolved via the in-process secrets source (DirectSecrets— the colocated secrets broker, the same source every other broker credential uses); failures are logged to stderr only. The hook is applied on both the Postgressimple_rpcarm and the Turso dispatch branch (dispatch hands/blockto the Turso backend before the match, so a Turso-backed broker would otherwise never see it).Deployment, plainly: the CLI half is the live path once the CLI binary is replaced. The broker half cannot go live until the broker binary is replaced (the coordinated switch) — this PR does not replace any binary and does not restart queue-broker. The release
fleetbinary built from this branch is staged on the laptop at~/tools/staging/fleet-8568/fleet(sha2565735008dd51b85a11ee2412351e130dd416fab5155aca826b2ba691e683a0b90, 6,982,776 bytes) for that switch.Tests:
cargo test -p fleet-queue— 30 passed (default features);cargo test -p fleet-queue --all-features— 257 lib tests passed including the 7 newneeds_drewtests, plus 2broker_bin_argstests; 0 failures.cargo build --release -p fleetclean (pre-existing warnings only). Staged-binary smoke: new flags parse and bad--options-json/--links-jsondie with exit 2 before any broker contact. No live block was performed (that would block a real task and push Drew's phone).Refs #8568.
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.