Skip to content

Durable Atomic sessions and workflow runs - #77045

Closed
lavaman131 wants to merge 7 commits into
mainfrom
atomic-durable-storage
Closed

lavaman131 wants to merge 7 commits into
mainfrom
atomic-durable-storage

Conversation

@lavaman131

@lavaman131 lavaman131 commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

cc @pelikhan

Bottom of stack #77068 (#77045 → #77052). #77020 has merged.

Sessions and workflow runs saved on every run

  • Drop --no-session from shared/atomic.md. Every run now writes Atomic's sessions (sessions.sqlite), workflow journal (journal.sqlite), run-scoped workflow artifacts (runs/ via ATOMIC_WORKFLOW_ARTIFACT_DIR), and recorded root session ID (session-id, mode 0600) under /tmp/gh-aw/agent/atomic-store rather than relying on the parent of the temporary agent directory.
  • Within a single job, subagents, workflow stages, and history:// share /tmp/gh-aw/agent/atomic-store while local Intercom stays off (intercom: off in atomic storage status), avoiding an idle SQLite broker poll when no shared database is configured.

Artifact-backed durable mode (behaviors.durable)

  • Declare behaviors.durable in shared/atomic.md with files: [/tmp/gh-aw/agent/atomic-store] and matching execution and harness configuration.
  • After Atomic runs, the harness records the latest root (internal = 0) session ID into /tmp/gh-aw/agent/atomic-store/session-id (0600), ignoring child subagent and workflow-stage sessions (internal = 1).
  • When GH_AW_DURABLE_RESUMED=true, the harness passes --session <id> to continue that saved root session (--continue if no session-id file is present). Interrupted Atomic workflow runs remain in the restored journal.sqlite and runs/ folder for the agent to inspect or resume with the workflow tool; the harness does not auto-resume workflow runs.
  • Enable durable: { retention-days: 7 } explicitly on smoke-atomic.md for now (a separate compiler PR adds an engine-definition default). engine-conformance-atomic.md omits engine.durable because validateEngineDurable rejects work-queue workers (tools.work-queue.worker: true).

