Skip to content

Add comment-memory storage for ledgers - #77362

Merged
pelikhan merged 16 commits into
mainfrom
pelikhan/comment-memory-ledgers
Nov 13, 2026
Merged

pelikhan merged 16 commits into
mainfrom
pelikhan/comment-memory-ledgers

Conversation

@pelikhan

@pelikhan pelikhan commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Ledgers currently require Git-backed storage, even when a workflow already uses issue or PR comment memory. This adds storage: comment-memory so workflows can use the existing ledger operations against their configured comment-memory target.

Approach

  • Reuse transaction validation, canonical records, deterministic IDs, built-in reducers, JSONL parsing, segment validation, and authenticated-principal resolution for all six ledger types.
  • Persist readable JSONL in comments and reconstruct the same disposable, read-only /tmp/gh-aw/ledgers/<name>/ledger.db SQLite projection used by repo-memory for agent queries.
  • Publish every rotated shard in one immutable comment and one API request after complete state, size, and rendered-content validation. Reject malformed selected-ledger fences rather than restoring incomplete history.
  • Verify the publishing credential's numeric author identity before parsing. Neutralize reserved ledger languages in ordinary Markdown publication and ignore nested editable-memory fences, blocking managed same-publisher agent-comment forgery.
  • Keep comment writer credentials separate from Git ledger clients, share credential metadata and typed permission rendering, and reuse one early configuration write for projection and memory preparation.
  • Honor staged mode and the default-enabled group concurrency queue feature, emitting queue: max when enabled. Git remains the default backend.

Limits and trust boundary

JSONL batches are limited to 16 KiB and each ledger to 48 KiB total, without comment compaction. Targets must be literal issue/PR numbers or the triggering item. Opaque tokens fail explicitly when their publishing identity cannot be verified.

The agreed trust anchor is the verified publishing identity: holders of that credential are authorized writers, as with Git writer credentials. The managed-publication guards are not cryptographic authentication, and no separate signing key is required. Independent writers needing stronger isolation need a different credential or independently verified integrity mechanism.

Queue limits and workflow cancellation still apply; opting out of features.group-concurrency-queue restores pending-job replacement. Writers in different repositories sharing a target must coordinate externally.

Architecture decision

ADR: Comment-memory storage for ledgers. The ADR is complete and remains Proposed pending maintainer review.

Validation

Preserved concurrent remote review/CI fixes and main updates, resolved the overlapping rotation documentation, and fixed an incoming Unicode-unsafe schema excerpt with a failing-then-passing regression. Focused Go checks, 415 JavaScript tests, typechecking, build, the fast progress gate, and all 366 workflow drift checks passed. Safe-output conformance reported no critical or high failures, with existing medium/low warnings.

Regressions cover all six JSONL-to-SQLite round trips, rotation and atomic retries, forged/malformed untrusted shards, malformed selected fences, same-publisher managed publication, selected-token binding, credential separation, queue opt-in/out, single configuration writes, actionable validation errors, and UTF-8 preservation.

The full make agent-report-progress gate previously reported baseline custom Go lint diagnostics for sort.Strings in pkg/workflow/ledger.go and string-to-byte JSON decoding in pkg/parser/tools_merger.go; full test-unit was not repeated.

Reuse ledger transactions, canonical records, built-in replay and managed comment helpers. Store immutable bounded comment shards behind trusted persistence with target-scoped serialization.

Validation: focused compiler and JavaScript tests, typecheck, fast progress gate and workflow drift passed. The full gate is blocked by pre-existing custom Go lint diagnostics in ledger.go and tools_merger.go.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@pelikhan
pelikhan marked this pull request as ready for review November 13, 2026 05:42
Copilot AI adaptive review requested due to automatic review settings November 13, 2026 05:42
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

✅ Ponytail Reviewer completed successfully!

Generated by Ponytail Reviewer for #77362

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Code Quality Reviewer completed the code quality review.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

✅ Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Test Quality Sentinel · routed: haiku55 xhigh · ~1 AIC · ⌖ ~2 AIC · ◇ ~1 AIC · ⊞ 7.2K · ◷

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Specification Reviewer completed successfully!

Generated by PR Specification Reviewer for #77362

@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.

Reviewed the changed lines and related implementation paths. I found no actionable correctness, security, performance, or maintainability issues that warrant a blocking review comment. Static review only; tests were not run per review instructions.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~3 AIC · ⌖ ~1 AIC · ⊞ 1.6K
Comment /review to run again

@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.

What this change does: It adds comment-memory storage for ledgers while reusing ledger validation and projections. Git storage remains the default.

