-
Notifications
You must be signed in to change notification settings - Fork 581
perf(tools): parallelize read-only tool calls and consolidate three loops #490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TatsuKo-Tsukimi
wants to merge
5
commits into
dataelement:main
Choose a base branch
from
TatsuKo-Tsukimi:perf/parallel-tool-execution
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
114be24
fix(history): atomic pair-aware truncation for tool_call blocks
TatsuKo-Tsukimi 2a0040f
feat(agent): token-aware history truncation alongside message cap
TatsuKo-Tsukimi b01c0f1
feat(tools): truncate large tool results with workspace spill
TatsuKo-Tsukimi 3ebdaab
perf(tools): parallelize read-only tool calls and consolidate three l…
TatsuKo-Tsukimi 1979c02
fix(tools): bypass truncation for read_file/read_document outputs
TatsuKo-Tsukimi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| """add agents.context_window_tokens for token-aware history truncation | ||
|
|
||
| Revision ID: add_context_window_tokens | ||
| Revises: rm_agent_credential_secrets | ||
| Create Date: 2026-04-27 | ||
| """ | ||
|
|
||
| from typing import Sequence, Union | ||
|
|
||
| from alembic import op | ||
|
|
||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision: str = "add_context_window_tokens" | ||
| down_revision: Union[str, Sequence[str], None] = "rm_agent_credential_secrets" | ||
| branch_labels: Union[str, Sequence[str], None] = None | ||
| depends_on: Union[str, Sequence[str], None] = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| """Add context_window_tokens with a DDL default of 50000. | ||
|
|
||
| The four-step pattern is required because earlier in the migration chain, | ||
| ``alembic/versions/0000_initial_schema.py`` calls | ||
| ``Base.metadata.create_all(checkfirst=True)``, which creates ``agents`` | ||
| from the *current* model state — including any new columns. SQLAlchemy's | ||
| Python-side ``default=`` does NOT translate to a DDL ``DEFAULT`` clause, | ||
| so the column ends up ``NOT NULL`` with no default, and a naive | ||
| ``ADD COLUMN IF NOT EXISTS ... DEFAULT 50000`` short-circuits and never | ||
| sets the default. | ||
|
|
||
| This four-step approach is idempotent regardless of pre-existing state: | ||
| - column missing → created (nullable, no default initially) | ||
| - column present without default → default set | ||
| - any rows with NULL → backfilled to 50000 | ||
| - column made NOT NULL | ||
|
|
||
| Re-runnable: ALTER SET DEFAULT to the same value is a no-op; UPDATE | ||
| affecting 0 rows is a no-op; ALTER SET NOT NULL on an already-NOT-NULL | ||
| column is a no-op. | ||
| """ | ||
| # 1. Add the column if missing — do NOT specify NOT NULL or DEFAULT here, | ||
| # so existing rows (if any from create_all) aren't blocked. | ||
| op.execute( | ||
| "ALTER TABLE agents ADD COLUMN IF NOT EXISTS context_window_tokens INTEGER" | ||
| ) | ||
| # 2. Ensure the DDL default is set so future inserts that omit this | ||
| # column (raw SQL, restored backups, manual migrations) get 50000. | ||
| op.execute( | ||
| "ALTER TABLE agents ALTER COLUMN context_window_tokens SET DEFAULT 50000" | ||
| ) | ||
| # 3. Backfill any rows that were created before the default landed. | ||
| op.execute( | ||
| "UPDATE agents SET context_window_tokens = 50000 " | ||
| "WHERE context_window_tokens IS NULL" | ||
| ) | ||
| # 4. Now safe to enforce NOT NULL. | ||
| op.execute( | ||
| "ALTER TABLE agents ALTER COLUMN context_window_tokens SET NOT NULL" | ||
| ) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| # Downgrade omitted — dropping the column would lose per-tenant tuning. | ||
| pass |
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
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
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The heartbeat plaza hook increments
plaza_posts_made/plaza_comments_madebeforeexecute_toolruns, so a failedplaza_create_postorplaza_add_commentattempt still consumes quota and blocks retries in the same heartbeat tick. Previously counters were incremented only after a successful tool call, so this change can turn transient tool failures into hard false rate-limit blocks.Useful? React with 👍 / 👎.