fix(api): graceful 400 for non-table [memory]/[proactive_memory] in PATCH /api/memory/config#6301
Merged
Merged
Conversation
houko
force-pushed
the
fix/memory-config-patch-panic
branch
2 times, most recently
from
June 24, 2026 01:09
77ec986 to
7b46ce7
Compare
houko
enabled auto-merge (squash)
June 24, 2026 01:22
houko
force-pushed
the
fix/memory-config-patch-panic
branch
from
June 24, 2026 01:26
7b46ce7 to
cb5d93d
Compare
…ATCH /api/memory/config
memory_config_patch did root.entry("memory").or_insert_with(..).as_table_mut().unwrap() (and the same for proactive_memory).
entry() only inserts the default table when the key is absent, so a pre-existing scalar at that key (e.g. an operator hand-edited `memory = 5`) made as_table_mut() return None and the unwrap panicked into a 500.
Both sites now return a clear 400 instead of panicking. Adds integration tests seeding a non-table [memory] and a non-table [proactive_memory] entry.
houko
force-pushed
the
fix/memory-config-patch-panic
branch
from
June 24, 2026 03:16
cb5d93d to
5c5b25b
Compare
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.
Summary
memory_config_patch(PATCH /api/memory/config) read config.toml, parsed it as atoml::Value, then did:and the same for
proactive_memory.entry(..).or_insert_withonly inserts the default table when the key is absent. If config.toml already holds a scalar at that key — e.g. an operator hand-editedmemory = 5orproactive_memory = "x"—entry()returns the existing non-table value,as_table_mut()returnsNone, and theunwrap()panics.axum isolates the panic to the request task (the daemon survives and returns 500), so the blast radius is one failed admin PATCH, and the trigger requires a pre-existing malformed config on disk (operator-controlled, not attacker-controlled) — hence low severity. But the operator gets an opaque 500 + a panic in the logs instead of a useful message.
The top-level
table.as_table_mut().unwrap()(the document root) is left as-is: a valid TOML document root is always a table.Fix
Both
as_table_mut()sites now return a clear400 Bad Request(config.toml has a non-table [memory] entry; expected a table) instead of panicking.Tests
Adds two
#[tokio::test]cases tomemory_routes_integration.rs:patch_memory_config_with_non_table_memory_entry_is_graceful— seedsmemory = 5, asserts 400 + error body.patch_memory_config_with_non_table_proactive_memory_entry_is_graceful— seedsproactive_memory = "oops", asserts 400 + error body.Verification
This host has no native Rust toolchain and no working container runtime, so local
cargoverification was not possible — CI is the gate. Reviewers / CI:cargo test -p librefang-api.Scope
One of several independent findings from a repo audit; filed as its own PR per the one-PR-one-domain policy.