Skip to content

[TASK] Refactor subagent approval sidecar I/O into scheddomain #1929

Closed

Description

Summary

The subagent approval sidecar (scheddomain.SubagentApprovalFile) is written and read by hand in two other packages, while the subagent result file right next to it has owned helpers (scheddomain.WriteSubagentResultFile / scheddomain.ReadSubagentResultFile in internal/scheduler/domain/subagent.go).

  • Writer: internal/presentation/tui/toolcoordinator/approval_sidecar.go writeSubagentApprovalSidecar copies the body of WriteSubagentResultFile (marshal, os.WriteFile(path+".tmp", data, 0o600), rename) but ends with _ = os.Rename(tmp, path). A failed rename is swallowed and leaves a stale <path>.tmp behind, so the parent never sees the pending approval and nobody is told why.
  • Reader: internal/tools/agent.go readSubagentApproval repeats os.ReadFile + json.Unmarshal into scheddomain.SubagentApprovalFile, the same shape as ReadSubagentResultFile.

Principles applied: clean-code (duplication - copy-pasted function body, and a swallowed error) and domain-driven-design (an invariant enforced by every caller instead of the type that owns it - the "temp file then rename so a polling parent never reads a half-written file" rule and the wire format belong to the scheduler domain that defines SubagentApprovalFile, exactly as they already do for SubagentResultFile).

The fix is local: one package gains two small functions that reuse the existing write path, and two call sites shrink to one line each.

Acceptance Criteria

  • internal/scheduler/domain/subagent.go gains WriteSubagentApprovalFile(path string, af SubagentApprovalFile) error and ReadSubagentApprovalFile(path string) (SubagentApprovalFile, bool) next to the result-file pair, and both writers share one private temp-file-and-rename JSON helper instead of two copies of it.
  • Before: writeSubagentApprovalSidecar marshals, writes path + ".tmp" and calls _ = os.Rename(tmp, path). After: it calls scheddomain.WriteSubagentApprovalFile(path, ...) and the returned error is no longer discarded (logged with logger.Warn, as coordinator.go in the same package reports its own failures).
  • Before: readSubagentApproval in internal/tools/agent.go does its own os.ReadFile + json.Unmarshal. After: it calls scheddomain.ReadSubagentApprovalFile(subagentApprovalFilePath(sessionID)) and keeps only the Awaiting check and summary trim.
  • internal/tools/approve_subagent_test.go writes its fixture sidecar through scheddomain.WriteSubagentApprovalFile instead of hand-marshalling SubagentApprovalFile.
  • Existing tests still pass.

Activity

  1. moved this from Todo to In progress in 2026on Nov 22, 2026
  2. moved this from In progress to QA in 2026on Nov 22, 2026
  3. moved this from QA to Done in 2026on Nov 22, 2026
  4. inference-gateway-releaser commented on Nov 22, 2026

    @inference-gateway-releaser
    Contributor

    🎉 This issue has been resolved in version 0.266.1 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactorreleased

    Type

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions