Skip to content

feat: concurrency decorator#3089

Open
anish-sahoo wants to merge 4 commits into
mainfrom
issue-2811-concurrency
Open

feat: concurrency decorator#3089
anish-sahoo wants to merge 4 commits into
mainfrom
issue-2811-concurrency

Conversation

@anish-sahoo

@anish-sahoo anish-sahoo commented Jul 1, 2026

Copy link
Copy Markdown
Member

Summary

  • add @cog.concurrent for configuring async runner concurrency
  • statically extract decorator concurrency and bake it through COG_MAX_CONCURRENCY with existing precedence
  • enforce async requirements at decorator, build, and runtime; deprecate cog.yaml concurrency
  • update concurrency docs, llms.txt, examples, and integration fixtures

Example

import cog

class Runner(cog.BaseRunner):
    @cog.concurrent(max=4)
    async def run(self, prompt: str = cog.Input()) -> str:
        return await generate(prompt)

Testing

  • go test ./pkg/schema/python ./pkg/config ./pkg/image
  • golangci-lint run ./pkg/schema/python ./pkg/config ./pkg/image
  • uv run --with pytest pytest python/tests/test_concurrent.py
  • uv run --with ruff ruff check python/cog/init.py python/tests/test_concurrent.py
  • PYO3_PYTHON="$(uv run python -c 'import sys; print(sys.executable)')" cargo test -p coglet-python parse_max_concurrency
  • PYO3_PYTHON="$(uv run python -c 'import sys; print(sys.executable)')" cargo clippy --manifest-path crates/Cargo.toml -p coglet-python -- -D warnings
  • prettier --check docs/deploy.md docs/environment.md docs/python.md docs/yaml.md examples/hello-concurrency/README.md
  • git diff --check

Fixes #2811

@anish-sahoo anish-sahoo requested a review from a team as a code owner July 1, 2026 23:33
@anish-sahoo anish-sahoo changed the title Add concurrent decorator feat: concurrency decorator Jul 1, 2026
Comment thread pkg/schema/python/annotations.go Dismissed
@anish-sahoo anish-sahoo force-pushed the issue-2811-concurrency branch from 7ce91e8 to e433b85 Compare July 1, 2026 23:40

@ask-bonk ask-bonk Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm Bonk, and I've done a quick review of your PR.

This PR adds the @cog.concurrent decorator for configuring async predictor concurrency, with static extraction at build time and runtime enforcement. The decorator integrates cleanly with the existing precedence chain (runtime env > YAML > decorator > default) and properly deprecates the concurrency.max YAML field.

Issues found:

  1. Missing parser test for qualified alias import pattern — The tree-sitter parser tests cover direct import, qualified import (import cog), and imported alias (from cog import concurrent as foo), but lack coverage for the qualified alias pattern (import cog as c + @c.concurrent). The streaming decorator has this test (TestStreamingDecoratorQualifiedAliasOptIn) and the concurrent implementation uses the same attributeIsCogConcurrent helper, so it likely works — but explicit coverage prevents regressions.

Comment thread pkg/schema/python/parser_test.go
@ask-bonk

ask-bonk Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

I reviewed PR #3089 (add @cog.concurrent decorator) and posted a review with one suggestion:

Finding: Missing parser test for import cog as c + @c.concurrent(max=...) pattern in pkg/schema/python/parser_test.go. The streaming decorator has this coverage, but concurrent doesn't. I provided a suggestion comment adding TestConcurrentDecoratorQualifiedAliasMax to fill the gap.

Everything else looked solid — the decorator implementation, build-time static extraction, precedence handling, runtime enforcement in Coglet, and deprecation of YAML concurrency are all correctly implemented.

github run

@ask-bonk ask-bonk Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm Bonk, and I've done a quick review of your PR.

This PR adds the @cog.concurrent decorator for configuring async predictor concurrency, with static extraction at build time and runtime enforcement. Overall the implementation is solid — the decorator, precedence handling, runtime checks in Coglet, and deprecation of YAML concurrency are all correctly implemented.

Issues found:

  1. Missing parser test for qualified alias import pattern — The previous review already flagged this, but the test still hasn't been added. The tree-sitter parser tests cover direct import, qualified import (import cog), and imported alias (from cog import concurrent as foo), but lack coverage for the qualified alias pattern (import cog as c + @c.concurrent). The streaming decorator has this test (TestStreamingDecoratorQualifiedAliasOptIn) and the concurrent implementation uses the same attributeIsCogConcurrent helper, so it likely works — but explicit coverage prevents regressions.
  2. CodeQL integer conversion warning — The int64int conversion at pkg/schema/python/annotations.go:309 triggered a CodeQL alert. The code does have an upper bound check at line 306, but int64(math.MaxInt) may not be recognized as a proper bound by static analysis. Extracting the bound to a named constant silences the warning without changing behavior.

Comment thread pkg/schema/python/parser_test.go
Comment thread pkg/schema/python/annotations.go Outdated
@ask-bonk

ask-bonk Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Posted a batch review to PR #3089 with two suggestions:

  1. Missing parser testpkg/schema/python/parser_test.go needs a test for the import cog as c + @c.concurrent(max=...) import pattern (same as what exists for @cog.streaming).
  2. CodeQL integer conversionpkg/schema/python/annotations.go:306 should extract int64(math.MaxInt) to a named variable so CodeQL recognizes the bound check.

github run

Co-authored-by: ask-bonk[bot] <249159057+ask-bonk[bot]@users.noreply.github.com>
Signed-off-by: Anish Sahoo <anishsahoo2005@gmail.com>

@ask-bonk ask-bonk Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm Bonk, and I've done a quick review of your PR.

This PR adds the @cog.concurrent decorator for configuring async predictor concurrency, with static extraction at build time and runtime enforcement. Overall the implementation is solid — the decorator, precedence handling, runtime checks in Coglet, and deprecation of YAML concurrency are all correctly implemented.

Issues found:

  1. Go syntax error in parser tests — There's a duplicate empty function definition at line 1053 that will cause a compilation error.
  2. CodeQL integer conversion warning — The int64int conversion at pkg/schema/python/annotations.go:306 still triggers a CodeQL alert. Extracting the bound to a named constant silences the warning without changing behavior.

Comment thread pkg/schema/python/parser_test.go Outdated
Comment thread pkg/schema/python/annotations.go Outdated
anish-sahoo added a commit that referenced this pull request Jul 2, 2026
Merge from #3089 introduced a duplicate TestConcurrentDecoratorIgnoredWhenNotFromCog
function signature that caused a syntax error.
@ask-bonk

ask-bonk Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Posted a batch review to PR #3089 with two issues:

  1. Go syntax errorpkg/schema/python/parser_test.go:1053 has a duplicate empty TestConcurrentDecoratorIgnoredWhenNotFromCog function definition that will fail compilation.
  2. CodeQL integer conversionpkg/schema/python/annotations.go:306 still needs the int64(math.MaxInt) bound extracted to a named variable for CodeQL to recognize the check.

github run

@ask-bonk

ask-bonk Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

LGTM

github run

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.

Configure concurrency in predictor rather than in cog.yaml

2 participants