Skip to content

Keep Atomic sessions on a workflow-configured drive - #77253

Closed
lavaman131 wants to merge 6 commits into
mainfrom
atomic-drive-sessions
Closed

lavaman131 wants to merge 6 commits into
mainfrom
atomic-drive-sessions

Conversation

@lavaman131

@lavaman131 lavaman131 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

cc @pelikhan

Replaces 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 on main; #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:

  • Opt-in: the workflow declares a tools.drive-memory entry with id: atomic, which mounts /tmp/gh-aw/drive-memory-atomic/. Workflows without that drive keep running with --no-session, so behavior on main is unchanged.
  • Restore: when the drive is mounted, the harness copies sessions/*.jsonl from the drive into a private 0700 session directory inside the temporary agent directory, skipping files whose lines are not JSON objects with a string type.
  • Run: Atomic runs with --session-dir <private dir> instead of --no-session. Atomic also writes workflow-stage transcripts to the inherited session directory.
  • Persist: after the run, each transcript is redacted with redactArtifactContent from redact_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's sessions/ folder is atomically replaced by a staged copy. Unredacted transcripts never touch the drive.

Security model

  • Staged publication: drive memory, not this harness, publishes the drive. With threat detection enabled, gh-aw stages the drive as an artifact, and update_drive_memory publishes 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.
  • Validation: the harness validates on both restore and persist. Workflows can additionally gate publication with drive-memory allowed-extensions: [".jsonl"] and validation.json-schemas; the docs show the recommended config (the array form, since the object form does not accept id).
  • What acceptance does not guarantee: restored sessions come from a drive that passed threat detection on an earlier run. Acceptance does not authenticate the content or make it safe for a later agent to interpret; the detector does not scan every drive file. Restored transcripts and workflow runs are untrusted history; an imported run replays its recorded (redacted) step results on resume. Redaction covers known values and token patterns only, not arbitrary encodings.
  • Drive scope: drive names are repository-wide and branch-aware, and the drive allows one writer at a time. Workflows should use their own drive-name. Drive memory is a private preview: it needs an enrolled repository and ubuntu-latest, and job containers are not supported.

Workflow runs (Atomic 0.9.84+)

Atomic 0.9.84 adds atomic storage export <dir> --workflows and atomic storage import <dir> --workflows, which carry workflow runs as versioned JSONL (<dir>/workflows/<runId>.jsonl: an atomic.workflow-run version 1 header, then one line per journal event). Import checks IDs, seq, epoch, key, at, type, name, cwd and status exactly, while string content may be redacted. When the drive is mounted, the harness now also:

  • Detects support with atomic storage export --help offering --workflows. With an older Atomic, including the pinned 0.9.79, it keeps sessions only and leaves the drive's workflows/ untouched. So this PR does not depend on the version bump (Bump experimental Atomic sample to 0.9.84 #77403, independent).
  • Restores before Atomic starts. It drops workflows/*.jsonl files that are not a version 1 export made of JSON object lines, then imports the rest with atomic storage import <private dir> --workflows into a private journal (ATOMIC_WORKFLOW_JOURNAL_PATH inside 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.
  • Persists after Atomic exits. It runs atomic storage export <private dir> --workflows and redacts each file with the same redactArtifactContent call 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's workflows/ 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.
  • Never fails the step: restore and persist problems for sessions or runs are logged as warnings.

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 keep GITHUB_WORKSPACE stable.

Dropped from #77045

  • libSQL/Turso/sqld plumbing and the Stage Atomic external storage step.
  • durable-packages and additional-package-names.
  • atomic_external_storage_policy.go and the schema changes.
  • behaviors.durable continuation and the matching durable_artifact/durable_session tweaks.

Validation

  • Merged 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=1 passes. TestAtomicHarnessDriveSessions covers the session paths. TestAtomicHarnessDriveWorkflowRuns runs the real harness against a temporary drive with a fake Atomic, and covers:
    • the no-drive path: no storage calls and --no-session kept;
    • invalid files dropped before import, with import, run and export sharing one private journal;
    • redaction of a GitHub token and an MCP header value, with exact fields unchanged, and a run with a secret in cwd dropped;
    • unfinished runs first, then the newest, within the budget;
    • a run that import refuses neither blocking the others nor being deleted;
    • a failed or empty export leaving saved runs alone;
    • an Atomic without --workflows saving sessions only.
  • TestAtomicHarnessDriveWorkflowRunsPublishedCLI (gated by GH_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) and 0.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 one running export on the drive, with no ghp_ and REDACTED present. The second harness run imports it, resumes, replays "token ***REDACTED***" without rerunning the first step, and saves the run as completed.
  • Real-CLI evidence against the published @bastani/[email protected] (flat layout, so outside the harness): the same SDK workflow was killed after its first step, its atomic storage export contained a ghp_ token, and redactArtifactContent rewrote it to ***REDACTED*** while every exactly checked field stayed equal. atomic storage import into a fresh journal succeeded (1 added), and importing again was a no-op (1 already up to date). Resuming by runId then completed, with the first step not rerun (first.count=1) and replaying "token ***REDACTED***". Re-export gave status completed. 0.9.83-alpha.1's storage export --help has 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, and make agent-report-progress-no-test pass.

Agent guidance

.github/aw/syntax-engine.md and .github/aw/drive-memory.md tell the workflow-authoring agent that Atomic keeps sessions, and with 0.9.84 or newer its workflow runs, only when the workflow itself declares a tools.drive-memory entry with id: 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

💥 [THE END] — Illustrated by Smoke Claude · claude · sonnet46 · ~79 AIC · ⌖ ~6 AIC · ⊞ 1K · ◷
Comment /smoke-claude to run again

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;

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💥 [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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good clear changeset entry. The description of the drive-memory feature is well documented - nice job specifying the 32 MiB budget constraint explicitly.

Comment thread .github/workflows/shared/atomic.md Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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.
Comment thread .github/workflows/shared/atomic.md Outdated
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;
@pelikhan

Copy link
Copy Markdown
Collaborator

Moving atomic integration to own repo.

@pelikhan pelikhan closed this Nov 13, 2026
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.

4 participants