Skip to content

feat(memory): support inline-with-candidate apply and converge auto-sync - #41

Merged
thxCode merged 3 commits into
mainfrom
feat/memory-inline-and-auto-sync
Nov 22, 2026
Merged

thxCode merged 3 commits into
mainfrom
feat/memory-inline-and-auto-sync

Conversation

@thxCode

@thxCode thxCode commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add spec.memory.apply: 'inline-with-candidate' across @loopwright/taskpack, @loopwright/cli, and @loopwright/github-app:
    • Preserves the memory trust boundary: memory.directory remains strictly non-writable during untrusted agent turns and verification.
    • Exposes PublishedCandidatePullRequest metadata from NativePullRequestPublisherServer and forwards it to finalizeAndPublishTurnkeyMemory.
    • Skips cleanly (no_candidate_pull_request) whenever no candidate PR was published (no_change, failed, blocked, or publication.mode: disabled), eliminating standalone shadow memory PRs.
    • When a candidate PR is published, validates the memory proposal through the same five-gate CAS checks, confirms managed memory paths were untouched by the candidate commit, builds a memory-only commit on top of the candidate PR head (skipCi defaults to false so branch-protected PR checks still execute, with DCO Signed-off-by), and pushes with --force-with-lease onto the same PR branch.
    • Fails closed locally (TASKPACK_HOST_BINDING_INVALID) in finalizeLocalTurnkeyMemory and loopwright run --taskpack when no GitHub PR publisher is bound.
  • Converge Loopwright's own .auto-sync/taskpack.yaml, .auto-sync/instructions.md, .auto-sync/digests.lock.json, and .github/workflows/auto-sync.yml:
    • Unify taskpack metadata (metadata.name: auto-sync, auto-sync-verify, memory.directory: .auto-sync/memory/auto-sync, apply: inline-with-candidate, titleTemplate: "chore(deps): auto-sync runtime dependencies"), remove stale .auto-sync/memory/self-upgrade/ entries, and drop the legacy vars.SELF_UPGRADE_RUNNER fallback.
  • Update configuration, operations, and contributor documentation (docs/configuration/taskpack.md, docs/operations/github-action.md, docs/operations/cli.md, docs/contribute/memory.md, docs/contribute/github-app-internals.md, docs/references/bootstrap-interview.md).

/kind feature
/area memory
/area github-app
/area cli
/area docs

Verification

  • npm run build
  • npm run typecheck
  • npm run lint
  • npm run lint:docs
  • node scripts/prepare-self-upgrade.mjs --offline-check and digest sync --check
  • Targeted tests (turnkey-memory.test.js, schema.test.js, turnkey.test.js, step-cli.test.js, docs-and-site.test.js, self-upgrade-taskpack.test.js, self-upgrade-verifier.test.js)
  • Signed-off-by DCO trailer present on all commits

@gpustack-code-review

gpustack-code-review Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

🔍 OpenCodeReview found 1 issue(s) in this PR.

  • ✅ Successfully posted inline: 0 comment(s)
  • 📋 Routed to summary by policy: 1 comment(s)

maintainability · low

📄 packages/github-app/src/turnkey-memory.ts (L780-L795)

⚠️ GitHub could not post this as an inline comment: Routed to summary (severity low · category maintainability)

This refused-summary literal duplicates the one at lines 811–821 field-for-field (only reason differs). Consider extracting a small local helper, e.g. buildRefusedReceipt(existingReceipt, reason) that applies scrubTurnkeyReason, so the two refusal paths can't drift apart if the summary shape gains fields.

Reviewed 5260cfb..14172f4 only; earlier commits in this PR were reviewed in a previous run.

Comment on lines +773 to +775
const expectedReceiptBranch = isInlineMode
? (candidatePublication?.branchName ?? existingReceipt.branchName)
: memoryBranch;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

