Skip to content

Cache config reads on streaming and rendering hot paths - #786

Open
kvandre12-commits wants to merge 5 commits into
mpfaffenberger:mainfrom
kvandre12-commits:fix/config-hot-path-cache
Open

Cache config reads on streaming and rendering hot paths#786
kvandre12-commits wants to merge 5 commits into
mpfaffenberger:mainfrom
kvandre12-commits:fix/config-hot-path-cache

Conversation

@kvandre12-commits

Copy link
Copy Markdown
Contributor

Summary

Fixes #784.

code_puppy/config.py was re-reading and INI-parsing puppy.cfg on repeated
configuration lookups. Those getters are used from streaming and rendering
hot paths, turning ordinary display decisions into repeated filesystem I/O
and config parsing.

This PR addresses the issue at the three affected boundaries:

  • config.py — caches the parsed ConfigParser using the config file's
    (st_mtime_ns, st_size) signature. In-process mutations explicitly
    invalidate the cache, while external file changes are still detected.

  • agents/event_stream_handler.py — snapshots the output level and
    suppression decisions once when handling a stream instead of resolving
    them repeatedly as streamed deltas arrive.

  • messaging/rich_renderer.py — resolves output_level once for a
    message dispatch and reuses that value through collapse, suppression,
    and subagent rendering decisions.

The result keeps the existing configuration semantics while removing repeated
disk reads and INI parsing from high-frequency streaming and rendering paths.

@kvandre12-commits

Copy link
Copy Markdown
Contributor Author

Updated this branch to current main and revalidated the config-cache behavior against the intervening configuration changes.

During validation, the external-edit regression test was found to be writing literal \\n characters rather than valid INI newlines. I corrected the fixture and kept the production parser behavior unchanged.

Validation on Python 3.14:

  • 296 passed across tests/test_config_full_coverage.py, tests/agents/test_event_stream_handler.py, and tests/messaging/test_rich_renderer.py
  • Ruff E4,E7,E9,F,I checks passed for all changed files
  • Ruff formatting check passed
  • git diff --check passed

The branch now includes current upstream main without a history rewrite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Config is read + INI-parsed uncached on hot paths (per streamed delta and per output line)

1 participant