Skip to content

Document panic() contract for embed-guarded lazy-load panic sites - #54599

Merged
pelikhan merged 4 commits into
mainfrom
copilot/document-panic-contract
Aug 21, 2026
Merged

Document panic() contract for embed-guarded lazy-load panic sites#54599
pelikhan merged 4 commits into
mainfrom
copilot/document-panic-contract

Conversation

Copilot AI commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

8 panic() calls in pkg/workflow/pkg/actionpins fire only if lazily-loaded, go:embed-ed JSON data fails to (un)marshal — a condition that should be build-time-impossible. These relied only on the panic-in-library-code linter's incidental exemption (e.g. BUG: prefix, sync.Once) rather than an explicit documented contract, risking a future refactor accidentally routing dynamic input through one of these paths.

  • Added explicit invariant comments immediately above each panic site, stating why the condition is build-time-guarded and unreachable in practice:
    • pkg/workflow/model_aliases.go (2 sites): embedded model_aliases.json unmarshal
    • pkg/actionpins/data.go (3 sites): cache init, embedded action_pins.json unmarshal, empty-SHA validation
    • pkg/workflow/agentic_engine.go: built-in engine registration
    • pkg/workflow/permissions_toolset_data.go: embedded GitHub toolsets JSON unmarshal
    • pkg/workflow/pi_engine.go: internal payload marshal
    • pkg/workflow/mcp_setup_gateway.go: internal env var name list marshal
    • pkg/workflow/mcp_setup_safe_outputs.go: internal file render config marshal
  • Verified test coverage: each package already has tests exercising the embedded/generated data path (TestBuiltinModelAliases, actionpins internal tests, TestToolsetPermissionsLoadedFromJSON), so corrupted data fails go test rather than only surfacing as a runtime panic — no new tests needed.
  • No behavior change: panic logic and messages are untouched, only doc comments added.
if err != nil {
    // Build-time invariant: model_aliases.json is embedded at compile time and
    // validated by TestBuiltinModelAliases; a real unmarshal failure here can only
    // follow a corrupted release build, never dynamic user input.
    panic(err)
}

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 19.5 AIC · ⌖ 10.7 AIC · ⊞ 9.3K ·
Comment /souschef to run again

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Document panic() contract for embed-guarded lazy-load panic sites Document panic() contract for embed-guarded lazy-load panic sites Aug 21, 2026
Copilot AI requested a review from pelikhan August 21, 2026 19:29
@pelikhan
pelikhan marked this pull request as ready for review August 21, 2026 19:59
Copilot AI balanced review requested due to automatic review settings August 21, 2026 19:59
@github-actions

github-actions Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Ponytail Reviewer completed successfully!

Lean already. Ship. Diff is pure comment additions documenting existing panic invariants; no logic, abstractions, or dead code to cut.

Generated by Ponytail Reviewer for #54599

@github-actions

github-actions Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Design Decision Gate 🏗️ completed the design decision gate check.

No ADR enforcement needed: PR #54599 does not have the implementation label and has only 25 new lines of code in business logic directories (threshold: 100).

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Aug 21, 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

github-actions Bot commented Aug 21, 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 Aug 21, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

No test files were added or modified in this PR. Test Quality Sentinel skipped. PR #54599 adds documentation (panic contract comments) to 7 production Go files without any behavioral test changes.

🧪 Test quality analysis by Test Quality Sentinel

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

The added // Build-time invariant: comments clearly explain why each panic() is a programming-error guard rather than a user-facing failure path. The wording is consistent, accurate, and correctly distinguishes embedded-data corruption from dynamic user input. No actionable issues found.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 18.6 AIC · ⌖ 8.94 AIC · ⊞ 6.2K

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.

Pull request overview

Documents why internal panic paths are unreachable during normal operation without changing behavior.

Changes:

  • Adds invariant comments for embedded JSON/cache failures.
  • Documents type- and configuration-guarded marshal/registration failures.