bug · high
Receipt replay can accept a stale receipt written by a different memory apply mode. In inline mode with candidatePublication === null, expectedReceiptBranch falls back to existingReceipt.branchName, so validateReceiptBindings is fed the receipt's own branch and trivially matches — e.g. a receipt from a prior separate-pull-request run on the default loopwright/memory/<taskpack>/<targetBranch> branch would be replayed as published even though inline mode never writes that branch. Suggestion: when isInlineMode && candidatePublication === null, treat any existing receipt as a binding mismatch (or reconcile_required) instead of falling back to the receipt's own branch.

Suggestion:

Suggested change
const expectedReceiptBranch = isInlineMode
? (candidatePublication?.branchName ?? existingReceipt.branchName)
: memoryBranch;
const expectedReceiptBranch = isInlineMode
? (candidatePublication?.branchName ?? null)
: memoryBranch;
if (expectedReceiptBranch === null) {
return Object.freeze({
status: 'refused',
/* ... reuse mismatch payload ... */
});
}

Comment on lines +1459 to +1463
branchName: memoryBranch,
pullRequestUrl: null,
pullRequestNumber: null,
reason: 'GitHub credentials, API URL, or git remote unavailable for separate memory PR publication',
pullRequestUrl: candidatePublication?.pullRequestUrl ?? null,
pullRequestNumber: candidatePublication?.pullRequestNumber ?? null,
reason: isInlineMode
? 'GitHub credentials or git remote unavailable for inline memory commit'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

bug · medium
Misleading summary on the local_only fallback: when inline mode lacks credentials/remote, nothing is appended to the candidate PR, yet the summary reports branchName: memoryBranch (the candidate branch) and the candidate's pullRequestUrl/pullRequestNumber. Downstream consumers (action.ts / CLI reporting) will present this as if the memory commit landed on the open PR. Suggestion: in inline mode return branchName: null (or the default memory branch) and null PR fields on this fallback, keeping the URL only for statuses where the push actually happened.

Signed-off-by: thxCode <thxcode0824@gmail.com>
Comment on lines +791 to +797
?? validateReceiptBindings(existingReceipt, {
repositoryFullName: options.repositoryFullName,
taskpack,
targetBranch,
memoryDirectory,
memoryBranch: expectedReceiptBranch!,
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

maintainability · medium
The non-null assertion expectedReceiptBranch! is only safe because of the subtle short-circuit ordering: when inline mode has no candidate publication, inlineReceiptBranchInvalid is true so the ?? chain returns before validateReceiptBindings runs. This invariant is fragile — any future reordering of the nullish chain or the invalid check would silently pass null into receipt binding validation, which is security-sensitive trust-boundary logic. Prefer making the nullability explicit, e.g. branch the inline-null case into its own early return, or pass expectedReceiptBranch ?? memoryBranch with a comment.

Suggestion:

Suggested change
?? validateReceiptBindings(existingReceipt, {
repositoryFullName: options.repositoryFullName,
taskpack,
targetBranch,
memoryDirectory,
memoryBranch: expectedReceiptBranch!,
})
if (isInlineMode && expectedReceiptBranch === null) {
return Object.freeze({
status: 'refused',
/* ...existing fields... */
reason: scrubTurnkeyReason('inline memory receipt cannot be replayed without matching candidate pull request publication', scrubber),
});
}
const bindingMismatchReason = (inlineReceiptBranchInvalid
? `inline memory receipt branch "${expectedReceiptBranch}" is invalid or targets "${targetBranch}"`
: null)
?? validateReceiptBindings(existingReceipt, {
memoryBranch: expectedReceiptBranch,
})
?? retainedRunMismatch;

Signed-off-by: thxCode <thxcode0824@gmail.com>
@thxCode
thxCode merged commit a595aea into main Nov 22, 2026
15 checks passed
@thxCode
thxCode deleted the feat/memory-inline-and-auto-sync branch November 22, 2026 09:55
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.

1 participant