Repository navigation
fix(alerts): refuse an alert that cannot be delivered (#790) - #793
Merged
Merged
Conversation
`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 Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This was referenced Oct 11, 2026
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.
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 createvalidated five trigger types, wrote the record, printedAlert created: <id>and exited 0 — while the only reader of that table,lambda/alert-handler, is deployed nowhere. Every alert ever created was inertand
spawn alerts historystayed permanently empty, which reads like "nothinghas gone wrong" rather than "nothing is watching".
Verified live against the shared account: exit 1, and an independent
DynamoDB scan of
spawn-alertsfor the probe sweep ID returns Count=0.A check that cannot run does not refuse
AccessDenied/ no networkThe check costs one
lambda:GetFunction, which a caller able to write to thealerts 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/infrastructureasDeliverability.Decidesoit is unit-tested directly. In
cmd/it could only be reached by a command thatneeds 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_ARNat its ownfunction is unaffected, and
TestCheckAlertDelivery_RespectsConfiguredARNexistsso "refuse when the shared function is missing" cannot degrade into "always
refuse".
An existing gate rejected the first attempt
TestNoNewAWSSDKImportsInCmd(#326/#327) fails acmd/file that reaches for anew
aws-sdk-go-v2/servicepackage, andcmd/alerts.gohad gainedservice/lambda. Its own instruction is to route throughpkg/rather than growthe allowlist, so client construction moved into
pkg/infrastructure.Tier 0
The round-trip drives
alerts createand expects success, so it now seeds theconsumer — confirmed load-bearing by removing
seedAlertHandler()and watchingthe round-trip fail with the refusal.
TestTier0_AlertsCreateRefusedWhenUndeliverableasserts the non-zero exit andthat 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
runAlertsCreateCreateAlertDeciderefuse on undeterminedAll three build and vet clean before failing, so the gate actually ran.
Verification
Full Tier 0 suite (65s),
make checkincluding all 12 nested modules,check-docs, andsemgrep(0 findings) green. Public API surface unchanged —pkg/infrastructureis not imported by another repo.Also filed #792: Tier 0 e2e reuses an existing
bin/spawnunconditionally,which gave me a passing
TestTier0_AlertsRoundTripfrom a nine-hour-old binarycontaining none of this. The failing test sent me looking; the passing one would
not have.