Skip to content

fleet-queue: needs-drew alerts into the PM throat on escalated blocks (code#8568) - #8598

Merged
dezren39 merged 1 commit into
mainfrom
queue/8568-notifications-phase1-fleet
Nov 11, 2026
Merged

dezren39 merged 1 commit into
mainfrom
queue/8568-notifications-phase1-fleet

Conversation

@dezren39

@dezren39 dezren39 commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

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 override FLEET_ALERTS_URL), Authorization: Bearer <token> where the token is the Bitwarden secret named pm-aggregator.alerts-intake-token resolved 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 builder build_throat_body(&BlockNeedsDrew) -> serde_json::Value pinned 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 std TcpStream (client.rs transport style); post_needs_drew(token, nd) returning the response's answerUrl when present; plus the snake_case needs_drew block-request parser both halves share.
  • src/client.rs (cmd_block): new optional flags --ledger-id, --question, --context, --options-json, --links-json. For escalated-to-user blocks with --ledger-id + --question: the /block body gains "needs_drew": {ledger_id, question, context?, options, links}, and "needs_drew": {"ledger_id": …} is merged into the progress object (preserving caller --progress content) 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 via fleet_secrets::Resolver::default_chain — the exact machinery behind the fleet secrets get verb (direct secrets-broker source on the laptop, session-proxy source in the sandbox, bws fallback; the queue CLI has no other named-secret resolver of its own) — and the alert posts. Emission failure prints repo-queue: WARNING: needs-drew throat post failed: <err> to stderr and still exits 0; success prints repo-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 with reason_class == "escalated-to-user" and a needs_drew payload, 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 Postgres simple_rpc arm and the Turso dispatch branch (dispatch hands /block to 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 fleet binary built from this branch is staged on the laptop at ~/tools/staging/fleet-8568/fleet (sha256 5735008dd51b85a11ee2412351e130dd416fab5155aca826b2ba691e683a0b90, 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 new needs_drew tests, plus 2 broker_bin_args tests; 0 failures. cargo build --release -p fleet clean (pre-existing warnings only). Staged-binary smoke: new flags parse and bad --options-json/--links-json die 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.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…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.
@dezren39
dezren39 requested a review from a team as a code owner November 11, 2026 07:37
@coderabbitai

coderabbitai Bot commented Nov 11, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ab97342e-0abd-4fb4-b14d-86972d2c6675
Commits

Reviewing files that changed from the base of the PR and between 1a06801 and 995161f.

Files selected for processing: 4

  • pkgs/fleet/crates/fleet-queue/src/client.rs
  • pkgs/fleet/crates/fleet-queue/src/lib.rs
  • pkgs/fleet/crates/fleet-queue/src/needs_drew.rs
  • pkgs/fleet/crates/fleet-queue/src/queue_broker.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T07:41:18.042992Z 995161f PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@dezren39

Copy link
Copy Markdown
Member Author

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.

@dezren39
dezren39 merged commit ab15e73 into main Nov 11, 2026
1 of 11 checks passed
@dezren39
dezren39 deleted the queue/8568-notifications-phase1-fleet branch November 11, 2026 07:39

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +100 to +103
"severity": "warning",
"title": block.question,
"body": body,
"needsDrew": needs_drew,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Comment on lines +838 to +840
if resp.get("ok").and_then(|v| v.as_bool()) != Some(true) {
return;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

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.

1 participant