Skip to content

fix: Bound the two uncapped in-memory buffers in the agent run#516

Merged
gewenyu99 merged 4 commits into
mainfrom
posthog-code/bound-inmemory-buffers
Jun 5, 2026
Merged

fix: Bound the two uncapped in-memory buffers in the agent run#516
gewenyu99 merged 4 commits into
mainfrom
posthog-code/bound-inmemory-buffers

Conversation

@gewenyu99

Copy link
Copy Markdown
Collaborator

What

Two buffers grew without limit during an agent run. This bounds both.

collectedText held every assistant text block for the whole run. Line 1187 re-joined the whole array on every assistant message, so cost was O(n squared). It is replaced by AgentOutputSignals, a class that keeps only lines containing a known signal and drops all other prose. One OUTPUT_SIGNALS table drives both what gets kept and every query, so the filter and the consumers cannot fall out of sync. Consumers now call typed methods like has('API_ERROR_401') instead of scanning raw strings.

$statusMessages appended forever via pushStatus. It now caps at 100 entries with a FIFO that drops the oldest. The status bar renders at most 10, so nothing visible changes.

Why

Both buffers leaked memory for the lifetime of a run. The log file tailing was already safe. These were the real growth points.

Behavior

Detection logic is byte for byte identical. No user facing change.

Tests

  • New tests for AgentOutputSignals: prose is dropped, each marker is detected, API error lines and the remark are extracted.
  • New test for the status FIFO: 250 pushes leave 100 entries, newest kept, oldest dropped.
  • Updated the 3 createStopHook tests to the new type. Assertions unchanged.
  • pnpm build && pnpm test && pnpm lint all pass. 766 tests green.

collectedText grew for the whole run and was re-joined on every assistant
message. Replace it with AgentOutputSignals, which keeps only signal-bearing
lines. One OUTPUT_SIGNALS table drives both retention and every query, so the
filter and consumers cannot drift.

$statusMessages appended forever. Cap it at 100 with a FIFO that drops the
oldest entry. The status bar shows at most 10, so nothing visible changes.

Generated-By: PostHog Code
Task-Id: dc10b8c8-7d3c-494e-a7e2-95a9ca412017
@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown

🧙 Wizard CI

Run the Wizard CI and test your changes against wizard-workbench example apps by replying with a GitHub comment using one of the following commands:

Test all apps:

  • /wizard-ci all

Test all apps in a directory:

  • /wizard-ci basic-integration
  • /wizard-ci error-tracking-upload-source-maps
  • /wizard-ci misc
  • /wizard-ci revenue

Test an individual app:

  • /wizard-ci basic-integration/android
  • /wizard-ci basic-integration/angular
  • /wizard-ci basic-integration/astro
Show more apps
  • /wizard-ci basic-integration/django
  • /wizard-ci basic-integration/fastapi
  • /wizard-ci basic-integration/flask
  • /wizard-ci basic-integration/javascript-node
  • /wizard-ci basic-integration/javascript-web
  • /wizard-ci basic-integration/laravel
  • /wizard-ci basic-integration/next-js
  • /wizard-ci basic-integration/nuxt
  • /wizard-ci basic-integration/python
  • /wizard-ci basic-integration/rails
  • /wizard-ci basic-integration/react-native
  • /wizard-ci basic-integration/react-router
  • /wizard-ci basic-integration/sveltekit
  • /wizard-ci basic-integration/swift
  • /wizard-ci basic-integration/tanstack-router
  • /wizard-ci basic-integration/tanstack-start
  • /wizard-ci basic-integration/vue
  • /wizard-ci error-tracking-upload-source-maps/android
  • /wizard-ci error-tracking-upload-source-maps/flutter
  • /wizard-ci error-tracking-upload-source-maps/ios
  • /wizard-ci error-tracking-upload-source-maps/next
  • /wizard-ci error-tracking-upload-source-maps/next-no-posthog
  • /wizard-ci error-tracking-upload-source-maps/node-raw
  • /wizard-ci error-tracking-upload-source-maps/node-rollup
  • /wizard-ci error-tracking-upload-source-maps/node-rollup-typescript-plugin
  • /wizard-ci error-tracking-upload-source-maps/node-webpack
  • /wizard-ci error-tracking-upload-source-maps/nuxt-3-6
  • /wizard-ci error-tracking-upload-source-maps/nuxt-4-3
  • /wizard-ci error-tracking-upload-source-maps/react-native
  • /wizard-ci error-tracking-upload-source-maps/react-vite
  • /wizard-ci error-tracking-upload-source-maps/rust
  • /wizard-ci misc/quack-quack
  • /wizard-ci revenue/stripe

