-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add skip_permissions, continue command, and build retry for resilient opencode automation #2
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
jc01rho
wants to merge
3
commits into
cortexkit:main
Choose a base branch
from
jc01rho:main
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.
+287
−34
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import { describe, test, expect } from "bun:test"; | ||
| import { isRetryableError } from "./retry"; | ||
|
|
||
| describe("isRetryableError", () => { | ||
| test("returns false for non-Error values", () => { | ||
| expect(isRetryableError("string error", "")).toBe(false); | ||
| expect(isRetryableError(42, "provider returned error")).toBe(false); | ||
| expect(isRetryableError(null, "provider returned error")).toBe(false); | ||
| }); | ||
|
|
||
| test("returns false when error message lacks 'exited with'", () => { | ||
| const err = new Error("some other error"); | ||
| expect(isRetryableError(err, "provider returned error")).toBe(false); | ||
| }); | ||
|
|
||
| test("detects 'provider returned error' in log slice", () => { | ||
| const err = new Error("opencode exited with 1"); | ||
| expect(isRetryableError(err, "Error: provider returned error")).toBe(true); | ||
| }); | ||
|
|
||
| test("detects 'provider returned an error' in log slice", () => { | ||
| const err = new Error("opencode exited with 1"); | ||
| expect(isRetryableError(err, "Error: provider returned an error")).toBe(true); | ||
| }); | ||
|
|
||
| test("detects rate limit patterns", () => { | ||
| const err = new Error("opencode exited with 1"); | ||
| expect(isRetryableError(err, "Error: rate limit exceeded")).toBe(true); | ||
| expect(isRetryableError(err, "Error: too many requests")).toBe(true); | ||
| }); | ||
|
|
||
| test("detects network errors", () => { | ||
| const err = new Error("opencode exited with 1"); | ||
| expect(isRetryableError(err, "Error: fetch failed")).toBe(true); | ||
| expect(isRetryableError(err, "Error: socket hang up")).toBe(true); | ||
| expect(isRetryableError(err, "Error: ECONNRESET")).toBe(true); | ||
| expect(isRetryableError(err, "Error: ETIMEDOUT")).toBe(true); | ||
| }); | ||
|
|
||
| test("detects HTTP status codes with context", () => { | ||
| const err = new Error("opencode exited with 1"); | ||
| expect(isRetryableError(err, "Error: HTTP 429")).toBe(true); | ||
| expect(isRetryableError(err, "Error: status 502")).toBe(true); | ||
| expect(isRetryableError(err, "Error: response status 503")).toBe(true); | ||
| }); | ||
|
|
||
| test("rejects bare HTTP status codes without context", () => { | ||
| const err = new Error("opencode exited with 1"); | ||
| expect(isRetryableError(err, "Error: port 4292")).toBe(false); | ||
| expect(isRetryableError(err, "Error: line 5032")).toBe(false); | ||
| }); | ||
|
|
||
| test("detects '500 internal server error'", () => { | ||
| const err = new Error("opencode exited with 1"); | ||
| expect(isRetryableError(err, "Error: 500 internal server error")).toBe(true); | ||
| }); | ||
|
|
||
| test("returns false for non-retryable errors", () => { | ||
| const err = new Error("opencode exited with 1"); | ||
| expect(isRetryableError(err, "Error: build failed")).toBe(false); | ||
| expect(isRetryableError(err, "Error: syntax error")).toBe(false); | ||
| }); | ||
|
|
||
| test("per-attempt log slicing: stale content from attempt 1 does not affect attempt 2", () => { | ||
| const err = new Error("opencode exited with 1"); | ||
| const attempt1Log = "Error: provider returned error"; | ||
| const attempt2Log = "Error: build failed"; | ||
|
|
||
| // Attempt 1 log contains retryable error | ||
| expect(isRetryableError(err, attempt1Log)).toBe(true); | ||
|
|
||
| // Attempt 2 log does NOT contain retryable error (only new content) | ||
| expect(isRetryableError(err, attempt2Log)).toBe(false); | ||
| }); | ||
| }); |
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.
orw continuenever actually resumes the interrupted sessioncontinueRundelegates torunOpenCodeWithBuildRetry→runOpenCodeWithRetry, which only adds--continuewhenisRetry = attempt > 1. On the first attempt,isRetryisfalse, soopencode runis invoked without--continue— starting a brand-new session in the existing work directory rather than resuming the interrupted one. The flag only reaches opencode if that fresh run happens to fail with a retryable provider error and then retries.To fix this,
runOpenCodeWithRetry(and by extensionrunOpenCodeWithBuildRetry) needs an option like{ forceContinue?: boolean }thatcontinueRuncan pass through to make--continueunconditional on every attempt.