Skip to content

feat: add resource caching and progress spinner for init/pull/branch#50

Merged
amansingh1720 merged 2 commits intomainfrom
aman/adk/resource-cache
Mar 27, 2026
Merged

feat: add resource caching and progress spinner for init/pull/branch#50
amansingh1720 merged 2 commits intomainfrom
aman/adk/resource-cache

Conversation

@amansingh1720
Copy link
Copy Markdown
Contributor

@amansingh1720 amansingh1720 commented Mar 27, 2026

Summary

Batch MultiResourceYamlResource writes during poly init so each YAML file is written once instead of once per resource, and add a progress spinner to init, pull, and branch switch so the CLI doesn't appear stuck on large projects.

Also edited CONTRIBUTING.md to edit the clone url - changed org to PolyAI.

Motivation

poly init is very slow on projects with many pronunciations (or other multi-resource YAML types) because save() rewrites the full YAML file for every single item. On large projects like pacden, the process appears stuck with no output. The save_to_cache + write_cache_to_file pattern already exists for poly pull — this reuses it for init and adds a progress spinner across all three commands.

Changes

  • Use save_to_cache=True for all MultiResourceYamlResource saves during init_project(), then flush to disk once via write_cache_to_file()

  • Add an optional on_save(current, total) callback to init_project(), pull_project(), _update_multi_resource_yaml_resources(), _update_pulled_resources(), and switch_branch() for progress reporting

  • Wire up console.status() spinners in cli.py for init, pull, and branch switch, using nullcontext to skip the spinner in --json mode

  • Progress counter includes both multi-resource (per batch total) and non-multi-resource types for an accurate total

  • CONTRIBUTING.md to edit the clone url - changed org from PolyAI-LDN to PolyAI.

Test strategy

  • Added/updated unit tests
  • Manual CLI testing (poly <command>)
  • Tested against a live Agent Studio project
  • N/A (docs, config, or trivial change)

Checklist

  • ruff check . and ruff format --check . pass
  • pytest passes (361 tests, 0 failures)
  • No breaking changes to the poly CLI interface (or migration path documented)
  • Commit messages follow conventional commits

Screenshots / Logs

Before:
Screenshot 2026-03-25 at 10 04 14 PM

After:
Screenshot 2026-03-25 at 10 04 01 PM

@github-actions

This comment has been minimized.

@amansingh1720
Copy link
Copy Markdown
Contributor Author

adding tests with on_save and current/total

@github-actions
Copy link
Copy Markdown
Contributor

Coverage Report

Base (main) PR Change
70.2% 70.6% +0.4% ✅

Changed file coverage

File Coverage Change
poly/cli.py 30.6% -0.7% ⚠️
poly/project.py 66.1% +2.2% ✅
poly/resources/pronunciation.py 71.9% +2.1% ✅
poly/resources/resource.py 79.5% +1.7% ✅
poly/resources/keyphrase_boosting.py 91.8% +1.6% ✅

Comment on lines +891 to +910
ctx = (
console.status("[info]Saving resources...[/info]") if not output_json else nullcontext()
)
on_save = None

with ctx as status:
if status:

def on_save(current: int, total: int) -> None:
status.update(f"[info]Saving resources ({current}/{total})...[/info]")

project, projection = AgentStudioProject.init_project(
base_path=base_path,
region=region,
account_id=account_id,
project_id=project_id,
format=format,
projection_json=projection_json,
on_save=on_save,
)
Copy link
Copy Markdown
Collaborator

@Ruari-Phipps Ruari-Phipps Mar 27, 2026

Choose a reason for hiding this comment

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

We shouldn't pass on save if doing --json output

Copy link
Copy Markdown
Contributor Author

@amansingh1720 amansingh1720 Mar 27, 2026

Choose a reason for hiding this comment

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

that is already handled with this - on_save=None is passed to the function and inside project.py, the callback is guarded by if on:save so its effectively a no-op.
when output_json is True then
ctx = nullcontext() (no-op) from this line
console.status("[info]Saving resources...[/info]") if not output_json else nullcontext()
on_save = None
status is None inside the with block
'if status: False', so on_save stays None and falls outside the if block

  • This was done to try and avoid duplication

@amansingh1720
Copy link
Copy Markdown
Contributor Author

poly/cli.py | 30.6% | -0.7% ⚠️
Can't really add test coverage for this since it would require a running terminal :/

Copy link
Copy Markdown
Collaborator

@Ruari-Phipps Ruari-Phipps left a comment

Choose a reason for hiding this comment

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

LGTM!

@amansingh1720 amansingh1720 merged commit 2d4fc0a into main Mar 27, 2026
3 checks passed
@amansingh1720 amansingh1720 deleted the aman/adk/resource-cache branch March 27, 2026 17:22
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