Skip to content

fix(llmloop): propagate grace-round task_done completion - #2

Open
sf-jin-ku wants to merge 2 commits into
sendbirdfrom
fix/grace-round-completion
Open

sf-jin-ku wants to merge 2 commits into
sendbirdfrom
fix/grace-round-completion

Conversation

@sf-jin-ku

Copy link
Copy Markdown

Carry of upstream alibaba#1019 (by @AllenMuu, fixes alibaba#1018) on the sendbird build branch until it lands upstream.

alibaba#1019 conflicts with current upstream main, so this is its commit (author preserved) rebased onto main:

Why we need it: with per-file fan-out, a lane that exhausts its 50-round budget and closes with task_done in the grace round was reported as failed, which failed the whole file (5 files on CCO alibaba#948).

🤖 Generated with Claude Code

https://claude.ai/code/session_016fFEYAkexJ1sSe5eeLxxuH

AllenMuu and others added 2 commits October 4, 2026 19:02
The grace round that runs after the tool-request budget is exhausted
dropped the result of its task_done call: a model that spent all its
rounds on context tools and then called task_done(DONE) in the grace
round was still recorded as incomplete, so callers kept the misleading
"main_task did not complete before stopping" failure instead of a
reusable checkpoint. The grace round now mirrors the main loop's
terminal semantics:

- task_done(DONE) completes the run; comments issued alongside it in
  the same round still land.
- task_done(FAILED) surfaces as a task failure error and returns
  immediately without executing the rest of the round.
- Transient LLM errors are logged and swallowed so budget exhaustion
  stays the recorded stop cause.
- Cancellation wins over completion at every window and surfaces as
  ctx.Err() so callers classify the item as FailureCancelled instead
  of FailureBudget: before the grace call, inside the LLM call, after
  the response arrives, between the round's tool calls, and before
  returning completion.

Regression coverage includes the completion propagation, same-round
ordering for DONE and FAILED, the swallowed LLM error, all five
cancellation windows, and cross-protocol propagation over the OpenAI
chat-completions, Anthropic messages, and OpenAI responses formats.
Only the tool-request budget stop turns a grace-round task_done(DONE) into
completion; a token-budget stop must stay budget-stopped.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 5, 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-05T02:07:49.892147Z 595dd80 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.

@upwind-code-us

upwind-code-us Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Upwind Upwind Code Scan - ⚠️ Warn

21 newly introduced vulnerabilities · 0 resolved · 21 total in this PR vs main

Total breakdown: 🔴 1 Critical | 🔶 9 High | 🟡 9 Medium | 🟢 2 Low


🔴 Critical · 1 finding
CVE Package Version Fix
CVE-2026-84961 undici 8.10.0 8.10.2

🔶 High · 9 findings
CVE Package Version Fix
CVE-2026-69152 brace-expansion 5.0.8 5.0.9
CVE-2026-102276 brace-expansion 5.0.8 5.0.10
CVE-2026-84445 google.golang.org/grpc v1.83.1 1.83.2
CVE-2026-85152 undici 8.10.0 8.10.2
CVE-2026-67213 nanoid 3.3.16 3.3.18
CVE-2026-84933 undici 8.10.0 8.10.2
CVE-2026-19534 undici 8.10.0 8.10.2
CVE-2026-85014 undici 8.10.0 8.10.2
CVE-2026-102278 brace-expansion 5.0.8 5.0.11

🟡 Medium · 9 findings
CVE Package Version Fix
CVE-2026-102277 brace-expansion 5.0.8 5.0.12
CVE-2026-84890 undici 8.10.0 8.10.2
CVE-2026-86818 fast-uri 4.1.4 4.1.5
CVE-2026-84947 undici 8.10.0 8.10.2
CVE-2026-85024 undici 8.10.0 8.10.2
CVE-2026-82417 qs 6.15.3 6.16.0
CVE-2026-18149 undici 8.10.0 8.10.2
CVE-2026-85008 undici 8.10.0 8.10.2
CVE-2026-86472 fast-uri 4.1.4 4.1.5

🟢 Low · 2 findings
CVE Package Version Fix
CVE-2026-82562 qs 6.15.3 6.16.0
CVE-2026-18540 undici 8.10.0 8.10.2

View full analysis in Upwind Console

Scan completed in 10s

Scan history (1 scan)
Commit Scanned at New Resolved Net
595dd80 < 2026-10-05 02:07 UTC +21 0 +21

Last scanned: 595dd80 · 2026-10-05 02:07 UTC

@upwind-code-us

upwind-code-us Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Upwind Upwind IaC Scan - ✅ Passed

0 misconfigurations detected

No default-branch baseline yet — showing all findings.

View full analysis in Upwind Console →

Scan completed in 5s

Scan history (1 scan)
Commit Scanned at New Resolved Net
595dd80 < 2026-10-05 02:07 UTC 0 0 0

Last scanned: 595dd80 · 2026-10-05 02:07 UTC

@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: 595dd801e2

ℹ️ 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".

Comment thread internal/llmloop/loop.go
Comment on lines 635 to +636
if len(calls) == 0 {
return
return false, nil

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Check cancellation before accepting an empty grace response

When cancellation occurs while the grace-round request is in flight but the client still returns a successful response without tool calls, this early return runs before the new ctx.Err() check. RunMainTask therefore reports the original budget stop instead of context.Canceled; in scan mode, the item can be recorded as budget-failed and the command can return the generic all-scans-failed error rather than the cancellation. Check the context before the zero-call return.

Useful? React with 👍 / 👎.

Comment on lines +48 to +52
// Scenario A (the regression): the model spends all its rounds on
// context tools (file_read), then — given one last chance in the grace
// round — correctly calls task_done with state DONE. The completion must
// propagate: RunMainTask reports completed=true with StopNone, so callers
// record a reusable checkpoint instead of translating the run into

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Remove redundant narration from the added tests

This block is representative of extensive comments in the new tests that narrate the fixture and expected assertions already expressed by the test name, response construction, and checks. The root AGENTS.md requires comments to be sparse and limited to non-obvious reasons, explicitly excluding comments that restate or narrate the code; retain only explanations of genuinely subtle constraints.

AGENTS.md reference: AGENTS.md:L37-L40

Useful? React with 👍 / 👎.

@upwind-code-us

upwind-code-us Bot commented Oct 5, 2026

Copy link
Copy Markdown

Upwind Upwind Secrets Scan

42 findings detected

Total breakdown: 🔶 18 SECRET | 🔶 24 PII

No default-branch baseline yet — showing all findings.


🔶 SECRET · 11 findings
File Line Type Value
cmd/opencodereview/provider_tui_test.go 1947 generic-api-key sk-s••••abcd (+1 more)
examples/github_actions/README.md 525 pem-private-key -----BEGIN PRIVATE KEY----- *** -----END PRIVATE KEY----- (+5 more)
internal/llm/bedrock_test.go 332 generic-api-key sk-t••••-key
internal/llm/resolver.go 73 generic-api-key ANTH••••OKEN
scripts/github-actions/action-contract.test.js 1275 generic-api-key conf••••inel
scripts/github-actions/action-contract.test.js 1300 generic-api-key conf••••SIST
scripts/github-actions/action-contract.test.js 1335 generic-api-key conf••••inel
scripts/github-actions/action-contract.test.js 1378 generic-api-key prot••••inel (+1 more)
scripts/github-actions/action-contract.test.js 1529 generic-api-key lega••••inel
scripts/github-actions/action-contract.test.js 1555 generic-api-key extr••••inel
scripts/github-actions/action-contract.test.js 1588 generic-api-key retr••••inel

🔶 PII · 12 findings
File Line Type Value
cmd/opencodereview/git_test.go 19 Email ••••@test.com (+5 more)
cmd/opencodereview/misc_helpers_test.go 43 Email ••••@bar.com
cmd/opencodereview/rules_cmd_test.go 26 Email ••••@t.co (+4 more)
extensions/frontend/package-lock.json 2871 Email ••••@izs.me (+2 more)
internal/diff/git_resolve_test.go 168 Email ••••@github.com
internal/diff/git_resolve_test.go 170 Email ••••@github.com
internal/diff/git_resolve_test.go 178 Email ••••@host.com
internal/diff/git_resolve_test.go 178 Email ••••@c.git
internal/llm/client_test.go 1089 City •••••••• (+1 more)
internal/session/manifest_test.go 669 Email hu••••@github.com
internal/viewer/hostguard.go 44 IPv6 ••••••••
scripts/publish/publish.sh 163 Email ••••@open-code-review.local

A secret that has been pushed remains in the repository's history even after the line is removed.

Scan completed in 6s.


Scan history (1 scan)
Commit Scanned at New Resolved Net
595dd80 < 2026-10-05 02:07 UTC +23 0 +23

Last scanned: 595dd80 · 2026-10-05 02:07 UTC

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