Unified agent logging and fixes queue processor#171
Unified agent logging and fixes queue processor#171michaelerobertsjr wants to merge 6 commits intoTinyAGI:mainfrom
Conversation
- Switch queue, API, channels, daemon, and heartbeat to structured NDJSON logging - Add log rotation (10 MB, 5 archives) and expose merged history via `GET /api/logs` - Wire `LOG_LEVEL` through runtime config and update docs/TinyOffice log references
- Route API logs to a dedicated `api` runtime and make log reads async, filtered, and scalable - Add normalized log levels in shell scripts and preserve severity in structured logs - Ensure queue backlog drains reliably via microtask scheduling and stale-message recovery triggers - Centralize graceful shutdown/error exits for Discord, Telegram, and WhatsApp clients - Add queue DB query/count helpers and document response delivery options for non-delivery channels
Greptile SummaryThis PR fixes the queue processor's continuous-drain behavior and unifies all runtime logging under pino's structured NDJSON format, replacing ad-hoc Key changes:
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant API as API Server<br/>(messages route)
participant QE as queueEvents
participant QP as processQueue()
participant Chain as agentProcessingChain
participant DB as SQLite DB
participant Log as RotatingFileStream<br/>(pino)
Note over QP: Startup
QP->>DB: recoverStaleMessages()
QP->>QP: scheduleQueueDrain() [microtask]
QP->>DB: getPendingMessages()
QP->>Chain: build per-agent promise chain
Note over API,QE: New inbound message
API->>DB: enqueueMessage()
API->>QE: emit message:enqueued
QE->>QP: scheduleQueueDrain() [microtask]
QP->>DB: getPendingMessages()
QP->>Chain: append processMessage() to chain
Chain->>Log: logger.info(structured entry)
Chain->>DB: dbCompleteMessage()
Chain->>QP: scheduleQueueDrain() [microtask — keeps draining]
Note over QP,DB: Stale recovery (every 5 min)
QP->>DB: recoverStaleMessages()
DB-->>QP: count > 0
QP->>QP: scheduleQueueDrain()
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9af11f40d4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (options.messageId) { | ||
| clauses.push('message_id = ?'); | ||
| params.push(options.messageId); | ||
| } | ||
| const searchTerm = normalizeSearchTerm(options.search); |
There was a problem hiding this comment.
Apply conversationId filter to response queue queries
/api/queue/rows accepts a conversationId filter and passes it through, but getQueueResponses never applies that field, so response rows from unrelated conversations are still returned when callers filter by conversation. This makes the queue browser/API output internally inconsistent (messages are filtered, responses are not) and can mislead debugging for team handoff chains that share channels/senders.
Useful? React with 👍 / 👎.
- Store and expose `conversationId` for queued responses across DB, API, and UI types - Include `conversationId` when enqueueing completed conversation responses and allow filtering/searching by it - Prevent extra blank JSON log lines, validate/clamp log limits, and lower noisy queue status logs to debug - Stop auto-shutdown on unhandled rejections in Discord/Telegram/WhatsApp clients
|
Follow-up fixes addressed from review:
Verification performed:
Runtime verification:
|
|
@greptileai please take a look |
- Source heartbeat cron logging from `lib/common.sh` to reuse level parsing and rotation - Replace inline heartbeat JSON logging with `write_structured_log` - Tighten TypeScript logging source types to runtime log files and document safe stream rotation
- Catch ENOENT when reading rotated log files to avoid transient failures - Split Discord message excerpt into debug logs and stop logging pairing codes - Return HTTP 500 from PUT /api/agents/:id when provisioning fails
|
@greptileai please have a look |
- Escape `%`, `_`, and `\` in queue search terms and use `LIKE ... ESCAPE '\\'` - Make log level filtering case-insensitive in API parsing and log matching - Preserve explicit `limit=0` by checking `limit !== undefined` in TinyOffice API params
|
@greptileai please take a final pass |
|
@greptileai are there any additional comments? |
|
The only remaining open item is the P2 conversationId filter issue in |
|
That comment is stale. I already fixed it in this PR. The response-side conversationId issue was addressed by: adding conversation_id to responses in So the queue browser is now consistent for new response rows. The only caveat is historical rows created before the migration still have conversation_id = NULL, so they can’t be retroactively filtered by conversation. |
Summary
Fix the queue processor so pending messages drain continuously instead of advancing only when a new message is enqueued, and document options for handling non-delivery response channels (
heartbeat,web, andcli).Changes
heartbeat,web, andcliType of Change
Testing
npm run build:main./tinyclaw.sh restartagentbacklog began draining after restart (pendingcount decreased andprocessingadvanced)queue.logshowed consecutive heartbeat messages being processed without requiring fresh enqueue eventsChecklist