Repository navigation
AI-3902: a money refusal survives a session reopen - #2556
Conversation
…(WIP) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EZsRxWUwySyG1JAn9T7GpE
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EZsRxWUwySyG1JAn9T7GpE
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EZsRxWUwySyG1JAn9T7GpE
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EZsRxWUwySyG1JAn9T7GpE
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EZsRxWUwySyG1JAn9T7GpE
kanat
left a comment
There was a problem hiding this comment.
VERDICT: GO
[security R1]: one Nit, no Blocker and no Should fix.
Who can read support_money_refusal (author QUESTION, suspicion 1). It can stay in the reply's Chat custom data, and router-only storage is not needed. The field holds only a fixed code from policy.Code and one bool. It holds no amount and no error text. A device already gets more than this for the same refusal: the HTTP answer carries the code and the message (api/money.go moneyError/refusedRequest), and the session socket's error frame carries the full message (sessionws.go refusalText). refused is a member-visible flag of the same kind. Note: in a group or thread channel, every member, not only the turn's user, can read the code. That is acceptable.
Forging or erasing it (suspicion 2). On a reopen, the field is read only from a reply the agent wrote (readsAsWritten, in historyIn and in the receipt read), and only off assistant records (commandsIn). A member's message that carries the agent's fields plus a forged refusal reads back as no refusal. A member's later message saying completed does not erase a real refusal. A scratch-copy test as a member confirms this on this head, and that test fails when the author check is removed. The value is also limited to a fixed list (moneyRefusalOf + policy.Refusal).
Checked and fine: the error-text grep finds 0 hits. A rollback to the previous build ignores the extra custom key and falls back to the base behaviour. The decode of legacy messages cannot set the unexported field. There is no migration. Mutations: 4 checked, 0 survived (the flag check, the unknown-code case of policy.Refusal, the Observe money-only check, and readsAsWritten).
| // What the field holds is read back as a refusal only when it is one the router writes: any other | ||
| // shape, type or code reads as no refusal, so a reply never fails a delivery under a code no | ||
| // refusal gave. | ||
| func (s *MoneyRefusalSuite) TestOnlyAKeptRefusalReadsAsOne() { |
There was a problem hiding this comment.
[Nit] S1.1 Nothing in this suite pins that a channel member's message carrying support_money_refusal under a follow-up's command id is ignored after a reopen. Today readsAsWritten covers it, and TestAMembersMessageCarryingTheAgentsFieldsNamesNoCommand fails if that check goes. A row here would tie the new field to that guard. Suggested row: a member writes a copy of the reply with the field set, after a reply that failed for another reason, then the conversation reopens. Expect FollowUpFailure nil. Also: a member writes completed with no field after a real refusal. Expect the refusal kept. Optional.
There was a problem hiding this comment.
Fixed in 5d61d2d: TestAMembersForgedRefusalIsNotRead and TestAMembersCopyOfARefusedReplyDoesNotEraseTheRefusal (money_refusal_test.go). Mutation: readsAsWritten returning true fails both.
kanat
left a comment
There was a problem hiding this comment.
VERDICT: GO
Reviewed 7dfe085 (it already contains main at 21b2551). CI: the draft skips go and integration; they run at gh pr ready.
[Nit] R1.1 .claude/skills/scheduled-tasks/SKILL.md:211 still says the error "is kept in memory only" and that a retry after a reopen records reply_failed or delivered ("known gap"). This PR closes that gap. The brief gives the SKILL lines to AI-3904, so AI-3904 must drop that sentence. Not a blocker here.
Rulings on the author's open points:
- Thread retry after a reopen, no test: this goes to a ticket, not this PR. The PR changes no thread-only code. A reviewer probe ran
deliverOnThreadon a restarted node after a failedst_run. It fails underinsufficient_credits, final, on this head, and recordsreply_failedon base. Add the test once AI-3903 (deliverOnThread) lands. - Regenerated reply gets no refusal back: not a finding. The only reader of
FollowUpFailureisturnRefusal(scheduled_delivery.go:603), and it never asks for a regenerated command id. TheFailurecomment says so. support_money_refusalin Chat custom data: acceptable. It holds a code and a flag only, and the socket already sends the refusal text (sessionws.go:1049). Its only reader ismessageFromWire->commandsIn.Message.refusalis unexported, so it is not in the socket, history or snapshot JSON. Model context, cards and omnichannel never read it. A branch resend copies it only under new ids, whichresent()adds without overwriting. A message without the field reads back as on base. An old build ignores the extra top-level key (messageFromWireon main reads keys by name).
Checked and sound:
- The 3 new regression tests fail on base (
delivered, no error,reply_failed). The 2 controls pass on base and head. TestTelnyxUnpaidSuite, conversation and policy unit and integration all pass on the head. Vet and gofmt are clean.- 7 more mutations, 7 killed: refusal set after
finish, field written or read on any failed reply, any error kept, fixed code, stored flag ignored, spend check forced unchecked. - The retry after a reopen keeps the same code, and
Final = !policy.Transient. The text is not needed: the run records onlyReasonOf.
| // What the field holds is read back as a refusal only when it is one the router writes: any other | ||
| // shape, type or code reads as no refusal, so a reply never fails a delivery under a code no | ||
| // refusal gave. | ||
| func (s *MoneyRefusalSuite) TestOnlyAKeptRefusalReadsAsOne() { |
There was a problem hiding this comment.
[Nit] R1.2 This is a table test with an if tc.kind == nil branch in its body. The go-testing skill says to avoid table tests and write one test per behaviour ("reads as no refusal" and "reads back as its kind" are two). This is for a ticket, not this PR.
There was a problem hiding this comment.
Fixed in 5d61d2d: split into TestAShapeTheRouterNeverWritesReadsAsNoRefusal and TestAShapeTheRouterWritesReadsAsItsRefusal; same cases and assertions, no branch in either body.
…eopen Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EZsRxWUwySyG1JAn9T7GpE
…and erased refusal Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EZsRxWUwySyG1JAn9T7GpE
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EZsRxWUwySyG1JAn9T7GpE
…efusal-survives-reopen
Why
A scheduled reply refused for money must end its run failed, final, under the money code (AI-2055, AI-3183). #2278 made the wait read how the turn ended from the conversation (
FollowUpFailure), but the conversation kept the failure in memory only (commandRecord.Failure, "kept in memory only"). A session reopens after a router drain or restart, or after its 5-minute unwatched grace. After a reopen,commandsInrebuilt the records from the Chat messages without the failure. A retry of a reply refused for money then recordedreply_failed(text channels) ordelivered(conversation channel), although the user got nothing (AI-3902, #2278 R1.4).The placed-call path (
carryOutAnswered, AI-3904) is a separate PR.How it works
What is kept, and why:
code(policy.Code)deliveryReason,scheduled_delivery.go:374; schedulerError: reason,scheduler.go:452unchecked(policy.Transient)insufficient_creditsis transient when the balance is unread (policy/money.go:105)unpaid,scheduled_delivery.go:422scheduler.go:444A message without the field (any message written before this change, or a failure not about money) reads back with no failure, as before.
Changes
policy.Refusal(code, unchecked): the refusal of the kindCodenames, for a refusal read back from where it was kept.conversation:Observekeeps a money refusal on the failed reply;sendWithwrites it as thesupport_money_refusalcustom field;messageFromWirereads it back;commandsInrestoresFailurefor a follow-up and for a person's command. TheMessagefield is unexported, so no API oropenapi.yamlchange, and no migration.Validation
TestAConversationTaskWhoseTurnIsRefusedForMoneyIsNotRetriedTestAConversationTurnRefusedForMoneyBeforeAReopenFailsUnderTheMoneyinsufficient_creditsTestATextTurnRefusedForMoneyBeforeAReopenFailsUnderTheMoneyreply_failedinsufficient_creditsTestAConversationTurnRefusedUncheckedBeforeAReopenRunsAgainOnItsRetryTestATextTurnFailedNotForMoneyBeforeAReopenFailsAsAReplyThatFailedreply_failedreply_failedTestATextTurnCompletedBeforeAReopenIsTextedrestartedNode) then carries the session on. That router holds nothing in memory, so it reads the conversation from Chat, as after a restart, a drain to a peer or the end of the grace. A worker that takes the run over after the first attempt was cut short reads no reason from the row (Run.Errornil), which these tests use.readBackReply/refusedAgain(scheduled_thread_delivery.go:93,108) as the SMS test.internal/conversationMoneyRefusalSuite: each of the 7 money kinds, checked and unchecked, reads back after a reopen. A person's command reads back too. A failure not about money keeps no field. A table of field shapes (none, empty, a bare code, no flag, a flag of text, a number code, an unknown code, an empty code) reads as no refusal.internal/policy:Refusalround trips every code, checked and unchecked, and refuses unknown codes.🤖 Generated with Claude Code
https://claude.ai/code/session_01EZsRxWUwySyG1JAn9T7GpE