{"record":{"id":"14593fef517b4d99","repo":"openai/codex","slug":"all-within-lines-line-count-must-be-a-positive-int","errorCode":null,"errorMessage":"all_within_lines.line_count must be a positive integer","messagePattern":"all_within_lines\\.line_count must be a positive integer","errorType":"validation","errorClass":"MemoriesBackendError","httpStatus":null,"severity":"error","filePath":"codex-rs/ext/memories/src/backend.rs","lineNumber":159,"sourceCode":"    #[error(\"ad-hoc note '{filename}' already exists\")]\n    AdHocNoteAlreadyExists { filename: String },\n    #[error(\"path '{path}' {reason}\")]\n    InvalidPath { path: String, reason: String },\n    #[error(\"cursor '{cursor}' {reason}\")]\n    InvalidCursor { cursor: String, reason: String },\n    #[error(\"path '{path}' was not found\")]\n    NotFound { path: String },\n    #[error(\"line_offset must be a 1-indexed line number\")]\n    InvalidLineOffset,\n    #[error(\"max_lines must be a positive integer\")]\n    InvalidMaxLines,\n    #[error(\"line_offset exceeds file length\")]\n    LineOffsetExceedsFileLength,\n    #[error(\"path '{path}' is not a file\")]\n    NotFile { path: String },\n    #[error(\"queries must not be empty or contain empty strings\")]\n    EmptyQuery,\n    #[error(\"all_within_lines.line_count must be a positive integer\")]\n    InvalidMatchWindow,\n    #[error(\"I/O error while reading memories: {0}\")]\n    Io(#[from] std::io::Error),\n}\n\nimpl MemoriesBackendError {\n    pub fn invalid_filename(filename: impl Into<String>, reason: impl Into<String>) -> Self {\n        Self::InvalidFilename {\n            filename: filename.into(),\n            reason: reason.into(),\n        }\n    }\n\n    pub fn invalid_path(path: impl Into<String>, reason: impl Into<String>) -> Self {\n        Self::InvalidPath {\n            path: path.into(),\n            reason: reason.into(),\n        }","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/openai/codex/blob/339751715c64496cb86246bfb3935f40e309dd3d/codex-rs/ext/memories/src/backend.rs#L141-L177","documentation":"Thrown by the memories search path (codex-rs/ext/memories/src/local/search.rs:29-34) when SearchMemoriesRequest.match_mode is SearchMatchMode::AllWithinLines { line_count: 0 }. The window is the maximum number of lines across which all queries must co-occur, so a zero-width window is rejected before any scanning. The schema (codex-rs/ext/memories/src/backend.rs:105-108) declares schemars range(min = 1) on line_count, matching the backend check.","triggerScenarios":"Constructing AllWithinLines with a usize that defaulted to 0; deserializing JSON {\"type\":\"all_within_lines\",\"line_count\":0}; forwarding a user setting where 0 was supposed to disable the window.","commonSituations":"Default-constructed request structs; serde payloads from older or hand-written clients; porting a config whose 0 meant 'any distance' onto this API.","solutions":["Use line_count >= 1 (a window of 1 behaves like AllOnSameLine).","For 'queries may match anywhere in the file', use SearchMatchMode::Any instead of a zero window.","Validate at your deserialization boundary and coerce 0 to 1 or reject it with a clearer message."],"exampleFix":"// before\nlet mode = SearchMatchMode::AllWithinLines { line_count: window }; // window == 0\n\n// after\nlet mode = match window {\n    0 => SearchMatchMode::Any,\n    1 => SearchMatchMode::AllOnSameLine,\n    n => SearchMatchMode::AllWithinLines { line_count: n },\n};","handlingStrategy":"validation","validationCode":"// Rust - build a match mode that can never be a zero-width window\nfn match_mode(window: usize) -> SearchMatchMode {\n    match window {\n        0 => SearchMatchMode::Any,\n        1 => SearchMatchMode::AllOnSameLine,\n        n => SearchMatchMode::AllWithinLines { line_count: n },\n    }\n}","typeGuard":"// Rust - predicate mirroring the backend check\nfn match_mode_valid(mode: &SearchMatchMode) -> bool {\n    !matches!(mode, SearchMatchMode::AllWithinLines { line_count: 0 })\n}","tryCatchPattern":null,"preventionTips":["line_count must be >= 1; decide what 0 means in your layer and map it before the call.","Keep the schemars range(min = 1) constraint on all_within_lines.line_count in tool schemas.","Validate deserialized payloads from external clients before forwarding them."],"tags":["rust","codex","memories","search","validation","enum-payload"],"backgroundTag":"invalid-argument","analyzedSha":"339751715c64496cb86246bfb3935f40e309dd3d","analyzedAt":"2026-08-25T05:35:09.876Z","schemaVersion":2},"datasetVersion":"2026-08-25T06:17:31.827Z"}