Skip to content

refactor: extract readOrLazyHealInboundSecret to dedup chat_files + registry - #2376

Merged
HongmingWang-Rabbit merged 1 commit into
stagingfrom
auto/lazy-heal-secret-helper
Apr 30, 2026
Merged

HongmingWang-Rabbit merged 1 commit into
stagingfrom
auto/lazy-heal-secret-helper

Conversation

@HongmingWang-Rabbit

Copy link
Copy Markdown
Contributor

Summary

The lazy-heal-on-miss pattern landed in two places this session: #2372 (chat_files `resolveWorkspaceForwardCreds`) and #2375 (registry `Register`). Both did the same core mechanic — `read → if ErrNoInboundSecret mint inline → return outcome` — wrapped in different response-shape handling.

Drift class: future heal-time conditions (audit log, alert, secret rotation, observability) had to be applied to each site, with partial application silently re-opening the gap.

Changes

Extract `readOrLazyHealInboundSecret` in `workspace_provision_shared.go` returning `(secret, healed, err)`. Each caller maps the outcome to its response shape:

Behavior preservation

  • `TestRegister_NoInboundSecret_LazyHeals` ✅
  • `TestRegister_NoInboundSecret_LazyHealMintFailureOmitsField` ✅
  • `TestChatUpload_NoInboundSecret_LazyHeal` ✅
  • `TestChatUpload_NoInboundSecret_LazyHealFailure` ✅
  • `TestChatDownload_NoInboundSecret_LazyHeal` ✅
  • `TestChatDownload_NoInboundSecret_LazyHealFailure` ✅

Test plan

  • All 6 lazy-heal tests still pass unchanged
  • Full module green: `go test ./...`
  • `go vet` clean

Note on chat_files response shape

Pre-refactor chat_files distinguished:

Post-refactor both surface as 503 RFC-#2312. The caller response covers both "can't determine" and "can't mint" with the same operational hint (retry / reprovision). No tests assert the specific 500 path; this is a strict simplification.

🤖 Generated with Claude Code

…egistry

The lazy-heal-on-miss pattern landed in two places this session:
PR #2372 (chat_files.go::resolveWorkspaceForwardCreds — Upload + Download)
and PR #2375 (registry.go::Register). Both implementations did the same
thing:

  read → if ErrNoInboundSecret then mint inline → return outcome

Different response-shape requirements but the same core mechanic. Three
sites' worth of drift potential: any future heal-time condition we add
(audit log, alert, secret rotation, observability) had to be applied to
each site, with partial application silently re-opening the gap.

Fix: extract readOrLazyHealInboundSecret in workspace_provision_shared.go
returning (secret, healed, err). Each caller maps the outcome to its
response shape:

  - chat_files: healed=true → 503 with retry hint; err != nil → 503 with
    RFC-#2312 reprovision hint
  - registry:   healed=true|false + err==nil → include in response;
    err != nil → omit field (workspace can retry on next register)

Net effect:

  - Single source of truth for the read+heal mechanic
  - Response-shape decisions stay in callers (they DO differ per feature)
  - Future heal-time conditions go in one place
  - Behavior preserved: existing TestRegister_NoInboundSecret_LazyHeals,
    TestRegister_NoInboundSecret_LazyHealMintFailureOmitsField,
    TestChatUpload_NoInboundSecret_LazyHeal*,
    TestChatDownload_NoInboundSecret_LazyHeal* all pass unchanged

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@HongmingWang-Rabbit
HongmingWang-Rabbit added this pull request to the merge queue Apr 30, 2026
Merged via the queue into staging with commit 677b485 Apr 30, 2026
19 checks passed
@HongmingWang-Rabbit
HongmingWang-Rabbit deleted the auto/lazy-heal-secret-helper branch April 30, 2026 11:19
HongmingWang-Rabbit pushed a commit that referenced this pull request Jun 12, 2026
Serialized merge by gitea-merge-queue after current-main, genuine approvals, and required CI checks were green.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant