Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix: secret gate on managed Git effect pushes (#8896)

garrytan6f5dedf2f180
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d92f884578..a4d377284e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,17 @@ identifiers and attribution are available in the pre-removal Git revision
## [Unreleased]
+**The Git effects of page writes no longer publish a script's secret.** A script that commits into a managed checkout with plain `git commit` never passes the write path's secret scan. The refresh publish refused such a commit with `publish_secret_found`, but the next page write's Git effect pushed it anyway: its plain push published every unpublished commit unscanned, and when the remote had moved its keep-checkout publish ran without the scan. Both paths now scan the exact commits they push. A value that looks like a secret, added text too large to scan, a commit that changes `.gbrain-scan-allow` or a `.gitattributes`, or a range git cannot list (no tracking ref, or a remote without the branch) holds the effects with `publish_secret_found`. Nothing is pushed, and the page writes stay safe in the database and in local commits. `gbrain sync status` and doctor name the user's choice: remove the value from those commits, or allowlist a false positive by fingerprint. Then `gbrain sources writer retry-effects <source> --parked-pushes` runs the effects that parked. Every scanned push is also leased on the remote tip it scanned against. Before, a remote rewound past a pushed secret (an admin removing it with a force-push) left a stale tracking ref that hid the commit from the scan, and the next fast-forward put it back; now the scan runs against the remote's real tip.
+
+### Itemized changes
+
+- `src/core/persistence/effect-git.ts`: `pushGitRoot` reads the remote branch tip with `git ls-remote`, scans `<tip>..<HEAD sha>` and pushes that sha only as a fast-forward of the tip, leased on it; a tip that is not an ancestor, or a remote that moves before the push lands (`stale info`), goes to the keep-checkout publish, which now runs with `--scan-secrets`. A remote without the branch refuses. A refusal from either path holds the effects as `publish_secret_found` with the user's fix.
+- `src/core/git/commit-push.ts`: a `scanSecrets` publish scans `<base>..<candidate>` before every push and leases the push on that base, so each merge with a newly fetched remote tip is scanned again.
+- `src/core/git/range-secret-scan.ts`: `rangeSecretRefusal`, the one `publish_secret_found` refusal both callers throw.
+- `src/core/persistence/git-push-holds.ts`: `publish_secret_found` is a held push code, so doctor, `gbrain sync status` and `retry-effects --parked-pushes` cover it, with an ask-the-user fix that lists the refused commits.
+- Docs: `docs/guides/shared-checkout-git.md` (`publish_secret_found` row), `docs/guides/live-sync.md`.
+- Tests: `test/effect-git-secret-gate.test.ts` (an ahead checkout, a diverged one, a remote rewound past a pushed secret and a remote without the branch each refuse with nothing pushed; a clean ahead checkout pushes; through the effect worker the page write's effect holds, sync status names the fix, and an allowlisted false positive releases it); `test/guarded-publish.test.ts` (a remote rewound past a pushed secret is not published again); `test/git-literal-pathspec-hooks-7759.test.ts` publishes its probe `.gitattributes` commit first, since the effect's push now refuses one; `test/cli-flag-equals.test.ts` lists `range-secret-scan.ts` as a git child argv reader.
+
**A diverged managed checkout now publishes its local commits on refresh by default when Git durability is on, after a secret scan of those commits.** Commits a script made with plain `git commit` in a managed checkout used to strand there whenever the remote moved: every `gbrain sources refresh` refused `refresh_diverged` and asked the user, unless `sources.refresh_publish_diverged` was set to `true`. With the setting unset, a worktree whose Git durability is on (`gbrain sources writer git-durability <source> --enable`, or the legacy hook) now publishes them itself: the local commits merged with the upstream in memory, never a rebase or force-push, then the fast-forward. The publish child scans, under its publish lock and for the exact commits it pushes, what they add: commit messages, added lines (including a value a later commit removed) and merge-commit conflict resolutions. A value that looks like a secret, added text too large to scan, or a commit that changes `.gbrain-scan-allow` or a `.gitattributes` refuses the new `publish_secret_found` naming the file, line, rule and commit, never the value, with nothing pushed. The rewritten-upstream refusal and the `--expect-remote` bound are unchanged. `false` turns it off; `true` still publishes with durability off.
### Itemized changes
diff --git a/docs/guides/live-sync.md b/docs/guides/live-sync.md
index fdb96705f9..4d6ce655bc 100644
--- a/docs/guides/live-sync.md
+++ b/docs/guides/live-sync.md
@@ -697,6 +697,9 @@ vars — incident-time escape hatches, not everyday knobs.
file the upstream changed refuses `refresh_dirty` before anything is pushed,
an upstream rewritten by a force-push (or one gbrain has no earlier record
of) still refuses `refresh_diverged`, and `--dry-run` never publishes.
+ The Git effects of page writes push the same local commits with the same
+ scan: a script's commit holding a secret holds them with `publish_secret_found`
+ and nothing is pushed until the user removes it or allowlists a false positive.
**Say to your agent:** *"Bring my notes source up to date with its remote."*
diff --git a/docs/guides/shared-checkout-git.md b/docs/guides/shared-checkout-git.md
index 6f9e273c0e..f28954716a 100644
--- a/docs/guides/shared-checkout-git.md
+++ b/docs/guides/shared-checkout-git.md
@@ -185,7 +185,7 @@ Follow the error's `fix.next` as the
| `git_index_stale` | 1 | An `index.lock` older than 10 minutes blocks the checkout. Check that no git command is running there, tell the user, and remove the named lock file only with their agreement. |
| `git_operation_in_progress` | 1 | A rebase, merge, cherry-pick or revert is unfinished in the checkout. gbrain never aborts it for you. Follow [stuck rebase](#stuck-rebase). |
| `git_detached_head` | 1 | The checkout is on a detached HEAD or an unborn branch. Check out the branch the remote tracks (`git switch <branch>`), or make the first commit, then rerun. |
-| <a id="publish_secret_found"></a>`publish_secret_found` | 1 | Only with `--scan-secrets` (the publish `gbrain sources refresh` runs on its own): a commit about to be pushed adds a value that looks like a secret, in its message, an added line (even one a later commit removed) or a merge resolution, adds text too large to scan, or changes `.gbrain-scan-allow` or a `.gitattributes` (files that decide what the scan sees); nothing was pushed. The message names each file, line, rule and commit, never the value. Ask the user: remove the value from those unpushed commits, or add a false positive's fingerprint to `.gbrain-scan-allow`, then retry. Never publish them with a command that skips the scan. |
+| <a id="publish_secret_found"></a>`publish_secret_found` | 1 | Only with `--scan-secrets`, which every automatic publish uses: the one `gbrain sources refresh` runs on its own and the push of a managed worktree's Git effects. A commit about to be pushed adds a value that looks like a secret, in its message, an added line (even one a later commit removed) or a merge resolution, adds text too large to scan, or changes `.gbrain-scan-allow` or a `.gitattributes` (files that decide what the scan sees), or the range cannot be listed (a missing tracking ref, or a remote without the branch); nothing was pushed. The message names each file, line, rule and commit, never the value. Ask the user: remove the value from those unpushed commits, or add a false positive's fingerprint to `.gbrain-scan-allow`, then retry. Never publish them with a command that skips the scan. On a managed worktree its Git effects hold meanwhile (`gbrain sync status` and doctor list them; the page writes are safe in the database and in local commits); after the fix, `gbrain sources writer retry-effects <source> --parked-pushes` runs the ones that parked. |
| `integrate_conflict` | 1 | Local and remote commits changed the same file; nothing was merged and the checkout is unchanged. Stop, relay the question to the user, then [resolve](#conflicts). |
| `push_unconfirmed` | 4 | The commit is durable locally but no push destination confirmed it (network, credentials, branch protection, a remote that kept moving, or another push that held the push lock for the whole wait). Fix what the message names, then run `gbrain git commit-push --push-only`. Never force-push. |
| `writer_coordinator_required` | 1 | This is a managed worktree. Stop using git for pages; save them through `put_page` and the other gbrain write tools. |
diff --git a/llms-full.txt b/llms-full.txt
index b8356e3356..b3b08aab62 100644
--- a/llms-full.txt
+++ b/llms-full.txt
@@ -7702,6 +7702,9 @@ vars — incident-time escape hatches, not everyday knobs.
file the upstream changed refuses `refresh_dirty` before anything is pushed,
an upstream rewritten by a force-push (or one gbrain has no earlier record
of) still refuses `refresh_diverged`, and `--dry-run` never publishes.
+ The Git effects of page writes push the same local commits with the same
+ scan: a script's commit holding a secret holds them with `publish_secret_found`
+ and nothing is pushed until the user removes it or allowlists a false positive.
**Say to your agent:** *"Bring my notes source up to date with its remote."*
diff --git a/scripts/module-size-limits.tsv b/scripts/module-size-limits.tsv
index 91c4fa72d0..046792bb32 100644
--- a/scripts/module-size-limits.tsv
+++ b/scripts/module-size-limits.tsv
@@ -47,4 +47,4 @@ src/commands/doctor/checks/extraction-sync.ts 1500 ratchet +7 GBRA-130 A-1: link
src/core/search/evidence-delivery.ts 1759 ratchet +5 W5: EvidencePlan.rankCut resolved with the plan (logic in search/page-rank-cut.ts); +20 W5 whole_pages: wholeCost prices a block as delivery would emit it whole (needs the private Block/enrichBlock internals) and the cut is wired before allocate (cutWholePages lives in search/page-rank-cut.ts); new row: crossed the 1500 unlisted cap at the #6367 merge (master 1479, its explicit-budget cap) by the C1 date header threaded through every block path, cap included; pagePlanHits (search/page-plan-hits.ts) and the header loader (evidence-date.ts blockDateHeaders) were peeled first; peel candidate: allocateCapped; +8 at the #6396 merge: page evidence text cut through the fence-chunk trust overlay and the caller minTrust floor (re-summed: our 1504 + master +8); +119 Cat 40 next wave F2: the search.long_page_unit policy (withLongPagePolicy, selectLongPages size preflight with page/byte/deadline limits) and the long-page fetch and fallback in deliverEvidence, kept in the shared seam the plan names (gbrain-evals docs/plans/2026-10-11-cat40-next-wave, F2); +17 F2 rework to the frozen-comparison policy: search.long_page_min_chars (rendered-body characters, default 20,000) read in withLongPagePolicy, a character count in the preflight, the rendered-body confirmation in deliverEvidence, and the long-page row exemption in capDeliveredSnippets (re-summed at the 0.60.225.0 merge: master 1537 + F2 136); +39 Wave B PR 2 lane 2b: planSegmentedBlock joins the windows search/segmented-evidence.ts reads around a segmented page's hits into one run-marked document (needs the private Doc/Piece/buildDoc/locateAnchor internals), planBlock's unit cut split into blockFromDoc for both, sections bounded by their run, selectionCost counts a gap between runs, and the fetch skips the whole-body fence overlay for a segmented page; +4 segmented pages read at once before planning (segmentedReads; the read is search/segmented-evidence.ts, the statements page-body/read-range.ts); +17 GBRA-156: tail trim plan flag, DeliverOptions.query, DeliveryMeta.tail_trim, the trim call and the frozen-hit score/query library fields (logic in search/evidence-tail-trim.ts; interface fields cannot move); +7 GBRA-205: EvidencePlan.titleHeader and DeliveryMeta.title_header (interface fields cannot move) and the titles option on the header loader (logic in search/evidence-date.ts; the query budget key lives in search/evidence-packing.ts); +11 #7600: assemble_evidence quotes conversation rows and capEvidenceToBudget counts the quote fence (logic in search/transcript-quote.ts); +2 GBRA-156 /ship review: the cut-path admission and title room count the quote fence; +2 GBRA-156 /ship review pass 2: capEvidenceToBudget counts the fence only for the paths that fence (quote flag; recall counts the text as returned); +4 GST-687: page evidence and the extractive fallback quote below-owner-tier text for untrusted readers (untrusted flag; logic in search/transcript-quote.ts)
src/commands/config.ts 1526 ratchet +1 GBRA-216: recall.* config set value refusal (facts/recall-config.ts); +1 GBRA-216: config set refuses a dream.claim_conflicts.mode other than propose|off (refusal in facts/claim-conflicts.ts); new row: crossed the 1500 unlisted cap in wave 15 P7.4 #5461: set-time validation of think.pages_budget_chars / think.excerpt_ceiling_chars (range + parser live in core/think/pages-budget.ts), mirroring the cycle.consolidate.cluster_threshold hook; +1 wave 16 G5.1 (#6495): set-time refusal hook for search.keyword_statement_timeout_ms (check lives in commands/config/keyword-timeout-value.ts); +1 wave 18b lane 5 (#5012 item 6): search.contextual_retrieval prints the existing-pages hint after the write (text lives in commands/config/contextual-mode-hint.ts); +1 #6712 PR 2: retired/rollback sync key dispatch line (logic in core/sync-config-keys.ts handleSyncKeyConfig); +1 #6865: sync.slug_conflicts.auto_remove boolean validation at set time (refusal text in repair/slug-autoheal.ts); +1 #6948: sync.origin_twins.auto_resolve boolean validation at set time (refusal text in repair/origin-twins-heal.ts); +2 #6795: config set chat_model/expansion_model help line and the model-pin import (shadow report and file-pin unset live in commands/config/model-pin-shadow.ts); +1 #6712 PR 4b: sync.admission set-time hook (value logic in commands/config/sync-admission-value.ts); +4 #7130: set-time refusal hook for sync.max_deletes / sync.max_delete_ratio (and .source.<id>) / purge.retention_hours (check lives in core/sync-reconcile.ts deleteSafetyConfigRefusal); +1 GBRA-150: sync.metafile_pages set-time route (body in config/sync-metafile-pages-value.ts); re-summed at the v0.60.330.0 merge (1520 measured); +2 #7242 minions.terminal_hook file-plane key and its set branch (logic in minions/terminal-hook.ts); +1 GBRA-161: generations.* set-time route (refusal in commands/config/generations-values.ts); +1 GBRA-207 #7630: sync.repo_path set-time refusal hook (refusal in core/sync-config-keys.ts syncRepoPathRefusal)
src/commands/mcp-expose.ts 1519 ratchet hosted_option: Session carries the gbrain.io coaching notice on the first-receipt run and Tailscale/service friction exits (copy, refs and gating live in core/onboard/hosted-option.ts); +7 GBRA-199: --surface help lines, surfaceChosen option field and the advertise pass-through (registrationAdvertise in core/mcp-registration.ts)
-src/core/behavior-change-notice.ts 1687 ratchet +4 train R: #7491/#7492 keyword_identifier_probe and keyword_slug_handles rows and their comment, #7175 keyword phrase row; the BEHAVIOR_CHANGES table grows by one row per disclosed change: +4 the #7891 provenance-drift and #7917/#7918 maintenance-lowering rows and their comments (re-summed at the 0.60.495.0 merge: 1547 + 4); +1 GBRA-156 #7593: private_pages_granted_sources row (re-summed at the 0.60.527.0 merge: 1574 + 1); +3 GBRA-200 comment, write-grant refusal and degraded-stamp rows (re-summed at the 0.60.562.0 merge: 1615 + 3); +2 GBRA-280 get_page selector-precedence row and comment (re-summed at the 0.60.569.0 merge: 1619 + 2); the BEHAVIOR_CHANGES table grows by one row per disclosed change: +4 the #7891 provenance-drift and #7917/#7918 maintenance-lowering rows and their comments (re-summed at the 0.60.495.0 merge: 1547 + 4); +2 GBRA-205 saved_facts_stems row and its comment (re-summed at the #7901 0.60.492.0 merge: 1541 + 2); +2 GBRA-205 search.query_facts_block default-on row and its approval comment (re-summed at the #7610 0.60.490.0 merge: 1539 + 2); +2 the #7900 content checkpoint host-move row (since TBD until the merge slot), +2 the #7897 private-hold sweep row (since TBD until the merge slot), +2 the #7880 ingest_capture and company-brain private-hold row (since TBD until the merge slot), +5 the frozen-source wave comment and four rows (#7868, #7850, #7869/#7870, #7871), +2 the #7848 visibility_noncanonical hold row (since TBD until the merge slot), +2 the #7846 extract_atoms session-source row (re-summed at the 0.60.481.0 merge: master 1524 + 2), +2 the #7805 synthesize session-source and #7841 visibility_not_applied rows (re-summed at the 0.60.480.0 merge: master 1522 + 2), +2 strict door planned-state row (#7705, re-summed at the 0.60.470.0 merge: master 1514 + 2), +2 Bun floor 1.4.4 row (#7644), the GBRA-95 RLS backfill row (+2), +3 rows for #7596 pass_interrupted, #7599 read-only serve and the --access=read-only ceiling, +1 G5 lane C trust_release row, +1 #7619 cli_flag_equals, +3 GBRA-207 #7630 relative-anchor and stalled-write rows, +2 the #7632 function search_path disclosure row and +2 the #7679 orphaned worktree refresh row (re-summed at the 0.60.471.0 merge: master 1516 + 2), +2 the #7814 retired v0.13.1 grandfather row, +2 the #7618 conversion withhold/progress/push row (master 1520 + 2); the behavior-change table split (#7607) retires this row; +4 GBRA-188 #7489: the wave comment and three rows (brain-first instructions, starter surface default, per-turn rule); +1 GBRA-188 plugin_turn_hook_gbra188 row; +1 GBRA-242 provider_key_rules_7959 row (#7959), +2 the GBRA-199 registration_lists_verbs row (since TBD until the merge slot); +2 GBRA-133 #7652: the #7611 pass_abandoned reader row and the lean read-only serve socket row (re-summed at the 0.60.503.0 merge: master 1555 + 2); +1 GBRA-243: the per-turn hook disclosure row (rows are data and cannot move); +4 GBRA-156 #7598 harness wave comment and rows (remote page cap, sources_not_readable refusal, sources add next step); +4 GBRA-156 #7601 search_quotes_transcript_rows comment and row; +1 GBRA-175 #7475 autopilot_restarts_serve_7475 row (re-summed at the #8012 merge: 1566 + 1); +3 #7997/#8014/#8015 rows (redaction markers, company db_only keep, ignored supabase_only scope); +2 #7199 (re-port of #7228) classic_drift_rescreen_7199 comment and row; +2 #7931 file_drift_agrees_7931 comment and row; +1 #7950 file_drift_slug_release_7950 row; +1 #7974 file_drift_followups_7974 row; +1 #8059 quoted_fence_marker_8059 row; +2 GBRA-247 #8009 provenance_repair_held_8009 and #7982 pass_transient_streak_7982 rows; +4 GBRA-247 #7973 plain_directory_sync_7973, #7988 managed_marker_own_directory_7988, #7985 former_binding_parked_group_7985 and settle_effects_retire_7985 rows Train S merge: 1570 base + 5 (master since the #8077 base) + 13 (#8077) = 1588.; +2 GST-687 remote_quotes_unverified_text_gst687 row and its comment (re-summed at the gate-ahead on train S 0.60.534.0: 1588 + 2); +2 #8377: the quote fence follow-ups row and its comment; +2 #8384: the quote fence follow-ups 2 row and its comment; +2 #8384 wave 3: the quote fence follow-ups 3 row and its comment; +5 GBRA-218 train M rows (A1 member_read_access_gbra218 and member_access_hatch_scope_gbra218, B shared_agent_audience_gbra231, A2 folder_access_rules_gbra218, folder_access_scoped_role_gbra218), re-summed at the train M merge of master v0.60.541.0: 1596 + 5 = 1601 measured; +3 GST-359 train C rows (C1 qm_attested_actor_gst359, C2 member_facts_gst359, D qm_memory_provider_gst359), re-summed at the train C merge of master v0.60.543.0: 1601 + 3 = 1604 measured; +2 #8424: hook_launcher_8424 row and its comment (rows are data and cannot move), re-summed at the #8418 v0.60.546.0 merge: 1604 + 2 = 1606 measured; +2 #8426: mcp_lane_launcher_8426 row and its comment (rows are data and cannot move); +2 GST-927: empty_nonstring_args_gst927 row and its comment, re-summed at the gate-ahead on master v0.60.550.0 plus #8420: 1610 measured; +2 GBRA-283 Wave A (#8460): engine_keyed_caches_gbra283 row and its comment (rows are data and cannot move); +2 GBRA-287: segmented_freeze_hold_gbra287 and segmented_reexport_gbra287 rows (rows are data and cannot move); +1 GST-1209: segmented_tiling_gst1209 row (rows are data and cannot move); +1 GST-1251: skillopt_loop_deprecated_gst1251 row (rows are data and cannot move); +1 GST-1209 follow-up: untiled_hold_repair_gst1209 row (rows are data and cannot move); +1 GBRA-283 B3a: embedded_scope_required_gbra283 row (rows are data and cannot move); re-summed at the train R merge with v0.60.574.0: 1623 + 4; +2 GST-1387: refresh_fence_refusal_gst1387 row and its comment (rows are data and cannot move); re-summed at the memory train #8481 merge with v0.60.578.0 (1643 measured); +3 GBRA-253 #8109 rows (frontmatter_drift_write_8109, contacts_activity_advance_8109, contact_rows_dedupe_8109; rows are data and cannot move), re-summed at the master v0.60.581.0 merge: 1643 + 3 = 1646 measured; +3 #8123 part C rows: sync_write_through_off_writeback_7084, managed_sync_dry_run_counts_7087, frontmatter_missing_source_dir_7889 (since TBD until the merge slot; re-summed at the 0.60.583.0 merge: 1646 + 3); +4 PR B commit_ledger_prb, doctor_foreign_writers_prb and sources_guard_prb rows and their comment (rows are data and cannot move; since TBD until the merge slot); +1 PR B #8615: file_drift_held_needs_prefer_8615 row; +1 PR B #8617: refresh_source_changed_retry_8617 row; +1 PR B #8662: commit_push_checkout_not_a_source_8662 row (since TBD until the merge slot; rows are data and cannot move); +2 PR B refresh_barrier_prb and commit_push_base_prb rows (re-summed: 1658 measured); +3 convergence PR A: the wave comment and two rows (conversion_content_evidence_pr_a, git_gap_live_pages_pr_a; since TBD until the merge slot; rows are data and cannot move); re-summed at the gate-ahead on master v0.60.592.0 plus #8711: 1658 + 3 = 1661 measured; +4 GST-1094/GST-900 rows (memory_recall scope-read, member-bound acting_user, recall max_chars, unknown_param _meta-only) and +1 qm_scope_writes_gst1113 and +1 recall_question_terms_gst1304 rows (rows are data and cannot move), re-summed at the 0.60.595.0 slot merge: 1661 + 6; +1 GST-1582 refresh_barrier_import_gst1582 row (since TBD until the merge slot; rows are data and cannot move); +2 GST-1601 source_changed_origin_gst1601 and adopt_local_edits_gst1601 rows (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.596.0 merge: 1668 + 2; +1 GST-1623 refresh_barrier_capacity_gst1623 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.599.0 merge: 1670 + 1; +2 GBRA-224 W1 release_channel_stable_default row and its comment; +1 GST-1623 refresh_barrier_later_write_gst1623 row (#8765; rows are data and cannot move); +5 #8766 GST-1623 items 4/6-9 and #8755: the wave comment and four rows (doctor_foreign_writers_partial_gst1623, commit_push_enclosing_repo_gst1623, owner_guard_fail_closed_gst1623, adopt_local_edits_hardening_8755) and +1 managed_sync_kind_reserved_8765 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the gate-ahead on master v0.60.608.0 plus #8798: 1674 + 6; +1 GST-1853 refresh_barrier_aborted_refresh_sync_gst1853 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.613.0 merge: 1680 + 1; +1 GST-1674 refresh_refused_merge_recovery_gst1674 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.614.0 merge: 1681 + 1; +1 #8824/#8826/#8767: adopt_local_edits_replay_markers_8824 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the gate-ahead on #8837: 1682 + 1; +1 url_source_origin row (since TBD until the merge slot; rows are data and cannot move), re-summed at the gate-ahead on #8834: 1683 + 1; +1 #8828: the refresh_replan_own_commits_8828 row (1684 + 1 at the 0.60.618.0 slot); +1 the managed commit-push unpublished-count row; +1 the refresh publish-diverged default row
+src/core/behavior-change-notice.ts 1688 ratchet +4 train R: #7491/#7492 keyword_identifier_probe and keyword_slug_handles rows and their comment, #7175 keyword phrase row; the BEHAVIOR_CHANGES table grows by one row per disclosed change: +4 the #7891 provenance-drift and #7917/#7918 maintenance-lowering rows and their comments (re-summed at the 0.60.495.0 merge: 1547 + 4); +1 GBRA-156 #7593: private_pages_granted_sources row (re-summed at the 0.60.527.0 merge: 1574 + 1); +3 GBRA-200 comment, write-grant refusal and degraded-stamp rows (re-summed at the 0.60.562.0 merge: 1615 + 3); +2 GBRA-280 get_page selector-precedence row and comment (re-summed at the 0.60.569.0 merge: 1619 + 2); the BEHAVIOR_CHANGES table grows by one row per disclosed change: +4 the #7891 provenance-drift and #7917/#7918 maintenance-lowering rows and their comments (re-summed at the 0.60.495.0 merge: 1547 + 4); +2 GBRA-205 saved_facts_stems row and its comment (re-summed at the #7901 0.60.492.0 merge: 1541 + 2); +2 GBRA-205 search.query_facts_block default-on row and its approval comment (re-summed at the #7610 0.60.490.0 merge: 1539 + 2); +2 the #7900 content checkpoint host-move row (since TBD until the merge slot), +2 the #7897 private-hold sweep row (since TBD until the merge slot), +2 the #7880 ingest_capture and company-brain private-hold row (since TBD until the merge slot), +5 the frozen-source wave comment and four rows (#7868, #7850, #7869/#7870, #7871), +2 the #7848 visibility_noncanonical hold row (since TBD until the merge slot), +2 the #7846 extract_atoms session-source row (re-summed at the 0.60.481.0 merge: master 1524 + 2), +2 the #7805 synthesize session-source and #7841 visibility_not_applied rows (re-summed at the 0.60.480.0 merge: master 1522 + 2), +2 strict door planned-state row (#7705, re-summed at the 0.60.470.0 merge: master 1514 + 2), +2 Bun floor 1.4.4 row (#7644), the GBRA-95 RLS backfill row (+2), +3 rows for #7596 pass_interrupted, #7599 read-only serve and the --access=read-only ceiling, +1 G5 lane C trust_release row, +1 #7619 cli_flag_equals, +3 GBRA-207 #7630 relative-anchor and stalled-write rows, +2 the #7632 function search_path disclosure row and +2 the #7679 orphaned worktree refresh row (re-summed at the 0.60.471.0 merge: master 1516 + 2), +2 the #7814 retired v0.13.1 grandfather row, +2 the #7618 conversion withhold/progress/push row (master 1520 + 2); the behavior-change table split (#7607) retires this row; +4 GBRA-188 #7489: the wave comment and three rows (brain-first instructions, starter surface default, per-turn rule); +1 GBRA-188 plugin_turn_hook_gbra188 row; +1 GBRA-242 provider_key_rules_7959 row (#7959), +2 the GBRA-199 registration_lists_verbs row (since TBD until the merge slot); +2 GBRA-133 #7652: the #7611 pass_abandoned reader row and the lean read-only serve socket row (re-summed at the 0.60.503.0 merge: master 1555 + 2); +1 GBRA-243: the per-turn hook disclosure row (rows are data and cannot move); +4 GBRA-156 #7598 harness wave comment and rows (remote page cap, sources_not_readable refusal, sources add next step); +4 GBRA-156 #7601 search_quotes_transcript_rows comment and row; +1 GBRA-175 #7475 autopilot_restarts_serve_7475 row (re-summed at the #8012 merge: 1566 + 1); +3 #7997/#8014/#8015 rows (redaction markers, company db_only keep, ignored supabase_only scope); +2 #7199 (re-port of #7228) classic_drift_rescreen_7199 comment and row; +2 #7931 file_drift_agrees_7931 comment and row; +1 #7950 file_drift_slug_release_7950 row; +1 #7974 file_drift_followups_7974 row; +1 #8059 quoted_fence_marker_8059 row; +2 GBRA-247 #8009 provenance_repair_held_8009 and #7982 pass_transient_streak_7982 rows; +4 GBRA-247 #7973 plain_directory_sync_7973, #7988 managed_marker_own_directory_7988, #7985 former_binding_parked_group_7985 and settle_effects_retire_7985 rows Train S merge: 1570 base + 5 (master since the #8077 base) + 13 (#8077) = 1588.; +2 GST-687 remote_quotes_unverified_text_gst687 row and its comment (re-summed at the gate-ahead on train S 0.60.534.0: 1588 + 2); +2 #8377: the quote fence follow-ups row and its comment; +2 #8384: the quote fence follow-ups 2 row and its comment; +2 #8384 wave 3: the quote fence follow-ups 3 row and its comment; +5 GBRA-218 train M rows (A1 member_read_access_gbra218 and member_access_hatch_scope_gbra218, B shared_agent_audience_gbra231, A2 folder_access_rules_gbra218, folder_access_scoped_role_gbra218), re-summed at the train M merge of master v0.60.541.0: 1596 + 5 = 1601 measured; +3 GST-359 train C rows (C1 qm_attested_actor_gst359, C2 member_facts_gst359, D qm_memory_provider_gst359), re-summed at the train C merge of master v0.60.543.0: 1601 + 3 = 1604 measured; +2 #8424: hook_launcher_8424 row and its comment (rows are data and cannot move), re-summed at the #8418 v0.60.546.0 merge: 1604 + 2 = 1606 measured; +2 #8426: mcp_lane_launcher_8426 row and its comment (rows are data and cannot move); +2 GST-927: empty_nonstring_args_gst927 row and its comment, re-summed at the gate-ahead on master v0.60.550.0 plus #8420: 1610 measured; +2 GBRA-283 Wave A (#8460): engine_keyed_caches_gbra283 row and its comment (rows are data and cannot move); +2 GBRA-287: segmented_freeze_hold_gbra287 and segmented_reexport_gbra287 rows (rows are data and cannot move); +1 GST-1209: segmented_tiling_gst1209 row (rows are data and cannot move); +1 GST-1251: skillopt_loop_deprecated_gst1251 row (rows are data and cannot move); +1 GST-1209 follow-up: untiled_hold_repair_gst1209 row (rows are data and cannot move); +1 GBRA-283 B3a: embedded_scope_required_gbra283 row (rows are data and cannot move); re-summed at the train R merge with v0.60.574.0: 1623 + 4; +2 GST-1387: refresh_fence_refusal_gst1387 row and its comment (rows are data and cannot move); re-summed at the memory train #8481 merge with v0.60.578.0 (1643 measured); +3 GBRA-253 #8109 rows (frontmatter_drift_write_8109, contacts_activity_advance_8109, contact_rows_dedupe_8109; rows are data and cannot move), re-summed at the master v0.60.581.0 merge: 1643 + 3 = 1646 measured; +3 #8123 part C rows: sync_write_through_off_writeback_7084, managed_sync_dry_run_counts_7087, frontmatter_missing_source_dir_7889 (since TBD until the merge slot; re-summed at the 0.60.583.0 merge: 1646 + 3); +4 PR B commit_ledger_prb, doctor_foreign_writers_prb and sources_guard_prb rows and their comment (rows are data and cannot move; since TBD until the merge slot); +1 PR B #8615: file_drift_held_needs_prefer_8615 row; +1 PR B #8617: refresh_source_changed_retry_8617 row; +1 PR B #8662: commit_push_checkout_not_a_source_8662 row (since TBD until the merge slot; rows are data and cannot move); +2 PR B refresh_barrier_prb and commit_push_base_prb rows (re-summed: 1658 measured); +3 convergence PR A: the wave comment and two rows (conversion_content_evidence_pr_a, git_gap_live_pages_pr_a; since TBD until the merge slot; rows are data and cannot move); re-summed at the gate-ahead on master v0.60.592.0 plus #8711: 1658 + 3 = 1661 measured; +4 GST-1094/GST-900 rows (memory_recall scope-read, member-bound acting_user, recall max_chars, unknown_param _meta-only) and +1 qm_scope_writes_gst1113 and +1 recall_question_terms_gst1304 rows (rows are data and cannot move), re-summed at the 0.60.595.0 slot merge: 1661 + 6; +1 GST-1582 refresh_barrier_import_gst1582 row (since TBD until the merge slot; rows are data and cannot move); +2 GST-1601 source_changed_origin_gst1601 and adopt_local_edits_gst1601 rows (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.596.0 merge: 1668 + 2; +1 GST-1623 refresh_barrier_capacity_gst1623 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.599.0 merge: 1670 + 1; +2 GBRA-224 W1 release_channel_stable_default row and its comment; +1 GST-1623 refresh_barrier_later_write_gst1623 row (#8765; rows are data and cannot move); +5 #8766 GST-1623 items 4/6-9 and #8755: the wave comment and four rows (doctor_foreign_writers_partial_gst1623, commit_push_enclosing_repo_gst1623, owner_guard_fail_closed_gst1623, adopt_local_edits_hardening_8755) and +1 managed_sync_kind_reserved_8765 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the gate-ahead on master v0.60.608.0 plus #8798: 1674 + 6; +1 GST-1853 refresh_barrier_aborted_refresh_sync_gst1853 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.613.0 merge: 1680 + 1; +1 GST-1674 refresh_refused_merge_recovery_gst1674 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.614.0 merge: 1681 + 1; +1 #8824/#8826/#8767: adopt_local_edits_replay_markers_8824 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the gate-ahead on #8837: 1682 + 1; +1 url_source_origin row (since TBD until the merge slot; rows are data and cannot move), re-summed at the gate-ahead on #8834: 1683 + 1; +1 #8828: the refresh_replan_own_commits_8828 row (1684 + 1 at the 0.60.618.0 slot); +1 the managed commit-push unpublished-count row; +1 the refresh publish-diverged default row; +1 #8896: effect_git_secret_gate_gst1923 row (since TBD until the merge slot; rows are data and cannot move)
diff --git a/src/commands/persistence-admin.ts b/src/commands/persistence-admin.ts
index fe7af7f7d6..f8b0e67271 100644
--- a/src/commands/persistence-admin.ts
+++ b/src/commands/persistence-admin.ts
@@ -99,7 +99,7 @@ git-durability --pat-file retries every parked push of the worktree; requests re
on their own are listed in parked_pushes.refused, the result is status partial, and it exits 1.
retry-effects <source> --parked-pushes does the same without a credential change: one more
attempt per Git effect of the source's worktree parked on a push (git_push_unavailable,
-push_unconfirmed, integrate_conflict); a push the remote rejected because it moved publishes
+push_unconfirmed, integrate_conflict, publish_secret_found); a push the remote rejected because it moved publishes
over the remote without moving the checkout (gbrain sources refresh brings remote files in).
retry-effects <source> --parked-code <code> gives one more attempt to every Git effect of the
source's worktree with a target parked on that code; doctor parked_effects and writer status list
diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.ts
index 3b8a4ac17c..88bc4449ef 100644
--- a/src/core/behavior-change-notice.ts
+++ b/src/core/behavior-change-notice.ts
@@ -1489,6 +1489,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;
{ since: '0.60.618.0', id: 'refresh_replan_own_commits_8828', text: 'A `gbrain sources refresh` whose checkout HEAD moved while it waited for writes admitted before its fence no longer refuses `refresh_source_changed` when every commit since its start is one of gbrain\'s own (in the commit ledger) and the upstream branch holds them: it takes HEAD as its start and fast-forwards to the upstream. A HEAD move that includes a commit gbrain did not make, or gbrain\'s commits the upstream does not hold yet, still refuses as before.' },
{ since: '0.60.619.0', id: 'managed_commit_push_unpublished_gst1923', text: 'On a managed checkout, `gbrain git commit-push -m <msg> -- <paths>` now reports how many commits the upstream lacks as last fetched (`unpublished` in `--json`, `null` when there is no upstream) and says nothing was pushed, instead of answering `nothing to commit; <remote>/<branch> at -` and logging `[push] ok-already-on-remote` for a commit that already existed. It writes no push-log line on a managed checkout. It still never pushes there; `gbrain git commit-push --push-only --keep-checkout --path <checkout>` publishes.' },
{ since: '0.60.616.0', id: 'refresh_publish_diverged_default_gbra386', text: 'A diverged managed checkout now publishes its local commits on `gbrain sources refresh` by default when the worktree\'s Git durability is on: `sources.refresh_publish_diverged` unset now means on there (it used to mean off), merged with the upstream in memory, never rebased or forced. The refresh publish first scans what the local commits add (messages, added lines, merge resolutions) and refuses the new `publish_secret_found` naming the file, line and rule, never the value, when one looks like a secret; `gbrain git commit-push --push-only --scan-secrets` runs the same gate. Unset with durability not on still refuses, naming `gbrain sources writer git-durability <source> --enable`; `false` turns it off.' },
+ { since: '0.60.616.0', id: 'effect_git_secret_gate_gst1923', text: 'The Git effects of page writes on a managed worktree now scan the unpublished commits they push, as the refresh publish does: a value that looks like a secret (or text too large to scan, or a change to `.gbrain-scan-allow` or a `.gitattributes`) in a commit a script made with plain `git commit` holds the effects with `publish_secret_found` and nothing is pushed, where they used to push it with the next page write. The push now reads the remote branch tip and scans exactly what it adds, leased on that tip, so a remote rewound since the last fetch never gets a removed commit back; a remote without the branch refuses too. After the user removes the value or allowlists a false positive, `gbrain sources writer retry-effects <source> --parked-pushes` runs the effects that parked.' },
];
/** The newest disclosed change's release: the notice id moves only when a release adds rows. */
diff --git a/src/core/git/commit-push.ts b/src/core/git/commit-push.ts
index f93ee83f32..98861fac3b 100644
--- a/src/core/git/commit-push.ts
+++ b/src/core/git/commit-push.ts
@@ -27,7 +27,7 @@
*/
import { appendFileSync, existsSync, mkdtempSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
-import { findingsInLog, rangeScanArgs } from './range-secret-scan.ts';
+import { findingsInLog, rangeScanArgs, rangeSecretRefusal } from './range-secret-scan.ts';
import { isAbsolute, join, relative, resolve } from 'node:path';
import { execFileSync } from '../spawn.ts';
import { gitChildEnv, literalPathspecs } from '../git-env.ts';
@@ -931,8 +931,11 @@ export function readQuarantine(repo: string): QuarantineEntry[] {
* When the remote already holds the candidate, the published tip (which may be
* a merge built over it earlier) is returned so a lagging checkout catches up.
*/
-function publish(ctx: Ctx, start: string, resolutions: Map<string, Resolution> | undefined, expectRemote: string | undefined, cwd: string): Published {
+function publish(ctx: Ctx, start: string, resolutions: Map<string, Resolution> | undefined, expectRemote: string | undefined, cwd: string, scanSecrets = false): Published {
const bound = expectRemote && !resolutions?.size ? gitOk(ctx.root, ['rev-parse', '--verify', `${expectRemote}^{commit}`], 'rev-parse --expect-remote') : undefined;
+ // #8896: a scanned publish scans <base>..<candidate> before every push and leases the push on that base, so a remote that
+ // moved or was rewound since the tracking ref was fetched (a stale ref hides commits from the scan) is fetched and scanned again.
+ let scannedBase = scanSecrets ? git(ctx.root, ['rev-parse', '--verify', '--quiet', ctx.trackingRef]).stdout.trim() : '';
let candidate = start;
let integrated = 0;
let lastError = '';
@@ -948,12 +951,16 @@ function publish(ctx: Ctx, start: string, resolutions: Map<string, Resolution> |
if (attempt) Atomics.wait(sleeper, 0, 0, Math.min(2000, 50 * 2 ** attempt) + Math.floor(Math.random() * 100));
let remoteTip = bound && !isAncestor(ctx.root, bound, candidate) ? bound : null;
if (!remoteTip) {
- const push = remoteGit(ctx.root, 'push', [...(ctx.keepCheckout ? ['--no-verify'] : []), ...(bound ? [`--force-with-lease=${ctx.mergeRef}:${bound}`] : []), '--', ctx.remote, `${candidate}:${ctx.mergeRef}`]);
- if (push.code === 0) return { sha: candidate, integrated, confirmed: 'push', ...notes() };
- lastError = push.stderr.trim();
+ const lease = bound ?? (scanSecrets ? scannedBase : undefined);
+ if (scanSecrets) assertNoSecretsInRange({ ...ctx, trackingRef: lease || ctx.trackingRef }, candidate);
+ const push = lease && !isAncestor(ctx.root, lease, candidate) ? null
+ : remoteGit(ctx.root, 'push', [...(ctx.keepCheckout ? ['--no-verify'] : []), ...(lease ? [`--force-with-lease=${ctx.mergeRef}:${lease}`] : []), '--', ctx.remote, `${candidate}:${ctx.mergeRef}`]);
+ if (push?.code === 0) return { sha: candidate, integrated, confirmed: 'push', ...notes() };
+ if (push) lastError = push.stderr.trim();
if (remoteContains(ctx, candidate)) return onRemote();
remoteTip = fetchTracking(ctx);
if (!remoteTip) break;
+ scannedBase = remoteTip;
if (bound && remoteTip !== bound) {
throw opError('push_unconfirmed', `The remote moved to ${remoteTip.slice(0, 12)} after --expect-remote ${bound.slice(0, 12)} was checked, so nothing was pushed: publishing now could merge back commits a rewrite removed.`,
'Check the remote history first (gbrain sources refresh checks it for a force-push), then rerun.', { detail: candidate, retryable: true });
@@ -1029,23 +1036,11 @@ function assertLocalCommitsInsideRoots(ctx: Ctx, target: string, roots: string[]
docs: 'docs/guides/shared-checkout-git.md#source-roots' } });
}
-/** The automatic-publish secret gate: scan what the commits in trackingRef..target add (the exact range this publish pushes, under its lock). */
+/** The automatic-publish secret gate: scan what the commits in trackingRef..target add (publish passes the base it leases its push on, under its lock). */
function assertNoSecretsInRange(ctx: Ctx, target: string): void {
const log = git(ctx.root, rangeScanArgs(ctx.trackingRef, target), { timeoutMs: 300_000, maxBuffer: 1024 * 1024 * 1024 });
- const scan = log.code === 0 ? findingsInLog(ctx.root, log.stdout) : null;
- if (scan && !scan.findings.length && !scan.unscanned.length && !scan.gate_changes.length) return;
- const named = scan ? [...scan.findings.map(f => `${f.path}:${f.line} (${f.pattern}, ${f.commit.slice(0, 7)})`), ...scan.unscanned.map(u => `${u.path} (too large to scan, ${u.commit.slice(0, 7)})`),
- ...scan.gate_changes.map(g => `${g.path} (changes what the scan sees, ${g.commit.slice(0, 7)})`)] : [];
- throw opError('publish_secret_found', scan
- ? `${named.length} item(s) in the local commits ${ctx.trackingRef}..${target.slice(0, 12)} look like secrets or could not be scanned: ${named.slice(0, 10).join(', ')}${named.length > 10 ? ', ...' : ''}. Nothing was pushed.`
- : `git could not list the local commits ${ctx.trackingRef}..${target.slice(0, 12)} to scan them for secrets (${log.stderr.trim().slice(0, 200) || `exit ${log.code}`}). Nothing was pushed.`,
- 'Remove the value from those commits (rewriting unpushed local commits is the user\'s call), or add a false positive\'s fingerprint to .gbrain-scan-allow, then retry. Never publish them with a command that skips this scan.',
- { detail: JSON.stringify(scan ?? { error: 'unreadable' }),
- fix: { ask_user: true, consent: [], actor: 'user', requires_exclusive: false,
- argv: ['git', '-C', ctx.root, 'log', '--stat', `${ctx.trackingRef}..${target}`],
- why: 'Lists the unpublished commits the scan refused; read-only. A secret pushed to the remote stays in its history.',
- user_message: `Unpublished commits in ${ctx.root} hold ${named.length || 'some'} item(s) that look like secrets or could not be scanned (${named.slice(0, 3).join(', ')}). Nothing was pushed. Remove them from those commits, or confirm a false positive so it can be allowlisted by fingerprint?`,
- docs: 'docs/guides/shared-checkout-git.md#publish_secret_found' } });
+ const refusal = rangeSecretRefusal(ctx.root, ctx.trackingRef, target, log.code === 0 ? findingsInLog(ctx.root, log.stdout) : null, log.stderr.trim().slice(0, 200) || `exit ${log.code}`);
+ if (refusal) throw refusal;
}
/** Advance the shared checkout (caller holds the commit lock) with a real compare-and-swap: fast-forward only, hooks off, never autostash. */
@@ -1226,8 +1221,7 @@ export function commitAndPush(opts: CommitPushOptions): CommitPushResult {
const head = gitOk(root, ['rev-parse', 'HEAD'], 'rev-parse HEAD');
const target = start && !isAncestor(root, start, head) ? start : head;
if (!opts.allowOutsideSourceRoot) assertLocalCommitsInsideRoots(ctx, target, roots);
- if (opts.scanSecrets) assertNoSecretsInRange(ctx, target);
- const published = publish(ctx, target, resolutions, expectRemote, cwd);
+ const published = publish(ctx, target, resolutions, expectRemote, cwd, opts.scanSecrets);
if (!elsewhere) rmSync(absGitPath(root, CONFLICT_STATE_NAME), { force: true });
const moved = published.sha === head || elsewhere || opts.keepCheckout ? { checkout: 'unchanged' as const } : advanceWithLock(root, published.sha, head, onlyWhenClean, opts.lockWaitMs);
return { published, moved };
diff --git a/src/core/git/range-secret-scan.ts b/src/core/git/range-secret-scan.ts
index 220b22ab7a..03efbe68c2 100644
--- a/src/core/git/range-secret-scan.ts
+++ b/src/core/git/range-secret-scan.ts
@@ -10,6 +10,7 @@
* in the range that changes a file deciding what the scan sees (`.gbrain-scan-allow`, a `.gitattributes`) is reported
* too, so callers refuse rather than let the published commits widen their own gate.
*/
+import { opError, type OperationError } from '../ops/contract.ts';
import { loadWorkspaceAllowlist, pathAllowlisted, SCAN_ALLOW_FILENAME } from '../secret-scan-allowlist.ts';
import { scanText, SCAN_MAX_FILE_BYTES } from '../secret-scan.ts';
@@ -70,3 +71,24 @@ export function findingsInLog(root: string, log: string): RangeScan {
flush();
return scan;
}
+
+/**
+ * The automatic-publish refusal for the commits in `base..target` of `root`: null only when the scan read the range and
+ * found nothing; otherwise `publish_secret_found` naming each item (never its value), or, with no scan, that git could
+ * not list the range (`failure`: git's stderr or exit), so a range that cannot be read is never published unscanned.
+ */
+export function rangeSecretRefusal(root: string, base: string, target: string, scan: RangeScan | null, failure: string): OperationError | null {
+ if (scan && !scan.findings.length && !scan.unscanned.length && !scan.gate_changes.length) return null;
+ const named = scan ? [...scan.findings.map(f => `${f.path}:${f.line} (${f.pattern}, ${f.commit.slice(0, 7)})`), ...scan.unscanned.map(u => `${u.path} (too large to scan, ${u.commit.slice(0, 7)})`),
+ ...scan.gate_changes.map(g => `${g.path} (changes what the scan sees, ${g.commit.slice(0, 7)})`)] : [];
+ return opError('publish_secret_found', scan
+ ? `${named.length} item(s) in the local commits ${base}..${target.slice(0, 12)} look like secrets or could not be scanned: ${named.slice(0, 10).join(', ')}${named.length > 10 ? ', ...' : ''}. Nothing was pushed.`
+ : `git could not list the local commits ${base}..${target.slice(0, 12)} to scan them for secrets (${failure}). Nothing was pushed.`,
+ 'Remove the value from those commits (rewriting unpushed local commits is the user\'s call), or add a false positive\'s fingerprint to .gbrain-scan-allow, then retry. Never publish them with a command that skips this scan.',
+ { detail: JSON.stringify(scan ?? { error: 'unreadable' }),
+ fix: { ask_user: true, consent: [], actor: 'user', requires_exclusive: false,
+ argv: ['git', '-C', root, 'log', '--stat', `${base}..${target}`],
+ why: 'Lists the unpublished commits the scan refused; read-only. A secret pushed to the remote stays in its history.',
+ user_message: `Unpublished commits in ${root} hold ${named.length || 'some'} item(s) that look like secrets or could not be scanned (${named.slice(0, 3).join(', ')}). Nothing was pushed. Remove them from those commits, or confirm a false positive so it can be allowlisted by fingerprint?`,
+ docs: 'docs/guides/shared-checkout-git.md#publish_secret_found' } });
+}
diff --git a/src/core/persistence/effect-git.ts b/src/core/persistence/effect-git.ts
index 1d7fa8146d..f83ec43147 100644
--- a/src/core/persistence/effect-git.ts
+++ b/src/core/persistence/effect-git.ts
@@ -14,6 +14,7 @@ import type { NativeLockHandle } from './native-lock.ts';
import { proveIndexLockAbandoned, reclaimIndexLock, type IndexLockReclaim } from './index-lock-reclaim.ts';
import { recordCommitAsync, recordIntentAsync } from '../git/commit-ledger.ts';
import { supersededBy } from './import-deferral.ts';
+import { findingsInLog, rangeScanArgs, rangeSecretRefusal } from '../git/range-secret-scan.ts';
/** An index lock younger than this is contention; an older one is reported as stale. */
const INDEX_LOCK_GRACE_MS = 10 * 60 * 1000;
@@ -403,6 +404,8 @@ export async function gitRootAhead(root: string, signal?: AbortSignal): Promise<
/** Git's refusal of a push because the remote branch moved (LC_ALL=C keeps it untranslated). */
export const NON_FAST_FORWARD = /\[rejected\][^\n]*\((?:non-fast-forward|fetch first)\)/;
+/** Git's refusal of a leased push because the remote branch moved after its tip was read. */
+const STALE_LEASE = /\[rejected\][^\n]*\(stale info\)/;
/**
* Push the current branch to its tracking remote. A plain push is tried first (idempotent, cannot import remote
@@ -411,6 +414,13 @@ export const NON_FAST_FORWARD = /\[rejected\][^\n]*\((?:non-fast-forward|fetch f
* without moving the checkout, so `gbrain sources refresh` stays the only importer of remote files. That publish
* runs synchronously; it starts only after the remote answered this push. Both sides changing one file holds the
* effect with `integrate_conflict` and the user's choice as its fix.
+ * #8896: a script's plain `git commit` in the checkout never passed the write path's scan, so both paths scan what
+ * they publish. The plain push reads the remote branch tip (`git ls-remote`, never a possibly stale tracking ref,
+ * which would hide a commit a rewound remote no longer has), scans exactly `<tip>..<HEAD sha>` and pushes that sha
+ * only as a fast-forward of the tip, leased on it; a tip that is not an ancestor, or a remote that moves before the
+ * push lands, goes to the shared publish, which fetches first and runs with `--scan-secrets`. A finding, an
+ * unscannable file, a commit changing what the scan sees, a range git cannot list or a remote with no such branch
+ * holds the effect with `publish_secret_found`.
*/
export async function pushGitRoot(root: string, signal?: AbortSignal): Promise<{ push: 'committed'; integrated?: number } | { push: 'skipped'; reason: 'no_tracking_remote' }> {
return withSession(root, signal, undefined, false, async session => {
@@ -419,16 +429,35 @@ export async function pushGitRoot(root: string, signal?: AbortSignal): Promise<{
const remote = await git(session, ['config', '--get', `branch.${branch.stdout.trim()}.remote`]);
const merge = await git(session, ['config', '--get', `branch.${branch.stdout.trim()}.merge`]);
if (remote.code !== 0 || merge.code !== 0 || !remote.stdout.trim() || remote.stdout.trim() === '.') return { push: 'skipped', reason: 'no_tracking_remote' } as const;
- const push = await git(session, ['push', '--', remote.stdout.trim(), `HEAD:${merge.stdout.trim()}`]);
- if (push.code === 0) return { push: 'committed' } as const;
- if (!NON_FAST_FORWARD.test(push.stderr)) throw opError('git_push_unavailable', 'The canonical commit is durable locally; its push will retry.',
+ const head = await git(session, ['rev-parse', '--verify', 'HEAD']);
+ if (head.code !== 0) throw gitFailure('Cannot read the canonical checkout\'s HEAD.', 'git rev-parse HEAD failed, so nothing was scanned or pushed.');
+ const sha = head.stdout.trim(), short = merge.stdout.trim().replace(/^refs\/heads\//, ''), ref = `refs/heads/${short}`;
+ const unavailable = () => opError('git_push_unavailable', 'The canonical commit is durable locally; its push will retry.',
`git push to ${remote.stdout.trim()} failed (network, credentials or a remote that refused it). Nothing is lost locally and the worker pushes again on a later pass; gbrain never pulls or rebases the checkout. If it keeps failing, check the remote and its credentials with git push on the brain host.`,
{ fix: effectStatusFix });
+ const listed = await git(session, ['ls-remote', '--', remote.stdout.trim(), ref]);
+ if (listed.code !== 0) throw unavailable();
+ const tip = listed.stdout.split('\n').map(line => line.split('\t')).find(([, name]) => name === ref)?.[0] ?? '';
+ if (!tip) throw heldSecret(root, rangeSecretRefusal(root, `refs/remotes/${remote.stdout.trim()}/${short}`, sha, null, `${remote.stdout.trim()} has no branch ${short} to compare against`)!);
+ if ((await git(session, ['merge-base', '--is-ancestor', tip, sha])).code === 0) {
+ const scan = await execFileBounded('git', gitArgs(session, rangeScanArgs(tip, sha)),
+ { ...gitOptions(session), timeout: SECRET_SCAN_TIMEOUT_MS, maxBuffer: 1024 * 1024 * 1024, env: gitChildEnv(sessionEnv(session)) });
+ signal?.throwIfAborted();
+ const refusal = rangeSecretRefusal(root, tip, sha, scan.error ? null : findingsInLog(root, scan.stdout),
+ scan.stderr.trim().slice(0, 200) || `exit ${String(scan.error?.code ?? scan.error?.signal ?? 'unknown')}`);
+ if (refusal) throw heldSecret(root, refusal);
+ const push = await git(session, ['push', `--force-with-lease=${ref}:${tip}`, '--', remote.stdout.trim(), `${sha}:${ref}`]);
+ if (push.code === 0) return { push: 'committed' } as const;
+ if (!NON_FAST_FORWARD.test(push.stderr) && !STALE_LEASE.test(push.stderr)) throw unavailable();
+ }
signal?.throwIfAborted();
return publishKeepingCheckout(root, signal);
});
}
+/** #8896: the bound on the secret scan of the commits a plain push publishes (the shared publish allows the same). */
+const SECRET_SCAN_TIMEOUT_MS = 300_000;
+
/** #7010: the bound on one keep-checkout publish (a fetch, an in-memory merge and a push, repeated while the remote keeps moving). */
const KEEP_CHECKOUT_PUBLISH_TIMEOUT_MS = 600_000;
@@ -444,7 +473,7 @@ async function publishKeepingCheckout(root: string, signal?: AbortSignal): Promi
if (!cli) throw opError('git_push_unavailable', 'The canonical commit is durable locally; its push will retry.',
`The remote branch moved, and publishing over it runs gbrain git commit-push --push-only --keep-checkout, but this process could not locate its own gbrain executable (set ${CHILD_ENV.childCliOverride} to it). Nothing is lost locally.`,
{ fix: effectStatusFix });
- const child = await execFileBounded(cli.cmd, [...cli.argsPrefix, 'git', 'commit-push', '--push-only', '--keep-checkout', '--path', root, '--json'], {
+ const child = await execFileBounded(cli.cmd, [...cli.argsPrefix, 'git', 'commit-push', '--push-only', '--keep-checkout', '--scan-secrets', '--path', root, '--json'], {
timeout: KEEP_CHECKOUT_PUBLISH_TIMEOUT_MS, termGraceMs: GIT_TERM_GRACE_MS, maxBuffer: 1024 * 1024, signal,
env: { ...process.env, GBRAIN_PUBLISH_LOCK_WAIT_SECONDS: '0', GBRAIN_PUSH_LOCK_WAIT_SECONDS: '0' },
});
@@ -455,7 +484,7 @@ async function publishKeepingCheckout(root: string, signal?: AbortSignal): Promi
if (doc && typeof doc.code === 'string' && typeof doc.message === 'string') {
const error = opError(doc.code as Parameters<typeof opError>[0], doc.message, typeof doc.suggestion === 'string' ? doc.suggestion : '',
{ ...(typeof doc.detail === 'string' ? { detail: doc.detail } : {}), ...(doc.fix ? { fix: doc.fix as Action } : {}), retryable: doc.retryable === true });
- throw error.code === 'integrate_conflict' ? heldConflict(root, error) : error;
+ throw error.code === 'integrate_conflict' ? heldConflict(root, error) : error.code === 'publish_secret_found' ? heldSecret(root, error) : error;
}
throw opError('push_unconfirmed', 'The canonical commit is durable locally; its push will retry.',
`The remote branch moved and the keep-checkout publish did not report a push (${child.error ? `exit ${String(child.error.code ?? child.error.signal ?? 'unknown')}` : `outcome ${String(doc?.outcome ?? 'unreadable')}`}: ${child.stderr.trim().slice(0, 300) || 'no detail'}). Nothing is lost locally; the worker pushes again on a later pass.`,
@@ -478,6 +507,20 @@ function heldConflict(root: string, error: OperationError): OperationError {
return held;
}
+/**
+ * #8896: values that look like secrets in the unpublished commits hold the checkout's Git effects (they retry, then
+ * park): no retry can succeed until the user removes them from those commits or allowlists a false positive.
+ */
+function heldSecret(root: string, error: OperationError): OperationError {
+ const fix = error.fix as Action | undefined;
+ return opError('publish_secret_found', `Git backups of canonical page writes are held: ${error.message}`,
+ `${error.suggestion ?? ''} The page writes themselves are committed in the database and in local commits; nothing is lost, and nothing is pushed from ${root} while those commits hold the values. Afterwards, gbrain sources writer retry-effects with --parked-pushes for the source this checkout backs (gbrain sources writer status names it) retries the Git effects that parked meanwhile.`,
+ { ...(error.detail ? { detail: error.detail } : {}), fix: { ...(fix ?? { ask_user: true, consent: [], actor: 'user', requires_exclusive: false,
+ why: 'Rewriting unpublished commits or allowlisting a value is the user\'s call.' }),
+ user_message: `${fix?.user_message ?? `Unpublished commits in ${root} hold values that look like secrets.`} Until they are removed or allowlisted, Git backups of new page writes from ${root} are held (nothing is lost; the database has every write).`,
+ verify: { argv: ['gbrain', 'sources', 'writer', 'status', '--json'] } } });
+}
+
/** The outcome a Git effect records when its root has no durability hook: no git command ran. */
export const DURABILITY_NOT_ENABLED = { git: 'skipped', reason: 'durability_not_enabled', push: 'skipped' } as const;
diff --git a/src/core/persistence/git-push-holds.ts b/src/core/persistence/git-push-holds.ts
index b93b21c01a..afbf769531 100644
--- a/src/core/persistence/git-push-holds.ts
+++ b/src/core/persistence/git-push-holds.ts
@@ -13,7 +13,7 @@ import { readFix } from '../ops/op-fix.ts';
import { readIntegrateConflict, type IntegrateConflictState } from '../git/commit-push.ts';
/** The error codes of a Git effect whose commit is local but whose push did not land. */
-export const GIT_PUSH_CODES = ['git_push_unavailable', 'push_unconfirmed', 'integrate_conflict'] as const;
+export const GIT_PUSH_CODES = ['git_push_unavailable', 'push_unconfirmed', 'integrate_conflict', 'publish_secret_found'] as const;
export interface GitPushHold {
source_id: string;
@@ -68,6 +68,13 @@ function gitPushFix(hold: Omit<GitPushHold, 'fix'>): Action {
user_message: `This machine and the remote both changed ${hold.conflict.paths.join(', ')} in ${hold.root}, so ${held} Git backup(s) of page writes in source ${hold.source_id} are held (nothing is lost; the database has every write). Which version should win: this machine's (ours) or the remote's (theirs)? Afterwards run gbrain sources writer retry-effects ${hold.source_id} --parked-pushes, then gbrain sources refresh ${hold.source_id}.`,
verify: statusVerify(hold.source_id), docs: 'docs/guides/shared-checkout-git.md#conflicts',
};
+ if (hold.codes.includes('publish_secret_found') && hold.root) return {
+ ask_user: true, consent: [], actor: 'user', requires_exclusive: false,
+ argv: ['git', '-C', hold.root, 'log', '--stat', '@{upstream}..HEAD'],
+ why: 'Lists the unpublished commits the secret scan refused; read-only. A secret pushed to the remote stays in its history.',
+ user_message: `Unpublished commits in ${hold.root} hold values that look like secrets (or text too large to scan), so ${held} Git backup(s) of page writes in source ${hold.source_id} are held and nothing was pushed (nothing is lost; the database has every write). Remove the values from those commits, or confirm a false positive so its fingerprint can go in .gbrain-scan-allow? Afterwards run gbrain sources writer retry-effects ${hold.source_id} --parked-pushes.`,
+ verify: statusVerify(hold.source_id), docs: 'docs/guides/shared-checkout-git.md#publish_secret_found',
+ };
if (hold.parked && hold.former_worktree) return {
argv: ['gbrain', 'sources', 'writer', 'settle-effects', hold.source_id, '--parked-code', hold.codes[0]!, '--dry-run'], consent: [], actor: 'agent', requires_exclusive: false,
why: `${hold.parked} Git effect(s) of source ${hold.source_id} failed on a push (${hold.codes.join(', ')}) in a worktree the source is no longer bound to, so no retry reaches them. This previews settling each one whose current bytes the fetched remote already holds; it changes nothing.`,
diff --git a/test/cli-flag-equals.test.ts b/test/cli-flag-equals.test.ts
index a6627b6bd5..9b7939baf0 100644
--- a/test/cli-flag-equals.test.ts
+++ b/test/cli-flag-equals.test.ts
@@ -434,6 +434,7 @@ describe('#7619 split rules', () => {
'src/core/git/commit-guard.ts': 'git child argv',
'src/commands/doctor/checks/foreign-writers.ts': 'git child argv',
'src/core/persistence/pending-import.ts': 'git child argv',
+ 'src/core/git/range-secret-scan.ts': 'git child argv',
};
const READER = [/['"`]--[a-z0-9-]+=/, /(?:startsWith|indexOf|===)\(?\s*`\$\{\w+\}=`/, /startsWith\(\w+ \+ '='\)/];
const found = [...new Glob('src/**/*.ts').scanSync('.')].filter(p => !p.endsWith('.generated.ts') && READER.some(r => r.test(readFileSync(p, 'utf8'))));
diff --git a/test/effect-git-secret-gate.test.ts b/test/effect-git-secret-gate.test.ts
new file mode 100644
index 0000000000..cb0834683f
--- /dev/null
+++ b/test/effect-git-secret-gate.test.ts
@@ -0,0 +1,198 @@
+/**
+ * #8896: the managed writer's Git effects scan what they publish. A script's plain `git commit` in a managed checkout
+ * never passed the write path's scan; the Git effect's push used to publish it with the next page write, even after
+ * `gbrain sources refresh` refused it with `publish_secret_found`.
+ * Protects: a checkout only ahead of its upstream whose unpublished commits add a value that looks like a secret is
+ * refused `publish_secret_found` by `pushGitRoot` and nothing is pushed; a diverged checkout (the remote moved) is
+ * refused by the keep-checkout publish its child runs, and nothing is pushed; a remote rewound past a commit holding
+ * one (the tracking ref still names it) is not re-published; a remote without the branch refuses
+ * instead of scanning nothing; a clean ahead checkout still pushes. Through the effect worker, the page write's Git
+ * effect holds on `publish_secret_found` (the remote keeps its tip), `gbrain sync status` names the user's fix, and an
+ * allowlisted false positive releases it.
+ * Seams: real repositories and a bare remote; the keep-checkout publish runs this checkout's own CLI
+ * (GBRAIN_JOB_CHILD_CLI points at src/cli.ts); PGLite for the effect worker.
+ */
+import { afterEach, describe, expect, test } from 'bun:test';
+import { randomUUID } from 'node:crypto';
+import { chmodSync, mkdirSync, mkdtempSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { dirname, join, resolve } from 'node:path';
+import type { OperationContext } from '../src/core/ops/contract.ts';
+import { serializePageToMarkdown } from '../src/core/markdown.ts';
+import { pushGitRoot } from '../src/core/persistence/effect-git.ts';
+import { submissionAuthority } from '../src/core/persistence/authority.ts';
+import { localHostId, registerLocalWriter } from '../src/core/persistence/identity.ts';
+import { admitWrite, claimNextWrite } from '../src/core/persistence/journal.ts';
+import { publishMutation } from '../src/core/persistence/coordinator.ts';
+import { claimWorktree, getWorktreeBinding } from '../src/core/persistence/ownership.ts';
+import { runPersistenceEffects } from '../src/core/persistence/effects.ts';
+import { disposePersistenceConsumer } from '../src/core/persistence/service.ts';
+import { readSyncStatus } from '../src/core/persistence/sync-status.ts';
+import { scanText } from '../src/core/secret-scan.ts';
+import { isolatedSharedSkillsEngine } from './helpers/shared-skills-engine.ts';
+import { git } from './helpers/git-publication.ts';
+import { withEnv } from './helpers/with-env.ts';
+
+const token = 'ghp_' + 'Zt4q'.repeat(9);
+const config = { engine: 'pglite' as const, embedding_disabled: true };
+const dirs: string[] = [];
+afterEach(() => { for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true }); });
+
+interface Checkout { home: string; root: string; remote: string; other: string; cli: string }
+
+/** A checkout on main pushed to a bare remote, a second clone that can move the remote, and a child CLI wrapper. */
+function checkout(): Checkout {
+ const home = realpathSync(mkdtempSync(join(tmpdir(), 'gbrain-8896-'))); dirs.push(home);
+ const remote = join(home, 'remote.git'), root = join(home, 'brain'), other = join(home, 'other'), cli = join(home, 'gbrain-child');
+ writeFileSync(cli, `#!/bin/sh\nexec '${process.execPath}' '${resolve(import.meta.dir, '../src/cli.ts')}' "$@"\n`);
+ chmodSync(cli, 0o700);
+ git(home, 'init', '-q', '--bare', '-b', 'main', remote);
+ mkdirSync(join(root, 'notes'), { recursive: true });
+ git(root, 'init', '-q', '-b', 'main');
+ git(root, 'config', 'user.name', 'Example Writer'); git(root, 'config', 'user.email', '[email protected]');
+ writeFileSync(join(root, 'initial.md'), 'Initial\n');
+ git(root, 'add', 'initial.md'); git(root, 'commit', '-q', '-m', 'Initial');
+ git(root, 'remote', 'add', 'origin', remote); git(root, 'push', '-q', '-u', 'origin', 'main');
+ git(home, 'clone', '-q', remote, other);
+ git(other, 'config', 'user.name', 'Other Machine'); git(other, 'config', 'user.email', '[email protected]');
+ return { home, root, remote, other, cli };
+}
+
+/** A script's plain `git commit`: never through gbrain's write path, so never scanned there. */
+function scriptCommit(root: string, path: string, content: string): string {
+ mkdirSync(dirname(join(root, path)), { recursive: true });
+ writeFileSync(join(root, path), content);
+ git(root, 'add', path); git(root, 'commit', '-q', '-m', `script edits ${path}`);
+ return git(root, 'rev-parse', 'HEAD').trim();
+}
+/** Another machine pushes a commit to the shared branch. */
+function moveRemote(c: Checkout, path: string): string {
+ mkdirSync(dirname(join(c.other, path)), { recursive: true });
+ writeFileSync(join(c.other, path), 'From the other machine\n');
+ git(c.other, 'add', path); git(c.other, 'commit', '-q', '-m', `Other machine edits ${path}`); git(c.other, 'push', '-q');
+ return git(c.other, 'rev-parse', 'HEAD').trim();
+}
+const remoteTip = (c: Checkout) => git(c.remote, 'rev-parse', 'refs/heads/main').trim();
+const childEnv = (c: Checkout) => ({ GBRAIN_HOME: join(c.home, 'home'), GBRAIN_JOB_CHILD_CLI: c.cli, GBRAIN_GIT_ALLOW_FILE_TRANSPORT: '1',
+ DATABASE_URL: undefined, GBRAIN_DATABASE_URL: undefined });
+async function refusal(run: Promise<unknown>) {
+ try { await run; } catch (e) { return e as { code: string; message: string; suggestion?: string; detail?: string; fix?: { user_message?: string; ask_user?: boolean } }; }
+ throw new Error('expected publish_secret_found');
+}
+
+describe('#8896 pushGitRoot scans the commits it publishes', () => {
+ test('a checkout only ahead of its upstream with a script commit holding a token: refused, nothing pushed', async () => {
+ const c = checkout();
+ const before = remoteTip(c);
+ const added = scriptCommit(c.root, 'notes/deploy.md', `Deploy token ${token}\n`);
+ scriptCommit(c.root, 'notes/page.md', 'A clean page write on top\n');
+ const error = await withEnv(childEnv(c), () => refusal(pushGitRoot(c.root)));
+ expect(error.code).toBe('publish_secret_found');
+ expect(error.message).toContain('notes/deploy.md:1 (');
+ expect(error.message).toContain(added.slice(0, 7));
+ expect(error.message).toContain('Nothing was pushed');
+ expect(error.fix?.ask_user).toBe(true);
+ expect(error.fix?.user_message).toContain('held');
+ expect(JSON.stringify(error)).not.toContain(token);
+ expect(remoteTip(c)).toBe(before);
+ }, 60_000);
+
+ test('a diverged checkout (the remote moved): the keep-checkout publish refuses, nothing pushed', async () => {
+ const c = checkout();
+ scriptCommit(c.root, 'notes/deploy.md', `Deploy token ${token}\n`);
+ const theirs = moveRemote(c, 'notes/other-example.md');
+ const head = git(c.root, 'rev-parse', 'HEAD').trim();
+ const error = await withEnv(childEnv(c), () => refusal(pushGitRoot(c.root)));
+ expect(error.code).toBe('publish_secret_found');
+ expect(error.message).toContain('notes/deploy.md:1 (');
+ expect(error.fix?.user_message).toContain('held');
+ expect(JSON.stringify(error)).not.toContain(token);
+ expect(remoteTip(c)).toBe(theirs);
+ expect(git(c.root, 'rev-parse', 'HEAD').trim()).toBe(head);
+ }, 120_000);
+
+ test('a remote rewound past a published secret (the tracking ref is stale): it is not published again', async () => {
+ const c = checkout();
+ const base = remoteTip(c);
+ scriptCommit(c.root, 'notes/deploy.md', `Deploy token ${token}\n`);
+ git(c.root, 'push', '-q');
+ git(c.remote, 'update-ref', 'refs/heads/main', base);
+ scriptCommit(c.root, 'notes/page.md', 'A clean page write on top\n');
+ const error = await withEnv(childEnv(c), () => refusal(pushGitRoot(c.root)));
+ expect(error.code).toBe('publish_secret_found');
+ expect(error.message).toContain('notes/deploy.md:1 (');
+ expect(error.fix?.user_message).toContain('held');
+ expect(remoteTip(c)).toBe(base);
+ }, 120_000);
+
+ test('a remote without the branch refuses instead of scanning nothing', async () => {
+ const c = checkout();
+ scriptCommit(c.root, 'notes/page.md', 'A clean page\n');
+ git(c.remote, 'update-ref', '-d', 'refs/heads/main');
+ const error = await withEnv(childEnv(c), () => refusal(pushGitRoot(c.root)));
+ expect(error.code).toBe('publish_secret_found');
+ expect(error.message).toContain('origin has no branch main');
+ expect(() => git(c.remote, 'rev-parse', '--verify', 'refs/heads/main')).toThrow();
+ }, 60_000);
+
+ test('a clean ahead checkout still pushes', async () => {
+ const c = checkout();
+ scriptCommit(c.root, 'notes/page.md', 'A clean page\n');
+ expect(await withEnv(childEnv(c), () => pushGitRoot(c.root))).toEqual({ push: 'committed' });
+ expect(remoteTip(c)).toBe(git(c.root, 'rev-parse', 'HEAD').trim());
+ }, 60_000);
+});
+
+describe('#8896 through the effect worker', () => {
+ test('a page write\'s Git effect holds on publish_secret_found, sync status names the fix, and an allowlisted false positive releases it', async () => {
+ const c = checkout();
+ await withEnv({ ...childEnv(c), GBRAIN_AUDIT_DIR: join(c.home, 'audit'), GBRAIN_BRAIN_ID: 'host', GBRAIN_SOURCE: undefined }, async () => {
+ const { engine, close } = await isolatedSharedSkillsEngine(undefined);
+ try {
+ await registerLocalWriter(engine, 'cli');
+ const sourceId = `s8896-${randomUUID().slice(0, 8)}`;
+ await engine.executeRaw('INSERT INTO sources(id,name,local_path) VALUES($1,$1,$2)', [sourceId, c.root]);
+ const claimed = await claimWorktree(engine, sourceId, c.root, localHostId());
+ await engine.executeRaw("UPDATE persistence_host_bindings SET git_durability='enabled' WHERE worktree_id=$1::uuid", [claimed.worktree_id]);
+ const before = remoteTip(c);
+ scriptCommit(c.root, 'scripts-out/deploy.md', `Deploy token ${token}\n`);
+
+ const slug = 'notes/acme-example';
+ const page = (body: string) => ({ type: 'note', title: 'Acme example', compiled_truth: body, timeline: '', frontmatter: {} });
+ const bound = (await getWorktreeBinding(engine, sourceId, localHostId()))!;
+ await engine.putPage(slug, page('Before'), { sourceId });
+ const snapshot = (await engine.readPageSnapshot(slug, { sourceId }))!;
+ const file = join(c.root, `${slug}.md`);
+ writeFileSync(file, serializePageToMarkdown(snapshot.page, snapshot.tags));
+ const ctx: OperationContext = { engine, config, remote: false, dryRun: false, sourceId, logger: { info() {}, warn() {}, error() {} } };
+ const authority = await submissionAuthority(ctx, 'put_page', sourceId, bound.source_incarnation, slug);
+ await admitWrite(engine, { principal: authority.principal, authority, operation: 'put_page', sourceId,
+ sourceIncarnation: bound.source_incarnation, slug, pageId: snapshot.page.id, requestId: randomUUID(),
+ callerIntent: { content: 'After' }, intent: { content: 'After' }, worktreeId: bound.worktree_id, topologyGeneration: bound.topology_generation });
+ const row = (await claimNextWrite(engine, localHostId()))!;
+ const result = await publishMutation(engine, row, { observedRevision: snapshot.revision, file: { path: file, root: c.root, content: 'After' },
+ apply: async tx => { await tx.putPage(slug, page('After'), { sourceId }); return {}; } }, localHostId());
+ expect(result.state).toBe('committed');
+
+ const runEffects = async () => {
+ await engine.executeRaw("UPDATE persistence_effects SET next_attempt_at=now() WHERE kind='git'");
+ await runPersistenceEffects(engine, config, { hostId: localHostId(), limit: 10 });
+ };
+ const effect = async () => (await engine.executeRaw<{ state: string; error_code: string | null }>(
+ "SELECT state,error_code FROM persistence_effects WHERE request_id=$1::uuid AND kind='git'", [row.id]))[0]!;
+ await runEffects();
+ expect(await effect()).toMatchObject({ state: 'queued', error_code: 'publish_secret_found' });
+ expect(remoteTip(c)).toBe(before);
+ const hold = (await readSyncStatus(engine, sourceId)).git_push_holds[0]!;
+ expect(hold).toMatchObject({ retrying: 1, parked: 0, codes: ['publish_secret_found'] });
+ expect(hold.fix).toMatchObject({ ask_user: true, actor: 'user' });
+ expect(hold.fix.user_message).toContain('look like secrets');
+
+ writeFileSync(join(c.root, '.gbrain-scan-allow'), `${scanText(`Deploy token ${token}\n`)[0]!.fingerprint}\n`);
+ await runEffects();
+ expect(await effect()).toMatchObject({ state: 'committed', error_code: null });
+ expect(remoteTip(c)).toBe(git(c.root, 'rev-parse', 'HEAD').trim());
+ } finally { await disposePersistenceConsumer(engine); await close(); }
+ });
+ }, 180_000);
+});
diff --git a/test/git-literal-pathspec-hooks-7759.test.ts b/test/git-literal-pathspec-hooks-7759.test.ts
index 7cb464bb28..f6ba66fa04 100644
--- a/test/git-literal-pathspec-hooks-7759.test.ts
+++ b/test/git-literal-pathspec-hooks-7759.test.ts
@@ -158,6 +158,8 @@ git add -- ':(literal)tracked.txt' && echo "post-commit add ok" >> '${log}'
test('the Git effect and its push, also when gbrain\'s own environment sets it; the session runs no repository hook', async () => {
const { root, bare, hooks, log } = checkout({}, true);
doorProbes(root, hooks, log);
+ // #8896: the effect's push refuses an unpublished commit that changes a .gitattributes, so the probe's is published first.
+ git(root, 'push', '-q');
const receive = join(dirname(root), 'receive-probe');
script(receive, `${probe(log, 'receive-pack')}exec git-receive-pack "$@"\n`);
git(root, 'config', 'remote.origin.receivepack', receive);
diff --git a/test/guarded-publish.test.ts b/test/guarded-publish.test.ts
index bccc46a7dd..359d473db8 100644
--- a/test/guarded-publish.test.ts
+++ b/test/guarded-publish.test.ts
@@ -6,7 +6,8 @@
* value, and nothing is pushed; an added line whose text starts with `++` (printed `+++`, like a file header) is
* still scanned; added text over the scan cap, and a commit in the range that changes .gbrain-scan-allow or a
* .gitattributes, refuse; a fingerprint in the working tree's .gbrain-scan-allow and a binary file are skipped; a clean
- * range publishes; without scanSecrets nothing changes.
+ * range publishes; without scanSecrets nothing changes; a remote rewound past a pushed secret (the tracking ref still names
+ * it) is fetched and scanned again instead of fast-forwarded over (#8896).
* Seams: none; real repositories and a bare remote.
*/
import { afterAll, expect, test } from 'bun:test';
@@ -145,3 +146,14 @@ test('attributes outside the range and diff settings never hide a secret or a ga
expect(widened.message).toContain('.gbrain-scan-allow (changes what the scan sees, ');
expect(remoteTip(noprefix)).toBe(noprefix.base);
});
+
+test('a remote rewound past a pushed secret is not published again through a stale tracking ref', () => {
+ const r = repo('rewound');
+ commit(r.root, 'notes.md', `Deploy token ${token}\n`);
+ git(r.root, 'push', '-q');
+ git(r.remote, 'update-ref', 'refs/heads/main', r.base);
+ commit(r.root, 'page.md', 'a clean page\n');
+ const error = refused(() => publish(r.root));
+ expect(error.message).toContain('notes.md:1 (');
+ expect(remoteTip(r)).toBe(r.base);
+});