CoAgent8
    Preparing search index...

    Function tornTailOffset

    • Finds a torn final record left by a crash (AUDIT-001-A16-A18).

      Parameters

      • logFile: string

        The .jsonl log, read under the history lock.

      • size: number

        Its current size in bytes.

      Returns Promise<number | null>

      The byte length to truncate the log to, or null when its last record is whole or it holds only blank lines.

      Reads backward in 8 KiB blocks (TAIL_BLOCK_BYTES) until it holds the last non-blank line whole, so it reads about one record instead of the whole log (up to SESSION_LIMIT), which load() has read already. Records have no size limit: the scan continues to the file start if needed. Lines are split on \n bytes and decoded whole, so UTF-8 sequences never break. Semantics match the former whole-file scan: trailing blank lines are ignored, a final record that parses is kept (with or without its newline), and an unparsable one is removed together with everything after it.