Results will be posted here when complete.

@gewenyu99 gewenyu99 changed the title Bound the two uncapped in-memory buffers in the agent run fix: Bound the two uncapped in-memory buffers in the agent run Jun 5, 2026
Move the output parser out of the 1718-line agent-interface file. New leaf
modules signals.ts (the marker/error vocabulary) and output-signals.ts (the
AgentOutputSignals parser) break the import cycle. agent-interface re-exports
the moved symbols so existing importers are untouched.

Drop the redundant API_ERROR_401/429 table rows. API_ERROR is the one needle
and the status is a parameter: hasApiError() and hasApiErrorStatus(code).

Tie the status FIFO cap to the render window. New constants.ts holds
COLLAPSED_COUNT/EXPANDED_COUNT; the store caps at EXPANDED_COUNT instead of an
arbitrary 100, since the status bar is the only consumer and shows at most that
many lines.

Generated-By: PostHog Code
Task-Id: dc10b8c8-7d3c-494e-a7e2-95a9ca412017
@gewenyu99 gewenyu99 requested a review from a team June 5, 2026 15:37

@edwinyjlim edwinyjlim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@gewenyu99

Copy link
Copy Markdown
Collaborator Author

K I'm gonna hold this off for another release. I need to give this some good testing. It should be fine but just in case i missed smthing

@gewenyu99

Copy link
Copy Markdown
Collaborator Author

/wizard-ci basic-integration/next-js

@wizard-ci-bot

wizard-ci-bot Bot commented Jun 5, 2026

Copy link
Copy Markdown

🧙 Wizard CI Results

Trigger ID: bd04cbb
Workflow: View run

App Confidence PR YARA
basic-integration/next-js/15-app-router-saas N/A Failed (logs)
basic-integration/next-js/15-app-router-todo N/A Failed (logs)
basic-integration/next-js/15-pages-router-saas N/A Failed (logs)
basic-integration/next-js/15-pages-router-todo N/A Failed (logs)

Configuration

Setting Value
Wizard ref posthog-code/bound-inmemory-buffers
Context Mill ref main
PostHog ref master

Search for trigger ID bd04cbb in wizard-workbench PRs.

@gewenyu99

Copy link
Copy Markdown
Collaborator Author

/wizard-ci basic-integration/next-js

@gewenyu99

Copy link
Copy Markdown
Collaborator Author

This is working locally, gonna fix ci

@gewenyu99

Copy link
Copy Markdown
Collaborator Author

@gewenyu99

Copy link
Copy Markdown
Collaborator Author

Tested in CI and locally, is working, CI slightly broken by anthropic lol

@gewenyu99 gewenyu99 merged commit 4f59877 into main Jun 5, 2026
17 checks passed
@gewenyu99 gewenyu99 deleted the posthog-code/bound-inmemory-buffers branch June 5, 2026 21:12
sarahxsanders added a commit that referenced this pull request Jun 12, 2026
…n deletion

Conflict resolution: main's #516 introduced the bounded AgentOutputSignals
parser, including a signals-based checkYaraViolation. This branch deletes
output-text YARA sniffing entirely (yaraViolationReason from onTerminate is
the single source of truth), so the resolution keeps the deletion and adopts
signals for the API-error paths. Also removes the now-dead hasYaraViolation
and YARA needles from output-signals, with a comment explaining why YARA is
deliberately not an output signal.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

2 participants