Show a summary per file
File Description
pkg/actionpins/data.go Documents embedded pin and cache invariants.
pkg/workflow/agentic_engine.go Documents built-in registration panic.
pkg/workflow/mcp_setup_gateway.go Documents string-slice marshaling invariant.
pkg/workflow/mcp_setup_safe_outputs.go Documents fixed-config marshaling invariant.
pkg/workflow/model_aliases.go Documents embedded alias loading failures.
pkg/workflow/permissions_toolset_data.go Documents embedded toolset data failure.
pkg/workflow/pi_engine.go Documents model payload marshaling failure.

Review details

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 7/7 changed files
  • Comments generated: 2
  • Review effort level: Balanced

Comment thread pkg/workflow/pi_engine.go Outdated
Comment on lines +147 to +149
// Build-time invariant: payload above is built entirely from string/map
// literals, so Marshal cannot fail; json.Marshal only errors for
// non-serialisable types such as channels or functions.
Comment thread pkg/workflow/agentic_engine.go Outdated
Comment on lines +580 to +582
// Build-time invariant: the built-in engines list above has fixed, non-empty
// names, so registration can only fail if a future refactor introduces a
// duplicate or empty name — a programming error caught by CI, not user input.

@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 /grill-with-docs — one minor suggestion on comment self-containedness; otherwise LGTM.

📋 Key Themes & Highlights

Key Theme

  • Cross-reference comment (model_aliases.go:149): the public BuiltinModelAliases function's panic site uses see comment ... above rather than repeating the invariant inline. Public API sites are read in isolation; better to be self-contained.

Positive Highlights

  • ✅ Every panic site now carries a clear "build-time invariant" rationale
  • ✅ PR correctly distinguishes embed-guarded panics from dynamic-input panics
  • ✅ The pi_engine.go comment is a genuine improvement over the previous wording — it now names the non-serialisable types explicitly (channels, functions)
  • ✅ No behaviour change; the documentation is well-scoped and accurate

Skill selection used the fallback heuristic (documentation-only changed files → /grill-with-docs).

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 23.4 AIC · ⌖ 9.92 AIC · ⊞ 7.8K
Comment /matt to run again