Should fix

  1. Write the configuration once (pkg/workflow/compiler_main_job_ledger.go:17)

    • What this is: The main job writes comment-memory configuration for ledger projection and later for memory preparation.
    • Problem: A comment-backed ledger causes the same configuration step to run twice.
    • Fix: Reuse the earlier write for both readers and skip the later step in that case.
    • If we skip it: Every affected run retains an unnecessary action and eight generated YAML lines.

Verdict: Ship.

Lean: -8 lines possible.

Generated by ✂️ Ponytail Reviewer for #77362 · codex · routed: gpt61 medium · ~12 AIC · ⌖ ~1 AIC · ⊞ 182
Comment /ponytail to run again

@github-actions

Copy link
Copy Markdown
Contributor

🏗️ Design Decision Gate — ADR Required

This PR makes significant changes to core business logic (>100 new lines) but does not have a linked Architecture Decision Record (ADR).

📄 Draft ADR committed: docs/adr/77362-add-comment-memory-storage-for-ledgers.md — review and complete it before merging.

🔒 This PR cannot merge until an ADR is linked in the PR body.

📋 What to do next
  1. Review the draft ADR committed to your branch — it was generated from the PR diff

  2. Complete the missing sections — add context the AI couldn't infer, refine the decision rationale, and list real alternatives you considered

  3. Commit the finalized ADR to docs/adr/ on your branch

  4. Reference the ADR in this PR body by adding a line such as:

    ADR: ADR-77362: Add comment-memory storage for ledgers (link unavailable: invalid HTTPS URL)

Once an ADR is linked in the PR body, this gate will re-run and verify the implementation matches the decision.

❓ Why ADRs Matter

"AI made me procrastinate on key design decisions. Because refactoring was cheap, I could always say "I'll deal with this later." Deferring decisions corroded my ability to think clearly."

ADRs create a searchable, permanent record of why the codebase looks the way it does. Future contributors (and your future self) will thank you.

📋 Michael Nygard ADR Format Reference

An ADR must contain these four sections to be considered complete:

  • Context — What is the problem? What forces are at play?
  • Decision — What did you decide? Why?
  • Alternatives Considered — What else could have been done?
  • Consequences — What are the trade-offs (positive and negative)?

All ADRs are stored in docs/adr/ as Markdown files numbered by PR number (e.g., 0042-use-postgresql.md for PR #42).

🏗️ ADR gate enforced by Design Decision Gate 🏗️ · pi · routed: haiku55 xhigh · ~3 AIC · ⌖ ~2 AIC · ⊞ 8.6K · ◷
Comment /review to run again

pelikhan and others added 4 commits November 12, 2026 21:51
Persist canonical JSONL directly in fenced comments and expose read-only ledger.jsonl files to agents instead of SQLite databases. Reuse shared JSONL parsing, segment validation, and built-in reducers, and reject publication transformations that would invalidate record hashes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Keep durable comment shards as readable JSONL while reusing the existing read-only SQLite projection, query guidance and built-in replay for agent access, matching repo-memory.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

@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.

Skills-Based Review 🧠

Applied /tdd, /codebase-design, and /grill-with-docs, guided by the pr-triage classification (new_feature). Requesting changes because two defects in the comment-memory ledger path are reproducible.

📋 Key Themes & Highlights

Blocking

  • Data loss on rotation: a batch that rotates the segment writer reports persisted: 3, but only the last shard is posted, so earlier records are unrecoverable.
  • Forged records accepted: materializeCommentLedger has no author check. A record with a correct sha256 planted in a comment is accepted into the ledger, and a malformed shard blocks every later persist.

Non-blocking

  • setup_comment_memory_files.cjs: a bad target-repo now throws and skips injectCommentMemoryPrompt. This changes behavior for existing comment-memory users.
  • ledger_job.go: permissions are upgraded with strings.Replace on formatted YAML.
  • compiler_main_job_ledger.go: unnecessary fmt.Fprintf to WriteString(fmt.Sprintf) churn.
  • The spec says nothing about rotation, so the immutability guarantee is unenforced.
  • The tests do not cover multi-segment rotation or planted shards.

Positive Highlights

  • ✅ Clear separation between the comment backend and the Git backend in appendLedgerRecords.
  • ✅ Size limits and staged mode fail closed.
  • ✅ The existing suite covers conflicting transaction IDs and corrupt-history diagnostics.

@copilot please address the review comments above, starting with the rotation data loss and the shard-author check.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~13 AIC · ⌖ ~2 AIC · ⊞ 6.6K
Comment /matt to run again

Comment thread pkg/workflow/ledger_job.go Resolved
Preserve upstream comment-memory transaction history alongside ledger tags and typed JSONL blocks, and regenerate maintenance configuration.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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

Critical ledger flaws can discard validated transactions, accept forged history, and silently restore incomplete state, risking data loss and failures in subsequent projections and writes.

6 open issues
What changed in this PR

Adds an optional comment-memory backend to gh-aw ledgers, allowing existing ledger operations and SQLite projections to use an issue or PR instead of a Git branch. Git remains the default backend.

Changes:

  • Add storage selection and validate comment-memory dependencies, targets, and compaction restrictions.
  • Integrate comment-backed restoration and persistence with token configuration, permissions, staged mode, and target-level concurrency.
  • Extend schemas, documentation, and tests for comment-backed and mixed-storage workflows.
File Description
pkg/​workflow/​ledger.go Adds backend configuration and comment-storage compaction restrictions.
pkg/​workflow/​ledger_test.go Tests configuration, compilation, and mixed-storage permissions.
pkg/​workflow/​ledger_job.go Wires persistence configuration, credentials, permissions, staging, and concurrency.
pkg/​workflow/​compiler_orchestrator_workflow.go Validates required comment memory and literal targets.
pkg/​workflow/​compiler_main_job_ledger.go Configures comment-backed projection preparation.
pkg/​parser/​tools_merger.go Recognizes scalar storage settings in single-ledger declarations.
pkg/​parser/​tools_merger_test.go Tests storage-setting and named-ledger recognition.
pkg/​parser/​schemas/​main_workflow_schema.json Defines supported storage values and configuration forms.
docs/​src/​content/​docs/​specs/​repo-memory-ledger-specification.md Documents comment-storage lifecycle, constraints, and limits.
docs/​src/​content/​docs/​reference/​frontmatter-full.md Adds the storage option to the frontmatter reference.
actions/​setup/​js/​setup_comment_memory_files.cjs Exposes shared target resolution and configuration loading.
actions/​setup/​js/​push_ledger_changes.cjs Shares append validation and dispatches persistence by backend.
actions/​setup/​js/​create_ledger_projection.cjs Restores comment-backed history before projection creation.
actions/​setup/​js/​comment_memory.cjs Supports a separate ledger tag in managed-comment rendering.
actions/​setup/​js/​comment_memory_ledger.test.cjs Tests all six ledger types, retries, limits, staging, and failures.
actions/​setup/​js/​comment_memory_ledger.cjs Implements comment scanning, shard restoration, and batch publication.
actions/​setup/​js/​comment_memory_helpers.cjs Parameterizes memory tags while preserving existing defaults.

Review effort: Max (dynamic)

Comment thread pkg/workflow/ledger_job.go Resolved
Publish all rotated JSONL shards atomically, verify authenticated comment authors with shared credential resolution, isolate comment writer tokens from Git-backed ledgers, reuse typed permissions and token metadata, remove duplicate setup configuration, and complete the ADR.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@pelikhan

Copy link
Copy Markdown
Collaborator Author

In reply to #77362 (comment)

Accepted the associated duplicate-step finding. The agent job now shares its early comment-memory configuration between projection and memory preparation, with focused regression coverage.

@pelikhan

Copy link
Copy Markdown
Collaborator Author

In reply to #77362 (comment)

No change needed for this notification. The associated static code-quality review reported no actionable findings.

@pelikhan

Copy link
Copy Markdown
Collaborator Author

In reply to #77362 (comment)

Reviewed and completed the generated ADR with concrete rationale, alternatives, and consequences, and linked it in the PR description. Its status remains Proposed pending maintainer review.

@pelikhan

Copy link
Copy Markdown
Collaborator Author

In reply to #77362 (comment)

No code change was requested by this notification. Independently added and ran focused regression coverage for shard rotation, untrusted comment authors, and the shared agent projection.

@pelikhan

Copy link
Copy Markdown
Collaborator Author

In reply to #77362 (comment)

Accepted the substantive findings from the completed skills review. Publication now preserves every rotated shard, and ingestion verifies the selected writer's identity instead of trusting a marker or arbitrary bot author; focused regressions cover both cases.

@pelikhan

Copy link
Copy Markdown
Collaborator Author

In reply to #77362 (comment)

No change was requested by this completion notification. The specification now explicitly describes readable JSONL comments, the shared read-only SQLite projection, and the rotation and authenticated-author invariants.

@pelikhan

Copy link
Copy Markdown
Collaborator Author

In reply to #77362 (comment)

Accepted. Completed the ADR's context, decision, alternatives, and consequences and linked it in the PR description, without claiming maintainer approval.

if data.LedgerConfig.hasCommentStorage() {
permissions.Set(PermissionContents, PermissionRead)
permissions.Set(PermissionIssues, PermissionWrite)
permissions.Set(PermissionPullRequests, PermissionWrite)
@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. Review (pkg/workflow/ledger_job.go:92): address unresolved feedback - Review comment
  3. Review (actions/setup/js/setup_comment_memory_files.cjs:76): address unresolved feedback - Review comment
  4. Review (pkg/workflow/compiler_main_job_ledger.go:21): address unresolved feedback - Review comment
  5. Review (docs/src/content/docs/specs/repo-memory-ledger-specification.md:183): address unresolved feedback - Review comment
  6. Review (actions/setup/js/comment_memory_ledger.test.cjs:151): address unresolved feedback - Review comment
  7. Review (actions/setup/js/comment_memory_ledger.cjs:51): address unresolved feedback - Review comment
  8. Review (actions/setup/js/comment_memory_ledger.cjs:45): address unresolved feedback - Review comment
  9. Fix failing check Compile queue phases (FAILURE): Check run.
  10. Fix failing check lint-go-golangci (1) (FAILURE): Check run.
  11. Fix failing check lint-go-golangci (2) (FAILURE): Check run.
  12. Fix failing check NVX musl inference integration (FAILURE): Check run.
  13. Fix failing check verify-integration-build (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": "b9c054bbf88adddf8935e0a0bbbf8ba010507518",
  "kind": "requested",
  "schema_version": "1",
  "state": "d9e09688cca754be2f5b4ff0517d5cb866ba55bf740fca19b5b0b51359742128",
  "work": [
    "06ee8ef38e1bf49770c3c40f5d967c6d3ebc0d603c155e141e7699b89abd64c0",
    "078e6675393ce6769eef2b960932783bb8847a81110a854e8704a80ae62c3a34",
    "12e2d92b8c5b535f1d3147e14962e78f9a50d376e8a16f13e4326968dc5aa3f5",
    "1612451f13c5d54618082aa0d5b67fe89e2c3d1f16e5cfc6506fa9a24c2e9a24",
    "20c5fb9e2e37672daf5b7271dae9c95ff59f03cf41d0cde5ac7e2acc9456d2d1",
    "57b160f058c0cf0ae8470606e768b98956d9e31df7d52cc35017efdeeaeffab1",
    "59286ccd5b9a5d99c99f1f6ee41b805e9b73c298ad70c14863196bf31fdbf8da",
    "61de1bdb227e3731911529f00f65e50933350c026742f49b33b6e8ffdc2c92c9",
    "b946191b4d48ccbefd5245ab587c85f3a18094d252eac07de64953ec17d71dcc",
    "c03fdf64ae0afb7631cc55db5ec7e4057557a32c5aff692ff4c20c9d7a061fc0",
    "cabafb2817b103330ac0d1e2e098f214c40c4ca2be128895a8b14391f7e3306f",
    "e12f3ca123426c7ce7fac5980fecb0c13ba9a8c82172ef9a9c5c18b414b029f6"
  ],
  "workflow": "pr-sous-chef"
}

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

Copilot AI and others added 3 commits November 13, 2026 06:57
…ry-ledgers

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
@pelikhan

Copy link
Copy Markdown
Collaborator Author

@copilot enable comment memory tool ledger in some of the agentic workflow reviewers

pelikhan and others added 4 commits November 13, 2026 04:47
Reject malformed selected-ledger fences, prevent managed agent comments from emitting reserved ledger blocks, honor group concurrency queue policy, and make validation diagnostics actionable. Document the verified-publisher trust boundary selected for this backend.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Preserve incoming review and CI fixes, combine the rotation specification, and keep schema prompt truncation Unicode-safe with a focused regression.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Compile Markdown fixtures for comment-only, imported mixed-storage, staged queue opt-out, and default Git ledgers. Inspect generated YAML for cross-job configuration, permissions, credentials, ordering, queue policy, and transaction artifact handoff.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@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 push_ledger_changes (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": "81f9e94be8d4ca1aa9d714d84ff9efa909763a7c",
  "kind": "requested",
  "schema_version": "1",
  "state": "65d32e780a57d155660b3d68d3ca70e2f5c36c7829f7160217b77b2a2976c517",
  "work": [
    "2ec1c55a56c3bbc3d439b0f0d819e0f964a9c8ea5c8bbe45cc9676c7e7802a18"
  ],
  "workflow": "pr-sous-chef"
}

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

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

@copilot enable comment memory tool ledger in some of the agentic workflow reviewers

Both PR reviewer workflows now enable comment-memory ledgers for review history. This was implemented in 81f9e94.

@pelikhan
pelikhan merged commit 910cd8c into main Nov 13, 2026
85 of 86 checks passed
@pelikhan
pelikhan deleted the pelikhan/comment-memory-ledgers branch November 13, 2026 13:56
Copilot stopped work on behalf of gh-aw-bot due to an error November 13, 2026 13:56
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v1.3.0

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.

5 participants