Optional Turso and self-hosted sqld guide and plumbing

  • Document how to point Atomic at Turso or a self-hosted sqld server in docs/src/content/docs/reference/third-party-agent.md when runs need history past artifact expiry, local inspection from a developer machine (history://, /workflow status, /resume), cross-machine takeover of timed-out workflow runs, or Intercom multi-node routing between concurrent runners.
  • Keep the sandbox plumbing minimal and opt-in:
    • A Stage Atomic external storage pre-agent-steps step reads secrets.ATOMIC_STORAGE_URL and secrets.ATOMIC_STORAGE_TOKEN from step env:. When ATOMIC_STORAGE_URL is empty, it removes any stale staging file and exits 0 without running npm. Otherwise it masks the values, installs @bastani/[email protected] (NPM_CONFIG_IGNORE_SCRIPTS=true, NPM_CONFIG_MIN_RELEASE_AGE=0, pinned to match engine.version and enforced by test), and writes /tmp/gh-aw/atomic-storage-staging.json (0600).
    • Workflows opt in with non-secret ATOMIC_STORAGE: "on" (plus optional ATOMIC_STORAGE_NAMESPACE) in engine.env and add the database host to network.allowed.
    • The harness always unlinks /tmp/gh-aw/atomic-storage-staging.json before spawning Atomic (even when ATOMIC_STORAGE is unset, "off", or validation fails), registers secrets in sensitiveValues before any log or error path, validates the URL (libsql:, https:, wss:, or http:, rejecting userinfo and authToken query parameters), requires a token for libsql:/https:/wss:, writes storage-token (0600) in the private agent directory, and writes top-level storage with sanitized prefix gh_aw_<owner>_<repo>. On exit, if the run started an Intercom broker in the temporary agent directory, the harness sends SIGTERM to broker.pid before removing agentDir.

Compatibility and security notes

  • Workflows without ATOMIC_STORAGE: "on" never install or load the external adapter unless secrets.ATOMIC_STORAGE_URL is set in the repository, and even then they unlink the staging file before Atomic starts and keep using /tmp/gh-aw/agent/atomic-store.
  • Durable checkpoint artifacts hold restorable session transcripts, tool outputs, and file contents read by the agent; anyone with artifact read access in the repository can download them, and secret redaction is heuristic.
  • With external storage enabled, the agent can read its own temporary agent directory (including storage-token), and anyone with the database token can read saved sessions and workflow runs; scope tokens to one database and rotate them regularly. Unreachable databases fail closed without falling back to a temporary store.
  • Because --approve loads .atomic/settings.json (restored from the base branch before the agent starts), a repository's own storage, sessions.storage, or workflows.journal setting in .atomic/settings.json overrides the harness's store for sessions and workflow runs (while Intercom continues using global storage). Leave those keys out of .atomic/settings.json when using gh-aw durable sessions or ATOMIC_STORAGE.
  • Safe-update security review: Recompiling smoke-atomic.lock.yml and engine-conformance-atomic.lock.yml adds ATOMIC_STORAGE_URL and ATOMIC_STORAGE_TOKEN to the manifest secret inventory via shared/atomic.md's Stage Atomic external storage pre-agent step. Both are bound only in step env:, excluded from the AWF container environment via excluded-env, masked before adapter installation, staged 0600 only when non-empty, and unlinked by the harness before Atomic spawns. No new GitHub Actions or container images were added.

Validation

  • gh-aw compile smoke-atomic engine-conformance-atomic daily-declarative-engine-improver --validate passes (3 succeeded).
  • go test ./pkg/workflow -run Atomic -count=1 and GH_AW_ATOMIC_TEST_CLI=/fast/tmp/smoke-0979/prefix/bin/atomic go test ./pkg/workflow -run Atomic -count=1 pass, including unit tests for adapter-version parity, pre-agent-steps staging, local store paths, durable session-ID recording and continuation, Turso/sqld settings generation, staging unlinking, secret redaction, and input rejections.
  • End-to-end local verification with published @bastani/[email protected] and @bastani/[email protected]:
    • Layer 1 & 2: Ran turn 1 through atomic_harness.cjs against a local mock OpenAI server, verified sessions.sqlite and session-id (0600) in /tmp/gh-aw/agent/atomic-store, ran actions/setup/js/durable_files.cjs (stageFiles -> validateFiles -> restoreFiles), and ran turn 2 with GH_AW_DURABLE_RESUMED=true; verified turn 2's LLM request included turn 1's user prompt and assistant response and appended to the same session_sessions row (message_count: 6).
    • Layer 3 + Intercom + .atomic/settings.json: Started a local sqld container (ghcr.io/tursodatabase/libsql-server), installed @bastani/[email protected] with the exact npm install command, ran two invocations through atomic_harness.cjs with ATOMIC_STORAGE=on and GITHUB_REPOSITORY=Owner/My-Repo.name, and queried sqld directly to confirm both sessions in gh_aw_owner_my_repo_namesession_sessions. Verified atomic storage status, atomic intercom status, and broker.log (Intercom multi-node routing is on (adapter ..., prefix gh_aw_owner_repo)), and verified .atomic/settings.json precedence both without and with a repository storage key under --approve.
    • Not verified: Hosted GitHub Actions workflow execution (actions/upload-artifact / restoreCheckpoint against live GitHub Actions APIs) and a live remote libsql://*.turso.io cloud endpoint over TLS/WebSocket.

});
}
writeConfig("mcp.json", mcp);
const resumed = process.env.GH_AW_DURABLE_RESUMED === "true";
const actionsDir = path.join(process.env.RUNNER_TEMP, 'gh-aw', 'actions');
const { validateFiles } = require(path.join(actionsDir, 'durable_files.cjs'));
validateFiles({ core });
- name: Upload durable checkpoint artifact
Base automatically changed from atomic-tools-schedule-storage to main November 12, 2026 04:33
GH_AW_ATOMIC_STORAGE_ADAPTER: /tmp/gh-aw/atomic-storage/node_modules/@bastani/atomic-storage-libsql/libsql.js
GH_AW_ATOMIC_STORAGE_STAGING: /tmp/gh-aw/atomic-storage-staging.json
durable:
files:
Save Atomic sessions, workflow journals, and run-scoped workflow artifacts under /tmp/gh-aw/agent/atomic-store on every run, declare behaviors.durable in shared/atomic.md so engine.durable restores that store and continues the saved root session, enable engine.durable on smoke-atomic, and add opt-in libSQL storage (@bastani/[email protected]) for Turso or self-hosted sqld.
@lavaman131
lavaman131 marked this pull request as ready for review November 12, 2026 05:09
@lavaman131
lavaman131 force-pushed the atomic-durable-storage branch from 0c2f13a to 149cb7a Compare November 12, 2026 05:09
Copilot AI adaptive review requested due to automatic review settings November 12, 2026 05:09
@lavaman131
lavaman131 added this pull request to stack #77068 November 12, 2026 05:09
} finally {
try {
const brokerPid = Number(readFileSync(join(agentDir, "intercom", "broker.pid"), "utf8").trim());
if (Number.isInteger(brokerPid) && brokerPid > 0) process.kill(brokerPid, "SIGTERM");

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

Dependency release-age protection is disabled, while colliding storage keys and missing exact session IDs can expose or resume another repository’s or workflow’s saved conversation.

5 open issues
What changed in this PR

Adds persistent session and workflow storage to the experimental Atomic engine, building on gh-aw’s durable checkpoint support and offering optional libSQL storage beyond artifact retention.

Changes:

  • Save local sessions, workflow journals, run artifacts, and root session IDs for checkpoint-based continuation.
  • Add optional Turso or self-hosted sqld storage, credential staging, and setup documentation.
  • Enable durable mode for the Atomic smoke workflow and expand regression coverage.
File Description
pkg/​workflow/​atomic_workflow_test.go Tests storage configuration, staging, durable continuation, redaction, and validation.
docs/​src/​content/​docs/​reference/​third-party-agent.md Documents Atomic persistence, external storage setup, and security considerations.
.github/​workflows/​smoke-atomic.md Enables durable checkpoints with seven-day retention.
.github/​workflows/​smoke-atomic.lock.yml Regenerates smoke execution with durable checkpoints and storage plumbing.
.github/​workflows/​shared/​atomic.md Implements local persistence, session continuation, and optional external storage.
.github/​workflows/​engine-conformance-atomic.lock.yml Regenerates conformance execution with storage plumbing, without durable mode.
.changeset/​patch-atomic-durable-sessions-and-storage.md Records the Atomic persistence and external-storage additions as a patch release.

Review effort: Max (auto)

Comment thread .github/workflows/shared/atomic.md Resolved
Comment thread .github/workflows/shared/atomic.md Outdated
if (/^[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?$/.test(recordedSessionId)) {
sessionArgs.push("--session", recordedSessionId);
} else {
sessionArgs.push("--continue");
Comment thread .github/workflows/shared/atomic.md Outdated
url: rawUrl,
token: rawToken,
namespace,
prefix: `gh_aw_${repository.toLowerCase().replace(/[^a-z0-9_]/g, "_")}`,
Comment thread .github/workflows/shared/atomic.md Outdated
Comment on lines +39 to +43
const install = spawnSync(
"npm",
["install", "--prefix", "/tmp/gh-aw/atomic-storage", "--ignore-scripts", "--no-audit", "--no-fund", "@bastani/[email protected]"],
{ stdio: "inherit" }
);
Comment thread .github/workflows/shared/atomic.md Outdated
Comment on lines +364 to +367
if (resumed && !forwardedArgs.some(arg => ["--session", "--session-id", "--continue", "-c", "--no-session"].includes(arg))) {
const recordedSessionId = existsSync(sessionIdPath) ? readFileSync(sessionIdPath, "utf8").trim() : "";
if (/^[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?$/.test(recordedSessionId)) {
sessionArgs.push("--session", recordedSessionId);
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot run pr-finisher skill

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot atomic should not install additional packages in the setup script. It should be define in the declarative yaml so that the compiler can instal these packages as part of installing the agent

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot there security implications to this. In particular, data is escaping the sa bd box without staging and the threat detection is coming too later to stop malicious session from polluting the database.

This feature must be an error in strict mode and a warning in normal compilation.

Copilot AI commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

@copilot there security implications to this. In particular, data is escaping the sa bd box without staging and the threat detection is coming too later to stop malicious session from polluting the da...

Addressed in fb3cf705: enabling engine.env.ATOMIC_STORAGE: "on" now fails compilation in strict mode and emits a warning otherwise, explaining that agent-controlled session/workflow data reaches the external database before post-run threat detection. Added strict/non-strict regression coverage.

@copilot atomic should not install additional packages in the setup script. It should be define in the declarative yaml so that the compiler can instal these packages as part of installing the agent

Addressed in 21e17ce3: the adapter is now declared under engine.behaviors.installation.additional-package-names and installed by the compiler at the effective Atomic version with the same npm cooldown and script policy. The pre-agent step only masks and stages credentials.

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot extend the declarative agentic engine syntax to support "durable-packages" to allow declaring additional packages that need to be installed when durable is enabled. Apply to atomic.

Copilot AI commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

@copilot extend the declarative agentic engine syntax to support "durable-packages" to allow declaring additional packages that need to be installed when durable is enabled. Apply to atomic.

Added behaviors.durable.durable-packages; these npm packages are installed at the effective engine CLI version only when durable mode is enabled. Atomic now declares its storage adapter there. Commit: 7c1b8abc.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot

🍳 A little prep to help this PR along! Copilot assignment requested for the following outstanding work:

  1. Update this branch with the latest main using make merge-main, resolving any conflicts and preserving the intended changes.
  2. Fix failing check lint-go-golangci (2) (FAILURE): Check run.

Keeping the changes focused; human review and CI get the final taste test. No merging or CI triggering.

Structured data
{
  "completed_task": 0,
  "head": "7c1b8abc84d2fe49d3fee50cdefbe0b9efbe3ba0",
  "kind": "requested",
  "schema_version": "1",
  "state": "596d233c3430acb34182a69d5154159f0a98267f4435ce498aeea398d8da01da",
  "work": [
    "20c5fb9e2e37672daf5b7271dae9c95ff59f03cf41d0cde5ac7e2acc9456d2d1"
  ],
  "workflow": "pr-sous-chef"
}

Generated by 👨🍳 PR Sous Chef · pi · routed: haiku55 xhigh · ~3 AIC · ⌖ ~2 AIC · ⊞ 6.9K · ◷
Comment /souschef to run again

# Conflicts:
#	.github/workflows/engine-conformance-atomic.lock.yml
#	.github/workflows/smoke-atomic.lock.yml

Co-authored-by: gh-aw-bot <[email protected]>
@lavaman131

Copy link
Copy Markdown
Contributor Author

Superseded by #77253 and #77262, which are small independent PRs against main with no stacking.

  • Storage: sessions are stored on GitHub Drives through tools.drive-memory instead of external libSQL/Turso/sqld storage. Drive memory stages the contents and publishes them only after threat detection accepts the run, which addresses the concern that data escaped the sandbox before detection could stop it.
  • Opt-in: durability is turned on in the workflow's own frontmatter (a drive-memory entry with id: atomic). shared/atomic.md only reacts to that, and there is no engine or compiler default, in line with Allow behavior-defined engines to default durable continuation on #77058.
  • Dropped:
    • the libSQL adapter and staging step, durable-packages and additional-package-names, atomic_external_storage_policy.go, and the schema changes;
    • behaviors.durable continuation and its JS tweaks;
    • persistence of the binary SQLite workflow journal, which cannot be redacted or validated before publication.

Closing in favor of those PRs.

@lavaman131 lavaman131 closed this Nov 13, 2026
Copilot stopped work on behalf of gh-aw-bot due to an error November 13, 2026 00:18
Copilot AI requested a review from gh-aw-bot November 13, 2026 00:18
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.

6 participants