Skip to content

fix(agency): a launch stays closing while a team its seats launched holds a seat, and agency() warns about agencies - #644

Merged
jddunn merged 6 commits into
masterfrom
fix/agency-review-threads-read-T20-T21
Oct 29, 2026
Merged

jddunn merged 6 commits into
masterfrom
fix/agency-review-threads-read-T20-T21

Conversation

@jddunn

@jddunn jddunn commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Summary

A read of launch_agency's closing entry and of the agencies option found two places where the code does less than its rule says:

  • A team launched from a seat does not hold its root launch's place. A launch whose seats outlive the settle grace stays closing in the launch registry and counts toward its scope's maxConcurrent, so a session's retry against a tool that hangs past the deadline is refused (concurrency_exceeded) instead of seating another member. A team that one of the launch's seats launched (a nested launch, whose scope is the launch it came from) is held the same way, but the launch it came from was removed as soon as its own seats were released. With the defaults (maxDepth 2), a lead seat whose team's waiter calls a tool that hangs left the lead's team closing and the root launch gone: the session's next launch was admitted, and each retry seated one more waiter on the same hanging tool. A launch's entry now stays closing until every launch nested under it is removed as well.
  • agency() drops agencies without a word. agencies is a gmi() option: an agency launches no team itself and passes the option to none of its seats. AgencyOptions does not declare it, so a TypeScript literal is refused, but a JavaScript caller, or a host that spreads an agent's options object into agency()'s (a spread's properties are not checked against the target type), had it ignored in silence. agency() now warns, as it does for cognitiveMechanisms.

Linked issues

None.

Type of change

  • Bug fix
  • Feature
  • Performance
  • Documentation
  • Refactor
  • Tests
  • Build or CI

How this was verified

CI on this pull request: the tests were pushed ahead of the fixes and read red, then the fixes.

  • src/api/__tests__/agency-launch-nested-closing.gmi.e2e.test.ts runs the real gmi(), agency(), launch engine, completion gateway, GMI and tool orchestrator with only the provider classes stubbed: a root launch's lead seat launches a team whose waiter's tool hangs past the deadline; after the root launch returns timed_out and its lead is released, the root launch is still closing, the session's next launch is refused concurrency_exceeded, and once the tool returns both entries go and the session launches again.
  • src/api/runtime/agencyLaunch/__tests__/runLaunch.test.ts holds the same rule on the engine with a fake host and fake seats.
  • src/api/__tests__/agency-gmi-seats.e2e.test.ts: an agent's options spread into agency() with agencies set warn at construction, and the agency's GMI seat runs with no launch_agency offered.

Migration notes

None. No type changes; a launch nested under another holds its parent's entry only while its own seats are held.

Checklist

  • Tests cover the changed behavior.
  • Docs are updated.
  • The title follows Conventional Commits, with ! before the colon for a change that breaks users (feat!: or feat(api)!:).
  • No secrets or private data are included.
  • Every automated review thread is settled (how).
  • I have read this change and can explain every line.

Summary by Sourcery

Preserve launch concurrency limits across nested launches and surface ignored agencies configuration in agency().

Bug Fixes:

  • Keep parent launch entries in the closing state until all launches nested beneath them and their seats have been released, preventing premature concurrency admission and duplicate retries.
  • Warn when agency() receives an agencies configuration that it cannot apply to itself or its seats.

Documentation:

  • Document that agency() warns about unsupported agencies configuration and that agencies must be configured on gmi() agents.

Tests:

  • Add runtime and end-to-end coverage for nested launch closing behavior and agency() warnings.

Summary by CodeRabbit

  • Bug Fixes

    • Agencies now warn when given an agencies option they do not apply to themselves or their seats. Configure this option on a gmi() agent that may launch teams.
    • Nested launches keep their parent launch scope active while seats remain in use. This prevents conflicting launches until the nested work is released.
  • Documentation

    • Clarified how to configure team-launching behavior for agency seats.

@jddunn
jddunn requested a review from Victor-Evogor as a code owner October 29, 2026 13:56
@sourcery-ai

sourcery-ai Bot commented Oct 29, 2026

Copy link
Copy Markdown

Sorry @jddunn, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 1 day and 18 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between d9b3ea8 and b78b620.

Files selected for processing: 7
  • docs/AGENCIES.md
  • src/api/__tests__/agency-gmi-seats.e2e.test.ts
  • src/api/__tests__/agency-launch-nested-closing.gmi.e2e.test.ts
  • src/api/agency.ts
  • src/api/runtime/agencyLaunch/__tests__/runLaunch.test.ts
  • src/api/runtime/agencyLaunch/launchRegistry.ts
  • src/api/runtime/agencyLaunch/runLaunch.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

Walkthrough

The change adds a warning for agencies passed to agency() and keeps parent launch entries registered while nested launches remain active. Tests cover the warning, closing states, concurrency refusal, and cleanup after held work is released.

Changes: Agency option warning

Layer / File(s) Summary
Warn on unused agency options
src/api/agency.ts, src/api/__tests__/agency-gmi-seats.e2e.test.ts, docs/AGENCIES.md
agency() warns when runtime options include a non-null agencies value. The test checks the warning and verifies that agency seats are not offered launch_agency. The documentation describes where to configure agencies for team launches.

Nested launch lifecycle

Layer / File(s) Summary
Wait for nested launch removal
src/api/runtime/agencyLaunch/launchRegistry.ts, src/api/runtime/agencyLaunch/runLaunch.ts, src/api/runtime/agencyLaunch/__tests__/runLaunch.test.ts, src/api/__tests__/agency-launch-nested-closing.gmi.e2e.test.ts
launchRegistry tracks nested launches and removal waiters. runAdmitted waits for nested launch entries to be removed before removing the parent entry. Tests check closing states, concurrency refusal while seats remain held, and successful launch after cleanup.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant runAdmitted
  participant launchRegistry
  participant NestedSeat
  runAdmitted->>launchRegistry: Find launches nested under the parent
  launchRegistry-->>runAdmitted: Return registered nested launches
  runAdmitted->>launchRegistry: Wait for nested launch removal
  NestedSeat->>launchRegistry: Release held work and remove nested launch
  launchRegistry-->>runAdmitted: Resolve removal waiter
  runAdmitted->>launchRegistry: Remove parent launch entry
Loading

Possibly related issues

  • framerslab/agentos#626 — The changes affect nested team launch behavior, but the issue’s limits, budgets, and gates work remains outside this change.

Possibly related PRs

  • framerslab/agentos#382 — Introduced launchRegistry and runLaunch, which this change extends for nested launch cleanup.
  • framerslab/agentos#631 — Addresses launch lifecycle and held-seat cleanup behavior that this change extends to nested launches.
Merge Risk: Minimal · up to b78b6

Nested cleanup preserves timed-out responses. The change is mergeable after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies both primary fixes: nested launch closing behavior and the agency() agencies warning. It uses a valid Conventional Commits format.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description is thorough and follows the template. It has a Summary that explains two fixes: a nested team launch now holds its root launch's registry entry while its seats are held, and agency() n…
Full details: Description check

Explanation

The description is thorough and follows the template. It has a Summary that explains two fixes: a nested team launch now holds its root launch's registry entry while its seats are held, and agency() now warns when it receives agencies. Linked issues is None. The Type of change, How this was verified, Migration notes, and Checklist sections are all filled in. The verification section names the three test files and what each checks, and the Migration notes section says no type changes are made. The Summary by Sourcery block is extra and does not affect the check. The description matches the raw summary and the objectives.

Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 6 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T13:57:54.052444Z 7deb4d2 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@sourcery-ai

sourcery-ai Bot commented Oct 29, 2026

Copy link
Copy Markdown

Reviewer's Guide

This PR fixes launch-registry cleanup so a parent launch remains closing and counts against maxConcurrent while descendant launches still hold seats, preventing duplicate retries until all work finishes. It also adds a construction-time warning for unsupported agencies options passed to agency(), with coverage for both behaviors at runtime and end to end.

File-Level Changes

Change Details Files
Propagate nested launch lifetime to its parent’s closing state so concurrency remains occupied until all descendant seats are released.
  • Keep an ancestor launch in the registry as closing while nested launches remain active.
  • Remove ancestor and descendant entries only after the nested hanging seat completes.
  • Verify retry refusal and subsequent admission in both engine-level and full GMI end-to-end scenarios.
src/api/runtime/agencyLaunch/__tests__/runLaunch.test.ts
src/api/__tests__/agency-launch-nested-closing.gmi.e2e.test.ts
Warn when agency() receives an agencies configuration that it cannot apply to its seats.
  • Add an end-to-end test covering JavaScript/spread-based option leakage.
  • Confirm GMI-backed agency seats receive no launch_agency tool from the ignored configuration.
src/api/__tests__/agency-gmi-seats.e2e.test.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

test(agency): cover nested launch cleanup and ignored agencies options

🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Add engine and GMI regressions for keeping parent launches closing while nested seats remain
 active.
• Verify session retries are refused until a hanging nested tool releases its seat.
• Assert agency() warns about ignored agencies options without offering launch_agency to its GMI
 seats.
Diagram

graph TD
  S["GMI session"] --> R["Root launch"] --> N["Nested launch"] --> H["Hanging tool"]
  R --> G["Launch registry"] --> C{"Retry allowed?"}
  N --> G
  A["Agency options"] --> B["GMI seat"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Track child entries in the launch registry
  • ➕ Keeps lifecycle and admission accounting together.
  • ➕ Can release ancestors when their final descendant exits.
  • ➖ Requires explicit parent-child bookkeeping and cleanup.
2. Hold each parent until its child settles
  • ➕ Uses the launch engine's existing hold-and-close lifecycle.
  • ➖ Requires a reliable way for nested admissions to register a hold with the running parent.

Recommendation: Keep the regression tests, but do not describe this diff as the completed fix: it changes no production code. Add descendant-aware parent retention—preferably through explicit registry tracking—and an agency() warning analogous to the existing cognitiveMechanisms warning before merging.

Files changed (3) +163 / -1

Tests (3) +163 / -1
agency-gmi-seats.e2e.test.tsTest warnings for ignored agency-level agencies options +20/-1

Test warnings for ignored agency-level agencies options

• Adds a GMI-seat test that spreads an agent options object containing agencies into agency(). It expects a construction warning and verifies the seat runs without launch_agency being offered.

src/api/tests/agency-gmi-seats.e2e.test.ts

agency-launch-nested-closing.gmi.e2e.test.tsCover nested launch retention through the GMI integration path +103/-0

Cover nested launch retention through the GMI integration path

• Adds an end-to-end scenario where a nested seat's tool remains active beyond the root deadline. It expects both launch entries to remain closing, a session retry to be refused, and admission to resume after the tool releases.

src/api/tests/agency-launch-nested-closing.gmi.e2e.test.ts

runLaunch.test.tsTest parent launch retention in the launch engine +40/-0

Test parent launch retention in the launch engine

• Adds a fake-host scenario in which a lead launches a nested team with an unresponsive waiter. It checks that the root still occupies its concurrency slot after the lead closes and that both entries clear when the waiter finishes.

src/api/runtime/agencyLaunch/tests/runLaunch.test.ts

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Nested-launch tests fail at cleanup ✓ Resolved
Description
runAdmitted tracks only the parent launch's own work and removes its registry entry when that work
settles, without waiting for a nested launch's held seat. Once the lead closes while the nested
waiter remains held, the new tests expect the root to stay closing and reject a session retry, but
its entry is gone and the retry can be admitted.
Code

src/api/runtime/agencyLaunch/tests/runLaunch.test.ts[R683-684]

+    expect(launchRegistry.get(out.agencyId)?.state).toBe('closing');
+    expect((await refusalOf(host, args())).code).toBe('concurrency_exceeded');
Evidence
The parent cleanup waits only on its local holding set, while registry admission counts entries by
exact scope key. The added test launches the waiter under the lead's launch and then asserts that
the root still occupies the session's slot.

src/api/runtime/agencyLaunch/runLaunch.ts[493-501]
src/api/runtime/agencyLaunch/runLaunch.ts[577-600]
src/api/runtime/agencyLaunch/launchRegistry.ts[52-57]
src/api/runtime/agencyLaunch/tests/runLaunch.test.ts[665-684]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A nested launch can remain closing after its parent launch is removed, so the new tests fail and session retries can be admitted while the nested seat remains held.
## Fix Focus Areas
- src/api/runtime/agencyLaunch/runLaunch.ts[493-501]
- src/api/runtime/agencyLaunch/runLaunch.ts[577-600]
- src/api/runtime/agencyLaunch/launchRegistry.ts[52-57]
## Recommended Fix
Track admitted nested launches against their immediate parent entry. Keep each parent closing until both its own work and every nested entry have been removed, including on abort and error paths; only then free its session concurrency slot.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Agency warning test fails at construction ✓ Resolved
Description
agency() warns about cognitiveMechanisms but has no warning path for an agencies option. The
new test spies on console.warn before construction and immediately expects that warning, so it
fails before the seat-generation assertions run.
Code

src/api/tests/agency-gmi-seats.e2e.test.ts[254]

+    expect(warn).toHaveBeenCalledWith(expect.stringContaining('agency() accepted an agencies config'));
Evidence
The test checks for a warning immediately after calling agency(), but the factory's
construction-time warning block handles only cognitiveMechanisms.

src/api/tests/agency-gmi-seats.e2e.test.ts[249-254]
src/api/agency.ts[213-229]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new construction-time warning assertion fails because agency() silently ignores an agencies option.
## Fix Focus Areas
- src/api/agency.ts[213-229]
- src/api/__tests__/agency-gmi-seats.e2e.test.ts[249-254]
## Recommended Fix
Add a construction-time warning when agency() receives a non-null agencies option, explaining that it is not applied to seats. Keep the existing behavior that does not forward the option.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Tip of the day
💡 Did you know, you can add REVIEW.md to your repo root and Qodo follows it on every PR

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7deb4d2d2a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@jddunn

jddunn commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

On the docstring coverage check: every source function this change touches has its doc comment (runAdmitted, agency(), and the registry's nestedUnder, whenRemoved and remove). The functions it counts without one are the test callbacks the change adds: the fake host's seat factory in runLaunch.test.ts and the hanging tool's execute in the end-to-end test, each described by the comment above it.

@jddunn
jddunn merged commit cb0c8e2 into master Oct 29, 2026
20 checks passed
@jddunn
jddunn deleted the fix/agency-review-threads-read-T20-T21 branch October 29, 2026 15:39
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.

1 participant