monitor_agent: incremental metric collection with windowing and persisted state#56
Merged
seanwevans merged 2 commits intoApr 4, 2026
Conversation
seanwevans
deleted the
codex/refactor-metric-query-strategy-in-monitor_agent
branch
April 4, 2026 21:02
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Description
--since-hoursand--since-daysand acompute_since_timestamphelper to convert them into acompleted_at >= ...filter used in queries.monitor_statetable and helper functionsensure_monitor_state_table,load_monitor_state, andsave_monitor_stateto recordlast_completed_atandlast_command_idso the agent can query only rows newer than the watermark.collect_metricsto acceptsince_timestamp,last_completed_at, andlast_command_idand to build incremental WHERE predicates (completed_at >= %sor(completed_at > %s OR (completed_at = %s AND id > %s))) while preserving streaming server-side cursor behavior and stable orderingORDER BY day, user_id.get_watermarkto compute the latest(completed_at, id)after each run and updated CSV mode to append only newly computed intervals because each loop queries only unprocessed rows.sql/init_schema.sqlto createmonitor_stateand to add an indexcommands_status_completed_at_idx ON commands (status, completed_at, id)to support the incremental filter efficiently.tests/test_monitor_agent.pyto verify streaming behavior, SQL predicate and bound parameters for incremental mode, stable ordering clause, and window-argument conflict handling.Testing
pytest -q tests/test_monitor_agent.pywhich reported4 passed.Codex Task