Repository navigation
fix(onboarding): capture the nudge's message id, which is nested under message - #957
Merged
Merged
Conversation
…r `message` Found by reading production after #956 deployed. Ten nudges landed correctly in ten pods — right people, right pods, right commands — and all ten recorded `nudgeMessageId: ''`. `AgentMessageService.postMessage` returns `{ success, message, summary }`. The id lives at `message.id` (PG, the primary store) or `message._id` (the Mongo fallback). The code read `posted.id`, which is undefined. The messages were fine; the audit trail was not. "Why did this person never get nudged" is unanswerable without it, and the reactive responder inherits the same record. The tests did not catch it because the fixture returned `{ id: 'msg1' }` — the shape the bug expected. A mock built from the calling code's assumption rather than from the callee's actual return will agree with the bug every time. The fixture now matches what postMessage really returns, and there is a test asserting the recorded id. Also stops counting a declined post as a delivered nudge: postMessage can succeed-without-posting (`skipped: true` for duplicate/suppressed sends), and reporting that as `nudged` is the silent-success shape again. The episode stays claimed — something decided that room did not need the message — but the caller is no longer told a nudge went out when none did. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01XeUH4HVDsDHYPsHJthXjB8
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.
Found by reading production after #956 deployed, not by CI.
What happened
The first live pass did the right thing:
candidates=26 nudged=10 tooRecent=0 notStalled=16, and ten messages landed in ten pods — right people, right pods, right commands. Verified in PG, e.g.And all ten episodes recorded
nudgeMessageId: ''.AgentMessageService.postMessagereturns{ success, message, summary }— the id is atmessage.id(PG, the primary store) ormessage._id(Mongo fallback). The code readposted.id. Undefined every time.The messages were fine. The audit trail was not, and "why did this person never get nudged" is unanswerable without it — which is exactly the question this feature exists to make answerable. @sprint-impl's reactive responder inherits the same record.
Why the tests passed
The fixture returned
{ id: 'msg1' }— the shape the bug expected. I wrote the mock from the calling code's assumption instead of from whatpostMessageactually returns, so the test agreed with the bug rather than with the service.That is the third variant of this in two days, after "a test that re-declared the handler instead of importing it" and "a test that passed
podAuthorized: trueand so only proved the service honours a flag". Same root: a fixture asserted against an assumption is not evidence. The fixture now matches the real return shape and a test pins the recorded id.Second fix in here
postMessagecan succeed-without-posting ({ success: true, skipped: true }for duplicate or suppressed sends). That was being counted as a delivered nudge — the silent-success shape yet again. The episode stays claimed, which is right (something decided that room did not need the message), but the caller is no longer told a nudge went out when none did.Not fixed here
The ten already-sent episodes keep their empty ids. The messages exist (
53316–53325) and are recoverable by pod + timestamp if we want them backfilled — say the word. I did not do it silently because it is a data write to repair an audit field, and the messages themselves are already correctly delivered.Correction to something I said before deploying
I told Sam "nobody gets more than one" nudge. True for every real user, and false for the smoke fixture, which has two stalled seats in one pod and so got two messages there. Episodes are per (installation, token), so a user with two stalled seats in one pod gets two posts. Correct behaviour, wrong claim.
65 tests green,
tsc:checkclean.🤖 Generated with Claude Code
https://claude.ai/code/session_01XeUH4HVDsDHYPsHJthXjB8