feat(logging): cursor pagination and filtering for task_logs

task_logs could only read the newest N entries with no way to walk the
rest, so a task's log beyond the page cap was unreachable and the agent
had no honest way to say what was missing. Add logging.Page -- a
byte-offset cursor over the tail-most 8 MiB scan window -- plus
Query.Since/Until time bounds, and wire the gateway's task_logs tool to
expose level/since/until/after_id with cursor and more_available in the
result.

The reader now reads the scan window into a single in-memory buffer and
walks it by exact slice offsets. Offsets into a contiguous buffer are
trivially correct, which an incremental reader over the file is not:
bufio.Reader buffers ahead, so its underlying file position runs one
buffer past its logical position and cannot be used as a cursor. The
same rewrite removes f.Read in favour of f.ReadAt (full-or-error), since
a silent short read would drop the newest entries and still report
success.

The scan window is a documented hard ceiling: for a log over 8 MiB the
oldest bytes are unreachable by any cursor -- that is what Truncated
reports, and send_file remains the path for a complete archive. The
tool description teaches the model the difference between more_available
(more this call did not return) and truncated (older entries the scan
cap hides).

Closes archie-core-vq92 (#625).
This commit is contained in:
sam committed 2026-08-26 02:02:36 +10:00
1 parent 79d810ad13
commit 48133e68fe
7 files changed
+1247 -85

No files matched your search

+12 -7
View File
@@ -576,17 +576,20 @@ func (a chatTaskLogReaderAdapter) ReadChatTaskLogs(
return gateway.ChatTaskLogResult{Attempt: attempt, Entries: []gateway.ChatTaskLogEntry{}}, nil
}
result, err := logging.Tail(path, logging.Query{
page, err := logging.Page(path, logging.Query{
Component: q.Component,
Contains: q.Contains,
Levels: q.Levels,
Since: q.Since,
Until: q.Until,
Limit: q.Limit,
})
}, q.AfterID)
if err != nil {
return gateway.ChatTaskLogResult{}, err
}
entries := make([]gateway.ChatTaskLogEntry, len(result.Entries))
for i, e := range result.Entries {
entries := make([]gateway.ChatTaskLogEntry, len(page.Entries))
for i, e := range page.Entries {
entries[i] = gateway.ChatTaskLogEntry{
Time: e.Time,
Level: e.Level,
@@ -595,9 +598,11 @@ func (a chatTaskLogReaderAdapter) ReadChatTaskLogs(
}
}
return gateway.ChatTaskLogResult{
Entries: entries,
Attempt: attempt,
Truncated: result.Truncated,
Entries: entries,
Attempt: attempt,
Truncated: page.Truncated,
Cursor: page.Cursor,
MoreAvailable: page.MoreAvailable,
}, nil
}