-
Notifications
You must be signed in to change notification settings - Fork 0
fix(core): make workflow runs durable across resumes #23
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fffd383
ci: gate pull requests on tests and typecheck
miyaontherelay 475e25e
fix: await worker log cleanup
miyaontherelay f16686d
fix(core): make workflow runs durable across resumes
miyaontherelay 6357175
fix(core): restore config arg to resume() and repair regression test
10c3a5f
fix(core): address review feedback on resume durability
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| pull_request: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| test: | ||
| name: Test and typecheck | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '22' | ||
| cache: npm | ||
|
|
||
| - name: Install dependencies | ||
| run: npm ci | ||
|
|
||
| - name: Build primitives | ||
| run: npm run build:primitives | ||
|
|
||
| - name: Test | ||
| run: npm test | ||
|
|
||
| - name: Typecheck | ||
| run: npm run typecheck | ||
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,81 @@ | ||
| import { afterEach, describe, expect, it, vi } from 'vitest'; | ||
| import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'; | ||
| import os from 'node:os'; | ||
| import path from 'node:path'; | ||
| import { workflow } from '../builder.js'; | ||
| import { JsonFileWorkflowDb } from '../file-db.js'; | ||
| import { InMemoryWorkflowDb } from '../memory-db.js'; | ||
| import { runWorkflow } from '../run.js'; | ||
| import { WorkflowRunner } from '../runner.js'; | ||
| import type { WorkflowRunRow } from '../types.js'; | ||
|
|
||
| describe('workflow run persistence', () => { | ||
| const tmpDirs: string[] = []; | ||
|
|
||
| afterEach(() => { | ||
| vi.restoreAllMocks(); | ||
| for (const tmpDir of tmpDirs.splice(0)) { | ||
| rmSync(tmpDir, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
|
|
||
| it('constructs runWorkflow with the cwd JSONL database', async () => { | ||
| const tmpDir = mkdtempSync(path.join(os.tmpdir(), 'run-persistence-')); | ||
| tmpDirs.push(tmpDir); | ||
| const yamlPath = path.join(tmpDir, 'relay.yaml'); | ||
| writeFileSync( | ||
| yamlPath, | ||
| [ | ||
| 'version: "1"', | ||
| 'name: run-persistence-test', | ||
| 'swarm:', | ||
| ' pattern: sequential', | ||
| 'agents: []', | ||
| 'workflows:', | ||
| ' - name: default', | ||
| ' steps:', | ||
| ' - name: noop', | ||
| ' type: deterministic', | ||
| ' command: "true"', | ||
| ].join('\n') | ||
| ); | ||
| const dryRunSpy = vi.spyOn(WorkflowRunner.prototype, 'dryRun'); | ||
| vi.spyOn(console, 'log').mockImplementation(() => {}); | ||
|
|
||
| await runWorkflow(yamlPath, { cwd: tmpDir, dryRun: true }); | ||
|
|
||
| const runner = dryRunSpy.mock.instances[0] as unknown as { db: unknown }; | ||
| expect(runner.db).toBeInstanceOf(JsonFileWorkflowDb); | ||
| expect((runner.db as JsonFileWorkflowDb).getStoragePath()).toBe( | ||
| path.join(tmpDir, '.agent-relay', 'workflow-runs.jsonl') | ||
| ); | ||
| expect(runner.db).not.toBeInstanceOf(InMemoryWorkflowDb); | ||
| }); | ||
|
|
||
| it('honors WorkflowRunOptions.resume before executing a new run', async () => { | ||
| const tmpDir = mkdtempSync(path.join(os.tmpdir(), 'builder-resume-')); | ||
| tmpDirs.push(tmpDir); | ||
| const resumedRun = { id: 'resume-id', status: 'completed' } as WorkflowRunRow; | ||
| const resumeSpy = vi.spyOn(WorkflowRunner.prototype, 'resume').mockResolvedValue(resumedRun); | ||
| const executeSpy = vi.spyOn(WorkflowRunner.prototype, 'execute').mockResolvedValue(resumedRun); | ||
|
|
||
| const result = await workflow('builder-resume-test') | ||
| .agent('agent-a', { cli: 'claude' }) | ||
| .step('step-a', { agent: 'agent-a', task: 'Do step A' }) | ||
| .run({ cwd: tmpDir, renderer: false, resume: 'resume-id' }); | ||
|
|
||
| expect(result).toBe(resumedRun); | ||
| // The third arg is the parsed config: resume() feeds it to | ||
| // reconstructRunFromCache() when workflow-runs.jsonl is absent, so dropping | ||
| // it silently disables the cached-step-output fallback. | ||
| expect(resumeSpy).toHaveBeenCalledWith( | ||
| 'resume-id', | ||
| undefined, | ||
| expect.objectContaining({ name: 'builder-resume-test' }), | ||
| // User-facing resume means "the previous process is gone", so the builder | ||
| // opts in to requeueing steps left running. The library default is off. | ||
| expect.objectContaining({ resetRunningSteps: true }) | ||
| ); | ||
| expect(executeSpy).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
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
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.
🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: AgentWorkforce/relayflows
Length of output: 1086
🏁 Script executed:
Repository: AgentWorkforce/relayflows
Length of output: 1692
🌐 Web query:
actions/checkout v4 persist-credentials default true README GitHub💡 Result:
In the actions/checkout action, the persist-credentials input defaults to true [1][2]. This setting configures the authentication token (or SSH key) into the local git configuration, which allows your workflow scripts to run authenticated git commands (such as git push or git fetch) [3][4][5]. The token or SSH key is automatically removed during the post-job cleanup phase [3][4]. If you do not want these credentials to be persisted in the local git configuration, you can explicitly set persist-credentials to false [3][4]. Note that in more recent versions of the action (such as v6.0.0), the implementation of this persistence has been updated to store credentials in a file under $RUNNER_TEMP rather than directly in the.git/config file, improving security while maintaining the same default behavior [5][6].
Citations:
Disable checkout credential persistence.
actions/checkout@v4storesGITHUB_TOKENin the local Git configuration by default. The workflow then runs pull-request-controllednpmcommands, which can read or forward the token. Setpersist-credentials: falseand provide separate credentials only when a later step requires authenticated Git access.🧰 Tools
🪛 zizmor (1.29.0)
[warning] 15-16: credential persistence through GitHub Actions artifacts (artipacked): does not set persist-credentials: false
(artipacked)
🤖 Prompt for AI Agents
Source: Linters/SAST tools