Refuse an answer that will not fit, by name
A reply larger than one send could carry was handed to the hub anyway. The hub
refused it, the loop printed the error and served past, and the client waited
for an answer nothing would ever send. A real-sized read was lost in silence,
which is the one thing this surface promises not to do: a refusal is typed, and
that has to hold at every size.
`within_window` now encodes the reply and measures it against the window this
module configures, before a send it can already see will fail. Over the limit,
the answer becomes `MindRefusal::ResponseTooLarge { bytes, limit }` on the
response schema, reaching the client exactly as every other refusal does, with
the encoded size and the limit so a caller can narrow its own request. Nothing
is truncated, paginated or retried.
The arithmetic, measured rather than estimated. One `PipelineCutSpec` with every
list at the leaf's bound -- 256 file changes, 64 deletes, keeps, adds, builds,
tests, negative checks and operator checks, a full authority map and structural
delta -- is about 980,000 bytes of field content. As a `View` response, base64
in the operation envelope and MessagePack around that, it encodes to 1,315,551
bytes. The window is `MAX_PENDING_RELIABLE_PACKETS` (1024) times
`MAX_FRAGMENT_BYTES` (1200), so 1,228,800. A single document at the leaf's own
bounds therefore does not fit, by 86,751 bytes.
The window's values are unchanged by ruling: what a list read should return is
an open question, and raising the window would bake multi-megabyte answers in
as ordinary traffic before that question is answered. The module documentation
states 1,228,800 as the current bound rather than as a design target.
The test admits two cut specs into a real mind: one at 256 file changes and one
narrowed to 180, whose view encodes to 1,189,495 bytes. Over one loopback
session the query, the wide view and the open items are each refused by name,
and the narrow view is then delivered whole. Both halves are load-bearing: the
delivered answer sits 39,305 bytes under the limit, so `D22` and `D22L`, which
shrink the configured window, break it.
`D20` removes the gate, `D20L` measures against a larger number than the hub
carries, `D20L2` and `D20L3` collapse the two fields the refusal reports, `D21`
sends it as a failure envelope instead, and `D22`, `D22L` and `D22L2` shrink
each half of the window the gate trusts. All eight die. The whole suite, 51
entries and M0, is green.
Two reads pipelined on one session are still not both answered, and the module
documentation says so: the window is per session and counts what is
unacknowledged, so a second large reply sent before the first is acknowledged
fails to send even though each passes the gate alone. The gate measures one
answer against the window, not against what the session still has room for.
That is not fixed here.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
25a841dc6d
commit
9bbe746719
5 changed files with 503 additions and 32 deletions
|
|
@ -1,4 +1,4 @@
|
|||
# Cut 10 mutations, D1-D19: the CultNet surface's rules. Each rule has a
|
||||
# Cut 10 mutations, D1-D22: the CultNet surface's rules. Each rule has a
|
||||
# revert, `Dn`, which removes the rule, and a loosening, `DnL`, which weakens
|
||||
# it rather than removing it, because a plain revert is the easy target. Every
|
||||
# entry names the test that must fail while it is applied. Run through
|
||||
|
|
@ -156,13 +156,9 @@
|
|||
Rule = 'A refusal is data in the response, never a transport failure the client must parse out of a failure envelope.'
|
||||
Test = 'serve::tests::a_malformed_envelope_is_answered_with_a_failure_and_touches_no_mind'
|
||||
File = 'crates/huginn-daemon/src/serve.rs'
|
||||
Old = @'
|
||||
let response = daemon.handle(request, now);
|
||||
match encode_response(&message_id, operation, &response, &runtime_id) {
|
||||
'@
|
||||
Old = ' let reply = encode_or_fail(&message_id, operation, &response, &runtime_id);'
|
||||
New = @'
|
||||
let response = daemon.handle(request, now);
|
||||
if let huginn_mind::wire::HuginnMindResponse::Refused(refusal) = &response {
|
||||
if let HuginnMindResponse::Refused(refusal) = &response {
|
||||
return encode_failure(
|
||||
&message_id,
|
||||
operation,
|
||||
|
|
@ -173,7 +169,7 @@
|
|||
&runtime_id,
|
||||
);
|
||||
}
|
||||
match encode_response(&message_id, operation, &response, &runtime_id) {
|
||||
let reply = encode_or_fail(&message_id, operation, &response, &runtime_id);
|
||||
'@
|
||||
}
|
||||
@{
|
||||
|
|
@ -237,6 +233,86 @@
|
|||
Old = ' if operation != request.operation() {'
|
||||
New = ' if operation.len() != request.operation().len() {'
|
||||
}
|
||||
@{
|
||||
Id = 'D20'
|
||||
Rule = 'An answer larger than one send can carry is refused by name, not handed to a send that fails silently.'
|
||||
Test = 'serve::tests::an_answer_too_large_for_one_send_is_a_typed_refusal_that_reaches_the_client'
|
||||
File = 'crates/huginn-daemon/src/serve.rs'
|
||||
Old = ' if encoded <= MAX_RESPONSE_BYTES {'
|
||||
New = ' if true {'
|
||||
}
|
||||
@{
|
||||
Id = 'D20L'
|
||||
Rule = 'It is measured against the window the hub was configured with, not against a number chosen to admit it.'
|
||||
Test = 'serve::tests::an_answer_too_large_for_one_send_is_a_typed_refusal_that_reaches_the_client'
|
||||
File = 'crates/huginn-daemon/src/serve.rs'
|
||||
Old = ' if encoded <= MAX_RESPONSE_BYTES {'
|
||||
New = ' if encoded <= MAX_RESPONSE_BYTES * 4 {'
|
||||
}
|
||||
@{
|
||||
Id = 'D20L2'
|
||||
Rule = 'The refusal carries the answer''s own encoded size, so a caller can tell how far it overshot.'
|
||||
Test = 'serve::tests::an_answer_too_large_for_one_send_is_a_typed_refusal_that_reaches_the_client'
|
||||
File = 'crates/huginn-daemon/src/serve.rs'
|
||||
Old = ' bytes: encoded,'
|
||||
New = ' bytes: MAX_RESPONSE_BYTES,'
|
||||
}
|
||||
@{
|
||||
Id = 'D20L3'
|
||||
Rule = 'And it carries the limit itself, not the size again, so the two are not one number twice.'
|
||||
Test = 'serve::tests::an_answer_too_large_for_one_send_is_a_typed_refusal_that_reaches_the_client'
|
||||
File = 'crates/huginn-daemon/src/serve.rs'
|
||||
Old = ' limit: MAX_RESPONSE_BYTES,'
|
||||
New = ' limit: encoded,'
|
||||
}
|
||||
@{
|
||||
Id = 'D21'
|
||||
Rule = 'The refusal rides the response schema like every other refusal, not a failure envelope the client must parse apart.'
|
||||
Test = 'serve::tests::an_answer_too_large_for_one_send_is_a_typed_refusal_that_reaches_the_client'
|
||||
File = 'crates/huginn-daemon/src/serve.rs'
|
||||
Old = @'
|
||||
let refusal = HuginnMindResponse::Refused(MindRefusal::ResponseTooLarge {
|
||||
bytes: encoded,
|
||||
limit: MAX_RESPONSE_BYTES,
|
||||
});
|
||||
encode_or_fail(message_id, operation, &refusal, runtime_id)
|
||||
'@
|
||||
New = @'
|
||||
encode_failure(
|
||||
message_id,
|
||||
operation,
|
||||
&crate::envelope::OperationFailure {
|
||||
code: "response-too-large".into(),
|
||||
message: format!("{encoded} bytes against a {MAX_RESPONSE_BYTES} limit"),
|
||||
},
|
||||
runtime_id,
|
||||
)
|
||||
'@
|
||||
}
|
||||
@{
|
||||
Id = 'D22'
|
||||
Rule = 'The window the gate measures against is the window the hub carries: a smaller one sends nothing and says nothing.'
|
||||
Test = 'serve::tests::an_answer_too_large_for_one_send_is_a_typed_refusal_that_reaches_the_client'
|
||||
File = 'crates/huginn-daemon/src/serve.rs'
|
||||
Old = ' options.max_pending_reliable_packets = Some(MAX_PENDING_RELIABLE_PACKETS);'
|
||||
New = ' options.max_pending_reliable_packets = Some(MAX_PENDING_RELIABLE_PACKETS / 2);'
|
||||
}
|
||||
@{
|
||||
Id = 'D22L'
|
||||
Rule = 'Not merely close to it: a window short by a few dozen packets still drops an answer the gate admitted.'
|
||||
Test = 'serve::tests::an_answer_too_large_for_one_send_is_a_typed_refusal_that_reaches_the_client'
|
||||
File = 'crates/huginn-daemon/src/serve.rs'
|
||||
Old = ' options.max_pending_reliable_packets = Some(MAX_PENDING_RELIABLE_PACKETS);'
|
||||
New = ' options.max_pending_reliable_packets = Some(MAX_PENDING_RELIABLE_PACKETS - 64);'
|
||||
}
|
||||
@{
|
||||
Id = 'D22L2'
|
||||
Rule = 'The fragment size is the window''s other half: a smaller one carries fewer bytes in the same packet count.'
|
||||
Test = 'serve::tests::an_answer_too_large_for_one_send_is_a_typed_refusal_that_reaches_the_client'
|
||||
File = 'crates/huginn-daemon/src/serve.rs'
|
||||
Old = ' options.max_fragment_bytes = Some(MAX_FRAGMENT_BYTES);'
|
||||
New = ' options.max_fragment_bytes = Some(MAX_FRAGMENT_BYTES - 64);'
|
||||
}
|
||||
@{
|
||||
Id = 'D17'
|
||||
Rule = 'A refusal `view` raised crosses the dispatch as itself, not rewrapped as unavailable.'
|
||||
|
|
|
|||
Loading…
Reference in a new issue