{"record":{"id":"f30bc517c7a68903","repo":"Hmbown/CodeWhale","slug":"session-goal-is-file-len-bytes-maximum-is-m","errorCode":null,"errorMessage":"Session goal {} is {file_len} bytes; maximum is {MAX_SESSION_GOAL_FILE_BYTES}","messagePattern":"Session goal (.+?) is (.+?) bytes; maximum is (.+?)","errorType":"validation","errorClass":"InvalidData","httpStatus":null,"severity":"error","filePath":"crates/tui/src/session_manager.rs","lineNumber":1740,"sourceCode":"        self.ensure_session_goals_dir()?;\n        Self::checked_existing_session_goal_file(&path)?;\n        let content = serde_json::to_string_pretty(goal)\n            .map_err(|error| io::Error::new(io::ErrorKind::InvalidData, error))?;\n        write_atomic(&path, content.as_bytes())\n    }\n\n    /// Load a saved session's durable goal, rejecting malformed or future\n    /// records instead of silently starting a different objective.\n    pub fn load_session_goal(&self, session_id: &str) -> std::io::Result<Option<SessionGoalState>> {\n        let path = self.validated_session_goal_path(session_id)?;\n        if self.checked_existing_session_goals_dir()?.is_none()\n            || !Self::checked_existing_session_goal_file(&path)?\n        {\n            return Ok(None);\n        }\n        let file_len = fs::metadata(&path)?.len();\n        if file_len > MAX_SESSION_GOAL_FILE_BYTES {\n            return Err(io::Error::new(\n                io::ErrorKind::InvalidData,\n                format!(\n                    \"Session goal {} is {file_len} bytes; maximum is {MAX_SESSION_GOAL_FILE_BYTES}\",\n                    path.display()\n                ),\n            ));\n        }\n        let raw = fs::read_to_string(path)?;\n        let goal: SessionGoalState = serde_json::from_str(&raw)\n            .map_err(|error| io::Error::new(io::ErrorKind::InvalidData, error))?;\n        goal.validate()?;\n        Ok(Some(goal))\n    }\n\n    fn hydrate_recovered_runtime_binding(&self, session: &mut SavedSession) -> std::io::Result<()> {\n        // Compare under the session write lock. A stale process may neither\n        // resurrect a missing binding nor replace a different recovered owner.\n        if let Some(incoming) = session.metadata.runtime_store.as_ref()","sourceCodeStart":1722,"sourceCodeEnd":1758,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/crates/tui/src/session_manager.rs#L1722-L1758","documentation":"Session goal files are capped at MAX_SESSION_GOAL_FILE_BYTES (64 KiB). If the goal file on disk exceeds that bound, loading is aborted with InvalidData naming the path, its actual size, and the maximum, preventing unbounded file reads from entering session state. A prior integrity check (checked_existing_session_goal_file) must also pass before this size gate runs.","triggerScenarios":"Reading an existing session goal file whose fs::metadata length is greater than 64 KiB — an externally edited or oversized goal file.","commonSituations":"Pasting a very large document into the goal file by hand; scripts appending to the goal file; wrong file placed at the goal path (e.g. a log or dataset).","solutions":["Trim the goal file to under 64 KiB (keep a concise goal summary, move details elsewhere)","Delete or rename the oversized file and write a fresh, short goal statement","Point the session at a different goal file within the size limit"],"exampleFix":"# before\nwc -c session-goal.md  # 200000 bytes\n# after\nhead -c 65000 session-goal.md > tmp && mv tmp session-goal.md","handlingStrategy":"validation","validationCode":"fn goal_file_ok(path: &Path) -> bool {\n    std::fs::metadata(path).map(|m| m.len() <= 64*1024).unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"match manager.load_session(&sid) {\n    Err(e) if e.kind() == io::ErrorKind::InvalidData\n        && e.to_string().contains(\"maximum is 65536\") => {\n        // prompt user to shrink the goal file, then retry\n    }\n    other => other,\n}","preventionTips":["Keep goal files concise; store large docs elsewhere and reference them","Enforce the 64 KiB limit in any tooling that writes goal files","Check file size after external edits to goal files"],"tags":["rust","filesystem","size-limit","session"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}