Skip to content

Conversation

@sjmiller609
Copy link
Collaborator

@sjmiller609 sjmiller609 commented Dec 10, 2025

Note

Introduce per-instance hypeman and VMM logs with API streaming (app/vmm/hypeman), resource-resolving middleware, and updated logging/ingress/network behaviors.

  • Logging & Paths:
    • Add per-instance operational log logs/hypeman.log and consolidate VMM output to logs/vmm.log; rename serial log to logs/app.log.
    • Implement InstanceLogHandler to auto-route logs with instance_id to hypeman.log; wire into global logger.
    • Rotate all three logs in RotateLogs.
  • API & Middleware:
    • Add ResolveResource middleware; handlers now consume resolved instance/volume/ingress/image from context and simplify error paths.
    • Update /instances/{id}/logs to support source query (app|vmm|hypeman) and return specific errors (tail missing, log not found).
    • WebSocket exec handler uses resolved instance and enriched logging.
  • Instances:
    • Stream logs by source; adjust create/start/stop/standby/restore/delete to use consistent instance_id logging and new log paths.
    • Expose ingress-compatible resolver and minor state/list/query logging tweaks.
  • Ingress:
    • Validate/resolve instances by name/ID; log ingress create/delete with ingress_id and target instance_id for per-instance audit logs.
  • Network:
    • Safer TAP cleanup: preserve devices for running/unknown instances; allow skipping on errors.
  • VMM:
    • Start process writes combined stdout+stderr to logs/vmm.log; tests updated accordingly.
  • OpenAPI/Client:
    • Extend spec and generated client with source param for log streaming and updated docs.
  • Server wiring & Tests:
    • Inject logger before access logging; enable resolver middleware for all routes; add context helpers in tests and refactor polling via managers.

Written by Cursor Bugbot for commit 228f6b1. This will update automatically on new commits. Configure here.

@github-actions
Copy link

github-actions bot commented Dec 10, 2025

✱ Stainless preview builds

This PR will update the hypeman SDKs with the following commit message.

feat: Operational logs over API: hypeman.log, vmm.log
hypeman-go studio · code

Your SDK built successfully.
generate ✅lint ✅test ✅

go get github.com/stainless-sdks/hypeman-go@ec614f5bdc0e110f31cec905d6deb7f1d460305b
hypeman-cli studio · conflict

There was a conflict between your custom code and your generated changes.
You don't need to resolve this conflict right now, but you will need to resolve it for your changes to be released to your users. Read more about why this happened here.


This comment is auto-generated by GitHub Actions and is automatically kept up to date as you push.
Last updated: 2025-12-11 03:02:40 UTC

1. Exec endpoint now has logger injection:

2. Simplified InstanceLogHandler - no more file caching:
- Removed `sharedState` struct with mutex and fileCache
- Each write now opens, writes, closes the file
- No cleanup methods needed = no leak possible
- Simpler code, no shared state complexity

The performance impact is negligible since instance operations (start, stop, standby, etc.) are infrequent. The tradeoff of slightly more I/O vs. guaranteed no leaks and simpler code is worth it.
Comment on lines 149 to 158
// Get instance IDs that might have a running VMM for TAP cleanup safety.
// Include Unknown state: we couldn't confirm their state, but they might still
// have a running VMM. Better to leave a stale TAP than crash a running VM.
allInstances, _ := app.InstanceManager.ListInstances(app.Ctx)
var preserveTAPs []string
for _, inst := range allInstances {
if inst.State == instances.StateRunning || inst.State == instances.StateUnknown {
preserveTAPs = append(preserveTAPs, inst.Id)
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is the fix for stopping a possibly running instance, the rest of the change is VMM and Hypeman logs feature, which was inspired by how this problem was debugged (find issue in CH logs)

@sjmiller609 sjmiller609 requested a review from rgarcia December 10, 2025 20:00
1. Fixed `ErrAmbiguousName` to return 409 Conflict (instead of 404)

Changed the HTTP status code from `http.StatusNotFound` to `http.StatusConflict` for ambiguous name errors, restoring the previous ingress behavior.

2. Added nil checks with 500 error responses for all `GetResolved*` calls

Added defensive nil checks to all 14 handlers that use the resolved resource from middleware. If the middleware didn't set the resource (which shouldn't happen in production but could in tests), the handler now returns a 500 error with `"resource not resolved"` message instead of panicking with a nil pointer dereference.
$ hypeman ingress create q  --hostname 'nginx-test' --port 80 --host-port 8081
Creating ingress nginx-test-wmbi...
e5hbxzwc6cq0tnjchw861exg

$ hypeman ingress list
ID            NAME             HOSTNAME    TARGET         TLS  CREATED
e5hbxzwc6cq0  nginx-test-wmbi  nginx-test  nginx-gi7w:80  no   4 seconds ago

Fix is shows "nginx-gi7w:80" instead of "g:80"
required: false
schema:
type: string
enum: [app, vmm, hypeman]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at first i thought maybe this endpoint should let you select more than one of these sources but i think for simplicity's sake it's fine to push this problem to clients to perform separate requests to get more than one source

logPath = m.paths.InstanceHypemanLog(id)
default:
// Default to app log for backwards compatibility
logPath = m.paths.InstanceAppLog(id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enjoy the freedom of not having to care about backwards compatability right now! :)

@sjmiller609 sjmiller609 merged commit a076e43 into main Dec 11, 2025
4 checks passed
@sjmiller609 sjmiller609 deleted the fix-stop-prematurely branch December 11, 2025 03:00
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.

3 participants