openai/codex · error · MemoriesBackendError
line_offset must be a 1-indexed line number
Error message
line_offset must be a 1-indexed line number
What it means
Thrown by the memories read path (codex-rs/ext/memories/src/local/read.rs:16-18) when ReadMemoryRequest.line_offset is 0. Memory files are addressed with 1-indexed lines, where line 1 is the first line, so 0 is never a valid start and the request is rejected before any filesystem access. The tool-level schema (codex-rs/ext/memories/src/tools/read.rs:29) already declares schemars range(min = 1) and defaults to 1, so this variant is reached mainly by code calling the MemoriesBackend trait directly.
Source
Thrown at codex-rs/ext/memories/src/backend.rs:149
pub content: String,
pub matched_queries: Vec<String>,
}
#[derive(Debug, thiserror::Error)]
pub enum MemoriesBackendError {
#[error("filename '{filename}' {reason}")]
InvalidFilename { filename: String, reason: String },
#[error("ad-hoc note must not be empty")]
EmptyAdHocNote,
#[error("ad-hoc note '{filename}' already exists")]
AdHocNoteAlreadyExists { filename: String },
#[error("path '{path}' {reason}")]
InvalidPath { path: String, reason: String },
#[error("cursor '{cursor}' {reason}")]
InvalidCursor { cursor: String, reason: String },
#[error("path '{path}' was not found")]
NotFound { path: String },
#[error("line_offset must be a 1-indexed line number")]
InvalidLineOffset,
#[error("max_lines must be a positive integer")]
InvalidMaxLines,
#[error("line_offset exceeds file length")]
LineOffsetExceedsFileLength,
#[error("path '{path}' is not a file")]
NotFile { path: String },
#[error("queries must not be empty or contain empty strings")]
EmptyQuery,
#[error("all_within_lines.line_count must be a positive integer")]
InvalidMatchWindow,
#[error("I/O error while reading memories: {0}")]
Io(#[from] std::io::Error),
}
impl MemoriesBackendError {
pub fn invalid_filename(filename: impl Into<String>, reason: impl Into<String>) -> Self {
Self::InvalidFilename {View on GitHub (pinned to 339751715c)
Solutions
- Pass line_offset >= 1 (the first line of the file is 1).
- Translate 0-based indexes with line_offset = index + 1.
- Default the value to 1 at your boundary, mirroring tools/read.rs (unwrap_or(1)).
- Keep a schemars range(min = 1) constraint on any JSON argument so invalid values fail schema validation with a clearer message.
Example fix
// before
let resp = backend.read(ReadMemoryRequest {
path,
line_offset: cursor_index, // 0-based index from the editor
max_lines: Some(200),
max_tokens: 0,
}).await?;
// after
let resp = backend.read(ReadMemoryRequest {
path,
line_offset: cursor_index + 1, // convert 0-based index to 1-indexed line
max_lines: Some(200),
max_tokens: 0,
}).await?; Defensive patterns
Strategy: validation
Validate before calling
// Rust - validate before calling MemoriesBackend::read
fn valid_line_offset(offset: usize) -> bool {
offset >= 1 // lines are 1-indexed
}
// convert a 0-based index safely at the boundary
let line_offset = raw_index.saturating_add(1).max(1); Try / catch
match backend.read(request).await {
Ok(response) => { /* ... */ }
Err(MemoriesBackendError::InvalidLineOffset) => {
// caller bug: 0 was passed; correct to 1 and retry once
}
Err(other) => return Err(other),
} Prevention
- Treat memory line numbers as 1-indexed end to end; convert 0-based indexes with +1 at the boundary.
- Default line_offset to 1 the way tools/read.rs does.
- Keep the schemars range(min = 1) constraint on JSON args so bad values are rejected at schema validation.
When it happens
Trigger: Calling backend.read with ReadMemoryRequest { line_offset: 0, .. }; a usize field that defaulted to 0; feeding a 0-based index from an editor, cursor, or grep-style output straight into line_offset; a custom ToolExecutor that parses args without the ReadArgs schema constraint.
Common situations: Porting editor or grep-style code that numbers lines from 0; tests constructing ReadMemoryRequest by hand; a UI passing its 0-based selection start; refactors that renamed an index field into line_offset without adding 1.
Related errors
- filename '{filename}' {reason}
- ad-hoc note must not be empty
- path '{path}' {reason}
- max_lines must be a positive integer
- path '{path}' is not a file
AI-assisted analysis of openai/codex@339751715c (2026-08-25).
Data as JSON: /api/errors/0d893a9270195df0.
Report an issue: GitHub.