Repository navigation
Keep Atomic sessions on a workflow-configured drive - #77253
lavaman131 wants to merge 6 commits into
Conversation
When a workflow declares tools.drive-memory with id: atomic, the Atomic sample harness restores validated JSONL sessions from the drive, runs Atomic with --session-dir, and writes back only redacted, well-formed transcripts within a 32 MiB budget. Drive memory stages them and publishes only after threat detection accepts the run. Without that drive the harness keeps --no-session.
| if (!existsSync(saved) || !lstatSync(saved).isDirectory()) return; | ||
| for (const name of listSessions(saved)) { | ||
| const content = readFileSync(join(sessionDrive, "sessions", name), "utf8"); | ||
| if (isSession(content)) writeFileSync(join(sessionDir, name), content, { mode: 0o600 }); |
| try { | ||
| let bytes = 0; | ||
| for (const name of listSessions(sessionDir).reverse()) { | ||
| const content = redactArtifactContent(readFileSync(join(sessionDir, name), "utf8"), [...sensitiveValues], []).content; |
There was a problem hiding this comment.
💥 [THE END] — Illustrated by Smoke Claude · claude · sonnet46 · ~79 AIC · ⌖ ~6 AIC · ⊞ 1K
Comment /smoke-claude to run again
| @@ -0,0 +1,5 @@ | |||
| --- | |||
| "gh-aw": patch | |||
There was a problem hiding this comment.
Good clear changeset entry. The description of the drive-memory feature is well documented - nice job specifying the 32 MiB budget constraint explicitly.
There was a problem hiding this comment.
🟡 Changes recommended
Short MCP credentials can leak into published transcripts, and an oversized newest transcript can cause existing session history to be replaced with an empty directory.
3 open issues
What changed in this PR
Adds workflow-controlled session persistence to the shared Atomic engine sample using GitHub drive memory. Workflows remain stateless unless they explicitly configure the Atomic drive; the engine and compiler are unchanged.
Changes:
- Restores validated JSONL sessions into a private directory and persists redacted transcripts within a 32 MiB budget.
- Adds harness tests for opt-in behavior, validation, redaction, and retention.
- Documents configuration and limitations, adds a patch changeset, and regenerates dependent workflow locks.
| File | Description |
|---|---|
pkg/workflow/atomic_workflow_test.go |
Tests session restore, redaction, malformed-file handling, and retention. |
docs/src/content/docs/reference/third-party-agent.md |
Documents Atomic drive configuration and persistence limitations. |
.github/workflows/smoke-atomic.lock.yml |
Embeds the updated harness and refreshes workflow hashes. |
.github/workflows/shared/atomic.md |
Implements opt-in session restore and redacted, bounded persistence. |
.github/workflows/engine-conformance-atomic.lock.yml |
Embeds the updated harness and refreshes workflow hashes. |
.changeset/patch-atomic-drive-sessions.md |
Records opt-in Atomic session persistence as a patch change. |
Review effort: Max (dynamic)
| try { | ||
| let bytes = 0; | ||
| for (const name of listSessions(sessionDir).reverse()) { | ||
| const content = redactArtifactContent(readFileSync(join(sessionDir, name), "utf8"), [...sensitiveValues], []).content; |
| log(`Not saving malformed session ${name}`); | ||
| continue; | ||
| } | ||
| bytes += Buffer.byteLength(content); |
| - runs Atomic with `--session-dir` instead of `--no-session`, so the agent can read earlier sessions through `history://`, and workflow-stage transcripts are saved too; | ||
| - after the run, redacts configured MCP header values and built-in token patterns, drops malformed transcripts, keeps the newest sessions up to 32 MiB, and replaces the drive's `sessions/` folder with the result. | ||
|
|
||
| Drive memory stages the folder and publishes it only after threat detection accepts the run, so content from a rejected or failed run never reaches the drive. Acceptance does not authenticate the transcripts: later runs still treat restored sessions as untrusted history, and redaction covers only known values and token patterns. Atomic's SQLite workflow journal is not saved, because it cannot be redacted or validated before publication; interrupted workflow runs cannot be resumed in a later run. |
The agent-facing engine and drive-memory guides now say that Atomic keeps sessions only when the workflow itself declares a drive-memory entry with id atomic, that the shared engine definition never enables it, and that it applies only to repositories enrolled in the Drives preview.
| if (existsSync(sessionDrive) && statSync(sessionDrive).isDirectory()) { | ||
| sessionDir = join(agentDir, "sessions"); | ||
| mkdirSync(sessionDir, { mode: 0o700 }); | ||
| restoreSessions(sessionDir); |
With Atomic 0.9.83 or newer, the harness imports validated workflows/*.jsonl exports into a private journal before the run and saves redacted atomic storage export files afterwards, keeping unfinished runs first and then the newest within 32 MiB. Runs whose exactly checked fields would change under redaction are dropped. Older Atomic versions keep sessions only, and persistence problems are logged instead of failing the agent step.
Resolve conflicts with the JSONL event output harness (#77052): keep its output sanitizers and --mode json, plus the drive sessions and runs. Workflow runs now use atomic storage import/export <dir> --workflows (Atomic 0.9.84+, detected from export --help offering --workflows), with <dir>/workflows/<runId>.jsonl. The drive's workflows/ folder is replaced only after a successful export, and saved runs the export lacks stay unless the budget prunes them.
…he real CLI Gated by GH_AW_ATOMIC_TEST_CLI: a tool-only SDK workflow is killed after its first step, its redacted export is carried through the drive, and a fresh harness run imports and resumes it without rerunning the first step.
| if (!existsSync(saved) || !lstatSync(saved).isDirectory()) return; | ||
| for (const name of listSessions(saved)) { | ||
| const content = readFileSync(join(sessionDrive, "sessions", name), "utf8"); | ||
| if (isSession(content)) writeFileSync(join(sessionDir, name), content, { mode: 0o600 }); |
| mkdirSync(sessionDir, { mode: 0o700 }); | ||
| tryPersist("sessions", () => restoreSessions(sessionDir)); | ||
| } | ||
| const runArgs = sessionDir ? [...args.filter(arg => arg !== "--no-session"), "--session-dir", sessionDir] : args; |
|
Moving atomic integration to own repo. |



cc
@pelikhanReplaces part of #77045, following your review there and on #77058. Sessions and workflow runs are stored on GitHub Drives through
tools.drive-memory; nothing goes to external libSQL/Turso/sqld storage. Durability is opted into in the workflow's own frontmatter, and the engine/compiler is unchanged. This PR is independent and based onmain; #77262 opts Smoke Atomic into it separately.Motivation
Atomic runs with
--no-session, so every run starts blind: the agent cannot look back at what earlier runs of the same workflow did (history://), workflow-stage transcripts are lost when the job ends, and an interrupted Atomic workflow run cannot be resumed.What changes
Only
.github/workflows/shared/atomic.md(the harness and its comment), its tests, and docs change. The shared engine definition reacts to what the workflow configured and turns nothing on by itself:tools.drive-memoryentry withid: atomic, which mounts/tmp/gh-aw/drive-memory-atomic/. Workflows without that drive keep running with--no-session, so behavior onmainis unchanged.sessions/*.jsonlfrom the drive into a private 0700 session directory inside the temporary agent directory, skipping files whose lines are not JSON objects with a stringtype.--session-dir <private dir>instead of--no-session. Atomic also writes workflow-stage transcripts to the inherited session directory.redactArtifactContentfromredact_secrets.cjs. That covers the configured MCP header values and the built-in token patterns. Malformed transcripts are dropped. The newest sessions are kept up to 32 MiB, and the drive'ssessions/folder is atomically replaced by a staged copy. Unredacted transcripts never touch the drive.Security model
update_drive_memorypublishes it only after the agent succeeds and detection explicitly accepts the run. It also verifies that the drive did not change since checkout. A failed or rejected run therefore cannot pollute the stored sessions or runs, which was the objection to the external database in Durable Atomic sessions and workflow runs #77045.allowed-extensions: [".jsonl"]andvalidation.json-schemas; the docs show the recommended config (the array form, since the object form does not acceptid).drive-name. Drive memory is a private preview: it needs an enrolled repository andubuntu-latest, and job containers are not supported.Workflow runs (Atomic 0.9.84+)
Atomic 0.9.84 adds
atomic storage export <dir> --workflowsandatomic storage import <dir> --workflows, which carry workflow runs as versioned JSONL (<dir>/workflows/<runId>.jsonl: anatomic.workflow-runversion 1 header, then one line per journal event). Import checks IDs,seq,epoch,key,at,type,name,cwdandstatusexactly, while string content may be redacted. When the drive is mounted, the harness now also:atomic storage export --helpoffering--workflows. With an older Atomic, including the pinned 0.9.79, it keeps sessions only and leaves the drive'sworkflows/untouched. So this PR does not depend on the version bump (Bump experimental Atomic sample to 0.9.84 #77403, independent).workflows/*.jsonlfiles that are not a version 1 export made of JSON object lines, then imports the rest withatomic storage import <private dir> --workflowsinto a private journal (ATOMIC_WORKFLOW_JOURNAL_PATHinside the temporary agent directory). Import is all or nothing, so if the batch is refused the harness retries file by file, and one bad run cannot block the others.atomic storage export <private dir> --workflowsand redacts each file with the sameredactArtifactContentcall used for sessions. It drops a run's new export when redaction would change one of the exactly checked fields, because a secret there can be neither kept nor redacted. The drive'sworkflows/folder is replaced through a staged copy, and only after export succeeded. Saved runs that the export does not replace stay. The budget is 32 MiB, alongside the session budget: unfinished runs come first, then the newest.An interrupted Atomic workflow can therefore be resumed in the next run (
/workflow resume <runId>). Resume treats a run from a different working directory as another project's, so it needs the same checkout path. GitHub-hosted runners keepGITHUB_WORKSPACEstable.Dropped from #77045
Stage Atomic external storagestep.durable-packagesandadditional-package-names.atomic_external_storage_policy.goand the schema changes.behaviors.durablecontinuation and the matchingdurable_artifact/durable_sessiontweaks.Validation
origin/main(JSONL event output harness from Convert Atomic sessions to the unified session format #77052). The conflict resolution keeps its output sanitizers and--mode json.go test ./pkg/workflow -run Atomic -count=1passes.TestAtomicHarnessDriveSessionscovers the session paths.TestAtomicHarnessDriveWorkflowRunsruns the real harness against a temporary drive with a fake Atomic, and covers:--no-sessionkept;cwddropped;--workflowssaving sessions only.TestAtomicHarnessDriveWorkflowRunsPublishedCLI(gated byGH_AW_ATOMIC_TEST_CLI) kills a tool-only SDK workflow after its first step, carries its redacted export through the drive, and resumes it in a fresh harness run. It checks that the first step replays its redacted result without running again. It passes against the published@bastani/[email protected](3.9s) and0.9.84-alpha.1(GH_AW_ATOMIC_TEST_CLI=<0.9.84-alpha.1>/atomic go test ./pkg/workflow -run TestAtomicHarnessDriveWorkflowRunsPublishedCLI, 4.3s). The first harness run is killed after one step and leaves onerunningexport on the drive, with noghp_andREDACTEDpresent. The second harness run imports it, resumes, replays"token ***REDACTED***"without rerunning the first step, and saves the run ascompleted.@bastani/[email protected](flat layout, so outside the harness): the same SDK workflow was killed after its first step, itsatomic storage exportcontained aghp_token, andredactArtifactContentrewrote it to***REDACTED***while every exactly checked field stayed equal.atomic storage importinto a fresh journal succeeded (1 added), and importing again was a no-op (1 already up to date). Resuming byrunIdthen completed, with the first step not rerun (first.count=1) and replaying"token ***REDACTED***". Re-export gave statuscompleted. 0.9.83-alpha.1'sstorage export --helphas no--workflows, so the harness correctly treats it as sessions-only.make build,./gh-aw compile smoke-atomic engine-conformance-atomic daily-declarative-engine-improver --validate(only the existing experimental and model-routing notices), the Atomic and redaction JS tests, andmake agent-report-progress-no-testpass.Agent guidance
.github/aw/syntax-engine.mdand.github/aw/drive-memory.mdtell the workflow-authoring agent that Atomic keeps sessions, and with 0.9.84 or newer its workflow runs, only when the workflow itself declares atools.drive-memoryentry withid: atomic. They also say that the shared engine definition never enables it, and that it applies only to repositories enrolled in the Drives preview.✨ PR Review Safe Output Test - Run 43334993910