Skip to content

fix(alerts): refuse an alert that cannot be delivered (#790) - #793

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/790-alerts-deliverability
Oct 11, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/790-alerts-deliverability

Conversation

@scttfrdmn

@scttfrdmn scttfrdmn commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

This is the last code item in #790. Refs #790 deliberately: the only thing
left there is the product decision in #783, so the issue must stay open.

spawn alerts create validated five trigger types, wrote the record, printed
Alert created: <id> and exited 0 — while the only reader of that table,
lambda/alert-handler, is deployed nowhere. Every alert ever created was inert
and spawn alerts history stayed permanently empty, which reads like "nothing
has gone wrong" rather than "nothing is watching".

Verified live against the shared account: exit 1, and an independent
DynamoDB scan of spawn-alerts for the probe sweep ID returns Count=0.

A check that cannot run does not refuse

state action
function absent (404) refuse, non-zero, nothing written
AccessDenied / no network warn, create anyway
function present silent

The check costs one lambda:GetFunction, which a caller able to write to the
alerts table may not hold. Refusing on an undetermined result would break working
installs to protect them from a defect they may not have — a worse bug than the
one being fixed, and the inverse of #624, where a check that could not tell
reported a verdict anyway.

The three-way branch lives in pkg/infrastructure as Deliverability.Decide so
it is unit-tested directly. In cmd/ it could only be reached by a command that
needs credentials, which in practice means not exercised — and an unexercised
code path is the entire defect here.

A self-hosted install pointing SPAWN_LAMBDA_ALERT_HANDLER_ARN at its own
function is unaffected, and TestCheckAlertDelivery_RespectsConfiguredARN exists
so "refuse when the shared function is missing" cannot degrade into "always
refuse".

An existing gate rejected the first attempt

TestNoNewAWSSDKImportsInCmd (#326/#327) fails a cmd/ file that reaches for a
new aws-sdk-go-v2/service package, and cmd/alerts.go had gained
service/lambda. Its own instruction is to route through pkg/ rather than grow
the allowlist, so client construction moved into pkg/infrastructure.

Tier 0

The round-trip drives alerts create and expects success, so it now seeds the
consumer — confirmed load-bearing by removing seedAlertHandler() and watching
the round-trip fail with the refusal.

TestTier0_AlertsCreateRefusedWhenUndeliverable asserts the non-zero exit and
that no record is left behind
. The write always worked — that is why this went
unnoticed since the initial commit — so "an error was returned" would not
distinguish the fix from a refusal that still wrote.

Gates verified against compiling reverts

revert gate says
remove the call from runAlertsCreate "does not call checkAlertsDeliverable"
move it after CreateAlert "calls it AFTER CreateAlert (offsets 2520 > 2415)"
make Decide refuse on undetermined the undetermined cases fail

All three build and vet clean before failing, so the gate actually ran.

Verification

Full Tier 0 suite (65s), make check including all 12 nested modules,
check-docs, and semgrep (0 findings) green. Public API surface unchanged —
pkg/infrastructure is not imported by another repo.

Also filed #792: Tier 0 e2e reuses an existing bin/spawn unconditionally,
which gave me a passing TestTier0_AlertsRoundTrip from a nine-hour-old binary
containing none of this. The failing test sent me looking; the passing one would
not have.

`spawn alerts create` validated five trigger types, wrote the record,
printed "Alert created: <id>" and exited 0 — while the only reader of
that table, lambda/alert-handler, is deployed nowhere. Every alert ever
created was inert, and `spawn alerts history` stayed permanently empty,
which reads like "nothing has gone wrong" rather than "nothing is
watching".

The live spawn-alert-evaluator is not a substitute: it reads
spawn-alert-preferences and covers cost alerts only, and never reads
spawn-alerts.

The command now checks that the consumer exists BEFORE writing, and exits
non-zero with what to do about it. Checking afterwards would leave a dead
record behind AND return an error: the worst of both.

## A check that cannot run does not refuse

The check costs one lambda:GetFunction, which a caller able to write to
the alerts table may not hold. So:

  function absent (404)        -> REFUSE
  AccessDenied / no network    -> warn, create anyway
  function present             -> silent

Refusing on an undetermined result would break working installs to
protect them from a defect they may not have — a worse bug than the one
being fixed, and the inverse of #624 where a check that could not tell
reported a verdict anyway.

The three-way branch lives in pkg/infrastructure as Deliverability.Decide
so it is unit-tested directly. In cmd/ it could only be reached by a
command that needs credentials, which in practice means not exercised —
and an unexercised code path is the whole defect here.

A self-hosted install pointing SPAWN_LAMBDA_ALERT_HANDLER_ARN at its own
deployed function is unaffected, and there is a test for that so "refuse
when the shared function is missing" cannot degrade into "always refuse".

## An existing gate rejected the first attempt

TestNoNewAWSSDKImportsInCmd (#326/#327) fails a cmd/ file that reaches
for a new aws-sdk-go-v2/service package, and cmd/alerts.go had gained
service/lambda. Its own instruction is to route through pkg/ rather than
grow the allowlist, so the client construction moved into
pkg/infrastructure and the exported entry point takes an aws.Config.

## Tier 0

The round-trip test drives `alerts create` and expects success, so it now
seeds the consumer. Confirmed load-bearing: removing seedAlertHandler()
makes the round-trip fail with the refusal.

Added TestTier0_AlertsCreateRefusedWhenUndeliverable, which asserts the
non-zero exit AND that no record is left behind. The write always worked —
that is why this went unnoticed since the initial commit — so "an error
was returned" would not distinguish the fix from a refusal that still
wrote.

## Gates verified against compiling reverts

  remove the call from runAlertsCreate -> "does not call
      checkAlertsDeliverable"
  move it after CreateAlert           -> "calls it AFTER CreateAlert
      (offsets 2520 > 2415)"
  make Decide refuse on undetermined  -> the undetermined cases fail

All three build and vet clean before failing, so the gate actually ran.

## Verified live

AWS_PROFILE=spore-host-infra: exit 1, and an independent DynamoDB scan of
spawn-alerts for the probe sweep ID returns Count=0. Nothing was written.

Full Tier 0 suite, make check (all 12 nested modules), check-docs and
semgrep (0 findings) green. Public API surface unchanged: pkg/infrastructure
is not imported by another repo.

Refs #790 — its remaining item is the product decision in #783.
Filed #792: Tier 0 e2e reuses an existing bin/spawn unconditionally, which
gave me a PASSING round-trip from a nine-hour-old binary containing none of
this.
@codecov

codecov Bot commented Oct 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.30769% with 18 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/alerts.go 0.00% 16 Missing ⚠️
pkg/infrastructure/delivery.go 95.91% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

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