@@ -145,6 +148,7 @@ func isBuiltinOnlyAliasMap(m map[string][]string) bool {
func BuiltinModelAliases() map[string][]string {
data, err := loadBuiltinModelAliases()

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.

[/grill-with-docs] The cross-reference // Build-time invariant: see comment in getBuiltinOnlyAliasMap above. leaves BuiltinModelAliases (a public function) dependent on navigating to another function to understand the invariant. Readers encountering this in search results or generated docs won't have that context.

💡 Suggested inline wording
// Build-time invariant: model_aliases.json is embedded at compile time and
// validated by TestBuiltinModelAliases; unmarshal can only fail for corrupted
// release data, never dynamic user input.
panic(err)

Mirrors the comment in getBuiltinOnlyAliasMap directly, making each site self-contained.

@copilot please address this.

@github-actions github-actions Bot mentioned this pull request Aug 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Comment Memory

reviewed_at: 2026-08-21T00:00:00Z
review_event: REQUEST_CHANGES
top_themes:
  - missing executable guardrails for documented panic invariants
  - comments rely on tests that were not added in this patch
files_reviewed:
  - pkg/actionpins/data.go
  - pkg/workflow/agentic_engine.go
  - pkg/workflow/mcp_setup_gateway.go
  - pkg/workflow/mcp_setup_safe_outputs.go
  - pkg/workflow/model_aliases.go
  - pkg/workflow/permissions_toolset_data.go
  - pkg/workflow/pi_engine.go
comment_count: 0

Note

This comment is managed by comment memory.

It stores persistent context for this thread in the code block at the top of this comment.
Edit only the text inside the backtick fences; workflow metadata and the footer are regenerated automatically.

Learn more about comment memory

🔎 Code quality review by PR Code Quality Reviewer · gpt54 · 3.76 AIC · ⌖ 8.78 AIC · ⊞ 4.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.

Verdict

REQUEST_CHANGES — I don't see a behavioral regression in the code paths themselves, but this change does not add any executable guardrail for the new "build-time invariant" contract it documents.

Blocking theme

The patch explicitly reframes several panics as release-time invariants enforced by tests, yet it adds zero coverage tying those comments to the actual failure modes. That leaves the contract easy to drift: a future refactor can route non-embedded input through one of these helpers, keep the reassuring comment, and still panic at runtime. For a documentation-only hardening change whose whole premise is "CI guarantees this is unreachable," at least one focused test/assertion per pattern should exist to prove the guarantee instead of relying on prose.

🔎 Code quality review by PR Code Quality Reviewer · gpt54 · 3.76 AIC · ⌖ 8.78 AIC · ⊞ 4.6K
Comment /review to run again

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot

Please address the visible failed check and then run the pr-finisher skill with a concise maintainer handoff for the current head.

Failed check from the compact queue:

There is also still a blocking review from github-actions requesting executable guardrails/tests for the documented panic invariants. Please either add the focused coverage or explain precisely how the current branch resolves that review concern, then summarize validations and any remaining human action.

Run: https://github.com/github/gh-aw/actions/runs/32525213052

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 19.5 AIC · ⌖ 10.7 AIC · ⊞ 9.3K ·
Comment /souschef to run again

…x error message lint

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

Copilot AI commented Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

@copilot

Please address the visible failed check and then run the pr-finisher skill with a concise maintainer handoff for the current head....

Addressed both items.

lint-go-custom failure — root cause was the errormessage linter, which now audits the whole of pkg/workflow/model_aliases.go because this PR touched it. The pre-existing message at model_aliases.go:57 used negative language ("failed to parse") without a constructive-guidance keyword. Reworded to: could not parse embedded model_aliases.json: %w (expected valid JSON matching the aliases schema; run 'make build' to rebuild with the latest data). Verified locally with the same linter set/changed-files flags used by the job — clean.

Blocking review (executable guardrails) — added pkg/workflow/panic_invariants_test.go with one focused test per documented panic site, each exercising the real code path preceding the panic:

  • TestEmbeddedModelAliasesAreLoadableloadBuiltinModelAliases / getBuiltinOnlyAliasMap / BuiltinModelAliases
  • TestEmbeddedToolsetPermissionsAreLoadablegetToolsetPermissionsMap
  • TestBuiltinEnginesRegisterWithoutError → re-registers every built-in engine, asserting the only failure mode Register actually has (negative dedicatedLLMGatewayPort)
  • TestBuildPiModelsJSONMarshalsRuntimeValuesbuildPiModelsJSON with runtime args, output parsed back as JSON
  • TestMCPGatewayCustomEnvNamesMarshalwriteMCPGatewayStepEnvWithCustomGatewayEnvNames emitting the marshaled env-name array
  • TestFileRenderConfigMarshals → the fileRenderConfig literal used by generateSafeOutputsSetup

pkg/actionpins already covers its embed path (TestGetCachedActionPins_InitializesCache, TestLoadActionPinsData_*), so no new tests there.

Also corrected two inaccurate invariant comments from the earlier Copilot review: pi_engine.go now documents the type invariant (payload mixes runtime args with literals) rather than claiming everything is literal, and agentic_engine.go now names the real Register failure mode (negative gateway port) instead of duplicate/empty names. BuiltinModelAliases' comment is now self-contained rather than cross-referencing.

Validations: make fmt; targeted go test ./pkg/workflow -run ... (all new + TestBuiltinModelAliases pass); make golint-custom with the job's linter flags on the changed files (clean); BASE_REF=origin/main make agent-report-progress — impacted unit tests pass. The full-package lint stage reports only pre-existing issues untouched by this PR (largefunc across many pkg/workflow files, copyloopvar in pkg/actionpins/actionpins_internal_test.go, and the model_aliases.go:96 shared-map warning).

Human action needed: agent pushes don't trigger CI, so lint-go-custom and the rest must be re-triggered by a maintainer (close/reopen, workflow_dispatch, or a push) to confirm green. The branch is also ~3 commits behind main; update if the repo requires up-to-date branches before merge.

Copilot AI requested a review from gh-aw-bot August 21, 2026 21:05
@pelikhan
pelikhan merged commit c3c0cf7 into main Aug 21, 2026
31 checks passed
@pelikhan
pelikhan deleted the copilot/document-panic-contract branch August 21, 2026 21:33
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.87.4

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.

[deep-report] Document panic() contract for 8 embed-guarded lazy-load panic sites in pkg/workflow/pkg/actionpins

4 participants