Skip to content

CHASM: improve support for implementing Terminate method#9351

Merged
yycptt merged 3 commits intotemporalio:mainfrom
yycptt:chasm-terminate
Feb 23, 2026
Merged

CHASM: improve support for implementing Terminate method#9351
yycptt merged 3 commits intotemporalio:mainfrom
yycptt:chasm-terminate

Conversation

@yycptt
Copy link
Copy Markdown
Member

@yycptt yycptt commented Feb 19, 2026

What changed?

  • Define TerminableComponent and RootComponent interface
  • Make metrics handler available through chasm context
  • Add support for passing key value pairs with chasm context similar to context.Context
  • Add support for specifying key values pairs that will always be available in the Context when a component is accessed.
  • Add requestID to TerminateComponentRequest

Why?

  • Improve support for library authors to implement the Terminate method.

How did you test it?

  • built
  • run locally and tested manually
  • covered by existing tests
  • added new unit test(s)
  • added new functional test(s)

registry *Registry,
) (bool, error) {
return validator.Validate(
augmentContextForComponent(ctx, component, registry),
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

we can do the same thing for registered tasks as well.

// This is useful for propagating values needed for those processing logic but are not avaiable via the
// component's struct definition, such as configurations.
func WithContextValue(
keyVals map[any]any,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

since the keyVals are the same across component instances, we don't really need to use context.Context.Value() to implement this which adds overhead. The chasmContext.Value() method can just check the registry for a key. The semantic will be different from context.Context though.

@yycptt yycptt requested a review from bergundy February 19, 2026 02:03
@yycptt yycptt requested a review from awln-temporal February 19, 2026 02:03
Copy link
Copy Markdown
Member

@bergundy bergundy left a comment

Choose a reason for hiding this comment

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

Had some small suggestions but otherwise LGTM.

// ContextWithValue returns a new Context with the given key-value pair added.
// Added key-value pairs will be accessible via the Value() method on the returned Context,
// and the behavior of the key-value pair is the same as context.Context.WithValue().
func ContextWithValue[C Context](c C, key any, value any) C {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You could consider structuring this as the Go stdlib does this: https://cs.opensource.google/go/go/+/refs/tags/go1.26.0:src/context/context.go;l=727.

You should be able to do this with type valueCtx[C Context] struct.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

hmm... I tried this before but embedding C directly into the valueCtx struct is not allowed.

type valueCtx[C Context] struct {
	C

	ctx context.Context
}

that won't compile..... so valueCtx still can't sometimes implement Context and sometimes implement MutableContext...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmmm you can wrap it with base C but that's not critical IMHO.

//
// This is useful for propagating values needed for those processing logic but are not avaiable via the
// component's struct definition, such as configurations.
func WithContextValue(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
func WithContextValue(
func WithContextValues(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

But I'm also wondering if we want a function that takes a context and returns a context here. What you have is fine for now though.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Renamed.

if we want a function that takes a context and returns a context here

Not sure I follow the use case here as this one is a registration option. Happy to add one when we have a need for it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah the idea is that you can inject a metrics handler that is bound to the current request's namespace instead of passing in bits to construct that handler for example:

metricsHandler := enrichMetricsHandler(
a,
event.MetricsHandlerBuilderParams.Handler,
event.MetricsHandlerBuilderParams.NamespaceName,
metrics.HistoryRespondActivityTaskCompletedScope,
event.MetricsHandlerBuilderParams.BreakdownMetricsByTaskQueue)

@yycptt yycptt marked this pull request as ready for review February 23, 2026 06:02
@yycptt yycptt requested review from a team as code owners February 23, 2026 06:02
@yycptt yycptt merged commit 6875191 into temporalio:main Feb 23, 2026
46 checks passed
@yycptt yycptt deleted the chasm-terminate branch February 23, 2026 07:30
02strich added a commit that referenced this pull request Feb 23, 2026
* origin/main:
  CHASM: improve support for implementing Terminate method (#9351)
  Add testhooks package documentation (#9373)
  Improve re-usability of ringpop membership & PerNamespaceWorker (#9321)
  Fairness counter: fix heap bug in map counter (#9370)
  Avoid finalGC when ack level is zero (#9371)
  Fairness counter: persist top K keys (#9188)
  Flake Fix: In Reactivation Cache tests, wait for appropriate delays when confirming expected drainage status (#9352)
  Include transient and speculative WFT events in GetWorkflowExecutionHistoryResponse (#9325)
  Fix flaky test TestTransitionDuringTransientTask (#9356)
  Add per-workflow scheduler for history task processing (#9141)
  Populate currentAttemptScheduledTime on PollActivityTaskQueueResponse for standalone activities (#9333)
  Standalone activity heartbeating bug fix (#9354)
  Revert "Last part of making Nexus work OOTB" (#9343)
  Convert flake report from Python to Go (#9334)
  Do not enforce payload limits for system nexus endpoint (#9344)
stephanos pushed a commit to stephanos/temporal that referenced this pull request Feb 23, 2026
…9351)

## What changed?
- Define TerminableComponent and RootComponent interface
- Make metrics handler available through chasm context
- Add support for passing key value pairs with chasm context similar to
context.Context
- Add support for specifying key values pairs that will always be
available in the Context when a component is accessed.
- Add requestID to TerminateComponentRequest

## Why?
- Improve support for library authors to implement the Terminate method.

## How did you test it?
- [ ] built
- [ ] run locally and tested manually
- [x] covered by existing tests
- [ ] added new unit test(s)
- [x] added new functional test(s)
govambam pushed a commit to code-review-studio/temporal that referenced this pull request Feb 27, 2026
…9351)

## What changed?
- Define TerminableComponent and RootComponent interface
- Make metrics handler available through chasm context
- Add support for passing key value pairs with chasm context similar to
context.Context
- Add support for specifying key values pairs that will always be
available in the Context when a component is accessed.
- Add requestID to TerminateComponentRequest

## Why?
- Improve support for library authors to implement the Terminate method.

## How did you test it?
- [ ] built
- [ ] run locally and tested manually
- [x] covered by existing tests
- [ ] added new unit test(s)
- [x] added new functional test(s)
birme pushed a commit to eyevinn-osaas/temporal that referenced this pull request Mar 23, 2026
…9351)

## What changed?
- Define TerminableComponent and RootComponent interface
- Make metrics handler available through chasm context
- Add support for passing key value pairs with chasm context similar to
context.Context
- Add support for specifying key values pairs that will always be
available in the Context when a component is accessed.
- Add requestID to TerminateComponentRequest

## Why?
- Improve support for library authors to implement the Terminate method.

## How did you test it?
- [ ] built
- [ ] run locally and tested manually
- [x] covered by existing tests
- [ ] added new unit test(s)
- [x] added new functional test(s)
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